Skip to content

Commit

Permalink
[frontend] Avoid freeze when having a lot of external references (#4652)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed Oct 19, 2023
1 parent 0805c3d commit 1d77656
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import makeStyles from '@mui/styles/makeStyles';
import { Field } from 'formik';
import { append, union } from 'ramda';
import { append, union, take } from 'ramda';
import React, { FunctionComponent, useState } from 'react';
import { RecordSourceSelectorProxy } from 'relay-runtime';
import AutocompleteField from '../../../../components/AutocompleteField';
Expand All @@ -10,7 +10,10 @@ import { commitMutation, fetchQuery } from '../../../../relay/environment';
import { insertNode } from '../../../../utils/store';
import { truncate } from '../../../../utils/String';
import { ExternalReferenceCreationMutation$data } from '../../analyses/external_references/__generated__/ExternalReferenceCreationMutation.graphql';
import { ExternalReferencesQueriesSearchQuery$data, ExternalReferencesQueriesSearchQuery$variables } from '../../analyses/external_references/__generated__/ExternalReferencesQueriesSearchQuery.graphql';
import {
ExternalReferencesQueriesSearchQuery$data,
ExternalReferencesQueriesSearchQuery$variables,
} from '../../analyses/external_references/__generated__/ExternalReferencesQueriesSearchQuery.graphql';
import { externalReferenceLinesMutationRelationAdd } from '../../analyses/external_references/AddExternalReferencesLines';
import ExternalReferenceCreation from '../../analyses/external_references/ExternalReferenceCreation';
import { externalReferencesQueriesSearchQuery } from '../../analyses/external_references/ExternalReferencesQueries';
Expand Down Expand Up @@ -62,7 +65,7 @@ interface ExternalReferencesFieldProps {
url: string | null;
};
}[],
shouldValidate?: boolean
shouldValidate?: boolean,
) => void;
values?: ExternalReferencesValues;
helpertext?: string;
Expand Down Expand Up @@ -147,12 +150,12 @@ ExternalReferencesFieldProps
value: n.node.id,
entity: n.node,
}));
setExternalReferences((o) => union(o, newExternalReferences));
setExternalReferences((o) => union(take(50, o), newExternalReferences));
});
};

return (
<div>
<>
<Field
component={AutocompleteField}
style={style}
Expand Down Expand Up @@ -244,6 +247,6 @@ ExternalReferencesFieldProps
}
}}
/>
</div>
</>
);
};

0 comments on commit 1d77656

Please sign in to comment.