Skip to content

Commit

Permalink
Merge pull request #3485 from bcgov/NDT-363-Internal-and-External-Sta…
Browse files Browse the repository at this point in the history
…tus-not-sorting-according-to-established-sort-order

fix: sort order for status ccbc and cbc combined
  • Loading branch information
rafasdc authored Aug 22, 2024
2 parents b87e7a9 + d303e29 commit 8b8ce91
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.181.1](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.181.0...v1.181.1) (2024-08-22)

### Bug Fixes

- sort order for status ccbc and cbc combined ([2cef172](https://github.com/bcgov/CONN-CCBC-portal/commit/2cef172553b1fb832d28409d245167b6ddc76419))

# [1.181.0](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.180.4...v1.181.0) (2024-08-20)

### Features
Expand Down
44 changes: 39 additions & 5 deletions app/components/AnalystDashboard/AllDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import ClearFilters from 'components/Table/ClearFilters';
import type { AllDashboardTable_query$key } from '__generated__/AllDashboardTable_query.graphql';
import { TableCellProps } from '@mui/material';
import { useFeature } from '@growthbook/growthbook-react';
import { filterZones, sortZones } from './AssessmentAssignmentTable';
import {
filterZones,
sortStatus,
sortZones,
} from './AssessmentAssignmentTable';
import AdditionalFilters, {
additionalFilterColumns,
} from './AdditionalFilters';
Expand All @@ -49,15 +53,16 @@ export const filterNumber = (row, id, filterValue) => {
return numericProperty === Number(filterValue);
};

// matching the status with `applicant statuses` since cbc only has external status
const cbcProjectStatusConverter = (status) => {
if (status === 'Conditionally Approved') {
return 'conditionally_approved';
return 'applicant_conditionally_approved';
}
if (status === 'Reporting Complete') {
return 'complete';
}
if (status === 'Agreement Signed') {
return 'approved';
return 'applicant_approved';
}
if (status === 'Withdrawn') {
return 'withdrawn';
Expand Down Expand Up @@ -163,6 +168,12 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
graphql`
fragment AllDashboardTable_query on Query {
...AssignLead_query
allApplicationStatusTypes {
nodes {
name
statusOrder
}
}
allApplications(
first: 1000
filter: { archivedAt: { isNull: true } }
Expand Down Expand Up @@ -228,7 +239,8 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
},
[queryFragment]
);
const { allApplications, allCbcData } = queryFragment;
const { allApplications, allCbcData, allApplicationStatusTypes } =
queryFragment;
const isLargeUp = useMediaQuery('(min-width:1007px)');

const [isFirstRender, setIsFirstRender] = useState(true);
Expand Down Expand Up @@ -263,6 +275,13 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
zones: 91,
});

const statusOrderMap = useMemo(() => {
return allApplicationStatusTypes?.nodes?.reduce((acc, status) => {
acc[status.name] = status.statusOrder;
return acc;
}, {});
}, [allApplicationStatusTypes?.nodes]);

useEffect(() => {
const sortingSession = cookie.get('mrt_sorting_application');
if (sortingSession) {
Expand Down Expand Up @@ -402,6 +421,8 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
projectTitle: application.node.projectName,
isCbcProject: false,
showLink: true,
externalStatusOrder: statusOrderMap[application.node.externalStatus],
internalStatusOrder: statusOrderMap[application.node.analystStatus],
})),
...(showCbcProjects
? allCbcData.edges.map((project) => ({
Expand All @@ -415,6 +436,11 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
externalStatus: project.node.jsonData.projectStatus
? cbcProjectStatusConverter(project.node.jsonData.projectStatus)
: null,
externalStatusOrder: project.node.jsonData.projectStatus
? statusOrderMap[
cbcProjectStatusConverter(project.node.jsonData.projectStatus)
]
: null,
packageNumber: null,
organizationName:
project.node.jsonData.currentOperatingName || null,
Expand All @@ -424,7 +450,13 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
})) ?? []
: []),
];
}, [allApplications, allCbcData, showCbcProjects, showCbcProjectsLink]);
}, [
allApplications.edges,
allCbcData.edges,
showCbcProjects,
showCbcProjectsLink,
statusOrderMap,
]);

const columns = useMemo<MRT_ColumnDef<Application>[]>(() => {
const uniqueIntakeNumbers = [
Expand Down Expand Up @@ -499,6 +531,7 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
filterVariant: 'multi-select',
filterFn: statusFilter,
filterSelectOptions: analystStatuses,
sortingFn: sortStatus,
},
{
accessorKey: 'externalStatus',
Expand All @@ -507,6 +540,7 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
filterVariant: 'multi-select',
filterFn: statusFilter,
filterSelectOptions: externalStatuses,
sortingFn: sortStatus,
},
{
accessorKey: 'projectTitle',
Expand Down
11 changes: 11 additions & 0 deletions app/components/AnalystDashboard/AssessmentAssignmentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ export const filterZones = (row, id, filterValue) => {
return zones.some((zone) => parseInt(zone, 10) === parseInt(filterValue, 10));
};

export const sortStatus = (rowA, rowB, columnId) => {
const sortColumn =
columnId === 'analystStatus'
? 'internalStatusOrder'
: 'externalStatusOrder';
const statusA = (rowA.original?.[sortColumn] as number) ?? 0;
const statusB = (rowB.original?.[sortColumn] as number) ?? 0;

return statusA - statusB;
};

export const sortZones = (rowA, rowB, columnId) => {
const valueA = rowA.getValue(columnId) as Array<string>;
const valueB = rowB.getValue(columnId) as Array<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AssessmentAssignmentTable, {
filterAnalysts,
filterCcbcId,
sortAnalysts,
sortStatus,
} from 'components/AnalystDashboard/AssessmentAssignmentTable';
import compiledQuery, {
AssessmentAssignmentTableTestQuery,
Expand Down Expand Up @@ -673,3 +674,41 @@ describe('The sortAnalysts function', () => {
expect(sortAnalysts(mockDataA, mockDataB, 1)).toEqual(-1);
});
});

describe('The sortStatus function', () => {
it('should sort based on internalStatusOrder when columnId is "analystStatus"', () => {
const rowA = { original: { internalStatusOrder: 2 } };
const rowB = { original: { internalStatusOrder: 1 } };

const result = sortStatus(rowA, rowB, 'analystStatus');

expect(result).toBeGreaterThan(0);
});

it('should sort based on externalStatusOrder when columnId is not "analystStatus"', () => {
const rowA = { original: { externalStatusOrder: 1 } };
const rowB = { original: { externalStatusOrder: 2 } };

const result = sortStatus(rowA, rowB, 'someOtherStatus');

expect(result).toBeLessThan(0);
});

it('should return 0 when both statuses are equal', () => {
const rowA = { original: { externalStatusOrder: 3 } };
const rowB = { original: { externalStatusOrder: 3 } };

const result = sortStatus(rowA, rowB, 'someOtherStatus');

expect(result).toBe(0);
});

it('should handle missing status values by treating them as 0', () => {
const rowA = { original: { internalStatusOrder: undefined } };
const rowB = { original: { internalStatusOrder: 1 } };

const result = sortStatus(rowA, rowB, 'analystStatus');

expect(result).toBeLessThan(0);
});
});
1 change: 1 addition & 0 deletions db/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,4 @@ computed_columns/application_project_name [computed_columns/application_project_
@1.180.4 2024-08-19T22:41:47Z CCBC Service Account <ccbc@button.is> # release v1.180.4
tables/cbc_add_fk_update_constraint 2024-07-11T20:32:11Z Rafael Solorzano <61289255+rafasdc@users.noreply.github.com> # add a foreign key update cascade constraint
@1.181.0 2024-08-20T20:20:29Z CCBC Service Account <ccbc@button.is> # release v1.181.0
@1.181.1 2024-08-22T14:38:05Z CCBC Service Account <ccbc@button.is> # release v1.181.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CONN-CCBC-portal",
"version": "1.181.0",
"version": "1.181.1",
"main": "index.js",
"repository": "https://github.com/bcgov/CONN-CCBC-portal.git",
"author": "Romer, Meherzad CITZ:EX <Meherzad.Romer@gov.bc.ca>",
Expand Down

0 comments on commit 8b8ce91

Please sign in to comment.