@pautena/react-design-system 0.1.1 → 0.1.2

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 (188) hide show
  1. package/package.json +1 -1
  2. package/.eslintrc.js +0 -26
  3. package/.github/workflows/ci.yml +0 -23
  4. package/.github/workflows/deploy-storybook.yaml +0 -23
  5. package/.github/workflows/publish.yml +0 -31
  6. package/.husky/pre-commit +0 -5
  7. package/.prettierignore +0 -5
  8. package/.storybook/main.js +0 -10
  9. package/.storybook/preview.js +0 -36
  10. package/babel.config.js +0 -13
  11. package/jest.config.js +0 -17
  12. package/jest.setup.ts +0 -5
  13. package/rollup.config.js +0 -52
  14. package/src/components/app-bar/app-bar.stories.tsx +0 -54
  15. package/src/components/app-bar/app-bar.test.tsx +0 -142
  16. package/src/components/app-bar/app-bar.tsx +0 -150
  17. package/src/components/app-bar/app-bar.types.ts +0 -17
  18. package/src/components/app-bar/index.ts +0 -3
  19. package/src/components/app-bar/mini-app-bar/index.ts +0 -1
  20. package/src/components/app-bar/mini-app-bar/mini-app-bar.tsx +0 -31
  21. package/src/components/bullet/bullet.stories.tsx +0 -43
  22. package/src/components/bullet/bullet.test.tsx +0 -24
  23. package/src/components/bullet/bullet.tsx +0 -30
  24. package/src/components/bullet/index.ts +0 -1
  25. package/src/components/center-container/center-container.stories.tsx +0 -50
  26. package/src/components/center-container/center-container.test.tsx +0 -16
  27. package/src/components/center-container/center-container.tsx +0 -32
  28. package/src/components/center-container/index.ts +0 -1
  29. package/src/components/content/content.stories.tsx +0 -23
  30. package/src/components/content/content.test.tsx +0 -26
  31. package/src/components/content/content.tsx +0 -11
  32. package/src/components/content/content.types.ts +0 -5
  33. package/src/components/content/index.ts +0 -2
  34. package/src/components/drawer/__snapshots__/drawer.test.tsx.snap +0 -20
  35. package/src/components/drawer/drawer.context.ts +0 -20
  36. package/src/components/drawer/drawer.mixins.ts +0 -24
  37. package/src/components/drawer/drawer.mock.tsx +0 -100
  38. package/src/components/drawer/drawer.provider.tsx +0 -23
  39. package/src/components/drawer/drawer.test.tsx +0 -97
  40. package/src/components/drawer/drawer.tsx +0 -30
  41. package/src/components/drawer/drawer.types.ts +0 -53
  42. package/src/components/drawer/index.ts +0 -5
  43. package/src/components/drawer/mini-drawer/index.ts +0 -1
  44. package/src/components/drawer/mini-drawer/mini-drawer.stories.tsx +0 -34
  45. package/src/components/drawer/mini-drawer/mini-drawer.tsx +0 -67
  46. package/src/components/drawer-content/drawer-content.stories.tsx +0 -29
  47. package/src/components/drawer-content/drawer-content.test.tsx +0 -34
  48. package/src/components/drawer-content/drawer-content.tsx +0 -18
  49. package/src/components/drawer-content/index.ts +0 -1
  50. package/src/components/drawer-item/drawer-item.stories.tsx +0 -62
  51. package/src/components/drawer-item/drawer-item.test.tsx +0 -119
  52. package/src/components/drawer-item/drawer-item.tsx +0 -71
  53. package/src/components/drawer-item/index.ts +0 -1
  54. package/src/components/drawer-section/drawer-section.mock.tsx +0 -39
  55. package/src/components/drawer-section/drawer-section.stories.tsx +0 -28
  56. package/src/components/drawer-section/drawer-section.test.tsx +0 -44
  57. package/src/components/drawer-section/drawer-section.tsx +0 -40
  58. package/src/components/drawer-section/index.ts +0 -1
  59. package/src/components/header/header.dummy.ts +0 -55
  60. package/src/components/header/header.stories.tsx +0 -116
  61. package/src/components/header/header.test.tsx +0 -169
  62. package/src/components/header/header.tsx +0 -121
  63. package/src/components/header/header.types.ts +0 -61
  64. package/src/components/header/index.ts +0 -2
  65. package/src/components/index.ts +0 -18
  66. package/src/components/label/index.ts +0 -1
  67. package/src/components/label/label.stories.tsx +0 -49
  68. package/src/components/label/label.test.tsx +0 -30
  69. package/src/components/label/label.tsx +0 -60
  70. package/src/components/link/index.ts +0 -1
  71. package/src/components/link/link.tsx +0 -17
  72. package/src/components/loading-area/index.ts +0 -1
  73. package/src/components/loading-area/loading-area.stories.tsx +0 -17
  74. package/src/components/loading-area/loading-area.test.tsx +0 -11
  75. package/src/components/loading-area/loading-area.tsx +0 -13
  76. package/src/components/placeholder/index.ts +0 -1
  77. package/src/components/placeholder/placeholder.mock.ts +0 -15
  78. package/src/components/placeholder/placeholder.stories.tsx +0 -44
  79. package/src/components/placeholder/placeholder.test.tsx +0 -76
  80. package/src/components/placeholder/placeholder.tsx +0 -75
  81. package/src/components/query-container/index.ts +0 -1
  82. package/src/components/query-container/query-container.stories.tsx +0 -68
  83. package/src/components/query-container/query-container.test.tsx +0 -95
  84. package/src/components/query-container/query-container.tsx +0 -71
  85. package/src/components/sign-in/index.ts +0 -1
  86. package/src/components/sign-in/sign-in.stories.tsx +0 -36
  87. package/src/components/sign-in/sign-in.test.tsx +0 -95
  88. package/src/components/sign-in/sign-in.tsx +0 -97
  89. package/src/components/tab/index.ts +0 -2
  90. package/src/components/tab/tab-card/index.ts +0 -1
  91. package/src/components/tab/tab-card/tab-card.dummy.tsx +0 -30
  92. package/src/components/tab/tab-card/tab-card.stories.tsx +0 -22
  93. package/src/components/tab/tab-card/tab-card.test.tsx +0 -53
  94. package/src/components/tab/tab-card/tab-card.tsx +0 -27
  95. package/src/components/tab/tab-panel/index.ts +0 -1
  96. package/src/components/tab/tab-panel/tab-panel.test.tsx +0 -26
  97. package/src/components/tab/tab-panel/tab-panel.tsx +0 -27
  98. package/src/components/table/enhanced-remote-table/enhanced-remote-table.mock.tsx +0 -27
  99. package/src/components/table/enhanced-remote-table/enhanced-remote-table.stories.tsx +0 -24
  100. package/src/components/table/enhanced-remote-table/enhanced-remote-table.test.tsx +0 -77
  101. package/src/components/table/enhanced-remote-table/enhanced-remote-table.tsx +0 -74
  102. package/src/components/table/enhanced-remote-table/index.ts +0 -1
  103. package/src/components/table/enhanced-table/enhanced-table-head.tsx +0 -58
  104. package/src/components/table/enhanced-table/enhanced-table.mock.tsx +0 -93
  105. package/src/components/table/enhanced-table/enhanced-table.stories.tsx +0 -21
  106. package/src/components/table/enhanced-table/enhanced-table.test.tsx +0 -107
  107. package/src/components/table/enhanced-table/enhanced-table.tsx +0 -136
  108. package/src/components/table/enhanced-table/index.ts +0 -2
  109. package/src/components/table/index.ts +0 -2
  110. package/src/components/table-list/index.ts +0 -1
  111. package/src/components/table-list/table-list.stories.tsx +0 -75
  112. package/src/components/table-list/table-list.test.tsx +0 -284
  113. package/src/components/table-list/table-list.tsx +0 -127
  114. package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +0 -35
  115. package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +0 -26
  116. package/src/components/value-displays/group-value-card/group-value-card.test.tsx +0 -58
  117. package/src/components/value-displays/group-value-card/group-value-card.tsx +0 -63
  118. package/src/components/value-displays/group-value-card/index.ts +0 -1
  119. package/src/components/value-displays/index.ts +0 -4
  120. package/src/components/value-displays/value-boolean/index.ts +0 -1
  121. package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +0 -25
  122. package/src/components/value-displays/value-boolean/value-boolean.test.tsx +0 -27
  123. package/src/components/value-displays/value-boolean/value-boolean.tsx +0 -33
  124. package/src/components/value-displays/value-card/index.ts +0 -1
  125. package/src/components/value-displays/value-card/value-card.stories.tsx +0 -22
  126. package/src/components/value-displays/value-card/value-card.test.tsx +0 -18
  127. package/src/components/value-displays/value-card/value-card.tsx +0 -12
  128. package/src/components/value-displays/value-text/index.ts +0 -1
  129. package/src/components/value-displays/value-text/value-test.test.tsx +0 -21
  130. package/src/components/value-displays/value-text/value-text.stories.tsx +0 -26
  131. package/src/components/value-displays/value-text/value-text.tsx +0 -32
  132. package/src/generators/generators.mock.ts +0 -238
  133. package/src/generators/generators.model.ts +0 -46
  134. package/src/generators/index.ts +0 -4
  135. package/src/generators/model-form/index.ts +0 -1
  136. package/src/generators/model-form/model-form.stories.tsx +0 -30
  137. package/src/generators/model-form/model-form.test.tsx +0 -100
  138. package/src/generators/model-form/model-form.tsx +0 -97
  139. package/src/generators/model-router/index.ts +0 -1
  140. package/src/generators/model-router/model-router.test.tsx +0 -666
  141. package/src/generators/model-router/model-router.tsx +0 -29
  142. package/src/generators/model-router/model-router.types.ts +0 -14
  143. package/src/generators/model-router/screens/add-screen.tsx +0 -69
  144. package/src/generators/model-router/screens/details-screen.tsx +0 -62
  145. package/src/generators/model-router/screens/index.ts +0 -4
  146. package/src/generators/model-router/screens/list-screen.tsx +0 -110
  147. package/src/generators/model-router/screens/screens.types.ts +0 -13
  148. package/src/generators/model-router/screens/update-screen.tsx +0 -96
  149. package/src/generators/model-router/stories/details-screen.stories.tsx +0 -38
  150. package/src/generators/model-router/stories/list-screen.stories.tsx +0 -45
  151. package/src/generators/model-router/stories/model-router.stories.tsx +0 -164
  152. package/src/generators/model-router/stories/templates.tsx +0 -39
  153. package/src/generators/object-details/index.ts +0 -1
  154. package/src/generators/object-details/object-details.stories.tsx +0 -20
  155. package/src/generators/object-details/object-details.test.tsx +0 -21
  156. package/src/generators/object-details/object-details.tsx +0 -76
  157. package/src/index.ts +0 -4
  158. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.stories.tsx +0 -28
  159. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.test.tsx +0 -30
  160. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.tsx +0 -37
  161. package/src/layouts/app-bar-with-drawer-layout/index.ts +0 -1
  162. package/src/layouts/header-layout/header-layout.stories.tsx +0 -204
  163. package/src/layouts/header-layout/header-layout.test.tsx +0 -37
  164. package/src/layouts/header-layout/header-layout.tsx +0 -23
  165. package/src/layouts/header-layout/index.ts +0 -1
  166. package/src/layouts/index.ts +0 -2
  167. package/src/providers/index.ts +0 -2
  168. package/src/providers/notification-center/index.ts +0 -2
  169. package/src/providers/notification-center/notification-center.context.ts +0 -37
  170. package/src/providers/notification-center/notification-center.provider.tsx +0 -51
  171. package/src/providers/notification-center/notification-center.stories.tsx +0 -52
  172. package/src/providers/notification-center/notification-center.test.tsx +0 -112
  173. package/src/providers/tab-provider/index.ts +0 -2
  174. package/src/providers/tab-provider/tab-provider.context.ts +0 -8
  175. package/src/providers/tab-provider/tab-provider.provider.tsx +0 -13
  176. package/src/storybook.tsx +0 -90
  177. package/src/tests/assertions.ts +0 -76
  178. package/src/tests/components.tsx +0 -60
  179. package/src/tests/content-placeholder.stories.tsx +0 -16
  180. package/src/tests/index.ts +0 -3
  181. package/src/tests/skeleton-card.stories.tsx +0 -18
  182. package/src/tests/testing-library.tsx +0 -65
  183. package/src/utils/arrays.test.ts +0 -9
  184. package/src/utils/arrays.ts +0 -7
  185. package/src/utils/index.ts +0 -2
  186. package/src/utils/theme.ts +0 -11
  187. package/tsconfig.json +0 -25
  188. package/tsconfig.rollup.json +0 -28
@@ -1,69 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { useNavigate } from "react-router-dom";
3
- import { Header, Content } from "~/components";
4
- import { BasicModelInstance, ModelForm } from "~/generators";
5
- import { HeaderLayout } from "../../../layouts";
6
- import { useNotificationCenter } from "../../../providers";
7
- import { RequestState } from "../model-router.types";
8
- import { BaseScreenProps } from "./screens.types";
9
-
10
- export interface AddScreenProps<T extends BasicModelInstance> extends BaseScreenProps {
11
- /**
12
- * Callback executed when the user wants to
13
- * add a new item
14
- */
15
- onSubmitNewItem: (obj: T) => void;
16
-
17
- /**
18
- * Current status of the request to retrieve
19
- * add a new item
20
- */
21
- newItemRequest: RequestState;
22
- }
23
-
24
- export const AddScreen = <T extends BasicModelInstance>({
25
- model,
26
- modelName,
27
- onSubmitNewItem,
28
- newItemRequest,
29
- }: AddScreenProps<T>) => {
30
- const navigate = useNavigate();
31
- const { show } = useNotificationCenter();
32
-
33
- useEffect(() => {
34
- if (newItemRequest.success) {
35
- show({ message: "Item added successfully", severity: "success" });
36
- navigate("/");
37
- }
38
- }, [newItemRequest.success]);
39
-
40
- useEffect(() => {
41
- if (newItemRequest.error) {
42
- show({ title: "We had an error", message: newItemRequest.error, severity: "error" });
43
- }
44
- }, [newItemRequest.error]);
45
-
46
- return (
47
- <HeaderLayout loading={newItemRequest.loading}>
48
- <Header
49
- title={`Add ${modelName}`}
50
- preset="default"
51
- breadcrumbs={[
52
- {
53
- id: "list",
54
- text: modelName,
55
- link: "/",
56
- },
57
- {
58
- id: "add",
59
- text: `Add new ${modelName}`,
60
- link: "/add",
61
- },
62
- ]}
63
- />
64
- <Content>
65
- <ModelForm model={model} saveButtonText="Save" onSubmit={onSubmitNewItem} />
66
- </Content>
67
- </HeaderLayout>
68
- );
69
- };
@@ -1,62 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { useParams } from "react-router-dom";
3
- import { RequestState } from "../model-router.types";
4
- import { Content, Header } from "~/components";
5
- import { HeaderLayout } from "~/layouts";
6
- import { BaseScreenProps } from "./screens.types";
7
- import { BasicModelInstance, ObjectDetails } from "~/generators";
8
-
9
- export interface DetailsScreenProps<T extends BasicModelInstance> extends BaseScreenProps {
10
- /**
11
- * Callback executed each time we want
12
- * the details information of an item
13
- */
14
- onRequestItem: (id: string) => void;
15
-
16
- /**
17
- * Current status of the request to retrieve
18
- * an item
19
- */
20
- itemRequest: RequestState;
21
-
22
- /**
23
- * Item to be displayed
24
- */
25
- detailsItem?: T;
26
- }
27
-
28
- export const DetailsScreen = <T extends BasicModelInstance>({
29
- model,
30
- modelName,
31
- onRequestItem,
32
- itemRequest,
33
- detailsItem,
34
- }: DetailsScreenProps<T>) => {
35
- const { id = "" } = useParams();
36
-
37
- useEffect(() => {
38
- onRequestItem(id);
39
- }, [id]);
40
-
41
- return (
42
- <HeaderLayout loading={itemRequest.loading}>
43
- <Header
44
- title={id}
45
- preset="default"
46
- breadcrumbs={[
47
- {
48
- id: "list",
49
- text: modelName,
50
- link: "/",
51
- },
52
- {
53
- id: "detail",
54
- text: id,
55
- link: `/${id}`,
56
- },
57
- ]}
58
- />
59
- <Content>{detailsItem && <ObjectDetails model={model} instance={detailsItem} />}</Content>
60
- </HeaderLayout>
61
- );
62
- };
@@ -1,4 +0,0 @@
1
- export * from "./update-screen";
2
- export * from "./list-screen";
3
- export * from "./add-screen";
4
- export * from "./details-screen";
@@ -1,110 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { useNavigate } from "react-router-dom";
3
- import { Content, Header, TableList } from "~/components";
4
- import { BasicModelInstance } from "~/generators";
5
- import { HeaderLayout } from "../../../layouts";
6
- import { RequestState } from "../model-router.types";
7
- import { BaseScreenProps } from "./screens.types";
8
-
9
- export interface ListScreenProps<T extends BasicModelInstance> extends BaseScreenProps {
10
- /**
11
- * Callback executed each time the list screen
12
- * requests for a data update
13
- */
14
- onRequestList: () => void;
15
-
16
- /**
17
- * List of items to be displayed in the list screen
18
- */
19
- listData: T[];
20
-
21
- /**
22
- * Callback executed when the user clicks an option
23
- * to delete an item
24
- */
25
- onClickDeleteItem: (item: T) => void;
26
-
27
- /**
28
- * Current status of the request to retrieve
29
- * the list items
30
- */
31
- listRequest: RequestState;
32
-
33
- /**
34
- * Current status of the request to delete
35
- * an item
36
- */
37
- deleteRequest: RequestState;
38
- }
39
-
40
- export const ListScreen = <T extends BasicModelInstance>({
41
- model,
42
- modelName,
43
- listData,
44
- onRequestList,
45
- onClickDeleteItem,
46
- listRequest,
47
- deleteRequest,
48
- }: ListScreenProps<T>) => {
49
- const navigate = useNavigate();
50
-
51
- useEffect(() => {
52
- onRequestList();
53
- }, []);
54
-
55
- const handleClickListItem = (item: T) => {
56
- navigate(`/${item.id}`);
57
- };
58
-
59
- const handleClickListOption = (optionId: "edit" | "remove", item: T) => {
60
- if (optionId === "edit") {
61
- navigate(`/${item.id}/update`);
62
- } else {
63
- onClickDeleteItem(item);
64
- }
65
- };
66
-
67
- return (
68
- <HeaderLayout loading={listRequest.loading || deleteRequest.loading}>
69
- <Header
70
- title={modelName}
71
- preset="default"
72
- actions={[
73
- {
74
- id: "add",
75
- text: "Add",
76
- href: "/add",
77
- },
78
- ]}
79
- />
80
- <Content>
81
- <TableList
82
- columns={model.fields
83
- .filter(({ listable }) => listable)
84
- .map(({ id, name, type }) => ({
85
- disablePadding: false,
86
- id,
87
- label: name,
88
- numeric: type === "number",
89
- sort: false,
90
- }))}
91
- data={listData}
92
- defaultSort={model.fields[0].id}
93
- onClick={handleClickListItem}
94
- options={[
95
- {
96
- id: "edit",
97
- label: "Edit",
98
- onClick: (item) => handleClickListOption("edit", item),
99
- },
100
- {
101
- id: "remove",
102
- label: "Remove",
103
- onClick: (item) => handleClickListOption("remove", item),
104
- },
105
- ]}
106
- />
107
- </Content>
108
- </HeaderLayout>
109
- );
110
- };
@@ -1,13 +0,0 @@
1
- import { Model } from "../../generators.model";
2
-
3
- export interface BaseScreenProps {
4
- /**
5
- * UI-friendly string that represents the model
6
- */
7
- modelName: string;
8
-
9
- /**
10
- * Structure that represents the fields of the model
11
- */
12
- model: Model;
13
- }
@@ -1,96 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { useNavigate, useParams } from "react-router-dom";
3
- import { Content, Header } from "~/components";
4
- import { BasicModelInstance, ModelForm } from "~/generators";
5
- import { HeaderLayout } from "../../../layouts";
6
- import { useNotificationCenter } from "../../../providers";
7
- import { RequestState } from "../model-router.types";
8
- import { BaseScreenProps } from "./screens.types";
9
-
10
- export interface UpdateScreenProps<T extends BasicModelInstance> extends BaseScreenProps {
11
- /**
12
- * Callback executed when the user wants to update
13
- * an item
14
- */
15
- onSubmitUpdateItem: (obj: T) => void;
16
- /**
17
- * Current status of the request to update an item
18
- */
19
- submitUpdateItemRequest: RequestState;
20
-
21
- /**
22
- * Current status of the request to retrieve
23
- * the item to be updated
24
- */
25
- updateItemRequest: RequestState;
26
-
27
- /**
28
- * Callback executed to retrive the item that
29
- * has to going tobe updated
30
- */
31
- onRequestUpdateItem: (id: string) => void;
32
-
33
- /**
34
- * Item that is going to be updated
35
- */
36
- updateItem?: T;
37
- }
38
-
39
- export const UpdateScreen = <T extends BasicModelInstance>({
40
- model,
41
- modelName,
42
- submitUpdateItemRequest,
43
- updateItemRequest,
44
- updateItem,
45
- onSubmitUpdateItem,
46
- onRequestUpdateItem,
47
- }: UpdateScreenProps<T>) => {
48
- const { id = "" } = useParams();
49
- const navigate = useNavigate();
50
- const { show } = useNotificationCenter();
51
- const loading = updateItemRequest.loading || submitUpdateItemRequest.loading;
52
-
53
- useEffect(() => {
54
- onRequestUpdateItem(id);
55
- }, [id]);
56
-
57
- useEffect(() => {
58
- if (submitUpdateItemRequest.success) {
59
- show({
60
- title: "Item updated",
61
- message: `The item ${id} has been updated successfully`,
62
- severity: "success",
63
- });
64
- navigate("/");
65
- }
66
- }, [submitUpdateItemRequest.success]);
67
-
68
- return (
69
- <HeaderLayout loading={loading}>
70
- <Header
71
- title={`Edit ${id}`}
72
- preset="default"
73
- breadcrumbs={[
74
- {
75
- id: "list",
76
- text: modelName,
77
- link: "/",
78
- },
79
- {
80
- id: "update",
81
- text: `Edit ${id}`,
82
- link: `/${id}/update`,
83
- },
84
- ]}
85
- />
86
- <Content>
87
- <ModelForm
88
- model={model}
89
- initialValues={updateItem}
90
- saveButtonText="Save"
91
- onSubmit={onSubmitUpdateItem}
92
- />
93
- </Content>
94
- </HeaderLayout>
95
- );
96
- };
@@ -1,38 +0,0 @@
1
- import { ComponentMeta } from "@storybook/react";
2
- import { withNotificationCenter, createTemplate, withActionRouter } from "../../../storybook";
3
- import { item1 } from "./templates";
4
- import { DetailsScreen } from "../screens";
5
- import { mockModel } from "../../generators.mock";
6
- import { IdleRequest, LoadingRequest } from "../model-router.types";
7
-
8
- export default {
9
- title: "Generators/ModelRouter/DetailsScreen",
10
- component: DetailsScreen,
11
- decorators: [
12
- withActionRouter({
13
- location: `/${item1.id}`,
14
- path: "/:id",
15
- }),
16
- withNotificationCenter,
17
- ],
18
- parameters: {
19
- layout: "fullscreen",
20
- },
21
- } as ComponentMeta<typeof DetailsScreen>;
22
-
23
- const Template = createTemplate(DetailsScreen);
24
-
25
- export const Loading = Template.bind({});
26
- Loading.args = {
27
- modelName: "Items",
28
- model: mockModel,
29
- itemRequest: LoadingRequest,
30
- };
31
-
32
- export const Details = Template.bind({});
33
- Details.args = {
34
- modelName: "Items",
35
- model: mockModel,
36
- itemRequest: IdleRequest,
37
- detailsItem: item1,
38
- };
@@ -1,45 +0,0 @@
1
- import { ComponentMeta } from "@storybook/react";
2
- import { withActionRouter, withNotificationCenter } from "../../../storybook";
3
- import { IdleRequest, LoadingRequest } from "../model-router.types";
4
- import { data } from "./templates";
5
- import { createTemplate } from "../../../storybook";
6
- import { ListScreen } from "../screens";
7
- import { mockModel } from "../../generators.mock";
8
-
9
- export default {
10
- title: "Generators/ModelRouter/ListScreen",
11
- component: ListScreen,
12
- decorators: [withActionRouter(), withNotificationCenter],
13
- parameters: {
14
- layout: "fullscreen",
15
- },
16
- } as ComponentMeta<typeof ListScreen>;
17
-
18
- const Template = createTemplate(ListScreen);
19
-
20
- export const ListLoading = Template.bind({});
21
- ListLoading.args = {
22
- modelName: "Items",
23
- model: mockModel,
24
- listData: data,
25
- listRequest: LoadingRequest,
26
- deleteRequest: IdleRequest,
27
- };
28
-
29
- export const DeleteLoading = Template.bind({});
30
- DeleteLoading.args = {
31
- modelName: "Items",
32
- model: mockModel,
33
- listData: data,
34
- listRequest: IdleRequest,
35
- deleteRequest: LoadingRequest,
36
- };
37
-
38
- export const List = Template.bind({});
39
- List.args = {
40
- modelName: "Items",
41
- model: mockModel,
42
- listData: data,
43
- listRequest: IdleRequest,
44
- deleteRequest: IdleRequest,
45
- };
@@ -1,164 +0,0 @@
1
- import React from "react";
2
- import { ComponentMeta } from "@storybook/react";
3
- import { withMemoryRouter, withNotificationCenter } from "../../../storybook";
4
- import { ModelRouter } from "../model-router";
5
- import { IdleRequest } from "../model-router.types";
6
- import { MockInstance, mockModel } from "../../generators.mock";
7
- import { HandlerFunction } from "@storybook/addon-actions";
8
- import { useState } from "react";
9
- import {
10
- data,
11
- onRequestDeleteAction,
12
- onRequestItem,
13
- onRequestListAction,
14
- onRequestUpdateItemAction,
15
- onSubmitNewItemAction,
16
- onSubmitUpdateAction,
17
- REQUEST_TIMEOUT,
18
- } from "./templates";
19
-
20
- interface DummyModelRouterProps {
21
- requestTimeout: number;
22
- initialData: MockInstance[];
23
- onRequestListAction: HandlerFunction;
24
- onSubmitNewItemAction: HandlerFunction;
25
- onRequestItem: HandlerFunction;
26
- onRequestUpdateItemAction: HandlerFunction;
27
- onSubmitUpdateAction: HandlerFunction;
28
- onRequestDeleteAction: HandlerFunction;
29
- }
30
-
31
- export const DummyModelRouter = (args: DummyModelRouterProps) => {
32
- const {
33
- requestTimeout,
34
- initialData,
35
- onRequestListAction,
36
- onSubmitNewItemAction,
37
- onRequestItem,
38
- onRequestUpdateItemAction,
39
- onSubmitUpdateAction,
40
- onRequestDeleteAction,
41
- } = args;
42
-
43
- const [data, setData] = useState<MockInstance[]>([]);
44
- const [updateItem, setUpdateItem] = useState<MockInstance | undefined>(undefined);
45
- const [listRequestState, setListRequestState] = useState(IdleRequest);
46
- const [newItemRequestState, setNewItemRequestState] = useState(IdleRequest);
47
- const [submitUpdateItemRequestState, setSubmitUpdateItemRequestState] = useState(IdleRequest);
48
- const [removeRequestState, setRemoveRequestState] = useState(IdleRequest);
49
- const [detailRequestState, setDetailRequestState] = useState(IdleRequest);
50
- const [updateItemRequestState, setUpdateItemRequestState] = useState(IdleRequest);
51
- const [detailInstance, setDetailInstance] = useState<MockInstance | undefined>(undefined);
52
-
53
- const handleRequestList = () => {
54
- onRequestListAction();
55
- setListRequestState({ idle: false, loading: true });
56
- setTimeout(() => {
57
- setData(initialData);
58
- setListRequestState({ idle: true, loading: false, success: true });
59
- }, requestTimeout);
60
- };
61
-
62
- const handleClickDeleteItem = (item) => {
63
- setRemoveRequestState({ idle: false, loading: true });
64
- onRequestDeleteAction(item);
65
-
66
- setTimeout(() => {
67
- setData((d) => [...d.filter((d) => d !== item)]);
68
- setRemoveRequestState({ idle: true, loading: false, success: true });
69
- }, requestTimeout);
70
- };
71
-
72
- const handleSubmitNewItem = (obj: MockInstance) => {
73
- setNewItemRequestState({ idle: false, loading: true });
74
- onSubmitNewItemAction(obj);
75
-
76
- setTimeout(() => {
77
- setData((d) => [...d, obj]);
78
- setNewItemRequestState({ idle: true, loading: false, success: true });
79
- }, requestTimeout);
80
- };
81
-
82
- const handleRequestItem = (id: string) => {
83
- setDetailInstance(undefined);
84
- setDetailRequestState({ idle: false, loading: true });
85
- onRequestItem(id);
86
-
87
- setTimeout(() => {
88
- setDetailInstance(data?.find((d) => d.id === id));
89
- setDetailRequestState({ idle: true, loading: false, success: true });
90
- }, requestTimeout);
91
- };
92
-
93
- const handleRequestUpdateItem = (id: string) => {
94
- setUpdateItemRequestState({ idle: false, loading: true });
95
- onRequestUpdateItemAction(id);
96
-
97
- setTimeout(() => {
98
- setUpdateItem(data?.find((d) => d.id === id));
99
- setUpdateItemRequestState({ idle: true, loading: false, success: true });
100
- }, requestTimeout);
101
- };
102
-
103
- const handleSubmitUpdateItem = (obj: MockInstance) => {
104
- setSubmitUpdateItemRequestState({ idle: false, loading: true });
105
- onSubmitUpdateAction(obj);
106
-
107
- setTimeout(() => {
108
- setData((d) => [
109
- ...(d || []).map((item) => {
110
- if (item === obj) {
111
- return obj;
112
- }
113
- return item;
114
- }),
115
- ]);
116
- setSubmitUpdateItemRequestState({ idle: true, loading: false, success: true });
117
- }, requestTimeout);
118
- };
119
-
120
- return (
121
- <ModelRouter
122
- {...args}
123
- modelName="Items"
124
- model={mockModel}
125
- onRequestList={handleRequestList}
126
- listData={data}
127
- listRequest={listRequestState}
128
- deleteRequest={removeRequestState}
129
- onClickDeleteItem={handleClickDeleteItem}
130
- itemRequest={detailRequestState}
131
- detailsItem={detailInstance}
132
- onRequestItem={handleRequestItem}
133
- newItemRequest={newItemRequestState}
134
- onSubmitNewItem={handleSubmitNewItem}
135
- submitUpdateItemRequest={submitUpdateItemRequestState}
136
- updateItemRequest={updateItemRequestState}
137
- updateItem={updateItem}
138
- onRequestUpdateItem={handleRequestUpdateItem}
139
- onSubmitUpdateItem={handleSubmitUpdateItem}
140
- />
141
- );
142
- };
143
-
144
- const args: DummyModelRouterProps = {
145
- requestTimeout: REQUEST_TIMEOUT,
146
- initialData: data,
147
- onRequestListAction,
148
- onSubmitNewItemAction,
149
- onRequestItem,
150
- onRequestUpdateItemAction,
151
- onSubmitUpdateAction,
152
- onRequestDeleteAction,
153
- };
154
-
155
- DummyModelRouter.args = args;
156
-
157
- export default {
158
- title: "Generators/ModelRouter",
159
- component: DummyModelRouter,
160
- decorators: [withMemoryRouter(), withNotificationCenter],
161
- parameters: {
162
- layout: "fullscreen",
163
- },
164
- } as ComponentMeta<typeof DummyModelRouter>;
@@ -1,39 +0,0 @@
1
- import { action } from "@storybook/addon-actions";
2
- import { ModelRouter } from "../model-router";
3
- import { createTemplate } from "../../../storybook";
4
- import { createModelInstance, MockInstance, mockModel } from "../../generators.mock";
5
- import { IdleRequest } from "../model-router.types";
6
-
7
- export const onRequestListAction = action("Request list data");
8
- export const onSubmitNewItemAction = action("Submit new item");
9
- export const onRequestItem = action("Details screen mount");
10
- export const onRequestUpdateItemAction = action("Request update instance");
11
- export const onSubmitUpdateAction = action("Submit update form");
12
- export const onRequestDeleteAction = action("click delete item option");
13
-
14
- export const REQUEST_TIMEOUT = 2000;
15
-
16
- export const item1 = createModelInstance<MockInstance>(mockModel, 100);
17
- export const data = [
18
- item1,
19
- createModelInstance<MockInstance>(mockModel, 101),
20
- createModelInstance<MockInstance>(mockModel, 102),
21
- createModelInstance<MockInstance>(mockModel, 103),
22
- createModelInstance<MockInstance>(mockModel, 104),
23
- ];
24
-
25
- export const ModelRouterTemplate = createTemplate(ModelRouter);
26
-
27
- export const baseArgs = {
28
- modelName: "Items",
29
- model: mockModel,
30
- listData: data,
31
- listRequest: IdleRequest,
32
- deleteRequest: IdleRequest,
33
- newItemRequest: IdleRequest,
34
- updateItemRequest: IdleRequest,
35
- submitUpdateItemRequest: IdleRequest,
36
- itemRequest: IdleRequest,
37
- // onRequestList:onRequestListAction,
38
- // onRequestUpdateItem: onRequestUpdateItemAction,
39
- };
@@ -1 +0,0 @@
1
- export * from "./object-details";
@@ -1,20 +0,0 @@
1
- import React from "react";
2
- import { ComponentMeta } from "@storybook/react";
3
- import { ObjectDetails } from "./object-details";
4
- import { withPadding } from "../../storybook";
5
- import { createModelInstance, mockModel } from "../generators.mock";
6
-
7
- const instance = createModelInstance(mockModel);
8
-
9
- export default {
10
- title: "Generators/ObjectDetails",
11
- component: ObjectDetails,
12
- decorators: [withPadding()],
13
- parameters: {
14
- layout: "fullscreen",
15
- },
16
- } as ComponentMeta<typeof ObjectDetails>;
17
-
18
- export const Default = () => {
19
- return <ObjectDetails model={mockModel} instance={instance} />;
20
- };
@@ -1,21 +0,0 @@
1
- import React from "react";
2
- import { expectModelFieldValue, render } from "../../tests";
3
- import { mockModel, createModelInstance } from "../generators.mock";
4
- import { ObjectDetails } from "./object-details";
5
-
6
- describe("ObjectDetails", () => {
7
- const renderComponent = () => {
8
- const instance = createModelInstance(mockModel);
9
- return {
10
- ...render(<ObjectDetails model={mockModel} instance={instance} />),
11
- instance,
12
- model: mockModel,
13
- };
14
- };
15
-
16
- it("would render a label/value pair for each detail", () => {
17
- const { instance, model } = renderComponent();
18
-
19
- model.fields.forEach((detail) => expectModelFieldValue(detail, instance));
20
- });
21
- });