Skip to content

Commit

Permalink
Sorts order of the dependency based on their names.
Browse files Browse the repository at this point in the history
  • Loading branch information
BriannaVH committed Jul 6, 2023
1 parent c57244e commit 43c7675
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions app/src/pages/[resourceType]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export default function ResourceIDPage({ jsonData }: InferGetServerSidePropsType
window.addEventListener('resize', handleResize);
}, []);

useEffect(() => {
setActiveTab('json');
}, [jsonData.id]);

const {
data: dataRequirements,
refetch,
Expand Down Expand Up @@ -83,9 +87,31 @@ export default function ResourceIDPage({ jsonData }: InferGetServerSidePropsType
}
);

//Sorts the dependencies of an artifact alphabetically based on display name. If a dependency has a link, however,
//it will appear at the top of the list.
useEffect(() => {
setActiveTab('json');
}, [jsonData.id]);
dataRequirements?.relatedArtifact?.sort((a, b) => {
const displayA = a?.display?.toUpperCase();
const displayB = b?.display?.toUpperCase();
if (displayA !== undefined && displayB !== undefined) {
if (
a.resource?.includes('Library') ||
a.resource?.includes('Measure') ||
b.resource?.includes('Library') ||
b.resource?.includes('Measure')
) {
return 1;
}
if (displayA < displayB) {
return -1;
}
if (displayA > displayB) {
return 1;
}
}
return 0;
});
}, [dataRequirements?.relatedArtifact]);

const draftMutation = trpc.draft.createDraft.useMutation({
onSuccess: data => {
Expand Down

0 comments on commit 43c7675

Please sign in to comment.