Skip to content

Commit

Permalink
Orv2-2040 - Refactor Frontend Permit and Application Types and Logic (#…
Browse files Browse the repository at this point in the history
…1261)

Co-authored-by: zgong-gov <[email protected]>
  • Loading branch information
praju-aot and zgong-gov authored Mar 11, 2024
1 parent 2967a65 commit 5c780be
Show file tree
Hide file tree
Showing 91 changed files with 1,846 additions and 1,325 deletions.
58 changes: 58 additions & 0 deletions database/mssql/scripts/versions/revert/v_21_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO

ALTER TABLE [permit].[ORBC_PERMIT_DATA]
DROP COLUMN VIN


IF @@ERROR <> 0 SET NOEXEC ON
GO
ALTER TABLE [permit].[ORBC_PERMIT_DATA]
ADD [APPLICANT] AS (CONCAT (json_value([PERMIT_DATA],'$.contactDetails.firstName'), ' ', json_value([PERMIT_DATA],'$.contactDetails.lastName')))

IF @@ERROR <> 0 SET NOEXEC ON
GO
EXEC sys.sp_addextendedproperty
@name=N'MS_Description',
@value=N'Calculated column for the applicant full name, pulled from the JSON PERMIT_DATA.',
@level0type=N'SCHEMA',
@level0name=N'permit',
@level1type=N'TABLE',
@level1name=N'ORBC_PERMIT_DATA',
@level2type=N'COLUMN',
@level2name=N'APPLICANT'
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Reverting addition of new columns to ORBC_PERMIT_DATA table'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (20, @VersionDescription, getutcdate())
IF @@ERROR <> 0 SET NOEXEC ON
GO

COMMIT TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @Success AS BIT
SET @Success = 1
SET NOEXEC OFF
IF (@Success = 1) PRINT 'The database update succeeded'
ELSE BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
PRINT 'The database update failed'
END
GO
64 changes: 64 additions & 0 deletions database/mssql/scripts/versions/v_21_ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO

ALTER TABLE [permit].[ORBC_PERMIT_DATA]
ADD [VIN] AS (json_value([PERMIT_DATA],'$.vehicleDetails.vin'))

IF @@ERROR <> 0 SET NOEXEC ON
GO

ALTER TABLE [permit].[ORBC_PERMIT_DATA]
DROP COLUMN APPLICANT
GO

IF @@ERROR <> 0 SET NOEXEC ON
GO

EXEC sys.sp_addextendedproperty
@name=N'MS_Description',
@value=N'Calculated column for the vehicle VIN, pulled from the JSON PERMIT_DATA.',
@level0type=N'SCHEMA',
@level0name=N'permit',
@level1type=N'TABLE',
@level1name=N'ORBC_PERMIT_DATA',
@level2type=N'COLUMN',
@level2name=N'VIN'
GO

IF @@ERROR <> 0 SET NOEXEC ON
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Add VIN derived column to Permit Data and drop APPLICANT column'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (21, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate())
IF @@ERROR <> 0 SET NOEXEC ON
GO

COMMIT TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @Success AS BIT
SET @Success = 1
SET NOEXEC OFF
IF (@Success = 1) PRINT 'The database update succeeded'
ELSE BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
PRINT 'The database update failed'
END
GO

2 changes: 1 addition & 1 deletion dops/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class AppService {
);
//TODO: Temporary stopgap for release 1
const templatefile = await this.s3Service.getFile(
templateMetadata.fileName, //TODO: Should be templateMetadata.s3ObjectId . Using filename as temporary stopgap for release 1 integration with BCBox.
templateMetadata.fileName, //TODO: Should be templateMetadata.s3ObjectId. Using filename as temporary stopgap for release 1 integration with BCBox.
);

return {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/common/helpers/tableHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Row } from "@tanstack/table-core/build/lib/types";
import { BC_COLOURS } from "../../themes/bcGovStyles";
import { DATE_FORMATS, toLocal, utcToLocalDayjs } from "../helpers/formatDate";
import { applyWhenNotNullable } from "../helpers/util";
import { Permit } from "../../features/permits/types/permit";
import { PermitListItem } from "../../features/permits/types/permit";
import { Nullable } from "../types/common";

/**
Expand All @@ -27,8 +27,8 @@ export const formatCellValuetoDatetime = (rawDateTime: Nullable<string>) => {
* @returns -1 if A < B, 0 if A == B and 1 if A > B
*/
export const dateTimeStringSortingFn = (
rowA: Row<Permit>,
rowB: Row<Permit>,
rowA: Row<PermitListItem>,
rowB: Row<PermitListItem>,
columnId: string,
) => {
const day1 = utcToLocalDayjs(rowA.getValue(columnId));
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/common/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { SearchFields } from "../../features/idir/search/types/types";
import {
Application,
ContactDetails,
} from "../../features/permits/types/application";
import { Application } from "../../features/permits/types/application";
import { PermitContactDetails } from "../../features/permits/types/PermitContactDetails";
import {
CreateCompanyRequest,
CompanyProfile,
Expand Down Expand Up @@ -34,7 +32,7 @@ export type ORBC_FormTypes =
| BCeIDAddUserRequest
| SearchFields
| VerifyClientRequest
| ContactDetails;
| PermitContactDetails;

/**
* The options for pagination.
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/features/idir/search/api/idirSearch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { VEHICLES_URL } from "../../../../common/apiManager/endpoints/endpoints";
import { httpGETRequest } from "../../../../common/apiManager/httpRequestHandler";
import { CompanyProfile } from "../../../manageProfile/types/manageProfile";
import { PermitListItem } from "../../../permits/types/permit";
import { SearchFields } from "../types/types";
import {
PaginatedResponse,
PaginationOptions,
} from "../../../../common/types/common";
import { CompanyProfile } from "../../../manageProfile/types/manageProfile";
import { Permit } from "../../../permits/types/permit";
import { SearchFields } from "../types/types";

/**
* Searches the data with options and value entered by the user.
Expand All @@ -16,7 +16,7 @@ import { SearchFields } from "../types/types";
export const getPermitDataBySearch = (
{ searchEntity, searchByFilter, searchString }: SearchFields,
{ page = 0, take = 10 }: PaginationOptions,
): Promise<PaginatedResponse<Permit>> => {
): Promise<PaginatedResponse<PermitListItem>> => {
const searchURL = new URL(`${VEHICLES_URL}/${searchEntity}`);
searchURL.searchParams.set("searchColumn", searchByFilter);
searchURL.searchParams.set("searchString", searchString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Optional } from "../../../../common/types/common";
import { USER_AUTH_GROUP } from "../../../../common/authentication/types";
import { hasPermitExpired } from "../../../permits/helpers/permitState";
import { isPermitInactive } from "../../../permits/types/PermitStatus";
import { Permit } from "../../../permits/types/permit";
import { PermitListItem } from "../../../permits/types/permit";
import { getPermitDataBySearch } from "../api/idirSearch";
import { PermitSearchResultColumnDef } from "../table/PermitSearchResultColumnDef";
import { SearchFields } from "../types/types";
Expand Down Expand Up @@ -94,22 +94,22 @@ export const IDIRPermitSearchResults = memo(
const { data, isPending, isError } = searchResultsQuery;

// Column definitions for the table
const columns = useMemo<MRT_ColumnDef<Permit>[]>(
const columns = useMemo<MRT_ColumnDef<PermitListItem>[]>(
() => PermitSearchResultColumnDef,
[],
);

/**
*
* @param initialData The initial data to filter by the active data toggle.
* @returns Permit[] containing the data to be displayed in table.
* @returns List of permit items containing the data to be displayed in table.
*/
const getFilteredData = (initialData: Permit[]): Permit[] => {
const getFilteredData = (initialData: PermitListItem[]): PermitListItem[] => {
if (!initialData.length) return [];
if (isActiveRecordsOnly) {
// Returns unexpired permits
return initialData.filter(
({ permitStatus, permitData: { expiryDate } }) =>
({ permitStatus, expiryDate }) =>
!hasPermitExpired(expiryDate) && !isPermitInactive(permitStatus),
);
}
Expand Down Expand Up @@ -164,9 +164,9 @@ export const IDIRPermitSearchResults = memo(
</Box>
);
},
renderRowActions: useCallback(({ row }: { row: MRT_Row<Permit> }) => {
renderRowActions: useCallback(({ row }: { row: MRT_Row<PermitListItem> }) => {
const isInactive =
hasPermitExpired(row.original.permitData.expiryDate) ||
hasPermitExpired(row.original.expiryDate) ||
isPermitInactive(row.original.permitStatus);

if (shouldShowRowActions(idirUserDetails?.userAuthGroup)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const IDIRPermitSearchRowActions = ({
/**
* The permit id.
*/
permitId: number;
permitId: string;
/**
* Is the permit inactive (voided/superseded/revoked) or expired?
*/
Expand Down Expand Up @@ -124,17 +124,15 @@ export const IDIRPermitSearchRowActions = ({
* @param selectedOption The selected option as a string.
*/
const onSelectOption = (selectedOption: string) => {
const permitIdStr = `${permitId}`;

if (selectedOption === PERMIT_ACTION_TYPES.RESEND) {
// For implementation
setIsResendOpen(() => true);
} else if (selectedOption === PERMIT_ACTION_TYPES.VIEW_RECEIPT) {
viewReceiptPdf(permitId.toString());
viewReceiptPdf(permitId);
} else if (selectedOption === PERMIT_ACTION_TYPES.VOID_REVOKE) {
navigate(`${routes.PERMITS_ROUTES.VOID(permitIdStr)}`);
navigate(`${routes.PERMITS_ROUTES.VOID(permitId)}`);
} else if (selectedOption === PERMIT_ACTION_TYPES.AMEND) {
navigate(`${routes.PERMITS_ROUTES.AMEND(permitIdStr)}`);
navigate(`${routes.PERMITS_ROUTES.AMEND(permitId)}`);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MRT_ColumnDef } from "material-react-table";

import { CustomActionLink } from "../../../../common/components/links/CustomActionLink";
import { Permit } from "../../../permits/types/permit";
import { PermitListItem } from "../../../permits/types/permit";
import { PERMIT_EXPIRED } from "../../../permits/types/PermitStatus";
import { PermitChip } from "../../../permits/components/permit-list/PermitChip";
import { viewPermitPdf } from "../../../permits/helpers/permitPDFHelper";
Expand All @@ -18,18 +18,18 @@ import {
* https://www.material-react-table.com/docs/api/column-options
*
*/
export const PermitSearchResultColumnDef: MRT_ColumnDef<Permit>[] = [
export const PermitSearchResultColumnDef: MRT_ColumnDef<PermitListItem>[] = [
{
accessorKey: "permitNumber",
header: "Permit #",
enableSorting: true,
sortingFn: "alphanumeric",
Cell: (props: { cell: any; row: any }) => {
const permit = props.row.original as Permit;
const permit = props.row.original as PermitListItem;
const {
permitId,
permitStatus,
permitData: { expiryDate },
expiryDate,
} = permit;

return (
Expand All @@ -56,7 +56,6 @@ export const PermitSearchResultColumnDef: MRT_ColumnDef<Permit>[] = [
sortingFn: "alphanumeric",
},
{
accessorKey: "permitData.commodities",
header: "Commodity",
enableSorting: true,
sortingFn: "alphanumeric",
Expand All @@ -65,19 +64,19 @@ export const PermitSearchResultColumnDef: MRT_ColumnDef<Permit>[] = [
Cell: () => <>NA</>,
},
{
accessorKey: "permitData.vehicleDetails.plate",
accessorKey: "plate",
header: "Plate",
enableSorting: true,
sortingFn: "alphanumeric",
},
{
accessorKey: "permitData.companyName",
accessorKey: "legalName",
header: "Company Name",
enableSorting: true,
sortingFn: "alphanumeric",
},
{
accessorKey: "permitData.startDate",
accessorKey: "startDate",
header: "Permit Start Date",
enableSorting: true,
sortingFn: dateTimeStringSortingFn,
Expand All @@ -87,7 +86,7 @@ export const PermitSearchResultColumnDef: MRT_ColumnDef<Permit>[] = [
},
},
{
accessorKey: "permitData.expiryDate",
accessorKey: "expiryDate",
header: "Permit End Date",
enableSorting: true,
sortingFn: dateTimeStringSortingFn,
Expand Down
Loading

0 comments on commit 5c780be

Please sign in to comment.