@evenicanpm/portal-editor-ui 1.5.0 → 1.7.0

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 (33) hide show
  1. package/package.json +5 -4
  2. package/{dist/editor.d.ts → src/editor.tsx} +14 -10
  3. package/src/features/editor/components/column-list/column-card/column-card-options.tsx +48 -0
  4. package/src/features/editor/components/column-list/column-card/column-card-title.tsx +13 -0
  5. package/src/features/editor/components/column-list/column-card/column-card.tsx +134 -0
  6. package/src/features/editor/components/column-list/column-card/drag-handle.tsx +32 -0
  7. package/src/features/editor/components/column-list/column-card/editable-label.tsx +132 -0
  8. package/src/features/editor/components/column-list/column-list-section.tsx +49 -0
  9. package/src/features/editor/components/column-list/column-list-skeleton.tsx +49 -0
  10. package/src/features/editor/components/column-list/column-list-state.ts +92 -0
  11. package/src/features/editor/components/column-list/column-list-title.tsx +18 -0
  12. package/src/features/editor/components/column-list/column-list.tsx +212 -0
  13. package/src/features/editor/components/editor-dms-card.tsx +79 -0
  14. package/src/features/editor/components/editor-tabs.tsx +42 -0
  15. package/src/features/editor/components/editor.tsx +62 -0
  16. package/{dist/index.d.ts → src/index.ts} +1 -0
  17. package/dist/features/editor/components/column-list/column-card/column-card-options.d.ts +0 -9
  18. package/dist/features/editor/components/column-list/column-card/column-card-title.d.ts +0 -4
  19. package/dist/features/editor/components/column-list/column-card/column-card.d.ts +0 -8
  20. package/dist/features/editor/components/column-list/column-card/drag-handle.d.ts +0 -6
  21. package/dist/features/editor/components/column-list/column-card/editable-label.d.ts +0 -11
  22. package/dist/features/editor/components/column-list/column-list-section.d.ts +0 -12
  23. package/dist/features/editor/components/column-list/column-list-skeleton.d.ts +0 -1
  24. package/dist/features/editor/components/column-list/column-list-state.d.ts +0 -33
  25. package/dist/features/editor/components/column-list/column-list-title.d.ts +0 -5
  26. package/dist/features/editor/components/column-list/column-list.d.ts +0 -8
  27. package/dist/features/editor/components/editor-dms-card.d.ts +0 -14
  28. package/dist/features/editor/components/editor-tabs.d.ts +0 -13
  29. package/dist/features/editor/components/editor.d.ts +0 -28
  30. package/dist/tsconfig.tsbuildinfo +0 -1
  31. /package/{dist/features/editor/components/column-list/column-card/index.d.ts → src/features/editor/components/column-list/column-card/index.ts} +0 -0
  32. /package/{dist/features/editor/components/column-list/index.d.ts → src/features/editor/components/column-list/index.ts} +0 -0
  33. /package/{dist/features/editor/index.d.ts → src/features/editor/index.ts} +0 -0
@@ -0,0 +1,212 @@
1
+ import {
2
+ closestCenter,
3
+ DndContext,
4
+ type DragEndEvent,
5
+ PointerSensor,
6
+ TouchSensor,
7
+ useSensor,
8
+ useSensors,
9
+ } from "@dnd-kit/core";
10
+ import {
11
+ arrayMove,
12
+ SortableContext,
13
+ verticalListSortingStrategy,
14
+ } from "@dnd-kit/sortable";
15
+ import type { Column, ViewConfig } from "@evenicanpm/portal-types-schemas";
16
+ import AddCircleOutlineIcon from "@mui/icons-material/AddCircleOutline";
17
+ import {
18
+ Box,
19
+ Button,
20
+ Card,
21
+ CardContent,
22
+ Chip,
23
+ Menu,
24
+ MenuItem,
25
+ Typography,
26
+ } from "@mui/material";
27
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
28
+ import { useState } from "react";
29
+ import type { EditorQueries } from "../editor";
30
+ import { ColumnCard } from "./column-card";
31
+ import {
32
+ addFieldToEnd,
33
+ getRemovedFields,
34
+ getVisibleFields,
35
+ patchField,
36
+ removeField,
37
+ reorderVisibleFields,
38
+ } from "./column-list-state";
39
+
40
+ export type ColumnListProps = {
41
+ resourceKey: string;
42
+ initialState: ViewConfig;
43
+ editorQueries: EditorQueries;
44
+ };
45
+
46
+ export function ColumnList({
47
+ resourceKey,
48
+ initialState,
49
+ editorQueries,
50
+ }: Readonly<ColumnListProps>) {
51
+ const columns = initialState.Columns;
52
+ const actions = initialState.Actions;
53
+ const [fields, setFields] = useState<Column[]>(columns ?? []);
54
+ const [addAnchor, setAddAnchor] = useState<null | HTMLElement>(null);
55
+ const addOpen = Boolean(addAnchor);
56
+
57
+ const sensors = useSensors(
58
+ useSensor(PointerSensor, { activationConstraint: { distance: 6 } }),
59
+ useSensor(TouchSensor, {
60
+ activationConstraint: { delay: 150, tolerance: 5 },
61
+ }),
62
+ );
63
+
64
+ const qc = useQueryClient();
65
+
66
+ const saveConfig = useMutation({
67
+ ...editorQueries.saveViewConfigMutation(resourceKey),
68
+ onSuccess: () => {
69
+ qc.invalidateQueries({ queryKey: ["viewConfig", resourceKey] });
70
+ },
71
+ });
72
+
73
+ const visibleFields = getVisibleFields(fields);
74
+ const removedFields = getRemovedFields(fields);
75
+
76
+ const onDragEnd = (event: DragEndEvent) => {
77
+ const { active, over } = event;
78
+ if (!over) return;
79
+ if (active.id === over.id) return;
80
+
81
+ setFields((prev) =>
82
+ reorderVisibleFields(prev, String(active.id), String(over.id), arrayMove),
83
+ );
84
+ };
85
+
86
+ const onChangeField = (id: string, patch: Partial<Column>) => {
87
+ setFields((prev) => patchField(prev, id, patch));
88
+ };
89
+
90
+ const onRemoveField = (id: string) => {
91
+ setFields((prev) => removeField(prev, id));
92
+ };
93
+
94
+ const onAddField = (id: string) => {
95
+ setFields((prev) => addFieldToEnd(prev, id));
96
+ };
97
+
98
+ const isDirty =
99
+ JSON.stringify(initialState.Columns) !== JSON.stringify(fields);
100
+
101
+ const onSaveClick = () => {
102
+ if (!isDirty) return;
103
+
104
+ saveConfig.mutate({
105
+ key: resourceKey,
106
+ viewConfig: { Columns: fields, Actions: actions },
107
+ });
108
+ };
109
+
110
+ return (
111
+ <>
112
+ <Box
113
+ sx={{
114
+ display: "flex",
115
+ justifyContent: "flex-end",
116
+ alignItems: "center",
117
+ position: "relative",
118
+ mb: 2,
119
+ height: 40,
120
+ }}
121
+ >
122
+ {isDirty && (
123
+ <Chip
124
+ label="Unsaved Changes"
125
+ size="small"
126
+ color="warning"
127
+ variant="outlined"
128
+ sx={{
129
+ fontWeight: "bold",
130
+ height: 20,
131
+ position: "absolute",
132
+ left: 0,
133
+ }}
134
+ />
135
+ )}
136
+ <Button
137
+ variant="contained"
138
+ onClick={onSaveClick}
139
+ disabled={!isDirty}
140
+ sx={{ minWidth: 150 }}
141
+ >
142
+ Save Changes
143
+ </Button>
144
+ </Box>
145
+
146
+ <DndContext
147
+ sensors={sensors}
148
+ collisionDetection={closestCenter}
149
+ onDragEnd={onDragEnd}
150
+ >
151
+ {fields.length === 0 ? (
152
+ <Card
153
+ variant="outlined"
154
+ sx={{
155
+ textAlign: "center",
156
+ color: "text.secondary",
157
+ }}
158
+ >
159
+ <CardContent>
160
+ <Typography variant="subtitle1">No fields found</Typography>
161
+ </CardContent>
162
+ </Card>
163
+ ) : (
164
+ <SortableContext
165
+ items={visibleFields.map((f) => f.Data)}
166
+ strategy={verticalListSortingStrategy}
167
+ >
168
+ <Box>
169
+ {visibleFields.map((field) => (
170
+ <ColumnCard
171
+ key={field.Data}
172
+ field={field}
173
+ onChange={onChangeField}
174
+ onRemove={onRemoveField}
175
+ />
176
+ ))}
177
+
178
+ <Box sx={{ display: "flex", justifyContent: "center", mt: 1 }}>
179
+ <Button
180
+ variant="outlined"
181
+ startIcon={<AddCircleOutlineIcon />}
182
+ onClick={(e) => setAddAnchor(e.currentTarget)}
183
+ disabled={removedFields.length === 0}
184
+ >
185
+ Add column
186
+ </Button>
187
+ </Box>
188
+
189
+ <Menu
190
+ anchorEl={addAnchor}
191
+ open={addOpen}
192
+ onClose={() => setAddAnchor(null)}
193
+ >
194
+ {removedFields.map((f) => (
195
+ <MenuItem
196
+ key={f.Data}
197
+ onClick={() => {
198
+ onAddField(f.Data);
199
+ setAddAnchor(null);
200
+ }}
201
+ >
202
+ {f.Label || f.Data}
203
+ </MenuItem>
204
+ ))}
205
+ </Menu>
206
+ </Box>
207
+ </SortableContext>
208
+ )}
209
+ </DndContext>
210
+ </>
211
+ );
212
+ }
@@ -0,0 +1,79 @@
1
+ "use client";
2
+
3
+ import { CheckCircle } from "@mui/icons-material";
4
+ import { Avatar, Box, Paper, Stack, Typography } from "@mui/material";
5
+
6
+ interface Props {
7
+ /** Currently selected resource */
8
+ selectedResourceKey: string;
9
+ /** A pojo with providers -> images */
10
+ providerImageMap: Record<string, string>;
11
+ /** A pojo with resources -> providers */
12
+ resourceProviderMap: Record<string, string>;
13
+ }
14
+
15
+ /**
16
+ * Editor view header contains provider details and other
17
+ * resource/view config data not related to the column list.
18
+ */
19
+ export function EditorDMSCard({
20
+ selectedResourceKey,
21
+ providerImageMap,
22
+ resourceProviderMap,
23
+ }: Readonly<Props>) {
24
+ const selectedResourceProvider = resourceProviderMap[selectedResourceKey];
25
+ const logoUrl = providerImageMap[selectedResourceProvider];
26
+ return (
27
+ <Paper
28
+ elevation={1}
29
+ sx={{
30
+ p: { xs: 2, sm: 3 },
31
+ mb: 3,
32
+ borderRadius: 2,
33
+ }}
34
+ >
35
+ <Stack
36
+ direction={{ xs: "column", sm: "row" }}
37
+ justifyContent="space-between"
38
+ alignItems={{ xs: "stretch", sm: "center" }}
39
+ spacing={2}
40
+ >
41
+ <Stack direction="row" spacing={2} alignItems="center">
42
+ <Avatar
43
+ src={logoUrl}
44
+ alt={`${selectedResourceKey}-${logoUrl}`}
45
+ sx={{
46
+ width: 56,
47
+ height: 56,
48
+ }}
49
+ />
50
+ <Box>
51
+ <Typography variant="h5" fontWeight={700}>
52
+ Resource: {selectedResourceKey || "None"}
53
+ </Typography>
54
+ <Stack
55
+ direction="row"
56
+ spacing={1}
57
+ alignItems="center"
58
+ sx={{ mt: 0.5 }}
59
+ >
60
+ <Typography variant="body2" color="text.secondary">
61
+ provider: {selectedResourceProvider}
62
+ </Typography>
63
+
64
+ <Stack direction="row" spacing={0.5} alignItems="center">
65
+ <CheckCircle sx={{ fontSize: 16, color: "success.main" }} />
66
+ <Typography
67
+ variant="body2"
68
+ sx={{ color: "success.main", fontWeight: 600 }}
69
+ >
70
+ enabled
71
+ </Typography>
72
+ </Stack>
73
+ </Stack>
74
+ </Box>
75
+ </Stack>
76
+ </Stack>
77
+ </Paper>
78
+ );
79
+ }
@@ -0,0 +1,42 @@
1
+ "use client";
2
+
3
+ import { Box, Paper, Tab, Tabs, Typography } from "@mui/material";
4
+
5
+ interface Props {
6
+ /** List of resource keys to select from */
7
+ resourceList: string[];
8
+ /** Currently selected key */
9
+ selectedResourceKey: string;
10
+ /** Action to take when resource changes. */
11
+ handleChangeResource: (id: string) => void;
12
+ }
13
+
14
+ /**
15
+ * Tab-based selection menu for resource keys on the editor page.
16
+ */
17
+ function EditorResourceTabs({
18
+ resourceList,
19
+ selectedResourceKey,
20
+ handleChangeResource,
21
+ }: Readonly<Props>) {
22
+ return (
23
+ <Box sx={{ my: 3 }}>
24
+ <Typography variant="subtitle1" fontWeight={600} gutterBottom>
25
+ Selected Resource
26
+ </Typography>
27
+ <Paper>
28
+ <Tabs
29
+ value={selectedResourceKey}
30
+ onChange={(_, v) => handleChangeResource(v)}
31
+ variant="fullWidth"
32
+ >
33
+ {resourceList.map((docType) => (
34
+ <Tab key={docType} label={docType} value={docType} />
35
+ ))}
36
+ </Tabs>
37
+ </Paper>
38
+ </Box>
39
+ );
40
+ }
41
+
42
+ export { EditorResourceTabs };
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import type { ViewConfig } from "@evenicanpm/portal-types-schemas";
3
+ import { Box } from "@mui/material";
4
+ import type { QueryKey } from "@tanstack/react-query";
5
+ import { useState } from "react";
6
+ import { ColumnListSection } from "./column-list";
7
+ import { EditorDMSCard } from "./editor-dms-card";
8
+ import { EditorResourceTabs } from "./editor-tabs";
9
+
10
+ export type SaveInput = { key: string; viewConfig: ViewConfig };
11
+
12
+ export type ViewConfigQuery = (resourceKey: string) => {
13
+ queryKey: QueryKey;
14
+ queryFn: () => Promise<ViewConfig>;
15
+ };
16
+
17
+ export type SaveViewConfigMutation = (resourceKey: string) => {
18
+ mutationKey: QueryKey;
19
+ mutationFn: (input: SaveInput) => Promise<ViewConfig>;
20
+ };
21
+
22
+ export type EditorQueries = {
23
+ viewConfigQuery: ViewConfigQuery;
24
+ saveViewConfigMutation: SaveViewConfigMutation;
25
+ };
26
+
27
+ export interface EditorProps {
28
+ resourceList: string[];
29
+ providerMetaData: Record<string, string>;
30
+ resourceProviderMap: Record<string, string>;
31
+ editorQueries: EditorQueries;
32
+ }
33
+ /**
34
+ * Top-Level editor component.
35
+ */
36
+ export function Editor({
37
+ resourceList,
38
+ providerMetaData,
39
+ resourceProviderMap,
40
+ editorQueries,
41
+ }: Readonly<EditorProps>) {
42
+ const [currentResource, setCurrentResource] = useState(resourceList[0]);
43
+
44
+ return (
45
+ <Box sx={{ p: { sm: 3 }, maxWidth: 1200, mx: "auto" }}>
46
+ <EditorResourceTabs
47
+ resourceList={resourceList}
48
+ handleChangeResource={setCurrentResource}
49
+ selectedResourceKey={currentResource}
50
+ />
51
+ <EditorDMSCard
52
+ selectedResourceKey={currentResource}
53
+ providerImageMap={providerMetaData}
54
+ resourceProviderMap={resourceProviderMap}
55
+ />
56
+ <ColumnListSection
57
+ currentResourceKey={currentResource}
58
+ editorQueries={editorQueries}
59
+ />
60
+ </Box>
61
+ );
62
+ }
@@ -1,2 +1,3 @@
1
1
  export { Portal, type PortalProps } from "./editor";
2
+
2
3
  export { Editor } from "./features/editor";
@@ -1,9 +0,0 @@
1
- export type ColumnCardOptionsValue = {
2
- isSortable: boolean;
3
- isSearchable: boolean;
4
- };
5
- export type ColumnCardOptionsProps = {
6
- value: ColumnCardOptionsValue;
7
- onChange: (patch: Partial<ColumnCardOptionsValue>) => void;
8
- };
9
- export declare function ColumnCardOptions({ value, onChange, }: Readonly<ColumnCardOptionsProps>): import("react").JSX.Element;
@@ -1,4 +0,0 @@
1
- export type ColumnCardTitleProps = {
2
- value: string;
3
- };
4
- export declare function ColumnCardTitle({ value }: Readonly<ColumnCardTitleProps>): import("react").JSX.Element;
@@ -1,8 +0,0 @@
1
- import type { Column } from "@evenicanpm/portal-types-schemas";
2
- import * as React from "react";
3
- export type ColumnCardProps = {
4
- field: Column;
5
- onChange: (id: string, patch: Partial<Column>) => void;
6
- onRemove: (id: string) => void;
7
- };
8
- export declare function ColumnCard({ field, onChange, onRemove, }: Readonly<ColumnCardProps>): React.JSX.Element;
@@ -1,6 +0,0 @@
1
- import type { DraggableAttributes, DraggableSyntheticListeners } from "@dnd-kit/core";
2
- export type DragHandleProps = {
3
- attributes: DraggableAttributes;
4
- listeners?: DraggableSyntheticListeners;
5
- };
6
- export declare function DragHandle({ attributes, listeners, }: Readonly<DragHandleProps>): import("react").JSX.Element;
@@ -1,11 +0,0 @@
1
- import * as React from "react";
2
- export type EditableLabelProps = {
3
- value: string;
4
- onCommit: (next: string) => void;
5
- labelPrefix?: string;
6
- inputWidth?: {
7
- xs: string | number;
8
- sm: string | number;
9
- };
10
- };
11
- export declare function EditableLabel({ value, onCommit, labelPrefix, inputWidth, }: Readonly<EditableLabelProps>): React.JSX.Element;
@@ -1,12 +0,0 @@
1
- import type { EditorQueries } from "../editor";
2
- interface ColumnProps {
3
- currentResourceKey: string;
4
- editorQueries: EditorQueries;
5
- }
6
- /**
7
- * The view config column list section that handles
8
- * fetching the initial view config data thats stored in the db
9
- * and handles loading state skeleton view while data is pending
10
- */
11
- export declare function ColumnListSection({ currentResourceKey, editorQueries, }: Readonly<ColumnProps>): import("react").JSX.Element;
12
- export {};
@@ -1 +0,0 @@
1
- export declare function ColumnListSkeleton(): import("react").JSX.Element;
@@ -1,33 +0,0 @@
1
- import type { Column } from "@evenicanpm/portal-types-schemas";
2
- /**
3
- * Reassigns sequential ColumnOrder values (1..n) to visible fields.
4
- */
5
- export declare function normalizeVisibleOrders(list: Column[]): Column[];
6
- /**
7
- * Returns fields that are currently visible (ColumnOrder not null),
8
- * sorted by ColumnOrder.
9
- */
10
- export declare function getVisibleFields(fields: Column[]): Column[];
11
- /**
12
- * Returns fields that are currently removed (ColumnOrder null),
13
- * sorted alphabetically by label or data key.
14
- */
15
- export declare function getRemovedFields(fields: Column[]): Column[];
16
- /**
17
- * Applies a partial update to a single field by id.
18
- */
19
- export declare function patchField(fields: Column[], id: string, patch: Partial<Column>): Column[];
20
- /**
21
- * Removes a field from the visible list by setting ColumnOrder to null
22
- * and re-normalizes remaining visible fields.
23
- */
24
- export declare function removeField(fields: Column[], id: string): Column[];
25
- /**
26
- * Adds a previously removed field back to the end of the visible list
27
- * and re-normalizes ordering.
28
- */
29
- export declare function addFieldToEnd(fields: Column[], id: string): Column[];
30
- /**
31
- * Reorders visible fields after a drag operation and updates ColumnOrder.
32
- */
33
- export declare function reorderVisibleFields(fields: Column[], activeId: string, overId: string, arrayMoveFn: <T>(array: T[], from: number, to: number) => T[]): Column[];
@@ -1,5 +0,0 @@
1
- interface Props {
2
- selectedResourceKey: string;
3
- }
4
- export declare function ColumnListTitle({ selectedResourceKey }: Readonly<Props>): import("react").JSX.Element;
5
- export {};
@@ -1,8 +0,0 @@
1
- import type { ViewConfig } from "@evenicanpm/portal-types-schemas";
2
- import type { EditorQueries } from "../editor";
3
- export type ColumnListProps = {
4
- resourceKey: string;
5
- initialState: ViewConfig;
6
- editorQueries: EditorQueries;
7
- };
8
- export declare function ColumnList({ resourceKey, initialState, editorQueries, }: Readonly<ColumnListProps>): import("react").JSX.Element;
@@ -1,14 +0,0 @@
1
- interface Props {
2
- /** Currently selected resource */
3
- selectedResourceKey: string;
4
- /** A pojo with providers -> images */
5
- providerImageMap: Record<string, string>;
6
- /** A pojo with resources -> providers */
7
- resourceProviderMap: Record<string, string>;
8
- }
9
- /**
10
- * Editor view header contains provider details and other
11
- * resource/view config data not related to the column list.
12
- */
13
- export declare function EditorDMSCard({ selectedResourceKey, providerImageMap, resourceProviderMap, }: Readonly<Props>): import("react").JSX.Element;
14
- export {};
@@ -1,13 +0,0 @@
1
- interface Props {
2
- /** List of resource keys to select from */
3
- resourceList: string[];
4
- /** Currently selected key */
5
- selectedResourceKey: string;
6
- /** Action to take when resource changes. */
7
- handleChangeResource: (id: string) => void;
8
- }
9
- /**
10
- * Tab-based selection menu for resource keys on the editor page.
11
- */
12
- declare function EditorResourceTabs({ resourceList, selectedResourceKey, handleChangeResource, }: Readonly<Props>): import("react").JSX.Element;
13
- export { EditorResourceTabs };
@@ -1,28 +0,0 @@
1
- import type { ViewConfig } from "@evenicanpm/portal-types-schemas";
2
- import type { QueryKey } from "@tanstack/react-query";
3
- export type SaveInput = {
4
- key: string;
5
- viewConfig: ViewConfig;
6
- };
7
- export type ViewConfigQuery = (resourceKey: string) => {
8
- queryKey: QueryKey;
9
- queryFn: () => Promise<ViewConfig>;
10
- };
11
- export type SaveViewConfigMutation = (resourceKey: string) => {
12
- mutationKey: QueryKey;
13
- mutationFn: (input: SaveInput) => Promise<ViewConfig>;
14
- };
15
- export type EditorQueries = {
16
- viewConfigQuery: ViewConfigQuery;
17
- saveViewConfigMutation: SaveViewConfigMutation;
18
- };
19
- export interface EditorProps {
20
- resourceList: string[];
21
- providerMetaData: Record<string, string>;
22
- resourceProviderMap: Record<string, string>;
23
- editorQueries: EditorQueries;
24
- }
25
- /**
26
- * Top-Level editor component.
27
- */
28
- export declare function Editor({ resourceList, providerMetaData, resourceProviderMap, editorQueries, }: Readonly<EditorProps>): import("react").JSX.Element;