Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid loading logos without a filtering defined #742

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/LogoSearchForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const LogoSearchForm = (props) => {
return (
<Stack direction="column" spacing={{ xs: 1, sm: 2, md: 4 }} {...other}>
<Stack direction={{ xs: "column", sm: "row" }} spacing={1} wrap="wrap">
<p>{innerType}</p>
<TextField
fullWidth
value={innerType}
Expand Down
11 changes: 10 additions & 1 deletion src/pages/logos/LogoSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const request = async ({ barcode, value, type, count }) => {
export default function LogoSearch() {
const { t } = useTranslation();

const [isLoading, setIsLoading] = React.useState(true);
const [isLoading, setIsLoading] = React.useState(false);
const [searchState, setSearchState] = useUrlParams(
{
type: "",
Expand All @@ -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
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
return () => {};
}
let isValidRequest = true;
setIsLoading(true);
setResult({ logos: [], count: undefined });
Expand Down
19 changes: 17 additions & 2 deletions src/pages/logos/ProductLogoAnnotations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
return () => {};
}

let isValid = true;
setIsLoading(true);
setCanLoadMore(false);
Expand Down Expand Up @@ -181,7 +193,7 @@ export default function AnnotateLogosFromProducts() {
{
tagtype: "labels",
tag_contains: "contains",
tag: "en:eg-oko-verordnung",
tag: "",
},
{
tag: ["valueTag", "value_tag", "value"],
Expand Down Expand Up @@ -228,7 +240,10 @@ export default function AnnotateLogosFromProducts() {
sx={{ minWidth: 200 }}
>
{logoTypeOptions.map(({ value: typeValue, labelKey }) => (
<MenuItem key={typeValue} value={typeValue}>
<MenuItem
key={typeValue}
value={ROBOTOFF_2_OFF[typeValue] ?? typeValue}
>
{t(labelKey)}
</MenuItem>
))}
Expand Down