Skip to content

Commit

Permalink
Fix robotoff API call for countries (#1002)
Browse files Browse the repository at this point in the history
* ingredients fix

* use new robotoff sort option

* prettier

* updat countries

* fix lower case
  • Loading branch information
alexfauquette authored Jul 22, 2024
1 parent 0f953c5 commit 18483aa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
36 changes: 18 additions & 18 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# Add labels to any any pull request with changes to the specified paths
Github Actions:
- changed-files:
- any-glob-to-any-file: '.github/**/*'
- changed-files:
- any-glob-to-any-file: ".github/**/*"

Questions game:
- changed-files:
- any-glob-to-any-file: 'src/pages/questions/**/*'
- changed-files:
- any-glob-to-any-file: "src/pages/questions/**/*"

🖼️ Logo game:
- changed-files:
- any-glob-to-any-file: 'src/pages/logos/**/*'
- any-glob-to-any-file: 'src/components/LogoForm.jsx'
- any-glob-to-any-file: 'src/pages/logos/LogoAnnotation.jsx'
- any-glob-to-any-file: 'src/pages/logos/LogoDeepSearch.jsx'
- changed-files:
- any-glob-to-any-file: "src/pages/logos/**/*"
- any-glob-to-any-file: "src/components/LogoForm.jsx"
- any-glob-to-any-file: "src/pages/logos/LogoAnnotation.jsx"
- any-glob-to-any-file: "src/pages/logos/LogoDeepSearch.jsx"

Insights:
- changed-files:
- any-glob-to-any-file: 'src/pages/insights/**/*'
- changed-files:
- any-glob-to-any-file: "src/pages/insights/**/*"

🌱 Eco-Score game:
- changed-files:
- any-glob-to-any-file: 'src/pages/eco-score/**/*'
- changed-files:
- any-glob-to-any-file: "src/pages/eco-score/**/*"

i18n:
- changed-files:
- any-glob-to-any-file: 'src/i18n/**/*'
- changed-files:
- any-glob-to-any-file: "src/i18n/**/*"

Nutrition game:
- changed-files:
- any-glob-to-any-file: 'src/pages/nutrition/**/*'
- any-glob-to-any-file: 'src/pages/nutrition/index.jsx'
- changed-files:
- any-glob-to-any-file: "src/pages/nutrition/**/*"
- any-glob-to-any-file: "src/pages/nutrition/index.jsx"
1 change: 1 addition & 0 deletions src/pages/ingredients/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useSearchParams } from "react-router-dom";
import { localSettings } from "../../localeStorageManager";
import countryNames from "../../assets/countries.json";
import { getCountryId } from "../../utils/getCountryId";
import { OFF_URL } from "../../const";

function ProductInterface(props) {
const { product, next } = props;
Expand Down
39 changes: 25 additions & 14 deletions src/robotoff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from "axios";
import { ROBOTOFF_API_URL, IS_DEVELOPMENT_MODE, OFF_IMAGE_URL } from "./const";
import { getLang } from "./localeStorageManager";
import COUNTRIES from "./assets/countries.json";
import { reformatValueTag, removeEmptyKeys } from "./utils";

export interface QuestionInterface {
Expand All @@ -16,6 +17,17 @@ export interface QuestionInterface {

type GetQuestionsResponse = { count: number; questions: QuestionInterface[] };

function countryId2countryCode(id: string | null) {
if (id === null) {
return null;
}
const code = COUNTRIES.find((c) => c.id === id)?.countryCode;
if (code) {
return code.toLowerCase();
}
return code;
}

const robotoff = {
annotate(insightId: string, annotation) {
if (IS_DEVELOPMENT_MODE) {
Expand Down Expand Up @@ -64,26 +76,24 @@ const robotoff = {
insight_types: insightType,
value_tag: valueTag,
brands: reformatValueTag(brandFilter),
country: countryFilter !== "en:world" ? countryFilter : null,
countries: countryId2countryCode(
countryFilter !== "en:world" ? countryFilter : null,
),
campaign,
predictor,
order_by: sortByPopularity ? "popularity" : "random",
};

const lang = getLang();

return axios.get<GetQuestionsResponse>(
`${ROBOTOFF_API_URL}/questions/${
sortByPopularity ? "popular" : "random"
}`,
{
params: removeEmptyKeys({
...searchParams,
lang,
count,
page,
}),
},
);
return axios.get<GetQuestionsResponse>(`${ROBOTOFF_API_URL}/questions/`, {
params: removeEmptyKeys({
...searchParams,
lang,
count,
page,
}),
});
},

insightDetail(insight_id) {
Expand Down Expand Up @@ -231,6 +241,7 @@ const robotoff = {
return axios.get(
`${ROBOTOFF_API_URL}/questions/unanswered/?${Object.keys({
...params,
countries: countryId2countryCode(params.country),
page,
})
.filter((key) => params[key] !== undefined)
Expand Down

0 comments on commit 18483aa

Please sign in to comment.