@headless-adminapp/fluent 0.0.17-alpha.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/App/App.d.ts +6 -0
- package/App/App.js +12 -0
- package/App/AppHeaderContianer.d.ts +2 -0
- package/App/AppHeaderContianer.js +67 -0
- package/App/AppLogo.d.ts +8 -0
- package/App/AppLogo.js +17 -0
- package/App/AppProvider.d.ts +9 -0
- package/App/AppProvider.js +50 -0
- package/App/AppStringContext.d.ts +16 -0
- package/App/AppStringContext.js +23 -0
- package/App/AppUI.d.ts +2 -0
- package/App/AppUI.js +16 -0
- package/App/NavigationContainer.d.ts +1 -0
- package/App/NavigationContainer.js +63 -0
- package/App/QuickActionItem.d.ts +10 -0
- package/App/QuickActionItem.js +32 -0
- package/App/index.d.ts +1 -0
- package/App/index.js +5 -0
- package/App/utils.d.ts +14 -0
- package/App/utils.js +27 -0
- package/CommandBar/Button.d.ts +11 -0
- package/CommandBar/Button.js +36 -0
- package/CommandBar/Divider.d.ts +2 -0
- package/CommandBar/Divider.js +10 -0
- package/CommandBar/IconButton.d.ts +9 -0
- package/CommandBar/IconButton.js +32 -0
- package/CommandBar/Label.d.ts +7 -0
- package/CommandBar/Label.js +23 -0
- package/CommandBar/MenuButton.d.ts +13 -0
- package/CommandBar/MenuButton.js +43 -0
- package/CommandBar/MenuItem.d.ts +11 -0
- package/CommandBar/MenuItem.js +37 -0
- package/CommandBar/MenuItems.d.ts +6 -0
- package/CommandBar/MenuItems.js +11 -0
- package/CommandBar/MenuList.d.ts +6 -0
- package/CommandBar/MenuList.js +13 -0
- package/CommandBar/Wrapper.d.ts +8 -0
- package/CommandBar/Wrapper.js +24 -0
- package/CommandBar/index.d.ts +9 -0
- package/CommandBar/index.js +17 -0
- package/CommandBar/types.d.ts +0 -0
- package/CommandBar/types.js +1 -0
- package/DataForm/SectionControl.d.ts +10 -0
- package/DataForm/SectionControl.js +8 -0
- package/DataGrid/ActionCell.d.ts +8 -0
- package/DataGrid/ActionCell.js +11 -0
- package/DataGrid/CommandContainer.d.ts +2 -0
- package/DataGrid/CommandContainer.js +11 -0
- package/DataGrid/CustomizeColumns/AddColumns.d.ts +10 -0
- package/DataGrid/CustomizeColumns/AddColumns.js +94 -0
- package/DataGrid/CustomizeColumns/ColumnItem.d.ts +16 -0
- package/DataGrid/CustomizeColumns/ColumnItem.js +86 -0
- package/DataGrid/CustomizeColumns/CustomizeColumns.d.ts +6 -0
- package/DataGrid/CustomizeColumns/CustomizeColumns.js +80 -0
- package/DataGrid/CustomizeColumns/index.d.ts +1 -0
- package/DataGrid/CustomizeColumns/index.js +5 -0
- package/DataGrid/FormSubgridCommandContainer.d.ts +2 -0
- package/DataGrid/FormSubgridCommandContainer.js +24 -0
- package/DataGrid/FormSubgridViewSelector.d.ts +2 -0
- package/DataGrid/FormSubgridViewSelector.js +41 -0
- package/DataGrid/GridColumnHeader/ConditionValueControl.d.ts +9 -0
- package/DataGrid/GridColumnHeader/ConditionValueControl.js +89 -0
- package/DataGrid/GridColumnHeader/FilterForm.d.ts +11 -0
- package/DataGrid/GridColumnHeader/FilterForm.js +55 -0
- package/DataGrid/GridColumnHeader/OperatorSelect.d.ts +9 -0
- package/DataGrid/GridColumnHeader/OperatorSelect.js +21 -0
- package/DataGrid/GridColumnHeader/TableHeaderFilterCell.d.ts +22 -0
- package/DataGrid/GridColumnHeader/TableHeaderFilterCell.js +152 -0
- package/DataGrid/GridColumnHeader/index.d.ts +1 -0
- package/DataGrid/GridColumnHeader/index.js +5 -0
- package/DataGrid/GridColumnHeader/utils.d.ts +5 -0
- package/DataGrid/GridColumnHeader/utils.js +18 -0
- package/DataGrid/GridHeaderContainer.d.ts +2 -0
- package/DataGrid/GridHeaderContainer.js +9 -0
- package/DataGrid/GridHeaderDesktop.d.ts +6 -0
- package/DataGrid/GridHeaderDesktop.js +40 -0
- package/DataGrid/GridPaginationContainer.d.ts +2 -0
- package/DataGrid/GridPaginationContainer.js +20 -0
- package/DataGrid/GridTableContainer.d.ts +12 -0
- package/DataGrid/GridTableContainer.js +248 -0
- package/DataGrid/ScrollbarWithMoreDataRequest.d.ts +9 -0
- package/DataGrid/ScrollbarWithMoreDataRequest.js +33 -0
- package/DataGrid/TableCell/TableCellAction.d.ts +8 -0
- package/DataGrid/TableCell/TableCellAction.js +41 -0
- package/DataGrid/TableCell/TableCellBase.d.ts +7 -0
- package/DataGrid/TableCell/TableCellBase.js +9 -0
- package/DataGrid/TableCell/TableCellCheckbox.d.ts +6 -0
- package/DataGrid/TableCell/TableCellCheckbox.js +14 -0
- package/DataGrid/TableCell/TableCellLink.d.ts +8 -0
- package/DataGrid/TableCell/TableCellLink.js +33 -0
- package/DataGrid/TableCell/TableCellText.d.ts +7 -0
- package/DataGrid/TableCell/TableCellText.js +24 -0
- package/DataGrid/TableCell/index.d.ts +4 -0
- package/DataGrid/TableCell/index.js +20 -0
- package/DataGrid/getAttributeFormattedValue.d.ts +16 -0
- package/DataGrid/getAttributeFormattedValue.js +92 -0
- package/DataGrid/index.d.ts +4 -0
- package/DataGrid/index.js +11 -0
- package/DataGrid/useTableColumns.d.ts +10 -0
- package/DataGrid/useTableColumns.js +251 -0
- package/DataGrid/utils.d.ts +2 -0
- package/DataGrid/utils.js +15 -0
- package/DialogContainer/AlertDialog.d.ts +10 -0
- package/DialogContainer/AlertDialog.js +15 -0
- package/DialogContainer/ConfirmDialog.d.ts +12 -0
- package/DialogContainer/ConfirmDialog.js +18 -0
- package/DialogContainer/DialogContainer.d.ts +1 -0
- package/DialogContainer/DialogContainer.js +43 -0
- package/DialogContainer/ErrorDialog.d.ts +10 -0
- package/DialogContainer/ErrorDialog.js +22 -0
- package/DialogContainer/PromptDialog.d.ts +27 -0
- package/DialogContainer/PromptDialog.js +99 -0
- package/DialogContainer/index.d.ts +1 -0
- package/DialogContainer/index.js +5 -0
- package/LICENSE +21 -0
- package/OverflowCommandBar/OverflowCommandBar.d.ts +10 -0
- package/OverflowCommandBar/OverflowCommandBar.js +32 -0
- package/OverflowCommandBar/OverflowMenu.d.ts +4 -0
- package/OverflowCommandBar/OverflowMenu.js +45 -0
- package/OverflowCommandBar/OverflowMenuDivider.d.ts +4 -0
- package/OverflowCommandBar/OverflowMenuDivider.js +14 -0
- package/OverflowCommandBar/index.d.ts +3 -0
- package/OverflowCommandBar/index.js +9 -0
- package/OverflowCommandBar/render.d.ts +2 -0
- package/OverflowCommandBar/render.js +26 -0
- package/OverflowCommandBar/utils.d.ts +4 -0
- package/OverflowCommandBar/utils.js +17 -0
- package/PageEntityForm/CommandContainer.d.ts +2 -0
- package/PageEntityForm/CommandContainer.js +49 -0
- package/PageEntityForm/FormTabRelated.d.ts +6 -0
- package/PageEntityForm/FormTabRelated.js +41 -0
- package/PageEntityForm/PageEntityForm.d.ts +8 -0
- package/PageEntityForm/PageEntityForm.js +30 -0
- package/PageEntityForm/PageEntityFormDesktopContainer.d.ts +2 -0
- package/PageEntityForm/PageEntityFormDesktopContainer.js +120 -0
- package/PageEntityForm/PageEntityFormStringContext.d.ts +8 -0
- package/PageEntityForm/PageEntityFormStringContext.js +15 -0
- package/PageEntityForm/RecordCard.d.ts +10 -0
- package/PageEntityForm/RecordCard.js +134 -0
- package/PageEntityForm/RecordSetNavigatorContainer.d.ts +2 -0
- package/PageEntityForm/RecordSetNavigatorContainer.js +72 -0
- package/PageEntityForm/RelatedViewSelector.d.ts +15 -0
- package/PageEntityForm/RelatedViewSelector.js +78 -0
- package/PageEntityForm/SectionContainer.d.ts +6 -0
- package/PageEntityForm/SectionContainer.js +62 -0
- package/PageEntityForm/StandardControl.d.ts +24 -0
- package/PageEntityForm/StandardControl.js +227 -0
- package/PageEntityForm/SubgridControl.d.ts +13 -0
- package/PageEntityForm/SubgridControl.js +66 -0
- package/PageEntityForm/index.d.ts +1 -0
- package/PageEntityForm/index.js +5 -0
- package/PageEntityView/FormSubgridContainer.d.ts +7 -0
- package/PageEntityView/FormSubgridContainer.js +65 -0
- package/PageEntityView/PageEntityView.d.ts +8 -0
- package/PageEntityView/PageEntityView.js +22 -0
- package/PageEntityView/PageEntityViewDesktopContainer.d.ts +2 -0
- package/PageEntityView/PageEntityViewDesktopContainer.js +14 -0
- package/PageEntityView/PageEntityViewDesktopFrame.d.ts +9 -0
- package/PageEntityView/PageEntityViewDesktopFrame.js +48 -0
- package/PageEntityView/PageEntityViewStringContext.d.ts +23 -0
- package/PageEntityView/PageEntityViewStringContext.js +30 -0
- package/PageEntityView/index.d.ts +1 -0
- package/PageEntityView/index.js +5 -0
- package/ProgressIndicatorContainer/index.d.ts +1 -0
- package/ProgressIndicatorContainer/index.js +30 -0
- package/ToastNotificationContainer/index.d.ts +1 -0
- package/ToastNotificationContainer/index.js +44 -0
- package/components/BodyLoading.d.ts +6 -0
- package/components/BodyLoading.js +19 -0
- package/components/DialogLogin.d.ts +6 -0
- package/components/DialogLogin.js +9 -0
- package/components/LoginForm.d.ts +6 -0
- package/components/LoginForm.js +101 -0
- package/components/PageBroken.d.ts +8 -0
- package/components/PageBroken.js +15 -0
- package/components/PageLoading.d.ts +5 -0
- package/components/PageLoading.js +15 -0
- package/components/PageLogin.d.ts +7 -0
- package/components/PageLogin.js +46 -0
- package/form/FormControl.d.ts +6 -0
- package/form/FormControl.js +95 -0
- package/form/FormControlLoading.d.ts +2 -0
- package/form/FormControlLoading.js +9 -0
- package/form/controls/CurrencyControl.d.ts +4 -0
- package/form/controls/CurrencyControl.js +16 -0
- package/form/controls/DateControl.d.ts +6 -0
- package/form/controls/DateControl.js +21 -0
- package/form/controls/DateRangeControl.d.ts +6 -0
- package/form/controls/DateRangeControl.js +49 -0
- package/form/controls/DateTimeControl.d.ts +6 -0
- package/form/controls/DateTimeControl.js +23 -0
- package/form/controls/EmailControl.d.ts +6 -0
- package/form/controls/EmailControl.js +22 -0
- package/form/controls/LookupControl.d.ts +26 -0
- package/form/controls/LookupControl.js +134 -0
- package/form/controls/MultiSelectControl.d.ts +6 -0
- package/form/controls/MultiSelectControl.js +17 -0
- package/form/controls/MultiSelectLookupControl.d.ts +26 -0
- package/form/controls/MultiSelectLookupControl.js +187 -0
- package/form/controls/NumberControl.d.ts +4 -0
- package/form/controls/NumberControl.js +15 -0
- package/form/controls/PasswordControl.d.ts +6 -0
- package/form/controls/PasswordControl.js +13 -0
- package/form/controls/SelectControl.d.ts +9 -0
- package/form/controls/SelectControl.js +29 -0
- package/form/controls/SwitchControl.d.ts +4 -0
- package/form/controls/SwitchControl.js +6 -0
- package/form/controls/TelephoneControl.d.ts +5 -0
- package/form/controls/TelephoneControl.js +16 -0
- package/form/controls/TextAreaControl.d.ts +6 -0
- package/form/controls/TextAreaControl.js +16 -0
- package/form/controls/TextControl.d.ts +10 -0
- package/form/controls/TextControl.js +24 -0
- package/form/controls/types.d.ts +14 -0
- package/form/controls/types.js +2 -0
- package/form/controls/useLookupData.d.ts +19 -0
- package/form/controls/useLookupData.js +104 -0
- package/form/layout/FormBody/FormBody.d.ts +2 -0
- package/form/layout/FormBody/FormBody.js +11 -0
- package/form/layout/FormBody/index.d.ts +1 -0
- package/form/layout/FormBody/index.js +17 -0
- package/form/layout/FormSection/FormSection.d.ts +16 -0
- package/form/layout/FormSection/FormSection.js +83 -0
- package/form/layout/FormSection/FormSectionColumn.d.ts +6 -0
- package/form/layout/FormSection/FormSectionColumn.js +15 -0
- package/form/layout/FormSection/FormSectionLoading.d.ts +6 -0
- package/form/layout/FormSection/FormSectionLoading.js +7 -0
- package/form/layout/FormSection/index.d.ts +1 -0
- package/form/layout/FormSection/index.js +5 -0
- package/form/layout/FormTab/FormTab.d.ts +13 -0
- package/form/layout/FormTab/FormTab.js +82 -0
- package/form/layout/FormTab/FormTabColumn.d.ts +6 -0
- package/form/layout/FormTab/FormTabColumn.js +15 -0
- package/form/layout/FormTab/index.d.ts +1 -0
- package/form/layout/FormTab/index.js +5 -0
- package/form/layout/TabContext.d.ts +6 -0
- package/form/layout/TabContext.js +5 -0
- package/form/layout/index.d.ts +3 -0
- package/form/layout/index.js +11 -0
- package/form/types.d.ts +74 -0
- package/form/types.js +5 -0
- package/package.json +30 -0
- package/types/index.d.ts +32 -0
- package/types/index.js +2 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTableColumns = useTableColumns;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
const datagrid_1 = require("@headless-adminapp/app/datagrid");
|
|
7
|
+
const hooks_1 = require("@headless-adminapp/app/datagrid/hooks");
|
|
8
|
+
const hooks_2 = require("@headless-adminapp/app/hooks");
|
|
9
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
10
|
+
const hooks_3 = require("@headless-adminapp/app/metadata/hooks");
|
|
11
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
12
|
+
const hooks_4 = require("@headless-adminapp/app/recordset/hooks");
|
|
13
|
+
const hooks_5 = require("@headless-adminapp/app/route/hooks");
|
|
14
|
+
const utils_1 = require("@headless-adminapp/app/utils");
|
|
15
|
+
const app_1 = require("@headless-adminapp/core/experience/app");
|
|
16
|
+
const react_table_1 = require("@tanstack/react-table");
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const GridColumnHeader_1 = require("../DataGrid/GridColumnHeader");
|
|
19
|
+
const TableCell_1 = require("../DataGrid/TableCell");
|
|
20
|
+
const TableCellLink_1 = require("../DataGrid/TableCell/TableCellLink");
|
|
21
|
+
const ActionCell_1 = require("./ActionCell");
|
|
22
|
+
const columnHelper = (0, react_table_1.createColumnHelper)();
|
|
23
|
+
const useStyles = (0, react_components_1.makeStyles)({
|
|
24
|
+
selectionCell: {
|
|
25
|
+
position: 'sticky',
|
|
26
|
+
left: 0,
|
|
27
|
+
background: react_components_1.tokens.colorNeutralBackground1,
|
|
28
|
+
zIndex: 1,
|
|
29
|
+
display: 'flex',
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
function useTableColumns({ disableSelection, disableContextMenu, disableColumnResize, disableColumnFilter, disableColumnSort, tableWrapperRef, }) {
|
|
34
|
+
const styles = useStyles();
|
|
35
|
+
const data = (0, hooks_1.useGridData)();
|
|
36
|
+
const columns = (0, hooks_1.useGridColumns)();
|
|
37
|
+
const [, setSorting] = (0, hooks_1.useGridSorting)();
|
|
38
|
+
const schema = (0, hooks_1.useDataGridSchema)();
|
|
39
|
+
const { getSchema } = (0, hooks_3.useMetadata)();
|
|
40
|
+
const [, setSelectedIds] = (0, hooks_1.useGridSelection)();
|
|
41
|
+
const setSelectedIdsRef = (0, react_1.useRef)(setSelectedIds);
|
|
42
|
+
setSelectedIdsRef.current = setSelectedIds;
|
|
43
|
+
const isSubgrid = (0, mutable_1.useContextSelector)(datagrid_1.GridContext, (state) => state.isSubGrid);
|
|
44
|
+
const contextCommands = isSubgrid
|
|
45
|
+
? (0, hooks_1.useSubGridCommands)()
|
|
46
|
+
: (0, hooks_1.useMainGridContextCommands)();
|
|
47
|
+
const mutableContextCommandState = (0, mutable_1.useMutableState)(contextCommands, true);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
mutableContextCommandState.setValue(contextCommands);
|
|
50
|
+
}, [contextCommands, mutableContextCommandState]);
|
|
51
|
+
const tableWrapperSize = (0, hooks_2.useElementSize)(tableWrapperRef);
|
|
52
|
+
const columnWidths = (0, react_1.useMemo)(() => {
|
|
53
|
+
var _a;
|
|
54
|
+
const availableWidth = Math.max(0, ((_a = tableWrapperSize.width) !== null && _a !== void 0 ? _a : 0) - 32 - 32 - 16);
|
|
55
|
+
const { columns: calculatedColumns } = (0, utils_1.calculateColumnWidths)({
|
|
56
|
+
availableWidth,
|
|
57
|
+
gapWidth: 0,
|
|
58
|
+
columns: columns.map((column) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
return ({
|
|
61
|
+
width: (_a = column.width) !== null && _a !== void 0 ? _a : 100,
|
|
62
|
+
maxWidth: (_b = column.maxWidth) !== null && _b !== void 0 ? _b : 1000,
|
|
63
|
+
});
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
return calculatedColumns;
|
|
67
|
+
}, [columns, tableWrapperSize.width]);
|
|
68
|
+
const gridColumns = (0, hooks_1.useGridColumns)();
|
|
69
|
+
const routeResolver = (0, hooks_5.useRouteResolver)();
|
|
70
|
+
const router = (0, hooks_5.useRouter)();
|
|
71
|
+
const recordSetSetter = (0, hooks_4.useRecordSetSetter)();
|
|
72
|
+
const openRecord = (0, react_1.useCallback)((id) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const path = routeResolver({
|
|
75
|
+
logicalName: schema.logicalName,
|
|
76
|
+
type: app_1.PageType.EntityForm,
|
|
77
|
+
id,
|
|
78
|
+
});
|
|
79
|
+
recordSetSetter(schema.logicalName, (_b = (_a = dataRef.current) === null || _a === void 0 ? void 0 : _a.records.map((x) => x[schema.idAttribute])) !== null && _b !== void 0 ? _b : []);
|
|
80
|
+
router.push(path);
|
|
81
|
+
}, [
|
|
82
|
+
recordSetSetter,
|
|
83
|
+
routeResolver,
|
|
84
|
+
router,
|
|
85
|
+
schema.idAttribute,
|
|
86
|
+
schema.logicalName,
|
|
87
|
+
]);
|
|
88
|
+
const { currency, dateFormats } = (0, locale_1.useLocale)();
|
|
89
|
+
const dataRef = (0, react_1.useRef)(data);
|
|
90
|
+
dataRef.current = data;
|
|
91
|
+
return (0, react_1.useMemo)(() => {
|
|
92
|
+
return [
|
|
93
|
+
...(disableSelection
|
|
94
|
+
? []
|
|
95
|
+
: [
|
|
96
|
+
columnHelper.accessor((info) => info[schema.idAttribute], {
|
|
97
|
+
id: '$selectColumn',
|
|
98
|
+
header: () => ((0, jsx_runtime_1.jsx)(react_components_1.TableSelectionCell, { checked: 'mixed', as: 'th', style: {
|
|
99
|
+
position: 'sticky',
|
|
100
|
+
display: 'flex',
|
|
101
|
+
left: 0,
|
|
102
|
+
top: 0,
|
|
103
|
+
background: react_components_1.tokens.colorNeutralBackground3,
|
|
104
|
+
zIndex: 1,
|
|
105
|
+
width: 32,
|
|
106
|
+
maxWidth: 32,
|
|
107
|
+
minWidth: 32,
|
|
108
|
+
} })),
|
|
109
|
+
cell: (info) => ((0, jsx_runtime_1.jsx)(react_components_1.TableSelectionCell, { className: (0, react_components_1.mergeClasses)(styles.selectionCell), checked: info.row.getIsSelected(), onClick: (event) => {
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
event.stopPropagation();
|
|
112
|
+
setSelectedIdsRef.current((ids) => {
|
|
113
|
+
const id = info.row.original[schema.idAttribute];
|
|
114
|
+
if (ids.includes(id)) {
|
|
115
|
+
return ids.filter((i) => i !== id);
|
|
116
|
+
}
|
|
117
|
+
return [...ids, id];
|
|
118
|
+
});
|
|
119
|
+
}, style: {
|
|
120
|
+
width: 32,
|
|
121
|
+
maxWidth: 32,
|
|
122
|
+
minWidth: 32,
|
|
123
|
+
} })),
|
|
124
|
+
enableResizing: false,
|
|
125
|
+
size: 32,
|
|
126
|
+
minSize: 32,
|
|
127
|
+
maxSize: 32,
|
|
128
|
+
}),
|
|
129
|
+
]),
|
|
130
|
+
...gridColumns.map((column, index) => {
|
|
131
|
+
return columnHelper.accessor((info) => info[column.name], {
|
|
132
|
+
id: column.id,
|
|
133
|
+
header: (props) => {
|
|
134
|
+
return ((0, jsx_runtime_1.jsx)(GridColumnHeader_1.TableHeaderFilterCell, { columnName: column.name, sortDirection: props.column.getIsSorted() || undefined, minWidth: props.header.getSize(), column: column, resizable: !disableColumnResize, disableFilter: disableColumnFilter, disableSort: disableColumnSort, onChangeSortDirection: (direction) => {
|
|
135
|
+
setSorting([
|
|
136
|
+
{
|
|
137
|
+
field: column.name,
|
|
138
|
+
order: direction,
|
|
139
|
+
},
|
|
140
|
+
]);
|
|
141
|
+
}, attribute: schema.attributes[column.name], onResetSize: props.column.resetSize, resizeHandler: props.header.getResizeHandler(), children: column.label }, column.id));
|
|
142
|
+
},
|
|
143
|
+
cell: (info) => {
|
|
144
|
+
var _a, _b, _c;
|
|
145
|
+
let attribute;
|
|
146
|
+
let value;
|
|
147
|
+
if (column.expandedKey) {
|
|
148
|
+
const lookup = column.name;
|
|
149
|
+
const field = column.expandedKey;
|
|
150
|
+
const entity = schema.attributes[lookup]
|
|
151
|
+
.entity;
|
|
152
|
+
const lookupSchema = getSchema(entity);
|
|
153
|
+
attribute = lookupSchema.attributes[field];
|
|
154
|
+
value = (_b = (_a = info.row.original.$expand) === null || _a === void 0 ? void 0 : _a[lookup]) === null || _b === void 0 ? void 0 : _b[field];
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
attribute = schema.attributes[column.name];
|
|
158
|
+
value = info.getValue();
|
|
159
|
+
}
|
|
160
|
+
const formattedValue = (_c = (0, utils_1.getAttributeFormattedValue)(attribute, value, {
|
|
161
|
+
currency: currency.currency,
|
|
162
|
+
dateFormat: dateFormats.short,
|
|
163
|
+
})) !== null && _c !== void 0 ? _c : '';
|
|
164
|
+
if (schema.primaryAttribute === column.name) {
|
|
165
|
+
const path = routeResolver({
|
|
166
|
+
logicalName: schema.logicalName,
|
|
167
|
+
type: app_1.PageType.EntityForm,
|
|
168
|
+
id: info.row.original[schema.idAttribute],
|
|
169
|
+
});
|
|
170
|
+
return ((0, jsx_runtime_1.jsx)(TableCellLink_1.TableCellLink, { value: value, width: info.column.getSize(), href: path, onClick: () => {
|
|
171
|
+
openRecord(info.row.original[schema.idAttribute]);
|
|
172
|
+
} }, column.id));
|
|
173
|
+
}
|
|
174
|
+
switch (attribute === null || attribute === void 0 ? void 0 : attribute.type) {
|
|
175
|
+
case 'money':
|
|
176
|
+
return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: formattedValue, width: info.column.getSize(), textAlignment: "right" }, column.id));
|
|
177
|
+
case 'lookup':
|
|
178
|
+
if (!value) {
|
|
179
|
+
return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: "", width: info.column.getSize() }, column.id));
|
|
180
|
+
}
|
|
181
|
+
const path = routeResolver({
|
|
182
|
+
logicalName: attribute.entity,
|
|
183
|
+
type: app_1.PageType.EntityForm,
|
|
184
|
+
id: value.id,
|
|
185
|
+
});
|
|
186
|
+
return ((0, jsx_runtime_1.jsx)(TableCellLink_1.TableCellLink, { value: formattedValue, width: info.column.getSize(), href: path, onClick: () => {
|
|
187
|
+
recordSetSetter('', []);
|
|
188
|
+
router.push(path);
|
|
189
|
+
} }, column.id));
|
|
190
|
+
}
|
|
191
|
+
return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: formattedValue, width: info.column.getSize() }, column.id));
|
|
192
|
+
},
|
|
193
|
+
enableResizing: true,
|
|
194
|
+
size: columnWidths[index],
|
|
195
|
+
minSize: 100,
|
|
196
|
+
maxSize: 1000,
|
|
197
|
+
});
|
|
198
|
+
}),
|
|
199
|
+
...(disableContextMenu
|
|
200
|
+
? []
|
|
201
|
+
: [
|
|
202
|
+
columnHelper.accessor((info) => info[schema.idAttribute], {
|
|
203
|
+
id: '$actionColumn',
|
|
204
|
+
header: () => ((0, jsx_runtime_1.jsx)(react_components_1.TableHeaderCell, { style: {
|
|
205
|
+
minWidth: 32,
|
|
206
|
+
flexShrink: 0,
|
|
207
|
+
// width: 32,
|
|
208
|
+
flex: 1,
|
|
209
|
+
position: 'sticky',
|
|
210
|
+
display: 'flex',
|
|
211
|
+
right: 0,
|
|
212
|
+
top: 0,
|
|
213
|
+
// zIndex: 1,
|
|
214
|
+
background: react_components_1.tokens.colorNeutralBackground3,
|
|
215
|
+
borderBottom: `${react_components_1.tokens.strokeWidthThin} solid ${react_components_1.tokens.colorNeutralStroke3}`,
|
|
216
|
+
}, children: "\u00A0" })),
|
|
217
|
+
cell: (info) => ((0, jsx_runtime_1.jsx)(ActionCell_1.ActionCell, { onOpen: () => {
|
|
218
|
+
const id = info.row.original[schema.idAttribute];
|
|
219
|
+
setSelectedIdsRef.current([id]);
|
|
220
|
+
}, mutableState: mutableContextCommandState })),
|
|
221
|
+
enableResizing: false,
|
|
222
|
+
size: 32,
|
|
223
|
+
minSize: 32,
|
|
224
|
+
maxSize: 32,
|
|
225
|
+
}),
|
|
226
|
+
]),
|
|
227
|
+
];
|
|
228
|
+
}, [
|
|
229
|
+
disableSelection,
|
|
230
|
+
gridColumns,
|
|
231
|
+
disableContextMenu,
|
|
232
|
+
schema.idAttribute,
|
|
233
|
+
schema.attributes,
|
|
234
|
+
schema.primaryAttribute,
|
|
235
|
+
schema.logicalName,
|
|
236
|
+
styles.selectionCell,
|
|
237
|
+
columnWidths,
|
|
238
|
+
disableColumnResize,
|
|
239
|
+
disableColumnFilter,
|
|
240
|
+
disableColumnSort,
|
|
241
|
+
setSorting,
|
|
242
|
+
currency.currency,
|
|
243
|
+
dateFormats.short,
|
|
244
|
+
getSchema,
|
|
245
|
+
routeResolver,
|
|
246
|
+
openRecord,
|
|
247
|
+
recordSetSetter,
|
|
248
|
+
router,
|
|
249
|
+
mutableContextCommandState,
|
|
250
|
+
]);
|
|
251
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adjustTableHeight = void 0;
|
|
4
|
+
const adjustTableHeight = (tableRef, virtualHeight) => {
|
|
5
|
+
if (!tableRef.current)
|
|
6
|
+
return;
|
|
7
|
+
// calculate the height for the pseudo element after the table
|
|
8
|
+
const existingPseudoElement = window.getComputedStyle(tableRef.current, '::after');
|
|
9
|
+
const existingPseudoHeight = parseFloat(existingPseudoElement.height) || 0;
|
|
10
|
+
const tableHeight = tableRef.current.clientHeight - existingPseudoHeight;
|
|
11
|
+
const pseudoHeight = Math.max(virtualHeight - tableHeight, 0);
|
|
12
|
+
document.documentElement.style.setProperty('--pseudo-height', `${pseudoHeight}px`);
|
|
13
|
+
return pseudoHeight;
|
|
14
|
+
};
|
|
15
|
+
exports.adjustTableHeight = adjustTableHeight;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface AlertDialogProps {
|
|
2
|
+
open: boolean;
|
|
3
|
+
title?: string;
|
|
4
|
+
message: string;
|
|
5
|
+
onConfirm?: () => void;
|
|
6
|
+
onDismiss?: () => void;
|
|
7
|
+
confirmText?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function AlertDialog(props: AlertDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlertDialog = AlertDialog;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
function AlertDialog(props) {
|
|
7
|
+
var _a;
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Dialog, { open: props.open, onOpenChange: () => {
|
|
9
|
+
var _a;
|
|
10
|
+
(_a = props.onDismiss) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
11
|
+
}, children: (0, jsx_runtime_1.jsx)(react_components_1.DialogSurface, { style: { maxWidth: 480 }, children: (0, jsx_runtime_1.jsxs)(react_components_1.DialogBody, { children: [!!props.title && (0, jsx_runtime_1.jsx)(react_components_1.DialogTitle, { children: props.title }), (0, jsx_runtime_1.jsx)(react_components_1.DialogContent, { children: props.message }), (0, jsx_runtime_1.jsx)(react_components_1.DialogActions, { children: (0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "primary", onClick: () => {
|
|
12
|
+
var _a;
|
|
13
|
+
(_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
14
|
+
}, children: (_a = props.confirmText) !== null && _a !== void 0 ? _a : 'Close' }) })] }) }) }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface ConfirmDialogProps {
|
|
2
|
+
open: boolean;
|
|
3
|
+
title?: string;
|
|
4
|
+
message: string;
|
|
5
|
+
onConfirm?: () => void;
|
|
6
|
+
onCancel?: () => void;
|
|
7
|
+
onDismiss?: () => void;
|
|
8
|
+
confirmText?: string;
|
|
9
|
+
cancelText?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function ConfirmDialog(props: ConfirmDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfirmDialog = ConfirmDialog;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
function ConfirmDialog(props) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Dialog, { open: props.open, onOpenChange: () => {
|
|
9
|
+
var _a;
|
|
10
|
+
(_a = props.onDismiss) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
11
|
+
}, children: (0, jsx_runtime_1.jsx)(react_components_1.DialogSurface, { style: { maxWidth: 480 }, children: (0, jsx_runtime_1.jsxs)(react_components_1.DialogBody, { children: [!!props.title && (0, jsx_runtime_1.jsx)(react_components_1.DialogTitle, { children: props.title }), (0, jsx_runtime_1.jsx)(react_components_1.DialogContent, { children: props.message }), (0, jsx_runtime_1.jsxs)(react_components_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "secondary", onClick: () => {
|
|
12
|
+
var _a;
|
|
13
|
+
(_a = props.onCancel) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
14
|
+
}, children: (_a = props.cancelText) !== null && _a !== void 0 ? _a : 'Cancel' }), (0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "primary", onClick: () => {
|
|
15
|
+
var _a;
|
|
16
|
+
(_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
17
|
+
}, children: (_b = props.confirmText) !== null && _b !== void 0 ? _b : 'Confirm' })] })] }) }) }));
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DialogContainer: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DialogContainer = void 0;
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const hooks_1 = require("@headless-adminapp/app/dialog/hooks");
|
|
17
|
+
const AlertDialog_1 = require("./AlertDialog");
|
|
18
|
+
const ConfirmDialog_1 = require("./ConfirmDialog");
|
|
19
|
+
const ErrorDialog_1 = require("./ErrorDialog");
|
|
20
|
+
const PromptDialog_1 = require("./PromptDialog");
|
|
21
|
+
const DialogContainer = () => {
|
|
22
|
+
const items = (0, hooks_1.useDialogItems)();
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: items.map((item) => {
|
|
24
|
+
const { id, isOpen } = item, options = __rest(item, ["id", "isOpen"]);
|
|
25
|
+
switch (options.type) {
|
|
26
|
+
case 'alert':
|
|
27
|
+
return ((0, jsx_runtime_1.jsx)(AlertDialog_1.AlertDialog, { message: options.text, open: isOpen, confirmText: options.confirmButtonLabel, onConfirm: options.onConfirm, onDismiss: options.onDismiss, title: options.title }, id));
|
|
28
|
+
case 'confirm':
|
|
29
|
+
return ((0, jsx_runtime_1.jsx)(ConfirmDialog_1.ConfirmDialog, { message: options.text, title: options.title, onCancel: options.onCancel, onConfirm: options.onConfirm, onDismiss: options.onDismiss, open: isOpen, cancelText: options.cancelButtonLabel, confirmText: options.confirmButtonLabel }, id));
|
|
30
|
+
case 'error':
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(ErrorDialog_1.ErrorDialog, { message: options.text, open: isOpen, confirmText: options.confirmButtonLabel, onConfirm: options.onConfirm, onDismiss: options.onDismiss, title: options.title }, id));
|
|
32
|
+
case 'prompt':
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(PromptDialog_1.PromptDialog, { attributes: options.attributes,
|
|
34
|
+
// cancelButtonLabel={options.cancelButtonLabel}
|
|
35
|
+
// confirmButtonLabel={options.confirmButtonLabel}
|
|
36
|
+
defaultValues: options.defaultValues, onCancel: options.onCancel, onDismiss: options.onDismiss, onConfirm: options.onConfirm, text: options.text, title: options.title, open: isOpen, cancelText: options.cancelButtonLabel, confirmText: options.confirmButtonLabel }, id));
|
|
37
|
+
case 'custom':
|
|
38
|
+
return ((0, jsx_runtime_1.jsx)(options.Component, Object.assign({ id: id, isOpen: isOpen }, options.props), id));
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}) }));
|
|
42
|
+
};
|
|
43
|
+
exports.DialogContainer = DialogContainer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface ErrorDialogProps {
|
|
2
|
+
open: boolean;
|
|
3
|
+
title?: string;
|
|
4
|
+
message: string;
|
|
5
|
+
onConfirm?: () => void;
|
|
6
|
+
onDismiss?: () => void;
|
|
7
|
+
confirmText?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function ErrorDialog(props: ErrorDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorDialog = ErrorDialog;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
const icons_1 = require("@headless-adminapp/icons");
|
|
7
|
+
function ErrorDialog(props) {
|
|
8
|
+
var _a;
|
|
9
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Dialog, { open: props.open, onOpenChange: () => {
|
|
10
|
+
var _a;
|
|
11
|
+
(_a = props.onDismiss) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
12
|
+
}, children: (0, jsx_runtime_1.jsx)(react_components_1.DialogSurface, { style: { maxWidth: 480 }, children: (0, jsx_runtime_1.jsxs)(react_components_1.DialogBody, { children: [(0, jsx_runtime_1.jsxs)(react_components_1.DialogTitle, { style: { display: 'flex', alignItems: 'center' }, children: [(0, jsx_runtime_1.jsx)("span", { style: {
|
|
13
|
+
color: react_components_1.tokens.colorPaletteRedForeground1,
|
|
14
|
+
// marginBottom: tokens.spacingVerticalL,
|
|
15
|
+
display: 'inline-flex',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
marginRight: react_components_1.tokens.spacingHorizontalS,
|
|
18
|
+
}, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Error, {}) }), props.title || 'Error'] }), (0, jsx_runtime_1.jsx)(react_components_1.DialogContent, { children: props.message }), (0, jsx_runtime_1.jsx)(react_components_1.DialogActions, { children: (0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "primary", style: { background: react_components_1.tokens.colorPaletteRedBackground3 }, onClick: () => {
|
|
19
|
+
var _a;
|
|
20
|
+
(_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
21
|
+
}, children: (_a = props.confirmText) !== null && _a !== void 0 ? _a : 'Close' }) })] }) }) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PromptDialogOptions } from '@headless-adminapp/core/experience/dialog';
|
|
2
|
+
import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
+
import * as yup from 'yup';
|
|
4
|
+
interface PromptDialogProps<SA extends SchemaAttributes = SchemaAttributes> {
|
|
5
|
+
open: boolean;
|
|
6
|
+
title?: PromptDialogOptions<SA>['title'];
|
|
7
|
+
text?: PromptDialogOptions<SA>['text'];
|
|
8
|
+
cancelText?: PromptDialogOptions<SA>['cancelButtonLabel'];
|
|
9
|
+
attributes: PromptDialogOptions<SA>['attributes'];
|
|
10
|
+
defaultValues: PromptDialogOptions<SA>['defaultValues'];
|
|
11
|
+
confirmText?: PromptDialogOptions<SA>['confirmButtonLabel'];
|
|
12
|
+
onConfirm?: PromptDialogOptions<SA>['onConfirm'];
|
|
13
|
+
onCancel?: PromptDialogOptions<SA>['onCancel'];
|
|
14
|
+
onDismiss?: PromptDialogOptions<SA>['onDismiss'];
|
|
15
|
+
}
|
|
16
|
+
export declare function PromptDialog(props: PromptDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare const formValidator: (<A extends SchemaAttributes = SchemaAttributes>(attributes: A) => (values: Record<string, any>, context: any, options: any) => Promise<import("react-hook-form").ResolverResult<{
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
[x: number]: any;
|
|
20
|
+
[x: symbol]: any;
|
|
21
|
+
}>>) & import("lodash").MemoizedFunction;
|
|
22
|
+
export declare const generateValidationSchema: (<A extends SchemaAttributes = SchemaAttributes>(attributes: A) => yup.ObjectSchema<{
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
}, yup.AnyObject, {
|
|
25
|
+
[x: string]: any;
|
|
26
|
+
}, "">) & import("lodash").MemoizedFunction;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.generateValidationSchema = exports.formValidator = void 0;
|
|
36
|
+
exports.PromptDialog = PromptDialog;
|
|
37
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
39
|
+
const utils_1 = require("@headless-adminapp/app/dataform/utils");
|
|
40
|
+
const yup_1 = require("@hookform/resolvers/yup");
|
|
41
|
+
const lodash_1 = require("lodash");
|
|
42
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
43
|
+
const yup = __importStar(require("yup"));
|
|
44
|
+
const SectionControl_1 = require("../DataForm/SectionControl");
|
|
45
|
+
const StandardControl_1 = require("../PageEntityForm/StandardControl");
|
|
46
|
+
function PromptDialog(props) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const form = (0, react_hook_form_1.useForm)({
|
|
49
|
+
mode: 'all',
|
|
50
|
+
defaultValues: props.defaultValues,
|
|
51
|
+
shouldUnregister: false,
|
|
52
|
+
resolver: (0, exports.formValidator)(props.attributes),
|
|
53
|
+
});
|
|
54
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Dialog, { open: props.open, onOpenChange: () => {
|
|
55
|
+
var _a;
|
|
56
|
+
(_a = props.onDismiss) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
57
|
+
}, children: (0, jsx_runtime_1.jsx)(react_components_1.DialogSurface, { style: { maxWidth: 480 }, children: (0, jsx_runtime_1.jsxs)(react_components_1.DialogBody, { children: [!!props.title && (0, jsx_runtime_1.jsx)(react_components_1.DialogTitle, { children: props.title }), (0, jsx_runtime_1.jsxs)(react_components_1.DialogContent, { children: [!!props.text && (0, jsx_runtime_1.jsx)(react_components_1.Body1, { children: props.text }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
58
|
+
display: 'flex',
|
|
59
|
+
flexDirection: 'column',
|
|
60
|
+
gap: react_components_1.tokens.spacingVerticalM,
|
|
61
|
+
marginTop: react_components_1.tokens.spacingVerticalL,
|
|
62
|
+
marginBottom: react_components_1.tokens.spacingVerticalL,
|
|
63
|
+
}, children: Object.entries(props.attributes).map(([attributeName, attribute]) => {
|
|
64
|
+
return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: form.control, name: attributeName, render: ({ field, fieldState, formState }) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
const isError = (fieldState.isTouched || formState.isSubmitted) &&
|
|
67
|
+
!!((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message);
|
|
68
|
+
const errorMessage = fieldState.isTouched || formState.isSubmitted
|
|
69
|
+
? (_b = fieldState.error) === null || _b === void 0 ? void 0 : _b.message
|
|
70
|
+
: '';
|
|
71
|
+
return ((0, jsx_runtime_1.jsx)(SectionControl_1.SectionControlWrapper, { label: attribute.label, labelPosition: "left", required: attribute.required, isError: isError, errorMessage: errorMessage, children: (0, jsx_runtime_1.jsx)(StandardControl_1.StandardControl, { attribute: attribute, name: attributeName, value: field.value, onChange: field.onChange, onBlur: field.onBlur, errorMessage: errorMessage, isError: isError }) }));
|
|
72
|
+
} }, attributeName));
|
|
73
|
+
}) })] }), (0, jsx_runtime_1.jsxs)(react_components_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "secondary", onClick: () => {
|
|
74
|
+
var _a;
|
|
75
|
+
(_a = props.onCancel) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
76
|
+
}, children: (_a = props.cancelText) !== null && _a !== void 0 ? _a : 'Cancel' }), (0, jsx_runtime_1.jsx)(react_components_1.Button, { appearance: "primary", disabled: form.formState.submitCount > 0 && !form.formState.isValid, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
yield form.handleSubmit((values) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
var _a;
|
|
79
|
+
(_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props, values);
|
|
80
|
+
}))();
|
|
81
|
+
}), children: (_b = props.confirmText) !== null && _b !== void 0 ? _b : 'Confirm' })] })] }) }) }));
|
|
82
|
+
}
|
|
83
|
+
exports.formValidator = (0, lodash_1.memoize)(function formValidator(attributes) {
|
|
84
|
+
return (values, context, options) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const validator = (0, exports.generateValidationSchema)(attributes);
|
|
86
|
+
const resolver = (0, yup_1.yupResolver)(validator);
|
|
87
|
+
const result = yield resolver(values, context, options);
|
|
88
|
+
// console.log(result);
|
|
89
|
+
return result;
|
|
90
|
+
});
|
|
91
|
+
}, (attributes) => JSON.stringify({ attributes }));
|
|
92
|
+
exports.generateValidationSchema = (0, lodash_1.memoize)(function generateValidationSchema(attributes) {
|
|
93
|
+
const columns = Object.keys(attributes);
|
|
94
|
+
return yup.object().shape(Object.assign({}, columns.reduce((acc, column) => {
|
|
95
|
+
const attribute = attributes[column];
|
|
96
|
+
const validationSchema = (0, utils_1.generateAttributeValidationSchema)(attribute, 'en', {});
|
|
97
|
+
return Object.assign(Object.assign({}, acc), { [column]: validationSchema });
|
|
98
|
+
}, {})));
|
|
99
|
+
}, (attributes) => JSON.stringify({ attributes }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DialogContainer } from './DialogContainer';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DialogContainer = void 0;
|
|
4
|
+
var DialogContainer_1 = require("./DialogContainer");
|
|
5
|
+
Object.defineProperty(exports, "DialogContainer", { enumerable: true, get: function () { return DialogContainer_1.DialogContainer; } });
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 headless-adminapp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommandItemState } from '@headless-adminapp/app/command';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
interface OverflowCommandBarProps {
|
|
4
|
+
commands: CommandItemState[][];
|
|
5
|
+
align?: 'start' | 'end';
|
|
6
|
+
beforeDivider?: boolean;
|
|
7
|
+
afterDivider?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const OverflowCommandBar: FC<OverflowCommandBarProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OverflowCommandBar = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
9
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const CommandBar_1 = __importDefault(require("../CommandBar"));
|
|
12
|
+
const OverflowMenu_1 = require("./OverflowMenu");
|
|
13
|
+
const render_1 = require("./render");
|
|
14
|
+
const OverflowCommandBar = ({ commands, align = 'start', afterDivider, beforeDivider, }) => {
|
|
15
|
+
const { language } = (0, locale_1.useLocale)();
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Overflow, { children: (0, jsx_runtime_1.jsxs)(CommandBar_1.default.Wrapper, { overflow: "hidden", align: align, children: [beforeDivider && (0, jsx_runtime_1.jsx)(CommandBar_1.default.Divider, {}), commands.map((group, groupIndex) => ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [groupIndex > 0 && ((0, jsx_runtime_1.jsx)(react_components_1.OverflowDivider, { groupId: String(groupIndex - 1), children: (0, jsx_runtime_1.jsx)(CommandBar_1.default.Divider, {}) })), group.map((item, index) => {
|
|
17
|
+
const commandType = item.type;
|
|
18
|
+
switch (item.type) {
|
|
19
|
+
case 'menu':
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.OverflowItem, { id: `${groupIndex}-${index}`, groupId: String(groupIndex), children: (0, render_1.renderCommandItem)(`${groupIndex}-${index}`, item, language) }, index));
|
|
21
|
+
case 'button':
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.OverflowItem, { id: `${groupIndex}-${index}`, groupId: String(groupIndex), children: (0, render_1.renderCommandItem)(`${groupIndex}-${index}`, item, language) }, index));
|
|
23
|
+
case 'label':
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.OverflowItem, { id: `${groupIndex}-${index}`, groupId: String(groupIndex), children: (0, render_1.renderCommandItem)(`${groupIndex}-${index}`, item, language) }, index));
|
|
25
|
+
case 'icon':
|
|
26
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.OverflowItem, { id: `${groupIndex}-${index}`, groupId: String(groupIndex), children: (0, render_1.renderCommandItem)(`${groupIndex}-${index}`, item, language) }, index));
|
|
27
|
+
default:
|
|
28
|
+
throw new Error(`Unknown command type: ${commandType}`);
|
|
29
|
+
}
|
|
30
|
+
})] }, groupIndex))), (0, jsx_runtime_1.jsx)(OverflowMenu_1.OverflowMenu, { items: commands }), afterDivider && (0, jsx_runtime_1.jsx)(CommandBar_1.default.Divider, {})] }) }));
|
|
31
|
+
};
|
|
32
|
+
exports.OverflowCommandBar = OverflowCommandBar;
|