From b004191139ad6112d7064efd3b9eea8e347c2986 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 22 Sep 2023 20:05:16 +0200 Subject: [PATCH 1/2] fix: Avoid loading logos without a filtering defined --- src/components/LogoSearchForm.jsx | 1 - src/pages/logos/LogoSearch.jsx | 11 ++++++++++- src/pages/logos/ProductLogoAnnotations.jsx | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/components/LogoSearchForm.jsx b/src/components/LogoSearchForm.jsx index d6ba7e2ee..1aa89438d 100644 --- a/src/components/LogoSearchForm.jsx +++ b/src/components/LogoSearchForm.jsx @@ -69,7 +69,6 @@ const LogoSearchForm = (props) => { return ( -

{innerType}

{ export default function LogoSearch() { const { t } = useTranslation(); - const [isLoading, setIsLoading] = React.useState(true); + const [isLoading, setIsLoading] = React.useState(false); const [searchState, setSearchState] = useUrlParams( { type: "", @@ -61,7 +61,16 @@ export default function LogoSearch() { [setSearchState] ); + const filterStateHasValue = + (searchState.type && + (TYPE_WITHOUT_VALUE.includes(searchState.type) || searchState.value)) || + searchState.barcode; + React.useEffect(() => { + if (!filterStateHasValue) { + // Avoid fetching data is no valiue to filter + return () => {}; + } let isValidRequest = true; setIsLoading(true); setResult({ logos: [], count: undefined }); diff --git a/src/pages/logos/ProductLogoAnnotations.jsx b/src/pages/logos/ProductLogoAnnotations.jsx index 2f25f23df..4a53660be 100644 --- a/src/pages/logos/ProductLogoAnnotations.jsx +++ b/src/pages/logos/ProductLogoAnnotations.jsx @@ -25,6 +25,12 @@ const OFF_2_ROBOTOFF = { labels: "label", packaging: "packaging", }; +const ROBOTOFF_2_OFF = { + category: "categories", + label: "labels", + packaging: "packaging", +}; + const fetchProducts = async ({ page, filter }) => { try { const { @@ -87,6 +93,12 @@ const useLogoFetching = (filter) => { }, [filter]); React.useEffect(() => { + const filterStateIsIncomplet = !filter.tagtype || !filter.tag; + if (filterStateIsIncomplet) { + // Avoid fetching data is no valiue to filter + return () => {}; + } + let isValid = true; setIsLoading(true); setCanLoadMore(false); @@ -181,7 +193,7 @@ export default function AnnotateLogosFromProducts() { { tagtype: "labels", tag_contains: "contains", - tag: "en:eg-oko-verordnung", + tag: "", }, { tag: ["valueTag", "value_tag", "value"], @@ -228,7 +240,10 @@ export default function AnnotateLogosFromProducts() { sx={{ minWidth: 200 }} > {logoTypeOptions.map(({ value: typeValue, labelKey }) => ( - + {t(labelKey)} ))} From 740ee6ecd267a89295c072692e625bed748a5403 Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Date: Sat, 23 Sep 2023 16:21:34 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Pierre Slamich --- src/pages/logos/LogoSearch.jsx | 2 +- src/pages/logos/ProductLogoAnnotations.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/logos/LogoSearch.jsx b/src/pages/logos/LogoSearch.jsx index 5569c77b0..cf1a1e8e4 100644 --- a/src/pages/logos/LogoSearch.jsx +++ b/src/pages/logos/LogoSearch.jsx @@ -68,7 +68,7 @@ export default function LogoSearch() { React.useEffect(() => { if (!filterStateHasValue) { - // Avoid fetching data is no valiue to filter + // Avoid fetching data if no value to filter return () => {}; } let isValidRequest = true; diff --git a/src/pages/logos/ProductLogoAnnotations.jsx b/src/pages/logos/ProductLogoAnnotations.jsx index 4a53660be..5cbd6687e 100644 --- a/src/pages/logos/ProductLogoAnnotations.jsx +++ b/src/pages/logos/ProductLogoAnnotations.jsx @@ -95,7 +95,7 @@ const useLogoFetching = (filter) => { React.useEffect(() => { const filterStateIsIncomplet = !filter.tagtype || !filter.tag; if (filterStateIsIncomplet) { - // Avoid fetching data is no valiue to filter + // Avoid fetching data if no value to filter return () => {}; }