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

feat: reuse Table component everywhere #1403

Merged
merged 28 commits into from
Aug 17, 2022
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
647e719
feat: add common table skeleton
dogfrogfog Aug 12, 2022
d953ff9
feat: moved table sort state from flamegraph renderer
dogfrogfog Aug 12, 2022
9731395
fix: remove duplicated styles from profile table component
dogfrogfog Aug 15, 2022
2570979
feat: add props to common table component
dogfrogfog Aug 15, 2022
e8a0b79
feat: reuse common table component for flamegraph profile table
dogfrogfog Aug 15, 2022
c5e5506
feat: add sort arrays to common table
dogfrogfog Aug 15, 2022
bd13784
fix: profile table tooltip, duplicated css styles
dogfrogfog Aug 15, 2022
7ed49fd
feat: reuse common table component for tag explorer table
dogfrogfog Aug 15, 2022
9fde717
feat: use common table for /settings/users table
dogfrogfog Aug 15, 2022
5a4f9c2
fix: styles for users table
dogfrogfog Aug 16, 2022
31a260c
feat: use common Table for apiKeys table
dogfrogfog Aug 16, 2022
f7031ea
feat: add common Table component to AdHoc FileList component
dogfrogfog Aug 16, 2022
b276114
fix: user table styles and types
dogfrogfog Aug 16, 2022
6a244a6
feat: add explorer page Loading state
dogfrogfog Aug 16, 2022
9332e2d
fix: FileList types
dogfrogfog Aug 16, 2022
0cd18ed
feat: add unsupported error message if viewDiff not equal to total/se…
dogfrogfog Aug 16, 2022
9e72250
feat: add default sort params, remove useTableSort call from tables w…
dogfrogfog Aug 17, 2022
78d4a1e
fix: remove ts-ignore, remove useTableSort hook from tag explorer pag…
dogfrogfog Aug 17, 2022
1e8f6cb
fix: types
dogfrogfog Aug 17, 2022
d4844f5
fix: lint
dogfrogfog Aug 17, 2022
b87be12
Merge branch 'main' into feature/add-common-table-component
dogfrogfog Aug 17, 2022
6701bc7
fix: jest
dogfrogfog Aug 17, 2022
d97aa1a
fix: test ids
dogfrogfog Aug 17, 2022
f0cd65c
feat: add optional default table sort column
dogfrogfog Aug 17, 2022
36c6c43
fix: lint
dogfrogfog Aug 17, 2022
7353eec
fix: remove webapp devDep from flamegraph package.json
dogfrogfog Aug 17, 2022
177d2f3
fix: adhoc table default column
dogfrogfog Aug 17, 2022
d69e9c8
fix: eslint and settings cy
dogfrogfog Aug 17, 2022
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
Prev Previous commit
Next Next commit
fix: FileList types
dogfrogfog committed Aug 16, 2022
commit 9332e2d834b202a3363745adb33d7ae255a95cf1
27 changes: 15 additions & 12 deletions webapp/javascript/components/FileList.tsx
Original file line number Diff line number Diff line change
@@ -3,9 +3,8 @@ import React, { useMemo } from 'react';
import { Maybe } from '@webapp/util/fp';
import { AllProfiles } from '@webapp/models/adhoc';
import TableUI, { useTableSort, BodyRow } from '@webapp/ui/Table';
// eslint-disable-next-line css-modules/no-unused-class
import styles from './FileList.module.scss';
import CheckIcon from './CheckIcon';
import styles from './FileList.module.scss';

const dateModifiedColName = 'updatedAt';
const fileNameColName = 'name';
@@ -69,28 +68,26 @@ function FileList(props: FileListProps) {
selectedProfileId,
} = props;

const tableProps = useTableSort(headRow);
const { sortBy, sortByDirection, ...rest } = useTableSort(headRow);
const sortedProfilesIds = useMemo(() => {
const m = tableProps.sortByDirection === 'asc' ? 1 : -1;
const m = sortByDirection === 'asc' ? 1 : -1;

let sorted: AllProfiles[number][] = [];

if (profiles) {
const filesInfo = Object.values(profiles);

switch (tableProps.sortBy) {
switch (sortBy) {
case fileNameColName:
sorted = filesInfo.sort(
(a, b) =>
m * a[tableProps.sortBy].localeCompare(b[tableProps.sortBy])
(a, b) => m * a[sortBy].localeCompare(b[sortBy])
);
break;
case dateModifiedColName:
sorted = filesInfo.sort(
(a, b) =>
m *
(new Date(a[tableProps.sortBy]).getTime() -
new Date(b[tableProps.sortBy]).getTime())
(new Date(a[sortBy]).getTime() - new Date(b[sortBy]).getTime())
);
break;
default:
@@ -99,22 +96,28 @@ function FileList(props: FileListProps) {
}

return sorted;
}, [profiles, tableProps.sortBy, tableProps.sortByDirection]);
}, [profiles, sortBy, sortByDirection]);

const tableBodyProps = profiles
? {
type: 'filled' as const,
bodyRows: getBodyRows(
sortedProfilesIds,
onProfileSelected,
selectedProfileId
),
}
: { error: { value: '' } };
: { type: 'not-filled' as const, value: '' };

return (
<>
<div className={`${styles.tableContainer} ${className}`}>
<TableUI {...tableProps} table={{ headRow, ...tableBodyProps }} />
<TableUI
sortBy={sortBy}
sortByDirection={sortByDirection}
table={{ headRow, ...tableBodyProps }}
{...rest}
/>
</div>
</>
);