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

CSG-818: Replace Dashboard Table with new Data Table #21

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
110 changes: 77 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
},
"dependencies": {
"@metrostar/comet-data-viz": "1.1.1",
"@metrostar/comet-extras": "1.1.0",
"@metrostar/comet-extras": "1.2.0",
"@metrostar/comet-uswds": "1.4.0",
"@tanstack/react-query": "4.32.0",
"@tanstack/react-table": "8.9.3",
"@types/keycloak-js": "^3.4.1",
"@uswds/uswds": "3.6.0",
"axios": "1.4.0",
Expand All @@ -47,9 +48,10 @@
"@babel/preset-env": "7.22.9",
"@babel/preset-react": "7.22.5",
"@babel/preset-typescript": "7.22.5",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/jest-dom": "6.1.3",
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "14.4.3",
"@types/jest": "^29.5.4",
"@types/react": "18.2.17",
"@types/react-dom": "18.2.7",
"@typescript-eslint/eslint-plugin": "6.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dashboard/dashboard-table/dashboard-table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ describe('DashboardTable', () => {
await act(async () => {
expect(baseElement).toBeTruthy();
});
expect(baseElement.querySelector('.usa-table')).toBeDefined();
expect(baseElement.querySelector('.data-table')).toBeDefined();
expect(
baseElement.querySelectorAll('.usa-table > tbody > tr'),
baseElement.querySelectorAll('.data-table > tbody > tr'),
).toHaveLength(5);
});
});
72 changes: 41 additions & 31 deletions src/pages/dashboard/dashboard-table/dashboard-table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Table, TableColumn } from '@metrostar/comet-uswds';
import { DataTable } from '@metrostar/comet-extras';
import { ColumnDef } from '@tanstack/react-table';
import React, { useEffect, useState } from 'react';
import { NavLink } from 'react-router-dom';
import { Launch } from '../../../types/launch';
Expand All @@ -12,52 +13,61 @@ export const DashboardTable = ({
items,
}: DashboardTableProps): React.ReactElement => {
const [data, setData] = useState<LaunchData[]>();
const cols = React.useMemo<ColumnDef<LaunchData>[]>(
() => [
{
accessorKey: 'name',
header: 'Name',
cell: (info) => info.getValue(),
},
{
accessorKey: 'provider',
header: 'Service Provider',
cell: (info) => info.getValue(),
},
{
accessorKey: 'status',
header: 'Status',
cell: (info) => info.getValue(),
},
{
accessorKey: 'last_updated',
header: 'Last Updated',
cell: (info) => info.getValue(),
},
],
[],
);

useEffect(() => {
if (items) {
const newData: LaunchData[] = [];
items.forEach((item: Launch) => {
newData.push({
name: {
value: (
<NavLink
id={`details-link-${item.id}`}
to={`/details/${item.id}`}
>
{item.name}
</NavLink>
),
sortValue: item.status.name,
},
provider: {
value: item.launch_service_provider.name,
sortValue: item.launch_service_provider.name,
},
status: { value: item.status.name, sortValue: item.status.name },
last_updated: {
value: item.last_updated,
sortValue: item.last_updated,
},
name: (
<NavLink id={`details-link-${item.id}`} to={`/details/${item.id}`}>
{item.name}
</NavLink>
),
provider: item.launch_service_provider.name,
status: item.status.name,
last_updated: item.last_updated,
});
});
setData(newData);
}
}, [items]);

const columns: TableColumn[] = [
{ id: 'name', name: 'Name' },
{ id: 'provider', name: 'Service Provider' },
{ id: 'status', name: 'Status' },
{ id: 'last_updated', name: 'Last Updated' },
];

return data ? (
<Table
<DataTable
id="launch-table"
className="width-full"
columns={columns}
columns={cols}
data={data}
sortable
/>
sortCol="last_updated"
sortDir="desc"
></DataTable>
) : (
<></>
);
Expand Down
13 changes: 4 additions & 9 deletions src/pages/dashboard/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { ReactNode } from 'react';

export interface LaunchData {
provider: SortableDataCell;
name: SortableDataCell;
status: SortableDataCell;
last_updated: SortableDataCell;
}

export interface SortableDataCell {
value: string | ReactNode;
sortValue: string;
name: string | ReactNode;
provider: string;
status: string;
last_updated: string;
}

export interface ChartData {
Expand Down
Loading