Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Jan 15, 2025
1 parent 6d64fcf commit b9a538b
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ const ManageNodeResourceSection: React.FC<ManageNodeResourceSectionProps> = ({
setNodeResources,
}) => {
const [searchParams] = useSearchParams();
const identifiersString = searchParams.get('identifiers');

const nodeResourcesFromSearchURL = React.useMemo(
() =>
searchParams
.get('identifiers')
?.split(',')
.map((identifier) => ({ ...EMPTY_IDENTIFIER, displayName: identifier, identifier })) ?? [],
[searchParams],
identifiersString
? identifiersString
.split(',')
.map((identifier) => ({ ...EMPTY_IDENTIFIER, displayName: identifier, identifier }))
: [],
[identifiersString],
);

React.useEffect(() => {
setNodeResources([...nodeResources, ...nodeResourcesFromSearchURL]);
// we only want this hook to trigger once based on the change in the search params
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [nodeResourcesFromSearchURL]);

const [isNodeResourceModalOpen, setIsNodeResourceModalOpen] = React.useState<boolean>(false);
const isEmpty = nodeResources.length === 0;
return (
Expand Down Expand Up @@ -76,7 +84,7 @@ const ManageNodeResourceSection: React.FC<ManageNodeResourceSectionProps> = ({
)}
{!isEmpty && (
<NodeResourceTable
nodeResources={[...nodeResources, ...nodeResourcesFromSearchURL]}
nodeResources={nodeResources}
onUpdate={(newResources) => setNodeResources(newResources)}
/>
)}
Expand Down

0 comments on commit b9a538b

Please sign in to comment.