Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typing all any types #328

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 68 additions & 33 deletions frontend/src/components/ActionsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,77 @@ import React from 'react';
import { Table, TableHead, TableRow, TableHeader, TableBody, TableCell } from "@carbon/react";
import StatusTag from "../StatusTag";
import ActivityTag from "../ActivityTag";
import { RecentAction } from '../../types/RecentAction';
import { ActivityTagFileFormatEnum, ActivityTagTypeEnum } from '../../types/ActivityTagType';
import { ITableHeader } from '../../types/TableHeader';

interface IActionsTable {
rows: any[];
headers: any[];
rows: RecentAction[];
headers: ITableHeader[];
}

const ActionsTable: React.FC<IActionsTable> = ({rows, headers}) => (
<Table size="lg" useZebraStyles={false} aria-label="actions table">
<TableHead>
<TableRow>
{headers.map(header => <TableHeader id={header.key} key={header.key}>
{header.header}
</TableHeader>)}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, idx) => <TableRow key={idx}>
{Object.keys(row).filter(key => key !== 'id').map(key => {
return (
<TableCell key={key}>
{key === "status" ? (
<StatusTag type={row[key]} />
):
key === "activityType" && !row["fileFormat"] ? (
<ActivityTag type={row[key]} fileFormat={"Unknown"} />
):
key === "activityType" && row["fileFormat"] ? (
<ActivityTag type={row[key]} fileFormat={row["fileFormat"]} />
):
row[key]}
</TableCell>
);
})}
</TableRow>)}
</TableBody>
</Table>
);
const ActionsTable: React.FC<IActionsTable> = ({ rows, headers }) => {
const getTypeEnum = (typeStr: string): ActivityTagTypeEnum => {
if (typeStr === ActivityTagTypeEnum.OPENING_DETAILS) {
return ActivityTagTypeEnum.OPENING_DETAILS;
} else if (typeStr === ActivityTagTypeEnum.OPENING_REPORT) {
return ActivityTagTypeEnum.OPENING_REPORT;
} else if (typeStr === ActivityTagTypeEnum.OPENING_SPATIAL) {
return ActivityTagTypeEnum.OPENING_SPATIAL;
} else if (typeStr === ActivityTagTypeEnum.UPDATE) {
return ActivityTagTypeEnum.UPDATE;
} else {
return ActivityTagTypeEnum.UNKNOWN;
}
};

const getFileFormatEnum = (formatStr: string): ActivityTagFileFormatEnum => {
if (formatStr === ActivityTagFileFormatEnum.PDF_FILE) {
return ActivityTagFileFormatEnum.PDF_FILE;
} else if (formatStr === ActivityTagFileFormatEnum.CSV_FILE) {
return ActivityTagFileFormatEnum.CSV_FILE;
} else if (formatStr === ActivityTagFileFormatEnum.EXCEL_FILE) {
return ActivityTagFileFormatEnum.EXCEL_FILE;
} else {
return ActivityTagFileFormatEnum.UNKNOWN;
}
};

return (
<Table size="lg" useZebraStyles={false} aria-label="actions table">
<TableHead>
<TableRow>
{headers.map(header => <TableHeader id={header.key} key={header.key}>
{header.header}
</TableHeader>)}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row: RecentAction, idx: number) =>
<TableRow key={idx}>
{ Object.keys(row).filter((rowKey: string) => rowKey !== 'id').map((key: string) => {
return (
<TableCell key={key}>
{key === "statusCode" ? (
<StatusTag code={row[key]} />
):
key === "activityType" && !row["fileFormat"] ? (
<ActivityTag type={getTypeEnum(row[key])} />
):
key === "activityType" && row["fileFormat"] ? (
<ActivityTag
type={getTypeEnum(row[key])}
fileFormat={getFileFormatEnum(row["fileFormat"])}
/>
):
row[key]}
</TableCell>
);
})}
</TableRow>)}
</TableBody>
</Table>
);
};

export default ActionsTable;
10 changes: 3 additions & 7 deletions frontend/src/components/ActivityTag/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React from 'react';
import { Tag } from '@carbon/react';
import * as Carbon from '@carbon/icons-react';

import { ActivityIconMap, FileIconMap } from './definitions';

import './styles.scss';
import { ActivityTagFileFormatEnum, ActivityTagTypeEnum } from '../../types/ActivityTagType';

type ActivityTagProps = {
type: keyof typeof ActivityIconMap;
fileFormat: keyof typeof FileIconMap; // Optional fileFormat
type: ActivityTagTypeEnum;
fileFormat?: ActivityTagFileFormatEnum; // Optional fileFormat
};

const ActivityTag = ({ type, fileFormat }: ActivityTagProps) => {
Expand All @@ -22,8 +20,6 @@ const ActivityTag = ({ type, fileFormat }: ActivityTagProps) => {
}
const Icon = Carbon[iconName]; // get the icon component by the icon name



return (
<>
<Icon size={18} /> {type}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/BCHeader/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface HeaderContainerProps {
isSideNavExpanded: boolean;
onClickSideNavExpand: Function;
}
15 changes: 5 additions & 10 deletions frontend/src/components/BCHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,21 @@ import {
SideNav,
SideNavItems,
HeaderSideNavItems,

} from '@carbon/react';
import { NavLink } from "react-router-dom";
import * as Icons from '@carbon/icons-react';

import './BCHeader.scss'


import { HeaderContainerProps } from "./definitions";

const BCHeader: React.FC = () => {
//can only be impored at component level
//can only be imported at component level
const { theme, setTheme } = useThemePreference();

return (
<>
<HeaderContainer
render={({ isSideNavExpanded, onClickSideNavExpand }: any) => (
<Header aria-label="React TS Carbon Quickstart"
render={({ isSideNavExpanded, onClickSideNavExpand }: HeaderContainerProps) => (
<Header aria-label="React TS Carbon QuickStart"
className="spar-header"
data-testid="header">
<SkipToContent />
Expand Down Expand Up @@ -73,8 +70,6 @@ const BCHeader: React.FC = () => {
</HeaderGlobalAction>
</NavLink>



<HeaderGlobalAction
aria-label="App Switch"
tooltipAlignment="end">
Expand Down Expand Up @@ -106,4 +101,4 @@ const BCHeader: React.FC = () => {
);
};

export default BCHeader;
export default BCHeader;
5 changes: 3 additions & 2 deletions frontend/src/components/BarChartGrouped/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dropdown, DatePicker, DatePickerInput } from "@carbon/react";
import "@carbon/charts/styles.css";
import "./BarChartGrouped.scss";
import { fetchOpeningsPerYear } from "../../services/OpeningService";
import { OpeningPerYearChart } from "../../types/OpeningPerYearChart";

interface IDropdownItem {
value: string,
Expand All @@ -12,7 +13,7 @@ interface IDropdownItem {

const BarChartGrouped = () => {
const [windowWidth, setWindowWidth] = useState<number>(window.innerWidth);
const [chartData, setChartData] = useState<any[]>([]);
const [chartData, setChartData] = useState<OpeningPerYearChart[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [orgUnitCode, setOrgUnitCode] = useState<string | null>(null);
const [statusCode, setStatusCode] = useState<string | null>(null);
Expand All @@ -37,7 +38,7 @@ const BarChartGrouped = () => {
formattedEndDate = formatDateToString(endDate);
}

const data = await fetchOpeningsPerYear({
const data: OpeningPerYearChart[] = await fetchOpeningsPerYear({
orgUnitCode,
statusCode,
entryDateStart: formattedStartDate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import React, { useState, useEffect, ChangeEvent, useCallback } from "react";
import { DonutChart } from "@carbon/charts-react";
import { Dropdown, DatePicker, DatePickerInput, TextInput } from "@carbon/react";
import "./DonutChartView.scss";
import { fetchFreeGrowingMilestones } from "../../services/OpeningService";

interface IDonutChart {
group: any;
value: any;
}
import "./DoughnutChartView.scss";
import { IFreeGrowingChartData, fetchFreeGrowingMilestones } from "../../services/OpeningService";

interface IDropdownItem {
value: string,
text: string
}

const DonutChartView: React.FC = () => {
const DoughnutChartView: React.FC = () => {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const [chartData, setChartData] = useState<IDonutChart[]>([]);
const [chartData, setChartData] = useState<IFreeGrowingChartData[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [orgUnitCode, setOrgUnitCode] = useState<string>("");
const [clientNumber, setClientNumber] = useState<string>("");
Expand All @@ -38,7 +33,7 @@ const DonutChartView: React.FC = () => {
setIsLoading(true);
const formattedStartDate = formatDateToString(startDate);
const formattedEndDate = formatDateToString(endDate);
const data = await fetchFreeGrowingMilestones({
const data: IFreeGrowingChartData[] = await fetchFreeGrowingMilestones({
orgUnitCode,
clientNumber,
entryDateStart: formattedStartDate,
Expand Down Expand Up @@ -146,4 +141,4 @@ const DonutChartView: React.FC = () => {
);
};

export default DonutChartView;
export default DoughnutChartView;
13 changes: 2 additions & 11 deletions frontend/src/components/MyProfile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import React, { useCallback, useState, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useSelector } from 'react-redux';
import {
SideNavLink
} from '@carbon/react';
import * as Icons from '@carbon/icons-react';


import AvatarImage from '../AvatarImage';

import { useThemePreference } from '../../utils/ThemePreference';

import './MyProfile.scss';
import { logout } from '../../services/AuthService';

const MyProfile = () => {
const { theme, setTheme } = useThemePreference();
const userData = {firstName:'Catherine', lastName:"Meng", idirUsername:"Jasgrewal", email:"[email protected]"};
const userDetails = useSelector((state:any) => state.userDetails)
const [goToURL, setGoToURL] = useState<string>('');
const [goTo, setGoTo] = useState<boolean>(false);

const navigate = useNavigate();

const changeTheme = () => {
if (theme === 'g10') {
setTheme('g100');
Expand All @@ -37,7 +29,6 @@ const MyProfile = () => {
useEffect(() => {
if (goTo) {
setGoTo(false);
navigate(goToURL);
}
}, [goTo]);

Expand Down Expand Up @@ -67,7 +58,7 @@ const MyProfile = () => {
<SideNavLink
className="cursor-pointer"
renderIcon={Icons.UserFollow}
onClick={()=>{logout()}}
onClick={()=>{ logout() }}
>
Log out
</SideNavLink>
Expand Down
42 changes: 30 additions & 12 deletions frontend/src/components/MyRecentActions/filesData.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
export const rows = [
import { RecentAction } from "../../types/RecentAction";
import { ITableHeader } from "../../types/TableHeader";

export const rows: RecentAction[] = [
{
activityType: 'Opening details',
openingId: '11',
statusCode: 'PND',
statusDescription: 'Pending',
fileFormat: 'PDF file',
status: 'Pending',
lastUpdated: 'Now'
lastUpdated: '-',
lastUpdatedLabel: 'Now'
},
{
activityType: 'Opening report',
openingId: '12',
statusCode: 'SUB',
statusDescription: 'Submitted',
fileFormat: 'Excel file',
status: 'Submitted',
lastUpdated: '1 minute ago'
lastUpdated: '-',
lastUpdatedLabel: '1 minute ago'
},
{
activityType: 'Opening spatial',
openingId: '13',
statusCode: 'APP',
statusDescription: 'Approved',
fileFormat: 'CSV file',
status: 'Approved',
lastUpdated: 'Aug 20, 2023'
lastUpdated: '-',
lastUpdatedLabel: 'Aug 20, 2023'
},
{
activityType:'Opening spatial',
openingId: '14',
statusCode: 'APP',
statusDescription: 'Approved',
fileFormat: 'PDF file',
status:'Approved',
lastUpdated:'Nov 20, 2023'
lastUpdated: '-',
lastUpdatedLabel:'Nov 20, 2023'
},
{
activityType:'Opening details',
openingId: '15',
statusCode: 'PRG',
statusDescription: 'In progress',
fileFormat: 'Excel file',
status:'In progress',
lastUpdated:'Now'
lastUpdated: '-',
lastUpdatedLabel:'Now'
}
];

export const headers = [
export const headers: ITableHeader[] = [
{
key: 'activityType',
header: 'Activity Type'
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/components/MyRecentActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { TabList, Tabs, Tab, TabPanels, TabPanel } from "@carbon/react";
import ActionsTable from "../ActionsTable";
import { fetchRecentActions } from '../../services/OpeningService';
import { rows as fileRows, headers as fileHeaders } from "./filesData";
import { RecentAction } from '../../types/RecentAction';
import { ITableHeader } from '../../types/TableHeader';

const MyRecentActions: React.FC = () => {
const [recentActions, setRecentActions] = useState<any[]>([]);
const [recentActions, setRecentActions] = useState<RecentAction[]>([]);

const headers = [
const headers: ITableHeader[] = [
{
key: 'activityType',
header: 'Activity Type',
Expand All @@ -29,7 +31,7 @@ const MyRecentActions: React.FC = () => {
useEffect(() => {
async function fetchData() {
try {
const actions = await fetchRecentActions();
const actions: RecentAction[] = await fetchRecentActions();
setRecentActions(actions);
} catch (error) {
console.error('Error fetching recent actions:', error);
Expand Down
Loading
Loading