@pautena/react-design-system 0.7.1 → 0.7.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.
Files changed (58) hide show
  1. package/dist/cjs/index.js +4 -4
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/components/alerts/expandable-alert/expandable-alert.d.ts +4 -1
  4. package/dist/cjs/types/components/data-display/board/board.d.ts +1 -2
  5. package/dist/cjs/types/components/feedback/query-container/query-container.d.ts +7 -3
  6. package/dist/cjs/types/components/inputs/index.d.ts +1 -0
  7. package/dist/cjs/types/components/placeholders/placeholder/placeholder.d.ts +2 -1
  8. package/dist/cjs/types/components/value-displays/group-value-card/group-value-card.mock.d.ts +3 -1
  9. package/dist/cjs/types/components/value-displays/value-base/value-edit.d.ts +7 -2
  10. package/dist/cjs/types/components/value-displays/value-content/value-content.d.ts +10 -1
  11. package/dist/cjs/types/layouts/header-layout/header-layout.d.ts +9 -2
  12. package/dist/esm/index.js +4 -4
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/types/components/alerts/expandable-alert/expandable-alert.d.ts +4 -1
  15. package/dist/esm/types/components/data-display/board/board.d.ts +1 -2
  16. package/dist/esm/types/components/feedback/query-container/query-container.d.ts +7 -3
  17. package/dist/esm/types/components/inputs/index.d.ts +1 -0
  18. package/dist/esm/types/components/placeholders/placeholder/placeholder.d.ts +2 -1
  19. package/dist/esm/types/components/value-displays/group-value-card/group-value-card.mock.d.ts +3 -1
  20. package/dist/esm/types/components/value-displays/value-base/value-edit.d.ts +7 -2
  21. package/dist/esm/types/components/value-displays/value-content/value-content.d.ts +10 -1
  22. package/dist/esm/types/layouts/header-layout/header-layout.d.ts +9 -2
  23. package/dist/index.d.ts +36 -11
  24. package/package.json +2 -1
  25. package/src/components/alerts/expandable-alert/expandable-alert.stories.tsx +23 -1
  26. package/src/components/alerts/expandable-alert/expandable-alert.tsx +11 -4
  27. package/src/components/data-display/board/board.test.tsx +60 -43
  28. package/src/components/data-display/board/board.tsx +13 -16
  29. package/src/components/feedback/feedback.stories.mdx +1 -0
  30. package/src/components/feedback/query-container/query-container.stories.tsx +19 -6
  31. package/src/components/feedback/query-container/query-container.test.tsx +41 -17
  32. package/src/components/feedback/query-container/query-container.tsx +17 -5
  33. package/src/components/inputs/index.ts +1 -0
  34. package/src/components/placeholders/placeholder/placeholder.tsx +3 -1
  35. package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +28 -8
  36. package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +19 -2
  37. package/src/components/value-displays/group-value-card/group-value-card.test.tsx +16 -18
  38. package/src/components/value-displays/value-base/value-edit.test.tsx +88 -0
  39. package/src/components/value-displays/value-base/value-edit.tsx +28 -6
  40. package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +9 -0
  41. package/src/components/value-displays/value-boolean/value-boolean.test.tsx +29 -15
  42. package/src/components/value-displays/value-boolean/value-boolean.tsx +18 -11
  43. package/src/components/value-displays/value-content/value-content.test.tsx +20 -6
  44. package/src/components/value-displays/value-content/value-content.tsx +24 -10
  45. package/src/components/value-displays/value-datetime/value-datetime.stories.tsx +11 -0
  46. package/src/components/value-displays/value-datetime/value-datetime.test.tsx +9 -9
  47. package/src/components/value-displays/value-datetime/value-datetime.tsx +14 -10
  48. package/src/components/value-displays/value-rating/value-rating.stories.tsx +10 -0
  49. package/src/components/value-displays/value-rating/value-rating.test.tsx +11 -11
  50. package/src/components/value-displays/value-rating/value-rating.tsx +10 -8
  51. package/src/components/value-displays/value-text/value-text.stories.tsx +9 -0
  52. package/src/components/value-displays/value-text/value-text.test.tsx +20 -9
  53. package/src/components/value-displays/value-text/value-text.tsx +23 -10
  54. package/src/generators/model-form/model-form.test.tsx +1 -1
  55. package/src/generators/model-router/model-router.test.tsx +3 -3
  56. package/src/layouts/header-layout/header-layout.stories.tsx +30 -2
  57. package/src/layouts/header-layout/header-layout.test.tsx +73 -8
  58. package/src/layouts/header-layout/header-layout.tsx +30 -4
@@ -1,14 +1,14 @@
1
- import { IconButton, TextField, Typography } from "@mui/material";
2
- import React from "react";
1
+ import { Typography, TextField } from "@mui/material";
2
+ import React, { useEffect, useRef } from "react";
3
3
  import {
4
4
  BaseValueProps,
5
5
  DefaultPlaceholder,
6
6
  EditableValueProps,
7
7
  useEditableValueDisplay,
8
+ ValueEditButton,
8
9
  ValueEditButtons,
9
10
  } from "../value-base";
10
11
  import { getValueContentLabelId, ValueContent } from "../value-content";
11
- import EditIcon from "@mui/icons-material/Edit";
12
12
 
13
13
  export type ValueTextProps = BaseValueProps<string | number> & EditableValueProps<string>;
14
14
 
@@ -23,30 +23,43 @@ export const ValueText = ({
23
23
  dense,
24
24
  onEdit = () => null,
25
25
  }: ValueTextProps) => {
26
+ const editInputRef = useRef<HTMLInputElement>(null);
26
27
  const { isEditing, editValue, startEdit, cancelEdit, setEditValue, submitEdit } =
27
28
  useEditableValueDisplay(valueProp?.toString(), onEdit);
28
29
  const id = getValueContentLabelId(label);
29
30
  const value = valueProp?.toString() || placeholder;
30
31
 
32
+ const editKeyPressListener = (e: KeyboardEvent) => {
33
+ if (e.key === "Enter") {
34
+ onEdit((e.target as any).value);
35
+ }
36
+ };
37
+
38
+ useEffect(() => {
39
+ editInputRef.current?.addEventListener("keypress", editKeyPressListener);
40
+ return () => editInputRef.current?.removeEventListener("keypress", editKeyPressListener);
41
+ }, [editInputRef.current]);
42
+
31
43
  return (
32
- <ValueContent label={label} tooltip={value} dense={dense}>
44
+ <ValueContent hideLabel={isEditing} label={label} tooltip={value} dense={dense}>
33
45
  {isEditing ? (
34
46
  <TextField
47
+ inputRef={editInputRef}
35
48
  value={editValue}
49
+ label={label}
36
50
  size="small"
37
51
  onChange={(e) => setEditValue(e.target.value)}
38
52
  InputProps={{
39
- endAdornment: <ValueEditButtons onClickCancel={cancelEdit} onSubmitEdit={submitEdit} />,
53
+ endAdornment: (
54
+ <ValueEditButtons onClickCancel={cancelEdit} onClickSubmit={submitEdit} />
55
+ ),
40
56
  }}
57
+ sx={{ marginY: !dense ? 1 : 0 }}
41
58
  />
42
59
  ) : (
43
60
  <Typography variant={dense ? "body1" : "h5"} noWrap aria-labelledby={id}>
44
61
  {value}
45
- {editable && (
46
- <IconButton size="small" onClick={startEdit} sx={{ ml: 1 }}>
47
- <EditIcon />
48
- </IconButton>
49
- )}
62
+ {editable && <ValueEditButton dense={dense} onClick={startEdit} />}
50
63
  </Typography>
51
64
  )}
52
65
  </ValueContent>
@@ -115,5 +115,5 @@ describe("ModelForm", () => {
115
115
  codes: ["foo", "bar"],
116
116
  identifiers: ["1", "2", "3"],
117
117
  });
118
- });
118
+ }, 20000);
119
119
  });
@@ -711,7 +711,7 @@ describe("ModelRouter", () => {
711
711
  const newInstance = await actions.fullfillModelForm({ model, submit: false });
712
712
 
713
713
  expectModelFieldInputValue(model.fields, newInstance);
714
- });
714
+ }, 20000);
715
715
 
716
716
  it("would make a request when the form is submitted", async () => {
717
717
  const { onSubmitNewItem, model } = await renderComponent({ screen: "add" });
@@ -721,7 +721,7 @@ describe("ModelRouter", () => {
721
721
  expectToHaveBeenCalledOnceWithMockInstance(onSubmitNewItem, {
722
722
  ...newInstance,
723
723
  });
724
- });
724
+ }, 20000);
725
725
 
726
726
  it("would show a loading indicator when the request is in progress", async () => {
727
727
  const { model } = await renderComponent({ screen: "add" });
@@ -729,7 +729,7 @@ describe("ModelRouter", () => {
729
729
  await actions.fullfillModelForm({ model, submit: true });
730
730
 
731
731
  expectProgressIndicator();
732
- });
732
+ }, 20000);
733
733
 
734
734
  it("would show a success message if the request finish with a success", async () => {
735
735
  renderAddScreen();
@@ -1,7 +1,7 @@
1
1
  import React, { ReactElement } from "react";
2
2
  import { Meta, StoryObj } from "@storybook/react";
3
3
  import { HeaderLayout, HeaderLayoutProps } from "./header-layout";
4
- import { withMemoryRouter } from "~/storybook";
4
+ import { withLocalizationProvider, withMemoryRouter } from "~/storybook";
5
5
  import { withFullHeight } from "../../storybook";
6
6
  import { Content, Header, HeaderProps, HeaderTab, SkeletonGrid, TabPanel } from "../../components";
7
7
  import { Box, Typography } from "@mui/material";
@@ -64,7 +64,7 @@ const DummyHeaderLayout = ({ headerProps, contentChildren, ...rest }: HeaderLayo
64
64
  export default {
65
65
  title: "Layouts/HeaderLayout",
66
66
  component: DummyHeaderLayout,
67
- decorators: [withMemoryRouter(), withFullHeight],
67
+ decorators: [withMemoryRouter(), withFullHeight, withLocalizationProvider],
68
68
  parameters: {
69
69
  layout: "fullscreen",
70
70
  },
@@ -215,3 +215,31 @@ export const Loading: Story = {
215
215
  contentChildren: <SkeletonGrid />,
216
216
  },
217
217
  };
218
+
219
+ export const Fetching: Story = {
220
+ args: {
221
+ fetching: true,
222
+ headerProps: {
223
+ title: "Lorem ipsum",
224
+ subtitle: "Dolor sit amet",
225
+ breadcrumbs,
226
+ actions,
227
+ },
228
+ contentChildren: <SkeletonGrid />,
229
+ },
230
+ };
231
+
232
+ export const Error: Story = {
233
+ args: {
234
+ error: {
235
+ message: "There is no user with that id",
236
+ },
237
+ headerProps: {
238
+ title: "Lorem ipsum",
239
+ subtitle: "Dolor sit amet",
240
+ breadcrumbs,
241
+ actions,
242
+ },
243
+ contentChildren: <SkeletonGrid />,
244
+ },
245
+ };
@@ -1,13 +1,18 @@
1
1
  import React from "react";
2
- import { HeaderLayout } from "./header-layout";
2
+ import { HeaderLayout, HeaderLayoutError } from "./header-layout";
3
3
  import { render, screen } from "~/tests/testing-library";
4
4
  import { Content, Header } from "../../components";
5
5
  import { Typography } from "@mui/material";
6
+ import { expectProgressIndicator } from "~/tests/assertions";
6
7
 
7
8
  describe("HeaderLayout", () => {
8
- const renderComponent = () => {
9
+ const renderComponent = ({
10
+ loading,
11
+ fetching,
12
+ error,
13
+ }: { loading?: boolean; fetching?: boolean; error?: HeaderLayoutError } = {}) => {
9
14
  return render(
10
- <HeaderLayout>
15
+ <HeaderLayout loading={loading} fetching={fetching} error={error}>
11
16
  <Header title="Lorem ipsum" subtitle="Dolor sit amet" />
12
17
  <Content>
13
18
  <Typography>Test content</Typography>
@@ -16,22 +21,82 @@ describe("HeaderLayout", () => {
16
21
  );
17
22
  };
18
23
 
19
- it("would render the header", () => {
24
+ it("should render the header", () => {
20
25
  renderComponent();
21
26
 
22
27
  expect(screen.getByRole("heading", { level: 1, name: /lorem ipsum/i })).toBeInTheDocument();
23
28
  expect(screen.getByRole("heading", { level: 2, name: /dolor sit amet/i })).toBeInTheDocument();
24
29
  });
25
30
 
26
- it("would render a main element", () => {
31
+ it("should render a main element", () => {
27
32
  renderComponent();
28
33
 
29
- expect(screen.getByRole("main")).toBeInTheDocument();
34
+ expect(screen.getByRole("main")).toBeVisible();
30
35
  });
31
36
 
32
- it("would render the content", () => {
37
+ it("should render the content", () => {
33
38
  renderComponent();
34
39
 
35
- expect(screen.getByText(/test content/i)).toBeInTheDocument();
40
+ expect(screen.getByText(/test content/i)).toBeVisible();
41
+ });
42
+
43
+ it("should render a loading indicator if loading=true", () => {
44
+ renderComponent({ loading: true });
45
+
46
+ expectProgressIndicator();
47
+ });
48
+
49
+ describe("fetching=true", () => {
50
+ it("should render a loading indicator", () => {
51
+ renderComponent({ fetching: true });
52
+
53
+ expectProgressIndicator();
54
+ });
55
+
56
+ it("should render the content", () => {
57
+ renderComponent({ fetching: true });
58
+
59
+ expect(screen.getByText(/test content/i)).toBeVisible();
60
+ });
61
+ });
62
+
63
+ describe("error", () => {
64
+ it("should not render the error if there is no one", () => {
65
+ renderComponent({ error: undefined });
66
+
67
+ expect(screen.queryByText(/there has been an error/i)).not.toBeInTheDocument();
68
+ });
69
+
70
+ it("should render a title if there is an error without title", () => {
71
+ renderComponent({
72
+ error: {
73
+ message: "Invalid user id",
74
+ },
75
+ });
76
+
77
+ expect(screen.queryByText(/there has been an error/i)).toBeVisible();
78
+ });
79
+
80
+ it("should render a title if there is an error with title", () => {
81
+ renderComponent({
82
+ error: {
83
+ title: "We had an error",
84
+ message: "Invalid user id",
85
+ },
86
+ });
87
+
88
+ expect(screen.queryByText(/we had an error/i)).toBeVisible();
89
+ });
90
+
91
+ it("should render the message", () => {
92
+ renderComponent({
93
+ error: {
94
+ title: "We had an error",
95
+ message: "Invalid user id",
96
+ },
97
+ });
98
+
99
+ expect(screen.queryByText(/invalid user id/i)).toBeVisible();
100
+ });
36
101
  });
37
102
  });
@@ -1,22 +1,48 @@
1
- import { Box } from "@mui/material";
1
+ import { Box, LinearProgress } from "@mui/material";
2
2
  import React from "react";
3
- import { ContentElement, HeaderElement } from "../../components";
3
+ import { ContentElement, HeaderElement, Placeholder, PlaceholderIcon } from "../../components";
4
4
  import { LoadingArea } from "../../components/feedback/loading-area";
5
5
  import { TabProvider } from "../../providers";
6
+ import ReportProblemIcon from "@mui/icons-material/ReportProblem";
7
+
8
+ export interface HeaderLayoutError {
9
+ icon?: PlaceholderIcon;
10
+ title?: string;
11
+ message: string;
12
+ }
6
13
 
7
14
  export interface HeaderLayoutProps {
8
15
  loading?: boolean;
16
+ fetching?: boolean;
17
+ error?: HeaderLayoutError;
9
18
  children: [HeaderElement, ContentElement];
10
19
  }
11
20
 
12
- export const HeaderLayout = ({ loading, children }: HeaderLayoutProps) => {
21
+ const DefaultErrorIcon = () => <ReportProblemIcon color="error" sx={{ width: 200, height: 200 }} />;
22
+
23
+ export const HeaderLayout = ({ loading, children, fetching, error }: HeaderLayoutProps) => {
13
24
  const [headerElement, contentElement] = children;
14
25
 
15
26
  return (
16
27
  <TabProvider>
17
28
  <Box display="flex" flexDirection="column" height={1}>
18
29
  {headerElement}
19
- {loading ? <LoadingArea /> : contentElement}
30
+ {fetching && (
31
+ <Box width={1}>
32
+ <LinearProgress />
33
+ </Box>
34
+ )}
35
+ {loading && <LoadingArea />}
36
+ {error && (
37
+ <Box mt={4}>
38
+ <Placeholder
39
+ icon={error.icon || DefaultErrorIcon}
40
+ title={error.title || "There has been an error"}
41
+ subtitle={error.message}
42
+ />
43
+ </Box>
44
+ )}
45
+ {!loading && !error && contentElement}
20
46
  </Box>
21
47
  </TabProvider>
22
48
  );