@pautena/react-design-system 0.2.0 → 0.2.1
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 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/generators/model-router/index.d.ts +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/generators/model-router/index.d.ts +1 -0
- package/dist/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/generators/model-router/index.ts +1 -0
- package/src/generators/model-router/model-router.test.tsx +55 -7
- package/src/generators/model-router/model-router.tsx +1 -1
- package/src/generators/model-router/stories/model-router.stories.tsx +48 -1
package/dist/index.d.ts
CHANGED
|
@@ -509,6 +509,8 @@ interface RequestState {
|
|
|
509
509
|
error?: string;
|
|
510
510
|
success?: boolean;
|
|
511
511
|
}
|
|
512
|
+
declare const IdleRequest: RequestState;
|
|
513
|
+
declare const LoadingRequest: RequestState;
|
|
512
514
|
|
|
513
515
|
interface BaseScreenProps {
|
|
514
516
|
/**
|
|
@@ -664,4 +666,4 @@ declare type TabProviderProps = PropsWithChildren<{
|
|
|
664
666
|
}>;
|
|
665
667
|
declare const TabProvider: ({ children, initialValue }: TabProviderProps) => JSX.Element;
|
|
666
668
|
|
|
667
|
-
export { AppBarComponent, AppBarElement, AppBarProfile, AppBarProps, AppBarWithDrawerLayout, AppBarWithDrawerLayoutProps, BasicModelInstance, Bullet, BulletProps, BulletVariant, CenterContainer, CenterContainerProps, Content, ContentComponent, ContentElement, ContentProps, Drawer, DrawerComponent, DrawerContent, DrawerContentComponent, DrawerContentElement, DrawerContentProps, DrawerContext, DrawerContextProps, DrawerElement, DrawerItem, DrawerItemProps, DrawerProps, DrawerProvider, DrawerSection, DrawerSectionProps, EnhancedRemoteTable, EnhancedTable, EnhancedTableHead, GroupField, GroupValueCard, GroupValueCardProps, GroupValueItem, GroupValueItemComponent, GroupValueItemElement, GroupValueItemProps, HeadCell, Header, HeaderAction, HeaderActionVariant, HeaderBreadcrumb, HeaderComponent, HeaderElement, HeaderLayout, HeaderPreset, HeaderProps, HeaderTab, Label, LabelProps, LabelVariant, Link, LinkBehaviour, MiniAppBar, MiniDrawer, Model, ModelField, ModelForm, ModelFormProps, ModelRouter, ModelRouterProps, Nav, NavItem, NavItemAvatar, NavItemBullet, NavItemLabel, NavSection, Notification, NotificationCenterContext, NotificationCenterProps, NotificationCenterProvider, NotificationCenterProviderProps, NotificationCenterProviderUndefinedError, ObjectDetails, ObjectDetailsProps, Order, Placeholder, PlaceholderAction, PlaceholderIconArgs, PlaceholderProps, QueryContainer, QueryContainerError, QueryContainerProps, QueryContainerSuccess, SignIn, SnackbarActionType, SnackbarContentType, TabCard, TabContext, TabContextProvider, TabPanel, TabProvider, TableList, TableListProps, TableRowOption, UndefinedProvider, ValueBoolean, ValueBooleanProps, ValueCard, ValueCardProps, ValueText, ValueTextProps, bulletClasses, getRandomItem, groupValueItemClasses, labelClasses, newArrayWithSize, useDrawer, useGetDefaultThemeColor, useNotificationCenter, useTab };
|
|
669
|
+
export { AppBarComponent, AppBarElement, AppBarProfile, AppBarProps, AppBarWithDrawerLayout, AppBarWithDrawerLayoutProps, BasicModelInstance, Bullet, BulletProps, BulletVariant, CenterContainer, CenterContainerProps, Content, ContentComponent, ContentElement, ContentProps, Drawer, DrawerComponent, DrawerContent, DrawerContentComponent, DrawerContentElement, DrawerContentProps, DrawerContext, DrawerContextProps, DrawerElement, DrawerItem, DrawerItemProps, DrawerProps, DrawerProvider, DrawerSection, DrawerSectionProps, EnhancedRemoteTable, EnhancedTable, EnhancedTableHead, GroupField, GroupValueCard, GroupValueCardProps, GroupValueItem, GroupValueItemComponent, GroupValueItemElement, GroupValueItemProps, HeadCell, Header, HeaderAction, HeaderActionVariant, HeaderBreadcrumb, HeaderComponent, HeaderElement, HeaderLayout, HeaderPreset, HeaderProps, HeaderTab, IdleRequest, Label, LabelProps, LabelVariant, Link, LinkBehaviour, LoadingRequest, MiniAppBar, MiniDrawer, Model, ModelField, ModelForm, ModelFormProps, ModelRouter, ModelRouterProps, Nav, NavItem, NavItemAvatar, NavItemBullet, NavItemLabel, NavSection, Notification, NotificationCenterContext, NotificationCenterProps, NotificationCenterProvider, NotificationCenterProviderProps, NotificationCenterProviderUndefinedError, ObjectDetails, ObjectDetailsProps, Order, Placeholder, PlaceholderAction, PlaceholderIconArgs, PlaceholderProps, QueryContainer, QueryContainerError, QueryContainerProps, QueryContainerSuccess, RequestState, SignIn, SnackbarActionType, SnackbarContentType, TabCard, TabContext, TabContextProvider, TabPanel, TabProvider, TableList, TableListProps, TableRowOption, UndefinedProvider, ValueBoolean, ValueBooleanProps, ValueCard, ValueCardProps, ValueText, ValueTextProps, bulletClasses, getRandomItem, groupValueItemClasses, labelClasses, newArrayWithSize, useDrawer, useGetDefaultThemeColor, useNotificationCenter, useTab };
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { DummyModelRouter } from "./stories/model-router.stories";
|
|
2
|
+
import { DummyModelRouter, InternalModelRouter } from "./stories/model-router.stories";
|
|
3
3
|
import {
|
|
4
4
|
expectModelFieldInputExist,
|
|
5
5
|
expectProgressIndicator,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
expectModelFieldValue,
|
|
11
11
|
expectModelFieldInputValue,
|
|
12
12
|
} from "~/tests";
|
|
13
|
+
import { data as mockData } from "./stories/templates";
|
|
13
14
|
import userEvent from "@testing-library/user-event";
|
|
14
15
|
import { getRandomItem } from "../../utils";
|
|
15
16
|
import { Model } from "../generators.model";
|
|
@@ -17,7 +18,7 @@ import { createModelInstance, MockInstance, mockModel } from "../generators.mock
|
|
|
17
18
|
import { NotificationCenterProvider } from "../../providers";
|
|
18
19
|
import { Box } from "@mui/system";
|
|
19
20
|
import { Button } from "@mui/material";
|
|
20
|
-
import { useNavigate } from "react-router-dom";
|
|
21
|
+
import { Route, Routes, useNavigate } from "react-router-dom";
|
|
21
22
|
|
|
22
23
|
const REQUEST_TIMEOUT = 20;
|
|
23
24
|
|
|
@@ -109,7 +110,7 @@ describe("ModelRouter", () => {
|
|
|
109
110
|
|
|
110
111
|
const actions = {
|
|
111
112
|
navigateToAddScreen: async () => {
|
|
112
|
-
await userEvent.click(screen.
|
|
113
|
+
await userEvent.click(await screen.findByRole("button", { name: "Add" }));
|
|
113
114
|
},
|
|
114
115
|
forceNavigateToAddScreen: async () => {
|
|
115
116
|
await userEvent.click(screen.getByRole("button", { name: /force add/i }));
|
|
@@ -124,6 +125,9 @@ describe("ModelRouter", () => {
|
|
|
124
125
|
navigateToDetailScreen: async ({ name }: { name: string }) => {
|
|
125
126
|
await userEvent.click(await screen.findByRole("cell", { name }));
|
|
126
127
|
},
|
|
128
|
+
navigateToInternal: async () => {
|
|
129
|
+
await userEvent.click(screen.getByRole("button", { name: /go to internal/i }));
|
|
130
|
+
},
|
|
127
131
|
forceNavigateToDetailsScreen: async () => {
|
|
128
132
|
await userEvent.click(screen.getByRole("button", { name: /force details/i }));
|
|
129
133
|
},
|
|
@@ -205,10 +209,10 @@ describe("ModelRouter", () => {
|
|
|
205
209
|
const renderComponent = async ({
|
|
206
210
|
router = "memory",
|
|
207
211
|
screen = "initial",
|
|
208
|
-
deleteFeature
|
|
209
|
-
updateFeature
|
|
210
|
-
addFeature
|
|
211
|
-
detailsFeature
|
|
212
|
+
deleteFeature,
|
|
213
|
+
updateFeature,
|
|
214
|
+
addFeature,
|
|
215
|
+
detailsFeature,
|
|
212
216
|
}: {
|
|
213
217
|
router?: TestRouter;
|
|
214
218
|
screen?: "initial" | "add" | "details" | "update";
|
|
@@ -283,6 +287,15 @@ describe("ModelRouter", () => {
|
|
|
283
287
|
};
|
|
284
288
|
};
|
|
285
289
|
|
|
290
|
+
const renderComponentInsideRouter = () => {
|
|
291
|
+
render(
|
|
292
|
+
<NotificationCenterProvider>
|
|
293
|
+
<InternalModelRouter />
|
|
294
|
+
</NotificationCenterProvider>,
|
|
295
|
+
{ router: "memory" },
|
|
296
|
+
);
|
|
297
|
+
};
|
|
298
|
+
|
|
286
299
|
describe("router screens", () => {
|
|
287
300
|
it("would render the list screen by default", async () => {
|
|
288
301
|
await renderComponent();
|
|
@@ -358,6 +371,41 @@ describe("ModelRouter", () => {
|
|
|
358
371
|
});
|
|
359
372
|
});
|
|
360
373
|
|
|
374
|
+
describe("inside another router", () => {
|
|
375
|
+
it("would navigate to the add screen", async () => {
|
|
376
|
+
renderComponentInsideRouter();
|
|
377
|
+
|
|
378
|
+
await actions.navigateToInternal();
|
|
379
|
+
await actions.navigateToAddScreen();
|
|
380
|
+
|
|
381
|
+
await assertions.expectAddScreen();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("would navigate to the detail screen", async () => {
|
|
385
|
+
renderComponentInsideRouter();
|
|
386
|
+
const {
|
|
387
|
+
item: { id, firstName },
|
|
388
|
+
} = getRandomItem<MockInstance>(mockData);
|
|
389
|
+
|
|
390
|
+
await actions.navigateToInternal();
|
|
391
|
+
await actions.navigateToDetailScreen({ name: firstName });
|
|
392
|
+
|
|
393
|
+
await assertions.expectDetailScreen({ id });
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("would navigate to the update screen", async () => {
|
|
397
|
+
renderComponentInsideRouter();
|
|
398
|
+
const {
|
|
399
|
+
item: { id },
|
|
400
|
+
} = getRandomItem<MockInstance>(mockData);
|
|
401
|
+
|
|
402
|
+
await actions.navigateToInternal();
|
|
403
|
+
await actions.navigateToUpdateScreen({ id });
|
|
404
|
+
|
|
405
|
+
await assertions.expectUpdateScreen({ id });
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
361
409
|
describe("list screen", () => {
|
|
362
410
|
it("would call onRequestList when is mounted", async () => {
|
|
363
411
|
const { onRequestList } = await renderComponent();
|
|
@@ -18,7 +18,7 @@ export type ModelRouterProps<T extends BasicModelInstance> = DetailsScreenProps<
|
|
|
18
18
|
UpdateScreenProps<T>;
|
|
19
19
|
|
|
20
20
|
export const ModelRouter = <T extends BasicModelInstance>(props: ModelRouterProps<T>) => {
|
|
21
|
-
const { updateFeature, addFeature, detailsFeature } = props;
|
|
21
|
+
const { updateFeature = true, addFeature = true, detailsFeature = true } = props;
|
|
22
22
|
return (
|
|
23
23
|
<Routes>
|
|
24
24
|
<Route path="" element={<ListScreen {...props} />} />
|
|
@@ -16,10 +16,13 @@ import {
|
|
|
16
16
|
onSubmitUpdateAction,
|
|
17
17
|
REQUEST_TIMEOUT,
|
|
18
18
|
} from "./templates";
|
|
19
|
+
import { Route, Routes, useNavigate } from "react-router-dom";
|
|
20
|
+
import { Box, Button, Typography } from "@mui/material";
|
|
19
21
|
|
|
20
22
|
interface DummyModelRouterProps {
|
|
21
23
|
requestTimeout: number;
|
|
22
24
|
initialData: MockInstance[];
|
|
25
|
+
basePath?: string;
|
|
23
26
|
deleteFeature?: boolean;
|
|
24
27
|
updateFeature?: boolean;
|
|
25
28
|
addFeature?: boolean;
|
|
@@ -36,6 +39,7 @@ export const DummyModelRouter = (args: DummyModelRouterProps) => {
|
|
|
36
39
|
const {
|
|
37
40
|
requestTimeout,
|
|
38
41
|
initialData,
|
|
42
|
+
basePath = "",
|
|
39
43
|
deleteFeature = true,
|
|
40
44
|
updateFeature = true,
|
|
41
45
|
addFeature = true,
|
|
@@ -130,6 +134,7 @@ export const DummyModelRouter = (args: DummyModelRouterProps) => {
|
|
|
130
134
|
{...args}
|
|
131
135
|
modelName="Items"
|
|
132
136
|
model={mockModel}
|
|
137
|
+
basePath={basePath}
|
|
133
138
|
deleteFeature={deleteFeature}
|
|
134
139
|
updateFeature={updateFeature}
|
|
135
140
|
addFeature={addFeature}
|
|
@@ -163,9 +168,51 @@ const args: DummyModelRouterProps = {
|
|
|
163
168
|
onSubmitUpdateAction,
|
|
164
169
|
onRequestDeleteAction,
|
|
165
170
|
};
|
|
166
|
-
|
|
167
171
|
DummyModelRouter.args = args;
|
|
168
172
|
|
|
173
|
+
export const InternalModelRouter = () => {
|
|
174
|
+
const navigate = useNavigate();
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<Routes>
|
|
178
|
+
<Route
|
|
179
|
+
path="/"
|
|
180
|
+
element={
|
|
181
|
+
<Box>
|
|
182
|
+
<Typography>Internal model route</Typography>
|
|
183
|
+
<Button variant="contained" onClick={() => navigate("/internal")}>
|
|
184
|
+
Go to Internal
|
|
185
|
+
</Button>
|
|
186
|
+
</Box>
|
|
187
|
+
}
|
|
188
|
+
/>
|
|
189
|
+
<Route
|
|
190
|
+
path="/internal/*"
|
|
191
|
+
element={
|
|
192
|
+
<ModelRouter
|
|
193
|
+
modelName="Items"
|
|
194
|
+
model={mockModel}
|
|
195
|
+
basePath="/internal"
|
|
196
|
+
onRequestItem={() => null}
|
|
197
|
+
itemRequest={IdleRequest}
|
|
198
|
+
onRequestList={() => null}
|
|
199
|
+
listData={data}
|
|
200
|
+
onClickDeleteItem={() => null}
|
|
201
|
+
listRequest={IdleRequest}
|
|
202
|
+
deleteRequest={IdleRequest}
|
|
203
|
+
onSubmitNewItem={() => null}
|
|
204
|
+
newItemRequest={IdleRequest}
|
|
205
|
+
onSubmitUpdateItem={() => null}
|
|
206
|
+
submitUpdateItemRequest={IdleRequest}
|
|
207
|
+
updateItemRequest={IdleRequest}
|
|
208
|
+
onRequestUpdateItem={() => null}
|
|
209
|
+
/>
|
|
210
|
+
}
|
|
211
|
+
/>
|
|
212
|
+
</Routes>
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
|
|
169
216
|
export default {
|
|
170
217
|
title: "Generators/ModelRouter",
|
|
171
218
|
component: DummyModelRouter,
|