@pautena/react-design-system 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -31
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/app-bar/app-bar.types.d.ts +2 -2
- package/dist/cjs/types/components/bullet/bullet.d.ts +1 -1
- package/dist/cjs/types/components/content/content.types.d.ts +3 -3
- package/dist/cjs/types/components/drawer/drawer.provider.d.ts +1 -1
- package/dist/cjs/types/components/drawer/drawer.types.d.ts +4 -4
- package/dist/cjs/types/components/enhanced-select/enhanced-select.d.ts +1 -2
- package/dist/cjs/types/components/header/header.dummy.d.ts +1 -1
- package/dist/cjs/types/components/header/header.types.d.ts +6 -6
- package/dist/cjs/types/components/label/label.d.ts +1 -1
- package/dist/cjs/types/components/link/link.d.ts +1 -1
- package/dist/cjs/types/components/placeholder/placeholder.d.ts +1 -1
- package/dist/cjs/types/components/query-container/query-container.d.ts +1 -1
- package/dist/cjs/types/components/sign-in/sign-in.d.ts +2 -3
- package/dist/cjs/types/components/tab/tab-card/tab-card.d.ts +3 -4
- package/dist/cjs/types/components/tab/tab-card/tab-card.dummy.d.ts +2 -3
- package/dist/cjs/types/components/table/enhanced-remote-table/enhanced-remote-table.d.ts +5 -6
- package/dist/cjs/types/components/table/enhanced-remote-table/enhanced-remote-table.mock.d.ts +6 -6
- package/dist/cjs/types/components/table/enhanced-table/enhanced-table-head.d.ts +8 -8
- package/dist/cjs/types/components/table/enhanced-table/enhanced-table.d.ts +2 -2
- package/dist/cjs/types/components/table/enhanced-table/enhanced-table.mock.d.ts +6 -7
- package/dist/cjs/types/components/table-list/table-list.d.ts +2 -2
- package/dist/cjs/types/components/value-displays/group-value-card/group-value-card.d.ts +7 -4
- package/dist/cjs/types/components/value-displays/group-value-card/group-value-card.mock.d.ts +2 -1
- package/dist/cjs/types/components/value-displays/index.d.ts +1 -0
- package/dist/cjs/types/components/value-displays/value-boolean/value-boolean.d.ts +3 -11
- package/dist/cjs/types/components/value-displays/value-card/value-card.d.ts +1 -1
- package/dist/cjs/types/components/value-displays/value-content/index.d.ts +1 -0
- package/dist/cjs/types/components/value-displays/value-content/value-content.d.ts +24 -0
- package/dist/cjs/types/components/value-displays/value-datetime/value-datetime.d.ts +3 -10
- package/dist/cjs/types/components/value-displays/value-displays.types.d.ts +15 -0
- package/dist/cjs/types/components/value-displays/value-image/index.d.ts +1 -0
- package/dist/cjs/types/components/value-displays/value-image/value-image.d.ts +11 -0
- package/dist/cjs/types/components/value-displays/value-text/value-text.d.ts +3 -11
- package/dist/cjs/types/generators/generators.mock.d.ts +2 -1
- package/dist/cjs/types/generators/generators.model.d.ts +36 -20
- package/dist/cjs/types/generators/generators.model.test.d.ts +1 -0
- package/dist/cjs/types/generators/model-router/model-router.d.ts +1 -1
- package/dist/cjs/types/generators/model-router/screens/add-screen.d.ts +1 -1
- package/dist/cjs/types/generators/model-router/screens/details-screen.d.ts +1 -1
- package/dist/cjs/types/generators/model-router/screens/list-screen.d.ts +1 -1
- package/dist/cjs/types/generators/model-router/screens/update-screen.d.ts +1 -1
- package/dist/cjs/types/layouts/header-layout/header-layout.d.ts +1 -2
- package/dist/cjs/types/providers/notification-center/notification-center.context.d.ts +0 -2
- package/dist/cjs/types/providers/notification-center/notification-center.provider.d.ts +1 -1
- package/dist/cjs/types/providers/tab-provider/tab-provider.provider.d.ts +1 -1
- package/dist/cjs/types/utils/theme.d.ts +1 -1
- package/dist/esm/index.js +1 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/app-bar/app-bar.types.d.ts +2 -2
- package/dist/esm/types/components/bullet/bullet.d.ts +1 -1
- package/dist/esm/types/components/content/content.types.d.ts +3 -3
- package/dist/esm/types/components/drawer/drawer.provider.d.ts +1 -1
- package/dist/esm/types/components/drawer/drawer.types.d.ts +4 -4
- package/dist/esm/types/components/enhanced-select/enhanced-select.d.ts +1 -2
- package/dist/esm/types/components/header/header.dummy.d.ts +1 -1
- package/dist/esm/types/components/header/header.types.d.ts +6 -6
- package/dist/esm/types/components/label/label.d.ts +1 -1
- package/dist/esm/types/components/link/link.d.ts +1 -1
- package/dist/esm/types/components/placeholder/placeholder.d.ts +1 -1
- package/dist/esm/types/components/query-container/query-container.d.ts +1 -1
- package/dist/esm/types/components/sign-in/sign-in.d.ts +2 -3
- package/dist/esm/types/components/tab/tab-card/tab-card.d.ts +3 -4
- package/dist/esm/types/components/tab/tab-card/tab-card.dummy.d.ts +2 -3
- package/dist/esm/types/components/table/enhanced-remote-table/enhanced-remote-table.d.ts +5 -6
- package/dist/esm/types/components/table/enhanced-remote-table/enhanced-remote-table.mock.d.ts +6 -6
- package/dist/esm/types/components/table/enhanced-table/enhanced-table-head.d.ts +8 -8
- package/dist/esm/types/components/table/enhanced-table/enhanced-table.d.ts +2 -2
- package/dist/esm/types/components/table/enhanced-table/enhanced-table.mock.d.ts +6 -7
- package/dist/esm/types/components/table-list/table-list.d.ts +2 -2
- package/dist/esm/types/components/value-displays/group-value-card/group-value-card.d.ts +7 -4
- package/dist/esm/types/components/value-displays/group-value-card/group-value-card.mock.d.ts +2 -1
- package/dist/esm/types/components/value-displays/index.d.ts +1 -0
- package/dist/esm/types/components/value-displays/value-boolean/value-boolean.d.ts +3 -11
- package/dist/esm/types/components/value-displays/value-card/value-card.d.ts +1 -1
- package/dist/esm/types/components/value-displays/value-content/index.d.ts +1 -0
- package/dist/esm/types/components/value-displays/value-content/value-content.d.ts +24 -0
- package/dist/esm/types/components/value-displays/value-datetime/value-datetime.d.ts +3 -10
- package/dist/esm/types/components/value-displays/value-displays.types.d.ts +15 -0
- package/dist/esm/types/components/value-displays/value-image/index.d.ts +1 -0
- package/dist/esm/types/components/value-displays/value-image/value-image.d.ts +11 -0
- package/dist/esm/types/components/value-displays/value-text/value-text.d.ts +3 -11
- package/dist/esm/types/generators/generators.mock.d.ts +2 -1
- package/dist/esm/types/generators/generators.model.d.ts +36 -20
- package/dist/esm/types/generators/generators.model.test.d.ts +1 -0
- package/dist/esm/types/generators/model-router/model-router.d.ts +1 -1
- package/dist/esm/types/generators/model-router/screens/add-screen.d.ts +1 -1
- package/dist/esm/types/generators/model-router/screens/details-screen.d.ts +1 -1
- package/dist/esm/types/generators/model-router/screens/list-screen.d.ts +1 -1
- package/dist/esm/types/generators/model-router/screens/update-screen.d.ts +1 -1
- package/dist/esm/types/layouts/header-layout/header-layout.d.ts +1 -2
- package/dist/esm/types/providers/notification-center/notification-center.context.d.ts +0 -2
- package/dist/esm/types/providers/notification-center/notification-center.provider.d.ts +1 -1
- package/dist/esm/types/providers/tab-provider/tab-provider.provider.d.ts +1 -1
- package/dist/esm/types/utils/theme.d.ts +1 -1
- package/dist/index.d.ts +155 -150
- package/package.json +58 -53
- package/src/components/app-bar/app-bar.stories.tsx +2 -1
- package/src/components/app-bar/app-bar.test.tsx +1 -1
- package/src/components/bullet/bullet.test.tsx +1 -1
- package/src/components/center-container/center-container.test.tsx +1 -1
- package/src/components/content/content.stories.tsx +1 -1
- package/src/components/content/content.test.tsx +1 -1
- package/src/components/drawer/__snapshots__/drawer.test.tsx.snap +3 -3
- package/src/components/drawer/drawer.test.tsx +8 -8
- package/src/components/drawer-content/drawer-content.stories.tsx +0 -1
- package/src/components/drawer-content/drawer-content.test.tsx +1 -1
- package/src/components/drawer-item/drawer-item.test.tsx +3 -3
- package/src/components/drawer-section/drawer-section.test.tsx +1 -1
- package/src/components/enhanced-select/enhanced-select.stories.tsx +10 -10
- package/src/components/enhanced-select/enhanced-select.test.tsx +9 -4
- package/src/components/enhanced-select/enhanced-select.tsx +1 -3
- package/src/components/header/header.dummy.ts +1 -1
- package/src/components/header/header.stories.tsx +0 -6
- package/src/components/header/header.test.tsx +1 -1
- package/src/components/label/label.test.tsx +1 -1
- package/src/components/link/link.tsx +2 -2
- package/src/components/loading-area/loading-area.test.tsx +2 -1
- package/src/components/placeholder/placeholder.test.tsx +3 -2
- package/src/components/query-container/query-container.test.tsx +2 -1
- package/src/components/sign-in/sign-in.test.tsx +2 -1
- package/src/components/sign-in/sign-in.tsx +3 -3
- package/src/components/tab/tab-card/tab-card.dummy.tsx +2 -2
- package/src/components/tab/tab-card/tab-card.stories.tsx +2 -2
- package/src/components/tab/tab-card/tab-card.test.tsx +1 -1
- package/src/components/tab/tab-card/tab-card.tsx +3 -3
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.mock.tsx +7 -6
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.test.tsx +3 -3
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.tsx +8 -8
- package/src/components/table/enhanced-table/enhanced-table-head.tsx +14 -9
- package/src/components/table/enhanced-table/enhanced-table.mock.tsx +12 -6
- package/src/components/table/enhanced-table/enhanced-table.test.tsx +6 -5
- package/src/components/table/enhanced-table/enhanced-table.tsx +8 -8
- package/src/components/table-list/table-list.stories.tsx +27 -17
- package/src/components/table-list/table-list.test.tsx +11 -6
- package/src/components/table-list/table-list.tsx +23 -12
- package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +2 -2
- package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +24 -1
- package/src/components/value-displays/group-value-card/group-value-card.test.tsx +7 -2
- package/src/components/value-displays/group-value-card/group-value-card.tsx +13 -4
- package/src/components/value-displays/index.ts +1 -0
- package/src/components/value-displays/value-boolean/value-boolean.test.tsx +15 -3
- package/src/components/value-displays/value-boolean/value-boolean.tsx +17 -17
- package/src/components/value-displays/value-card/value-card.test.tsx +1 -1
- package/src/components/value-displays/value-content/index.ts +1 -0
- package/src/components/value-displays/value-content/value-content.stories.tsx +20 -0
- package/src/components/value-displays/value-content/value-content.test.tsx +50 -0
- package/src/components/value-displays/value-content/value-content.tsx +55 -0
- package/src/components/value-displays/value-datetime/value-datetime.stories.tsx +13 -0
- package/src/components/value-displays/value-datetime/value-datetime.test.tsx +24 -5
- package/src/components/value-displays/value-datetime/value-datetime.tsx +15 -22
- package/src/components/value-displays/value-displays.types.ts +18 -0
- package/src/components/value-displays/value-image/index.ts +1 -0
- package/src/components/value-displays/value-image/value-image.stories.tsx +28 -0
- package/src/components/value-displays/value-image/value-image.test.tsx +22 -0
- package/src/components/value-displays/value-image/value-image.tsx +24 -0
- package/src/components/value-displays/value-text/value-text.stories.tsx +11 -0
- package/src/components/value-displays/value-text/value-text.test.tsx +19 -5
- package/src/components/value-displays/value-text/value-text.tsx +16 -22
- package/src/generators/generators.mock.ts +25 -22
- package/src/generators/generators.model.test.ts +77 -0
- package/src/generators/generators.model.ts +78 -6
- package/src/generators/model-form/model-form.test.tsx +11 -14
- package/src/generators/model-form/model-form.tsx +33 -65
- package/src/generators/model-router/model-router.test.tsx +45 -32
- package/src/generators/model-router/screens/add-screen.tsx +2 -1
- package/src/generators/model-router/screens/details-screen.tsx +2 -1
- package/src/generators/model-router/screens/list-screen.tsx +1 -1
- package/src/generators/model-router/screens/update-screen.tsx +4 -5
- package/src/generators/model-router/stories/model-router.stories.tsx +1 -1
- package/src/generators/object-details/object-details.test.tsx +2 -1
- package/src/generators/object-details/object-details.tsx +18 -9
- package/src/hooks/routing/routing.test.tsx +1 -1
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.stories.tsx +1 -1
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.test.tsx +2 -1
- package/src/layouts/header-layout/header-layout.stories.tsx +11 -4
- package/src/layouts/header-layout/header-layout.test.tsx +1 -1
- package/src/layouts/header-layout/header-layout.tsx +1 -1
- package/src/providers/notification-center/notification-center.context.ts +0 -6
- package/src/providers/notification-center/notification-center.stories.tsx +1 -1
- package/src/providers/notification-center/notification-center.test.tsx +6 -7
- package/src/storybook.tsx +1 -1
- package/src/tests/actions.ts +4 -0
- package/src/tests/assertions.ts +18 -10
- package/src/tests/components.tsx +35 -1
- package/src/tests/file-mock.ts +1 -0
- package/src/tests/mocks.ts +21 -0
- package/src/tests/testing-library.tsx +11 -8
- package/src/types/index.d.ts +4 -0
- package/src/tests/index.ts +0 -4
|
@@ -8,11 +8,11 @@ const StyledTabs = styled(Tabs)(({ theme }) => ({
|
|
|
8
8
|
},
|
|
9
9
|
}));
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export type TabCardProps = PropsWithChildren<{
|
|
12
12
|
tabs: string[];
|
|
13
|
-
}
|
|
13
|
+
}>;
|
|
14
14
|
|
|
15
|
-
export const TabCard = ({ children, tabs }:
|
|
15
|
+
export const TabCard = ({ children, tabs }: TabCardProps) => {
|
|
16
16
|
const [tab, setTab] = useTab();
|
|
17
17
|
return (
|
|
18
18
|
<Paper>
|
|
@@ -2,20 +2,21 @@ import React from "react";
|
|
|
2
2
|
import { TableCell, TableRow } from "@mui/material";
|
|
3
3
|
import { EnhancedRemoteTable } from "./enhanced-remote-table";
|
|
4
4
|
import { HeadCell, Order } from "../enhanced-table/enhanced-table-head";
|
|
5
|
+
import { Data } from "../enhanced-table/enhanced-table.mock";
|
|
5
6
|
|
|
6
|
-
interface
|
|
7
|
-
data:
|
|
7
|
+
export interface EnhancedRemoteDummyTableProps {
|
|
8
|
+
data: Data[];
|
|
8
9
|
loading: boolean;
|
|
9
|
-
defaultSort:
|
|
10
|
+
defaultSort: keyof Data;
|
|
10
11
|
defaultOrder?: Order;
|
|
11
|
-
columns: HeadCell[];
|
|
12
|
+
columns: HeadCell<Data>[];
|
|
12
13
|
onRequestSort: (col: string, orderBy: Order) => void;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export function EnhancedRemoteDummyTable
|
|
16
|
+
export function EnhancedRemoteDummyTable(props: EnhancedRemoteDummyTableProps) {
|
|
16
17
|
return (
|
|
17
18
|
<EnhancedRemoteTable {...props}>
|
|
18
|
-
{(d:
|
|
19
|
+
{(d: Data) => (
|
|
19
20
|
<TableRow key={d.id}>
|
|
20
21
|
<TableCell>{d.name}</TableCell>
|
|
21
22
|
<TableCell>{d.id}</TableCell>
|
|
@@ -2,13 +2,13 @@ import React from "react";
|
|
|
2
2
|
import { screen, render } from "@testing-library/react";
|
|
3
3
|
import { EnhancedRemoteDummyTable } from "./enhanced-remote-table.mock";
|
|
4
4
|
import userEvent from "@testing-library/user-event";
|
|
5
|
-
import { columns, data } from "../enhanced-table/enhanced-table.mock";
|
|
6
|
-
import { expectProgressIndicator } from "
|
|
5
|
+
import { columns, Data, data } from "../enhanced-table/enhanced-table.mock";
|
|
6
|
+
import { expectProgressIndicator } from "~/tests/assertions";
|
|
7
7
|
|
|
8
8
|
function renderInstance({
|
|
9
9
|
defaultSort = "startDate",
|
|
10
10
|
loading = false,
|
|
11
|
-
}: { defaultSort?:
|
|
11
|
+
}: { defaultSort?: keyof Data; loading?: boolean } = {}) {
|
|
12
12
|
const onRequestSort = jest.fn();
|
|
13
13
|
render(
|
|
14
14
|
<EnhancedRemoteDummyTable
|
|
@@ -10,14 +10,14 @@ import {
|
|
|
10
10
|
} from "@mui/material";
|
|
11
11
|
import { EnhancedTableHead, HeadCell, Order } from "../enhanced-table";
|
|
12
12
|
|
|
13
|
-
interface
|
|
13
|
+
export interface EnhancedRemoteTableProps<T> {
|
|
14
14
|
data: T[];
|
|
15
15
|
loading: boolean;
|
|
16
|
-
defaultSort:
|
|
16
|
+
defaultSort: keyof T;
|
|
17
17
|
defaultOrder?: Order;
|
|
18
|
-
columns: HeadCell[];
|
|
18
|
+
columns: HeadCell<T>[];
|
|
19
19
|
children: (data: T, index: number) => ReactNode;
|
|
20
|
-
onRequestSort: (col:
|
|
20
|
+
onRequestSort: (col: keyof T, orderBy: "asc" | "desc") => void;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const EnhancedRemoteTable = <T,>({
|
|
@@ -28,15 +28,15 @@ export const EnhancedRemoteTable = <T,>({
|
|
|
28
28
|
defaultSort,
|
|
29
29
|
defaultOrder,
|
|
30
30
|
onRequestSort,
|
|
31
|
-
}:
|
|
31
|
+
}: EnhancedRemoteTableProps<T>) => {
|
|
32
32
|
const [order, setOrder] = useState({
|
|
33
33
|
orderBy: defaultSort,
|
|
34
34
|
order: defaultOrder || "asc",
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
const handleRequestSort = (property:
|
|
38
|
-
setOrder((
|
|
39
|
-
const newOrder =
|
|
37
|
+
const handleRequestSort = (property: keyof T) => {
|
|
38
|
+
setOrder(({ orderBy, order }) => {
|
|
39
|
+
const newOrder = orderBy === property && order === "asc" ? "desc" : "asc";
|
|
40
40
|
onRequestSort(property, newOrder);
|
|
41
41
|
|
|
42
42
|
return {
|
|
@@ -3,23 +3,28 @@ import { TableSortLabel, TableRow, Box, TableCell, TableHead } from "@mui/materi
|
|
|
3
3
|
import { visuallyHidden } from "@mui/utils";
|
|
4
4
|
|
|
5
5
|
export type Order = "asc" | "desc";
|
|
6
|
-
export interface HeadCell {
|
|
6
|
+
export interface HeadCell<T> {
|
|
7
7
|
disablePadding: boolean;
|
|
8
|
-
id:
|
|
8
|
+
id: keyof T;
|
|
9
9
|
label: string;
|
|
10
10
|
numeric: boolean;
|
|
11
11
|
sort: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
interface
|
|
15
|
-
onRequestSort: (property:
|
|
14
|
+
interface EnhancedTableHeadProps<T> {
|
|
15
|
+
onRequestSort: (property: keyof T) => void;
|
|
16
16
|
order: Order;
|
|
17
|
-
orderBy:
|
|
18
|
-
headCells: HeadCell[];
|
|
17
|
+
orderBy: keyof T;
|
|
18
|
+
headCells: HeadCell<T>[];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export
|
|
22
|
-
|
|
21
|
+
export const EnhancedTableHead = <T,>({
|
|
22
|
+
order,
|
|
23
|
+
orderBy,
|
|
24
|
+
headCells,
|
|
25
|
+
onRequestSort,
|
|
26
|
+
}: EnhancedTableHeadProps<T>) => {
|
|
27
|
+
const createSortHandler = (property: keyof T) => () => {
|
|
23
28
|
onRequestSort(property);
|
|
24
29
|
};
|
|
25
30
|
|
|
@@ -55,4 +60,4 @@ export function EnhancedTableHead({ order, orderBy, headCells, onRequestSort }:
|
|
|
55
60
|
</TableRow>
|
|
56
61
|
</TableHead>
|
|
57
62
|
);
|
|
58
|
-
}
|
|
63
|
+
};
|
|
@@ -3,7 +3,7 @@ import { EnhancedTable } from ".";
|
|
|
3
3
|
import { TableCell, TableRow } from "@mui/material";
|
|
4
4
|
import { HeadCell, Order } from "./enhanced-table-head";
|
|
5
5
|
|
|
6
|
-
export const columns: HeadCell[] = [
|
|
6
|
+
export const columns: HeadCell<Data>[] = [
|
|
7
7
|
{
|
|
8
8
|
id: "name",
|
|
9
9
|
numeric: false,
|
|
@@ -27,7 +27,7 @@ export const columns: HeadCell[] = [
|
|
|
27
27
|
},
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
-
interface Data {
|
|
30
|
+
export interface Data {
|
|
31
31
|
id: number;
|
|
32
32
|
name: string;
|
|
33
33
|
startDate: string;
|
|
@@ -61,15 +61,21 @@ export const data: Data[] = [
|
|
|
61
61
|
},
|
|
62
62
|
];
|
|
63
63
|
|
|
64
|
-
interface
|
|
64
|
+
export interface TestTableProps {
|
|
65
65
|
data: Data[];
|
|
66
|
-
columns: HeadCell[];
|
|
67
|
-
defaultSort:
|
|
66
|
+
columns: HeadCell<Data>[];
|
|
67
|
+
defaultSort: keyof Data;
|
|
68
68
|
defaultOrder: Order;
|
|
69
69
|
loading: boolean;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export const TestTable = ({
|
|
72
|
+
export const TestTable = ({
|
|
73
|
+
data,
|
|
74
|
+
columns,
|
|
75
|
+
defaultOrder,
|
|
76
|
+
defaultSort,
|
|
77
|
+
loading,
|
|
78
|
+
}: TestTableProps) => {
|
|
73
79
|
return (
|
|
74
80
|
<EnhancedTable
|
|
75
81
|
search
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "~/tests/testing-library";
|
|
3
3
|
import { screen } from "@testing-library/react";
|
|
4
4
|
import userEvents from "@testing-library/user-event";
|
|
5
|
-
import { TestTable, columns, data } from "./enhanced-table.mock";
|
|
5
|
+
import { TestTable, columns, data, Data } from "./enhanced-table.mock";
|
|
6
|
+
import { expectProgressIndicator } from "~/tests/assertions";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
const renderInstance = ({
|
|
8
9
|
defaultSort = "startDate",
|
|
9
10
|
loading = false,
|
|
10
|
-
}: { defaultSort?:
|
|
11
|
+
}: { defaultSort?: keyof Data; loading?: boolean } = {}) => {
|
|
11
12
|
return render(
|
|
12
13
|
<TestTable
|
|
13
14
|
data={data}
|
|
@@ -17,7 +18,7 @@ function renderInstance({
|
|
|
17
18
|
loading={loading}
|
|
18
19
|
/>,
|
|
19
20
|
);
|
|
20
|
-
}
|
|
21
|
+
};
|
|
21
22
|
|
|
22
23
|
describe("EnhancedTable", () => {
|
|
23
24
|
it("all items are rendered in the correct order", async () => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
import React, { ChangeEvent } from "react";
|
|
3
2
|
import { ReactNode, useState } from "react";
|
|
4
3
|
import {
|
|
@@ -15,11 +14,12 @@ import {
|
|
|
15
14
|
import Search from "@mui/icons-material/Search";
|
|
16
15
|
import { EnhancedTableHead, HeadCell, Order } from "./enhanced-table-head";
|
|
17
16
|
|
|
18
|
-
function getFilter<T>(columns: HeadCell[], search: string) {
|
|
17
|
+
function getFilter<T>(columns: HeadCell<T>[], search: string) {
|
|
19
18
|
return (d: T) => {
|
|
20
19
|
return (
|
|
21
20
|
!search ||
|
|
22
21
|
columns.some((col) => {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
23
|
let value = (d as any)[col.id];
|
|
24
24
|
if (value?.toLowerCase) {
|
|
25
25
|
value = value.toLowerCase();
|
|
@@ -30,7 +30,7 @@ function getFilter<T>(columns: HeadCell[], search: string) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function getComparator(order: Order, orderBy:
|
|
33
|
+
function getComparator<T>(order: Order, orderBy: keyof T): (a: T, b: T) => number {
|
|
34
34
|
return order === "desc"
|
|
35
35
|
? (a, b) => descendingComparator(a, b, orderBy)
|
|
36
36
|
: (a, b) => -descendingComparator(a, b, orderBy);
|
|
@@ -48,10 +48,10 @@ function descendingComparator<T>(a: T, b: T, orderBy: keyof T) {
|
|
|
48
48
|
interface Props<T> {
|
|
49
49
|
readonly data: T[];
|
|
50
50
|
search?: boolean;
|
|
51
|
-
defaultSort:
|
|
51
|
+
defaultSort: keyof T;
|
|
52
52
|
defaultOrder?: Order;
|
|
53
53
|
loading?: boolean;
|
|
54
|
-
columns: HeadCell[];
|
|
54
|
+
columns: HeadCell<T>[];
|
|
55
55
|
children: (data: T[]) => ReactNode;
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -66,9 +66,9 @@ export const EnhancedTable = <T,>({
|
|
|
66
66
|
}: Props<T>) => {
|
|
67
67
|
const [searchFilter, setSearchFilter] = useState<string>("");
|
|
68
68
|
const [order, setOrder] = useState<Order>(defaultOrder);
|
|
69
|
-
const [orderBy, setOrderBy] = useState(defaultSort);
|
|
69
|
+
const [orderBy, setOrderBy] = useState<keyof T>(defaultSort);
|
|
70
70
|
|
|
71
|
-
const handleRequestSort = (property:
|
|
71
|
+
const handleRequestSort = (property: keyof T) => {
|
|
72
72
|
const isAsc = orderBy === property && order === "asc";
|
|
73
73
|
setOrder(isAsc ? "desc" : "asc");
|
|
74
74
|
setOrderBy(property);
|
|
@@ -95,7 +95,7 @@ export const EnhancedTable = <T,>({
|
|
|
95
95
|
</InputAdornment>
|
|
96
96
|
),
|
|
97
97
|
}}
|
|
98
|
-
onChange={(e: ChangeEvent<
|
|
98
|
+
onChange={(e: ChangeEvent<HTMLInputElement>) => setSearchFilter(e.target.value)}
|
|
99
99
|
/>
|
|
100
100
|
</Box>
|
|
101
101
|
)}
|
|
@@ -2,8 +2,9 @@ import React from "react";
|
|
|
2
2
|
import { useDemoData } from "@mui/x-data-grid-generator";
|
|
3
3
|
import { ComponentMeta } from "@storybook/react";
|
|
4
4
|
import { createTemplate } from "../../storybook";
|
|
5
|
-
import { TableList } from "./table-list";
|
|
5
|
+
import { TableList, TableListProps } from "./table-list";
|
|
6
6
|
import { action } from "@storybook/addon-actions";
|
|
7
|
+
import { BasicModelInstance } from "~/generators";
|
|
7
8
|
|
|
8
9
|
const maxColumns = 3;
|
|
9
10
|
|
|
@@ -15,23 +16,32 @@ export default {
|
|
|
15
16
|
},
|
|
16
17
|
} as ComponentMeta<typeof TableList>;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
maxColumns,
|
|
23
|
-
});
|
|
24
|
-
const { rows } = data;
|
|
25
|
-
const columns = data.columns.map(({ field, headerName }) => ({
|
|
26
|
-
id: field,
|
|
27
|
-
label: headerName,
|
|
28
|
-
sort: true,
|
|
29
|
-
disablePadding: false,
|
|
30
|
-
numeric: false,
|
|
31
|
-
}));
|
|
19
|
+
interface TemplateProps<T extends BasicModelInstance> extends TableListProps<T> {
|
|
20
|
+
size: number;
|
|
21
|
+
dataSetType: "Commodity" | "Employee";
|
|
22
|
+
}
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
})
|
|
24
|
+
const Template = createTemplate(
|
|
25
|
+
<T extends BasicModelInstance>({ dataSetType, size, ...rest }: TemplateProps<T>) => {
|
|
26
|
+
const { data } = useDemoData({
|
|
27
|
+
dataSet: dataSetType,
|
|
28
|
+
rowLength: size,
|
|
29
|
+
maxColumns,
|
|
30
|
+
});
|
|
31
|
+
const { rows } = data;
|
|
32
|
+
const columns = data.columns.map(({ field, headerName }) => ({
|
|
33
|
+
id: field,
|
|
34
|
+
label: headerName || "invalid",
|
|
35
|
+
sort: true,
|
|
36
|
+
disablePadding: false,
|
|
37
|
+
numeric: false,
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<TableList {...rest} columns={columns} data={rows as any} onClick={action("onClick row")} />
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
);
|
|
35
45
|
|
|
36
46
|
export const Default = Template.bind({});
|
|
37
47
|
Default.args = {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "~/tests/testing-library";
|
|
3
3
|
import { screen } from "@testing-library/react";
|
|
4
4
|
import userEvents from "@testing-library/user-event";
|
|
5
5
|
import { TableRowOption, TableList } from "./table-list";
|
|
6
6
|
import { HeadCell } from "../table/enhanced-table";
|
|
7
7
|
import { BasicModelInstance } from "../../generators";
|
|
8
|
+
import { expectProgressIndicator } from "~/tests/assertions";
|
|
8
9
|
|
|
9
|
-
const columns: HeadCell[] = [
|
|
10
|
+
const columns: HeadCell<BasicModelInstance>[] = [
|
|
10
11
|
{
|
|
11
12
|
id: "id",
|
|
12
13
|
numeric: true,
|
|
@@ -81,7 +82,7 @@ describe("TableList", () => {
|
|
|
81
82
|
defaultSort?: string;
|
|
82
83
|
loading?: boolean;
|
|
83
84
|
search?: boolean;
|
|
84
|
-
options?: TableRowOption<
|
|
85
|
+
options?: TableRowOption<BasicModelInstance>[];
|
|
85
86
|
onClick?: jest.Mock;
|
|
86
87
|
} = {}) => {
|
|
87
88
|
const instance = render(
|
|
@@ -109,8 +110,8 @@ describe("TableList", () => {
|
|
|
109
110
|
|
|
110
111
|
data.forEach(({ id, name, value }) => {
|
|
111
112
|
expect(screen.getByRole("cell", { name: id })).toBeInTheDocument();
|
|
112
|
-
expect(screen.getByRole("cell", { name: name })).toBeInTheDocument();
|
|
113
|
-
expect(screen.getByRole("cell", { name: value })).toBeInTheDocument();
|
|
113
|
+
expect(screen.getByRole("cell", { name: name as string })).toBeInTheDocument();
|
|
114
|
+
expect(screen.getByRole("cell", { name: value as string })).toBeInTheDocument();
|
|
114
115
|
});
|
|
115
116
|
});
|
|
116
117
|
|
|
@@ -149,7 +150,8 @@ describe("TableList", () => {
|
|
|
149
150
|
it("would render the items 2,3 and 4", async () => {
|
|
150
151
|
renderInstance({ search: true });
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
const search = screen.getByPlaceholderText(/search/i);
|
|
154
|
+
await userEvents.type(search, "a");
|
|
153
155
|
|
|
154
156
|
expect(screen.getByText(/item 2/i)).toBeInTheDocument();
|
|
155
157
|
expect(screen.getByText(/item 3/i)).toBeInTheDocument();
|
|
@@ -157,6 +159,8 @@ describe("TableList", () => {
|
|
|
157
159
|
|
|
158
160
|
expect(screen.queryByText(/item 1/i)).not.toBeInTheDocument();
|
|
159
161
|
expect(screen.queryByText(/item 5/i)).not.toBeInTheDocument();
|
|
162
|
+
|
|
163
|
+
await userEvents.clear(search);
|
|
160
164
|
});
|
|
161
165
|
|
|
162
166
|
it("would render all the items if I remove the search", async () => {
|
|
@@ -228,6 +232,7 @@ describe("TableList", () => {
|
|
|
228
232
|
await userEvents.click(screen.getByRole("row", { name: /item 3/i }));
|
|
229
233
|
});
|
|
230
234
|
|
|
235
|
+
// TODO: this tests are throwing a console.error
|
|
231
236
|
describe("options menu", () => {
|
|
232
237
|
it("would render a button to open the menu if doesn't have options", () => {
|
|
233
238
|
renderInstance({ options: undefined });
|
|
@@ -2,7 +2,7 @@ import { TableRow, TableCell, IconButton, MenuItem, Menu } from "@mui/material";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { EnhancedTable, HeadCell, Order } from "../table/enhanced-table";
|
|
4
4
|
import MoreVertIcon from "@mui/icons-material/MoreVert";
|
|
5
|
-
import { BasicModelInstance } from "
|
|
5
|
+
import { BasicModelInstance } from "../../generators/generators.model";
|
|
6
6
|
|
|
7
7
|
const OptionsId = "__options";
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ export interface TableRowOption<T extends BasicModelInstance> {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface TableListProps<T extends BasicModelInstance> {
|
|
16
|
-
columns: HeadCell[];
|
|
16
|
+
columns: HeadCell<T>[];
|
|
17
17
|
data: T[];
|
|
18
18
|
search?: boolean;
|
|
19
19
|
defaultSort: string;
|
|
@@ -23,6 +23,7 @@ export interface TableListProps<T extends BasicModelInstance> {
|
|
|
23
23
|
onClick?: (d: T) => void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// TODO: Move this to teh generators section
|
|
26
27
|
export const TableList = <T extends BasicModelInstance>({
|
|
27
28
|
columns: columnsProp,
|
|
28
29
|
options,
|
|
@@ -33,19 +34,19 @@ export const TableList = <T extends BasicModelInstance>({
|
|
|
33
34
|
defaultOrder,
|
|
34
35
|
loading,
|
|
35
36
|
}: TableListProps<T>) => {
|
|
36
|
-
const columns =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
40
|
-
if (options && !columns.some((c) => c.id === OptionsId)) {
|
|
41
|
-
columns.push({
|
|
37
|
+
const columns = [
|
|
38
|
+
...columnsProp,
|
|
39
|
+
{
|
|
42
40
|
id: OptionsId,
|
|
43
41
|
label: "",
|
|
44
42
|
disablePadding: false,
|
|
45
43
|
numeric: false,
|
|
46
44
|
sort: false,
|
|
47
|
-
}
|
|
48
|
-
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
const [anchorMenuEl, setAnchorMenuEl] = React.useState<null | { item: T; anchor: HTMLElement }>(
|
|
48
|
+
null,
|
|
49
|
+
);
|
|
49
50
|
|
|
50
51
|
return (
|
|
51
52
|
<>
|
|
@@ -68,8 +69,18 @@ export const TableList = <T extends BasicModelInstance>({
|
|
|
68
69
|
sx={{ cursor: onClick && "pointer" }}
|
|
69
70
|
>
|
|
70
71
|
{columns.map(({ id }, j) => (
|
|
71
|
-
<TableCell
|
|
72
|
-
|
|
72
|
+
<TableCell
|
|
73
|
+
role="cell"
|
|
74
|
+
scope="row"
|
|
75
|
+
key={id.toString()}
|
|
76
|
+
aria-rowindex={i}
|
|
77
|
+
aria-colindex={j}
|
|
78
|
+
>
|
|
79
|
+
{
|
|
80
|
+
row[
|
|
81
|
+
id
|
|
82
|
+
] as string /* TODO: This has to be reimplemented having a cell based on each model type */
|
|
83
|
+
}
|
|
73
84
|
</TableCell>
|
|
74
85
|
))}
|
|
75
86
|
{options && (
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ValueBoolean } from "../value-boolean/value-boolean";
|
|
3
3
|
import { ValueText } from "../value-text";
|
|
4
|
-
import { GroupValueCard, GroupValueItem } from "./group-value-card";
|
|
4
|
+
import { GroupValueCard, GroupValueCardProps, GroupValueItem } from "./group-value-card";
|
|
5
5
|
|
|
6
|
-
export const GroupValueCardDummy = (props) => {
|
|
6
|
+
export const GroupValueCardDummy = (props: GroupValueCardProps) => {
|
|
7
7
|
return (
|
|
8
8
|
<GroupValueCard {...props}>
|
|
9
9
|
<GroupValueItem xs={12} sm={6} md={4}>
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { ComponentMeta } from "@storybook/react";
|
|
2
|
-
import { GroupValueCard } from "./group-value-card";
|
|
2
|
+
import { GroupValueCard, GroupValueItem } from "./group-value-card";
|
|
3
3
|
import { createTemplate, withPadding } from "../../../storybook";
|
|
4
4
|
import { GroupValueCardDummy } from "./group-value-card.mock";
|
|
5
|
+
import { ValueImage } from "../value-image";
|
|
6
|
+
import workInProgressImg from "../../../stories/assets/work-in-progress.jpg";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { ValueContent } from "../value-content";
|
|
9
|
+
import { DatatablePlaceholder } from "~/tests/components";
|
|
5
10
|
|
|
6
11
|
export default {
|
|
7
12
|
title: "Value displays/GroupValueCard",
|
|
@@ -24,3 +29,21 @@ export const WihtoutSubtitle = Template.bind({});
|
|
|
24
29
|
WihtoutSubtitle.args = {
|
|
25
30
|
title: "Hello world",
|
|
26
31
|
};
|
|
32
|
+
|
|
33
|
+
export const WithImage = () => (
|
|
34
|
+
<GroupValueCard centered title="Hello world" subtitle="Lorem ipsum sit amet">
|
|
35
|
+
<GroupValueItem xs={12} bordered={false}>
|
|
36
|
+
<ValueImage label="Lorem ipsum" value={workInProgressImg} />
|
|
37
|
+
</GroupValueItem>
|
|
38
|
+
</GroupValueCard>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const WithDataTable = () => (
|
|
42
|
+
<GroupValueCard title="Hello world" subtitle="Lorem ipsum sit amet">
|
|
43
|
+
<GroupValueItem xs={12} bordered={false}>
|
|
44
|
+
<ValueContent label="lorem ipsum">
|
|
45
|
+
<DatatablePlaceholder />
|
|
46
|
+
</ValueContent>
|
|
47
|
+
</GroupValueItem>
|
|
48
|
+
</GroupValueCard>
|
|
49
|
+
);
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { render, screen } from "
|
|
1
|
+
import { render, screen } from "~/tests/testing-library";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { GroupValueCardDummy } from "./group-value-card.mock";
|
|
4
|
+
import { Placeholder } from "~/tests/components";
|
|
4
5
|
|
|
5
6
|
describe("GroupValueCard", () => {
|
|
6
7
|
const renderComponent = ({
|
|
7
8
|
title = "Hello world",
|
|
8
9
|
subtitle = undefined,
|
|
9
10
|
}: { title?: string; subtitle?: string } = {}) => {
|
|
10
|
-
return render(
|
|
11
|
+
return render(
|
|
12
|
+
<GroupValueCardDummy title={title} subtitle={subtitle}>
|
|
13
|
+
<Placeholder />
|
|
14
|
+
</GroupValueCardDummy>,
|
|
15
|
+
);
|
|
11
16
|
};
|
|
12
17
|
it("would render a title", () => {
|
|
13
18
|
renderComponent({ title: "Hello world" });
|
|
@@ -2,7 +2,9 @@ import { Grid, Paper, GridProps, Box, Typography } from "@mui/material";
|
|
|
2
2
|
import React, { FunctionComponent, PropsWithChildren, ReactElement } from "react";
|
|
3
3
|
import { useGetDefaultThemeColor } from "../../../utils/theme";
|
|
4
4
|
|
|
5
|
-
export type GroupValueItemProps = PropsWithChildren<
|
|
5
|
+
export type GroupValueItemProps = PropsWithChildren<
|
|
6
|
+
Omit<GridProps, "item" | "container"> & { bordered?: boolean }
|
|
7
|
+
>;
|
|
6
8
|
export type GroupValueItemComponent = FunctionComponent<GroupValueItemProps>;
|
|
7
9
|
export type GroupValueItemElement = ReactElement<GroupValueItemProps, GroupValueItemComponent>;
|
|
8
10
|
|
|
@@ -12,6 +14,7 @@ export const groupValueItemClasses = {
|
|
|
12
14
|
|
|
13
15
|
export const GroupValueItem: GroupValueItemComponent = ({
|
|
14
16
|
children,
|
|
17
|
+
bordered = true,
|
|
15
18
|
...rest
|
|
16
19
|
}: GroupValueItemProps) => {
|
|
17
20
|
const defaultColor = useGetDefaultThemeColor({ lightWeight: 200, darkWeight: 800 });
|
|
@@ -21,7 +24,7 @@ export const GroupValueItem: GroupValueItemComponent = ({
|
|
|
21
24
|
<Box
|
|
22
25
|
px={1}
|
|
23
26
|
sx={{
|
|
24
|
-
borderLeft: `solid ${defaultColor} 1px
|
|
27
|
+
borderLeft: bordered ? `solid ${defaultColor} 1px` : "none",
|
|
25
28
|
}}
|
|
26
29
|
>
|
|
27
30
|
{children}
|
|
@@ -33,10 +36,11 @@ export const GroupValueItem: GroupValueItemComponent = ({
|
|
|
33
36
|
export interface GroupValueCardProps {
|
|
34
37
|
title: string;
|
|
35
38
|
subtitle?: string;
|
|
39
|
+
centered?: boolean;
|
|
36
40
|
children: GroupValueItemElement | GroupValueItemElement[];
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
export const GroupValueCard = ({ title, subtitle, children }: GroupValueCardProps) => {
|
|
43
|
+
export const GroupValueCard = ({ title, subtitle, centered, children }: GroupValueCardProps) => {
|
|
40
44
|
const defaultColor = useGetDefaultThemeColor({ lightWeight: 200, darkWeight: 800 });
|
|
41
45
|
|
|
42
46
|
return (
|
|
@@ -55,7 +59,12 @@ export const GroupValueCard = ({ title, subtitle, children }: GroupValueCardProp
|
|
|
55
59
|
</Typography>
|
|
56
60
|
)}
|
|
57
61
|
</Box>
|
|
58
|
-
<Grid
|
|
62
|
+
<Grid
|
|
63
|
+
container
|
|
64
|
+
padding={1}
|
|
65
|
+
rowSpacing={2}
|
|
66
|
+
justifyContent={centered ? "center" : "flex-start"}
|
|
67
|
+
>
|
|
59
68
|
{children}
|
|
60
69
|
</Grid>
|
|
61
70
|
</Paper>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ValueBoolean } from "./value-boolean";
|
|
3
|
-
import { render, screen } from "
|
|
3
|
+
import { render, screen } from "~/tests/testing-library";
|
|
4
4
|
|
|
5
5
|
describe("ValueBoolean", () => {
|
|
6
|
-
const renderComponent = ({ value }: { value
|
|
7
|
-
return render(<ValueBoolean label="Hello world" value={value} />);
|
|
6
|
+
const renderComponent = ({ value, placeholder }: { value?: boolean; placeholder?: string }) => {
|
|
7
|
+
return render(<ValueBoolean label="Hello world" value={value} placeholder={placeholder} />);
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
it("would render the label", () => {
|
|
@@ -24,4 +24,16 @@ describe("ValueBoolean", () => {
|
|
|
24
24
|
|
|
25
25
|
expect(screen.getByTestId("CloseIcon")).toBeInTheDocument();
|
|
26
26
|
});
|
|
27
|
+
|
|
28
|
+
it("should render the placeholder if value is undefined", () => {
|
|
29
|
+
renderComponent({ value: undefined });
|
|
30
|
+
|
|
31
|
+
expect(screen.getByText(/-/i)).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should render the custom placeholder if value is undefined and placeholder has value", () => {
|
|
35
|
+
renderComponent({ value: undefined, placeholder: "_" });
|
|
36
|
+
|
|
37
|
+
expect(screen.getByText(/_/i)).toBeInTheDocument();
|
|
38
|
+
});
|
|
27
39
|
});
|