From 649af63211d1a734f588b3cb03147db626530850 Mon Sep 17 00:00:00 2001 From: Mariana Sartorato Date: Thu, 4 Jul 2024 17:00:29 -0300 Subject: [PATCH] feat: order the trees by its name and branch --- .../TreeListingPage/TreeListingPage.tsx | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dashboard/src/components/TreeListingPage/TreeListingPage.tsx b/dashboard/src/components/TreeListingPage/TreeListingPage.tsx index a9eb71b..9d91781 100644 --- a/dashboard/src/components/TreeListingPage/TreeListingPage.tsx +++ b/dashboard/src/components/TreeListingPage/TreeListingPage.tsx @@ -71,18 +71,25 @@ const TreeListingPage = (): JSX.Element => { const { data } = useTreeTable(); const listItems: TreeTableBody[] = useMemo(() => { - return data ? (data as Tree[]).map(tree => { - const fullHash = tree.git_commit_hash ?? tree.patchset_hash ?? ''; - const commitHash = fullHash.substring(0, NUMBER_CHAR_HASH) + (fullHash.length > NUMBER_CHAR_HASH ? '...' : ''); - const tagCommit = tree.git_commit_name ? `${tree.git_commit_name} - ${commitHash}` : commitHash; - return ({ - name: tree.tree_name ?? '', - branch: tree.git_repository_branch ?? '', - commit: tagCommit, - buildStatus: `${tree.build_status.valid} / ${tree.build_status.total}`, - testStatus: `${tree.test_status.fail} / ${tree.test_status.total}`, - }) - }) : []; + if(!data) { + return []; + } else { + return((data as Tree[]).map(tree => { + const fullHash = tree.git_commit_hash ?? tree.patchset_hash ?? ''; + const commitHash = fullHash.substring(0, NUMBER_CHAR_HASH) + (fullHash.length > NUMBER_CHAR_HASH ? '...' : ''); + const tagCommit = tree.git_commit_name ? `${tree.git_commit_name} - ${commitHash}` : commitHash; + + return ({ + name: tree.tree_name ?? '', + branch: tree.git_repository_branch ?? '', + commit: tagCommit, + buildStatus: `${tree.build_status.valid} / ${tree.build_status.total}`, + testStatus: `${tree.test_status.fail} / ${tree.test_status.total}`, + }) + }) + .sort((a, b) => a.name.localeCompare(b.name, undefined, {numeric: true}) + || a.branch.localeCompare(b.branch, undefined, {numeric: true}))); + } }, [data]); const [startIndex, setStartIndex] = useState(0);