@headless-adminapp/app 0.0.17-alpha.3 → 0.0.17-alpha.34
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/AuthWrapper.d.ts +1 -1
- package/app/AuthWrapper.js +4 -1
- package/app/LayoutProvider.d.ts +9 -14
- package/app/LayoutProvider.js +37 -4
- package/app/index.d.ts +1 -0
- package/app/index.js +3 -1
- package/auth/AuthProvider.d.ts +1 -1
- package/auth/AuthProvider.js +19 -3
- package/auth/context.d.ts +1 -0
- package/auth/hooks/useIsSkipAuthCheck.d.ts +1 -0
- package/auth/hooks/useIsSkipAuthCheck.js +8 -0
- package/builders/CommandBuilder/CommandBuilder.d.ts +10 -0
- package/builders/CommandBuilder/CommandBuilder.js +14 -0
- package/builders/CommandBuilder/DefaultCommandBuilder.d.ts +88 -0
- package/builders/CommandBuilder/DefaultCommandBuilder.js +191 -0
- package/builders/CommandBuilder/FormCommandBuilder.d.ts +46 -0
- package/builders/CommandBuilder/FormCommandBuilder.js +171 -0
- package/builders/CommandBuilder/SubgridCommandBuilder.d.ts +45 -0
- package/builders/CommandBuilder/SubgridCommandBuilder.js +240 -0
- package/builders/CommandBuilder/ViewCommandBuilder.d.ts +63 -0
- package/builders/CommandBuilder/ViewCommandBuilder.js +242 -0
- package/builders/CommandBuilder/index.d.ts +1 -0
- package/builders/CommandBuilder/index.js +5 -0
- package/builders/CommandBuilder/utils.d.ts +3 -0
- package/builders/CommandBuilder/utils.js +21 -0
- package/builders/SchemaExperienceBuilder.d.ts +2 -5
- package/builders/SchemaExperienceBuilder.js +16 -16
- package/builders/index.d.ts +1 -1
- package/builders/index.js +1 -2
- package/builders/utils.d.ts +28 -0
- package/builders/utils.js +185 -0
- package/command/hooks/useBaseCommandHandlerContext.js +22 -4
- package/command/hooks/useCommands.d.ts +1 -1
- package/command/hooks/useCommands.js +1 -1
- package/dataform/DataFormProvider/DataResolver.js +6 -6
- package/dataform/DataFormProvider/index.js +3 -3
- package/dataform/hooks/useFormSave.js +9 -2
- package/dataform/hooks/useLoadFormGridPage.js +7 -1
- package/dataform/hooks/useMainFormCommands.d.ts +1 -12
- package/dataform/hooks/useMainFormCommands.js +9 -1
- package/dataform/utils/index.d.ts +4 -3
- package/dataform/utils/index.js +24 -6
- package/datagrid/DataGridProvider/DataResolver.js +9 -49
- package/datagrid/DataGridProvider/index.d.ts +5 -0
- package/datagrid/DataGridProvider/index.js +8 -0
- package/datagrid/DataGridProvider/transformViewColumns.js +4 -4
- package/datagrid/DataGridProvider/utils.d.ts +7 -2
- package/datagrid/DataGridProvider/utils.js +52 -2
- package/datagrid/column-filter/constants.js +38 -3
- package/datagrid/context.d.ts +9 -6
- package/datagrid/hooks/useGridCommands.d.ts +3 -0
- package/datagrid/hooks/useGridCommands.js +3 -0
- package/datagrid/hooks/useMainGridCommands.d.ts +1 -13
- package/datagrid/hooks/useMainGridCommands.js +38 -26
- package/datagrid/hooks/useOpenRecord.d.ts +1 -0
- package/datagrid/hooks/useOpenRecord.js +34 -0
- package/datagrid/hooks/useSubGridCommands.js +25 -65
- package/defaults.d.ts +2 -0
- package/defaults.js +5 -0
- package/form/FormValidationStringContext.d.ts +1 -0
- package/form/FormValidationStringContext.js +1 -0
- package/hooks/useSystemColorScheme.d.ts +1 -1
- package/locale/LocaleProvider.d.ts +2 -1
- package/locale/LocaleProvider.js +3 -3
- package/locale/index.d.ts +1 -0
- package/locale/index.js +1 -0
- package/locale/useCurrencySymbol.d.ts +1 -0
- package/locale/useCurrencySymbol.js +13 -0
- package/locale/utils.d.ts +5 -0
- package/locale/utils.js +7 -0
- package/metadata/MetadataProvider.d.ts +8 -4
- package/metadata/MetadataProvider.js +23 -16
- package/metadata/hooks/useExperienceViewCommands.js +7 -1
- package/metadata/hooks/useExperienceViewSubgridCommands.js +7 -1
- package/metadata/hooks/useMetadata.d.ts +1 -0
- package/metadata/hooks/useMetadata.js +4 -2
- package/metadata/hooks/useSchema.js +2 -2
- package/mutable/context.js +1 -1
- package/navigation/hooks/index.d.ts +1 -0
- package/{appearance → navigation}/hooks/index.js +1 -1
- package/navigation/hooks/useOpenForm.d.ts +2 -4
- package/navigation/hooks/useOpenForm.js +7 -3
- package/navigation/index.d.ts +1 -0
- package/{appearance → navigation}/index.js +0 -3
- package/package.json +12 -3
- package/recordset/RecordSetProvider.js +1 -1
- package/recordset/hooks/useRecordSetResult.js +1 -1
- package/route/RouteProvider.d.ts +2 -2
- package/route/RouteProvider.js +4 -1
- package/store/ComponentStore.d.ts +1 -1
- package/store/ComponentStore.js +5 -9
- package/store/SchemaExperienceStore.d.ts +3 -3
- package/transport/RestDataService/index.d.ts +1 -1
- package/transport/RestDataService/index.js +17 -16
- package/transport/context.d.ts +3 -1
- package/transport/context.js +16 -1
- package/transport/hooks/index.d.ts +1 -0
- package/transport/hooks/index.js +1 -0
- package/transport/hooks/useFileService.d.ts +1 -0
- package/transport/hooks/useFileService.js +12 -0
- package/utils/getAttributeFormattedValue.d.ts +1 -0
- package/utils/getAttributeFormattedValue.js +12 -4
- package/appearance/context.d.ts +0 -7
- package/appearance/context.js +0 -5
- package/appearance/hooks/index.d.ts +0 -1
- package/appearance/hooks/useAppearanceContext.d.ts +0 -1
- package/appearance/hooks/useAppearanceContext.js +0 -12
- package/appearance/index.d.ts +0 -2
- package/builders/CommandBuilder.d.ts +0 -176
- package/builders/CommandBuilder.js +0 -474
- package/locale/types.d.ts +0 -2
- package/locale/types.js +0 -2
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ViewCommandBuilder = void 0;
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const utils_2 = require("./utils");
|
|
15
|
+
var EnabledRules;
|
|
16
|
+
(function (EnabledRules) {
|
|
17
|
+
function HasCreatePermisssion(context) {
|
|
18
|
+
var _a;
|
|
19
|
+
return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableCreate);
|
|
20
|
+
}
|
|
21
|
+
EnabledRules.HasCreatePermisssion = HasCreatePermisssion;
|
|
22
|
+
function HasUpdatePermission(context) {
|
|
23
|
+
var _a;
|
|
24
|
+
return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableUpdate);
|
|
25
|
+
}
|
|
26
|
+
EnabledRules.HasUpdatePermission = HasUpdatePermission;
|
|
27
|
+
function HasDeletePermission(context) {
|
|
28
|
+
var _a;
|
|
29
|
+
return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableDelete);
|
|
30
|
+
}
|
|
31
|
+
EnabledRules.HasDeletePermission = HasDeletePermission;
|
|
32
|
+
function HasSingleRecordSelected(context) {
|
|
33
|
+
return context.primaryControl.selectedIds.length === 1;
|
|
34
|
+
}
|
|
35
|
+
EnabledRules.HasSingleRecordSelected = HasSingleRecordSelected;
|
|
36
|
+
function HasAtLeastOneRecordSelected(context) {
|
|
37
|
+
return context.primaryControl.selectedIds.length > 0;
|
|
38
|
+
}
|
|
39
|
+
EnabledRules.HasAtLeastOneRecordSelected = HasAtLeastOneRecordSelected;
|
|
40
|
+
})(EnabledRules || (EnabledRules = {}));
|
|
41
|
+
var ViewCommandBuilder;
|
|
42
|
+
(function (ViewCommandBuilder) {
|
|
43
|
+
function createNewRecordCommand({ Icon, text, localizedTexts, }) {
|
|
44
|
+
return {
|
|
45
|
+
type: 'button',
|
|
46
|
+
Icon,
|
|
47
|
+
text,
|
|
48
|
+
localizedText: localizedTexts,
|
|
49
|
+
onClick: (context) => {
|
|
50
|
+
context.navigation.openForm({
|
|
51
|
+
logicalName: context.primaryControl.schema.logicalName,
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
hidden: (context) => {
|
|
55
|
+
if (!EnabledRules.HasCreatePermisssion(context)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
ViewCommandBuilder.createNewRecordCommand = createNewRecordCommand;
|
|
63
|
+
function createEditRecordCommand({ Icon, text, localizedTexts, }) {
|
|
64
|
+
return {
|
|
65
|
+
type: 'button',
|
|
66
|
+
Icon,
|
|
67
|
+
text,
|
|
68
|
+
localizedText: localizedTexts,
|
|
69
|
+
isContextMenu: true,
|
|
70
|
+
onClick: (context) => {
|
|
71
|
+
context.primaryControl.openRecord(context.primaryControl.selectedIds[0]);
|
|
72
|
+
},
|
|
73
|
+
hidden: [(context) => !EnabledRules.HasSingleRecordSelected(context)],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
ViewCommandBuilder.createEditRecordCommand = createEditRecordCommand;
|
|
77
|
+
ViewCommandBuilder.defaultDeleteRecordStringSet = {
|
|
78
|
+
confirmation: {
|
|
79
|
+
text: [
|
|
80
|
+
'Are you sure you want to delete this record?',
|
|
81
|
+
'Are you sure you want to delete selected records?',
|
|
82
|
+
],
|
|
83
|
+
title: ['Delete record', 'Delete records'],
|
|
84
|
+
buttonConfirm: 'Delete',
|
|
85
|
+
buttonCancel: 'Cancel',
|
|
86
|
+
},
|
|
87
|
+
status: {
|
|
88
|
+
deleting: ['Deleting record', 'Deleting records'],
|
|
89
|
+
},
|
|
90
|
+
successNotification: {
|
|
91
|
+
title: ['Record deleted', 'Records deleted'],
|
|
92
|
+
text: ['Record deleted successfully', 'Records deleted successfully'],
|
|
93
|
+
},
|
|
94
|
+
errorNotification: {
|
|
95
|
+
title: 'Error',
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
function createDeleteRecordCommand({ Icon, localizedText, text, stringSet = ViewCommandBuilder.defaultDeleteRecordStringSet, localizedStringSet, }) {
|
|
99
|
+
return {
|
|
100
|
+
type: 'button',
|
|
101
|
+
Icon,
|
|
102
|
+
text,
|
|
103
|
+
localizedText,
|
|
104
|
+
danger: true,
|
|
105
|
+
isContextMenu: true,
|
|
106
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const recordIds = context.primaryControl.selectedIds;
|
|
108
|
+
if (!recordIds.length) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const localizeSelector = (0, utils_2.createLocalizedSelector)(stringSet, localizedStringSet, context.locale.language);
|
|
112
|
+
try {
|
|
113
|
+
const confirmResult = yield context.utility.openConfirmDialog({
|
|
114
|
+
title: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.confirmation.title)),
|
|
115
|
+
text: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.confirmation.text)),
|
|
116
|
+
cancelButtonLabel: localizeSelector((s) => s.confirmation.buttonCancel),
|
|
117
|
+
confirmButtonLabel: localizeSelector((s) => s.confirmation.buttonConfirm),
|
|
118
|
+
});
|
|
119
|
+
if (!(confirmResult === null || confirmResult === void 0 ? void 0 : confirmResult.confirmed)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
context.utility.showProgressIndicator((0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.status.deleting)) + '...');
|
|
123
|
+
for (const recordId of recordIds) {
|
|
124
|
+
yield context.dataService.deleteRecord(context.primaryControl.logicalName, recordId);
|
|
125
|
+
}
|
|
126
|
+
context.utility.showNotification({
|
|
127
|
+
title: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.successNotification.title)),
|
|
128
|
+
text: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.successNotification.text)),
|
|
129
|
+
type: 'success',
|
|
130
|
+
});
|
|
131
|
+
context.primaryControl.refresh();
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
context.utility.showNotification({
|
|
135
|
+
title: localizeSelector((s) => s.errorNotification.title),
|
|
136
|
+
text: error.message,
|
|
137
|
+
type: 'error',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
context.utility.hideProgressIndicator();
|
|
142
|
+
}
|
|
143
|
+
}),
|
|
144
|
+
hidden: [
|
|
145
|
+
(context) => !EnabledRules.HasAtLeastOneRecordSelected(context),
|
|
146
|
+
(context) => !EnabledRules.HasDeletePermission(context),
|
|
147
|
+
],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
ViewCommandBuilder.createDeleteRecordCommand = createDeleteRecordCommand;
|
|
151
|
+
function createRefreshCommand({ Icon, localizedTexts, text, }) {
|
|
152
|
+
return {
|
|
153
|
+
type: 'button',
|
|
154
|
+
Icon,
|
|
155
|
+
text,
|
|
156
|
+
localizedText: localizedTexts,
|
|
157
|
+
onClick: (context) => {
|
|
158
|
+
context.primaryControl.refresh();
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
ViewCommandBuilder.createRefreshCommand = createRefreshCommand;
|
|
163
|
+
function createExportCommand({ button, csv, excel, }) {
|
|
164
|
+
return {
|
|
165
|
+
type: 'menu',
|
|
166
|
+
Icon: button.Icon,
|
|
167
|
+
text: button.text,
|
|
168
|
+
localizedTexts: button.localizedTexts,
|
|
169
|
+
items: [
|
|
170
|
+
[
|
|
171
|
+
{
|
|
172
|
+
Icon: excel.Icon,
|
|
173
|
+
text: excel.text,
|
|
174
|
+
localizedTexts: excel.localizedTexts,
|
|
175
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
context.utility.showProgressIndicator('Exporting to Excel...');
|
|
177
|
+
try {
|
|
178
|
+
const result = yield (0, utils_1.retriveRecords)({
|
|
179
|
+
columnFilters: context.primaryControl.columnFilter,
|
|
180
|
+
dataService: context.dataService,
|
|
181
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
182
|
+
schema: context.primaryControl.schema,
|
|
183
|
+
schemaStore: context.stores.schemaStore,
|
|
184
|
+
view: context.primaryControl.view,
|
|
185
|
+
search: context.primaryControl.searchText,
|
|
186
|
+
extraFilter: context.primaryControl.extraFilter,
|
|
187
|
+
sorting: context.primaryControl.sorting,
|
|
188
|
+
skip: 0,
|
|
189
|
+
limit: 5000,
|
|
190
|
+
});
|
|
191
|
+
yield (0, utils_1.exportRecordsXLS)({
|
|
192
|
+
fileName: context.primaryControl.view.name + '.xlsx',
|
|
193
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
194
|
+
records: result.records,
|
|
195
|
+
schema: context.primaryControl.schema,
|
|
196
|
+
schemaStore: context.stores.schemaStore,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
context.utility.hideProgressIndicator();
|
|
201
|
+
}
|
|
202
|
+
}),
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
Icon: csv.Icon,
|
|
206
|
+
text: csv.text,
|
|
207
|
+
localizedTexts: csv.localizedTexts,
|
|
208
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
context.utility.showProgressIndicator('Exporting to CSV...');
|
|
210
|
+
try {
|
|
211
|
+
const result = yield (0, utils_1.retriveRecords)({
|
|
212
|
+
columnFilters: context.primaryControl.columnFilter,
|
|
213
|
+
dataService: context.dataService,
|
|
214
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
215
|
+
schema: context.primaryControl.schema,
|
|
216
|
+
schemaStore: context.stores.schemaStore,
|
|
217
|
+
view: context.primaryControl.view,
|
|
218
|
+
search: context.primaryControl.searchText,
|
|
219
|
+
extraFilter: context.primaryControl.extraFilter,
|
|
220
|
+
sorting: context.primaryControl.sorting,
|
|
221
|
+
skip: 0,
|
|
222
|
+
limit: 5000,
|
|
223
|
+
});
|
|
224
|
+
yield (0, utils_1.exportRecordsCSV)({
|
|
225
|
+
fileName: context.primaryControl.view.name + '.csv',
|
|
226
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
227
|
+
records: result.records,
|
|
228
|
+
schema: context.primaryControl.schema,
|
|
229
|
+
schemaStore: context.stores.schemaStore,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
context.utility.hideProgressIndicator();
|
|
234
|
+
}
|
|
235
|
+
}),
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
],
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
ViewCommandBuilder.createExportCommand = createExportCommand;
|
|
242
|
+
})(ViewCommandBuilder || (exports.ViewCommandBuilder = ViewCommandBuilder = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CommandBuilder } from './CommandBuilder';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandBuilder = void 0;
|
|
4
|
+
var CommandBuilder_1 = require("./CommandBuilder");
|
|
5
|
+
Object.defineProperty(exports, "CommandBuilder", { enumerable: true, get: function () { return CommandBuilder_1.CommandBuilder; } });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Localized } from '@headless-adminapp/core/types';
|
|
2
|
+
export declare function createLocalizedSelector<T>(stringSet: T, localizedStringSet: Localized<T> | undefined, language: string): <U>(selector: (stringSet: T) => U) => U;
|
|
3
|
+
export declare function plurialize(count: number, singular: string | [string, string], plural?: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLocalizedSelector = createLocalizedSelector;
|
|
4
|
+
exports.plurialize = plurialize;
|
|
5
|
+
function createLocalizedSelector(stringSet, localizedStringSet, language) {
|
|
6
|
+
return function selectLocalized(selector) {
|
|
7
|
+
if (localizedStringSet && localizedStringSet[language]) {
|
|
8
|
+
return selector(localizedStringSet[language]);
|
|
9
|
+
}
|
|
10
|
+
return selector(stringSet);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function plurialize(count, singular, plural) {
|
|
14
|
+
if (Array.isArray(singular)) {
|
|
15
|
+
plural = singular[1];
|
|
16
|
+
singular = singular[0];
|
|
17
|
+
}
|
|
18
|
+
let msg = count === 1 ? singular : plural !== null && plural !== void 0 ? plural : singular;
|
|
19
|
+
msg = msg.replace('{count}', count.toString());
|
|
20
|
+
return msg;
|
|
21
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AsyncForm, AsyncQuickCreateForm,
|
|
1
|
+
import { AsyncForm, AsyncQuickCreateForm, Form, FormExperience, QuickCreateForm } from '@headless-adminapp/core/experience/form';
|
|
2
2
|
import { SchemaExperience } from '@headless-adminapp/core/experience/schema';
|
|
3
|
-
import { AsyncView,
|
|
3
|
+
import { AsyncView, View, ViewExperience } from '@headless-adminapp/core/experience/view';
|
|
4
4
|
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
5
5
|
declare abstract class BaseSchemaExperienceBuilder<S extends SchemaAttributes> {
|
|
6
6
|
protected readonly logicalName: string;
|
|
@@ -29,9 +29,6 @@ declare abstract class BaseSchemaExperienceBuilder<S extends SchemaAttributes> {
|
|
|
29
29
|
defineFormExperience(formExperience: FormExperience<S>): FormExperience<S>;
|
|
30
30
|
}
|
|
31
31
|
export interface SchemaExperienceBuilderDefaults {
|
|
32
|
-
formCommands?: EntityMainFormCommandItemExperience[][];
|
|
33
|
-
viewCommands?: EntityMainGridCommandItemExperience[][];
|
|
34
|
-
subgridCommands?: SubGridCommandItemExperience[][];
|
|
35
32
|
localizedViewNames?: Record<string, string>;
|
|
36
33
|
}
|
|
37
34
|
interface SchemaExperienceBuilderOptions {
|
|
@@ -36,17 +36,17 @@ class BaseSchemaExperienceBuilder {
|
|
|
36
36
|
if (!this.defaultLookupId) {
|
|
37
37
|
throw new Error('Default lookup is required');
|
|
38
38
|
}
|
|
39
|
-
if (!this.views.find(
|
|
39
|
+
if (!this.views.find(v => v.id === this.defaultViewId)) {
|
|
40
40
|
throw new Error('Default view not found');
|
|
41
41
|
}
|
|
42
|
-
if (!this.forms.find(
|
|
42
|
+
if (!this.forms.find(f => f.id === this.defaultFormId)) {
|
|
43
43
|
throw new Error('Default form not found');
|
|
44
44
|
}
|
|
45
|
-
if (!this.lookups.find(
|
|
45
|
+
if (!this.lookups.find(l => l.id === this.defaultLookupId)) {
|
|
46
46
|
throw new Error('Default lookup not found');
|
|
47
47
|
}
|
|
48
48
|
if (this.defaultQuickCreateFormId &&
|
|
49
|
-
!this.quickCreateForms.find(
|
|
49
|
+
!this.quickCreateForms.find(f => f.id === this.defaultQuickCreateFormId)) {
|
|
50
50
|
throw new Error('Default quick create form not found');
|
|
51
51
|
}
|
|
52
52
|
return {
|
|
@@ -158,9 +158,9 @@ class SchemaExperienceBuilder extends BaseSchemaExperienceBuilder {
|
|
|
158
158
|
var _a;
|
|
159
159
|
const langugesSet = new Set();
|
|
160
160
|
this.schema.localizedPluralLabels &&
|
|
161
|
-
Object.keys(this.schema.localizedPluralLabels).forEach(
|
|
161
|
+
Object.keys(this.schema.localizedPluralLabels).forEach(key => langugesSet.add(key));
|
|
162
162
|
((_a = this.defaults) === null || _a === void 0 ? void 0 : _a.localizedViewNames) &&
|
|
163
|
-
Object.keys(this.defaults.localizedViewNames).forEach(
|
|
163
|
+
Object.keys(this.defaults.localizedViewNames).forEach(key => langugesSet.add(key));
|
|
164
164
|
const localizedLabels = Array.from(langugesSet).reduce((acc, key) => {
|
|
165
165
|
var _a, _b, _c, _d, _e, _f;
|
|
166
166
|
const localizedPluralName = (_c = (_b = (_a = this.schema.localizedPluralLabels) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : this.schema.pluralLabel.toLowerCase();
|
|
@@ -178,13 +178,13 @@ class SchemaExperienceBuilder extends BaseSchemaExperienceBuilder {
|
|
|
178
178
|
if (!defaultId) {
|
|
179
179
|
return data[0].id;
|
|
180
180
|
}
|
|
181
|
-
if (!data.find(
|
|
181
|
+
if (!data.find(x => x.id === defaultId)) {
|
|
182
182
|
return data[0].id;
|
|
183
183
|
}
|
|
184
184
|
return defaultId;
|
|
185
185
|
}
|
|
186
186
|
defineExperience(experience) {
|
|
187
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
187
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
188
188
|
let lookups = experience.lookups;
|
|
189
189
|
let views = experience.views;
|
|
190
190
|
let forms = experience.forms;
|
|
@@ -243,14 +243,14 @@ class SchemaExperienceBuilder extends BaseSchemaExperienceBuilder {
|
|
|
243
243
|
defaultViewId,
|
|
244
244
|
defaultLookupId,
|
|
245
245
|
defaultAssociatedViewId,
|
|
246
|
-
quickCreateForms: (_d = (_c = experience.quickCreateForms) === null || _c === void 0 ? void 0 : _c.map(
|
|
247
|
-
views: (_e = views.map(
|
|
248
|
-
forms: (_f = forms.map(
|
|
249
|
-
lookups: (_g = lookups.map(
|
|
250
|
-
associatedViews: (_h = associatedViews.map(
|
|
251
|
-
formCommands:
|
|
252
|
-
subgridCommands:
|
|
253
|
-
viewCommands:
|
|
246
|
+
quickCreateForms: (_d = (_c = experience.quickCreateForms) === null || _c === void 0 ? void 0 : _c.map(x => (Object.assign(Object.assign({}, x), { logicalName: this.logicalName })))) !== null && _d !== void 0 ? _d : [],
|
|
247
|
+
views: (_e = views.map(x => (Object.assign(Object.assign({}, x), { logicalName: this.logicalName })))) !== null && _e !== void 0 ? _e : [],
|
|
248
|
+
forms: (_f = forms.map(x => (Object.assign(Object.assign({}, x), { logicalName: this.logicalName })))) !== null && _f !== void 0 ? _f : [],
|
|
249
|
+
lookups: (_g = lookups.map(x => (Object.assign(Object.assign({}, x), { logicalName: this.logicalName })))) !== null && _g !== void 0 ? _g : [],
|
|
250
|
+
associatedViews: (_h = associatedViews.map(x => (Object.assign(Object.assign({}, x), { logicalName: this.logicalName })))) !== null && _h !== void 0 ? _h : [],
|
|
251
|
+
formCommands: experience.formCommands,
|
|
252
|
+
subgridCommands: experience.subgridCommands,
|
|
253
|
+
viewCommands: experience.viewCommands,
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
256
|
}
|
package/builders/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { SchemaExperienceBuilder, type SchemaExperienceBuilderDefaults, } from './SchemaExperienceBuilder';
|
|
2
|
-
export { CommandBuilder
|
|
2
|
+
export { CommandBuilder } from './CommandBuilder';
|
package/builders/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CommandBuilder = exports.SchemaExperienceBuilder = void 0;
|
|
4
4
|
var SchemaExperienceBuilder_1 = require("./SchemaExperienceBuilder");
|
|
5
5
|
Object.defineProperty(exports, "SchemaExperienceBuilder", { enumerable: true, get: function () { return SchemaExperienceBuilder_1.SchemaExperienceBuilder; } });
|
|
6
6
|
var CommandBuilder_1 = require("./CommandBuilder");
|
|
7
7
|
Object.defineProperty(exports, "CommandBuilder", { enumerable: true, get: function () { return CommandBuilder_1.CommandBuilder; } });
|
|
8
|
-
Object.defineProperty(exports, "localizedLabel", { enumerable: true, get: function () { return CommandBuilder_1.localizedLabel; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ColumnCondition, SortingState, View } from '@headless-adminapp/core/experience/view';
|
|
2
|
+
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
+
import { ISchemaStore } from '@headless-adminapp/core/store';
|
|
4
|
+
import { Filter, IDataService } from '@headless-adminapp/core/transport';
|
|
5
|
+
import { TransformedViewColumn } from '../datagrid';
|
|
6
|
+
type ExportFn<S extends SchemaAttributes = SchemaAttributes> = (option: {
|
|
7
|
+
schema: Schema<S>;
|
|
8
|
+
records: unknown[];
|
|
9
|
+
gridColumns: TransformedViewColumn<SchemaAttributes>[];
|
|
10
|
+
schemaStore: ISchemaStore;
|
|
11
|
+
fileName: string;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
export declare const exportRecordsCSV: ExportFn;
|
|
14
|
+
export declare const exportRecordsXLS: ExportFn;
|
|
15
|
+
export declare function retriveRecords<S extends SchemaAttributes = SchemaAttributes>({ gridColumns, dataService, schema, search, view, extraFilter, columnFilters, schemaStore, sorting, skip, limit, }: {
|
|
16
|
+
gridColumns: TransformedViewColumn<SchemaAttributes>[];
|
|
17
|
+
dataService: IDataService;
|
|
18
|
+
schema: Schema<S>;
|
|
19
|
+
search?: string;
|
|
20
|
+
view: View<S>;
|
|
21
|
+
extraFilter?: Filter;
|
|
22
|
+
columnFilters?: Partial<Record<string, ColumnCondition>>;
|
|
23
|
+
schemaStore: ISchemaStore;
|
|
24
|
+
sorting: SortingState<S>;
|
|
25
|
+
skip: number;
|
|
26
|
+
limit: number;
|
|
27
|
+
}): Promise<import("@headless-adminapp/core/transport").RetriveRecordsResult<InferredSchemaType<S>>>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
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.exportRecordsXLS = exports.exportRecordsCSV = void 0;
|
|
36
|
+
exports.retriveRecords = retriveRecords;
|
|
37
|
+
const utils_1 = require("../datagrid/DataGridProvider/utils");
|
|
38
|
+
const utils_2 = require("../utils");
|
|
39
|
+
const getHeaders = (schema, gridColumns, schemaStore) => {
|
|
40
|
+
const headers = gridColumns.map((column) => {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
if (column.name.indexOf('.') !== -1) {
|
|
43
|
+
const [lookup, field] = column.name.split('.');
|
|
44
|
+
const entity = schema.attributes[lookup].entity;
|
|
45
|
+
const lookupSchema = schemaStore.getSchema(entity);
|
|
46
|
+
return `${(_a = lookupSchema.attributes[field]) === null || _a === void 0 ? void 0 : _a.label} (${(_b = schema.attributes[lookup]) === null || _b === void 0 ? void 0 : _b.label})`;
|
|
47
|
+
}
|
|
48
|
+
return (_c = schema.attributes[column.name]) === null || _c === void 0 ? void 0 : _c.label;
|
|
49
|
+
});
|
|
50
|
+
return headers;
|
|
51
|
+
};
|
|
52
|
+
function getAttribute({ column, schema, schemaStore, }) {
|
|
53
|
+
let attribute;
|
|
54
|
+
if (column.expandedKey) {
|
|
55
|
+
const lookup = column.name;
|
|
56
|
+
const field = column.expandedKey;
|
|
57
|
+
const entity = schema.attributes[lookup].entity;
|
|
58
|
+
const lookupSchema = schemaStore.getSchema(entity);
|
|
59
|
+
attribute = lookupSchema.attributes[field];
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
attribute = schema.attributes[column.name];
|
|
63
|
+
}
|
|
64
|
+
return attribute;
|
|
65
|
+
}
|
|
66
|
+
function extractAttributeData({ column, record, schema, schemaStore, }) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const attribute = getAttribute({ column, schema, schemaStore });
|
|
69
|
+
let value;
|
|
70
|
+
if (column.expandedKey) {
|
|
71
|
+
const lookup = column.name;
|
|
72
|
+
const field = column.expandedKey;
|
|
73
|
+
value = (_b = (_a = record.$expand) === null || _a === void 0 ? void 0 : _a[lookup]) === null || _b === void 0 ? void 0 : _b[field];
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
value = record[column.name];
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
attribute,
|
|
80
|
+
value,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const exportRecordsCSV = (_a) => __awaiter(void 0, [_a], void 0, function* ({ schema, records, gridColumns, schemaStore, fileName, }) {
|
|
84
|
+
const csvDownload = yield Promise.resolve().then(() => __importStar(require('json-to-csv-export')));
|
|
85
|
+
const headers = getHeaders(schema, gridColumns, schemaStore);
|
|
86
|
+
const cellData = records.map((record) => {
|
|
87
|
+
return gridColumns.map((column) => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const { attribute, value } = extractAttributeData({
|
|
90
|
+
column,
|
|
91
|
+
record,
|
|
92
|
+
schema,
|
|
93
|
+
schemaStore,
|
|
94
|
+
});
|
|
95
|
+
if (attribute.type === 'money' || attribute.type === 'number') {
|
|
96
|
+
return (_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : '';
|
|
97
|
+
}
|
|
98
|
+
return (_b = (0, utils_2.getAttributeFormattedValue)(attribute, value)) !== null && _b !== void 0 ? _b : '';
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
csvDownload.default({
|
|
102
|
+
headers,
|
|
103
|
+
data: cellData,
|
|
104
|
+
delimiter: ',',
|
|
105
|
+
filename: fileName,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
exports.exportRecordsCSV = exportRecordsCSV;
|
|
109
|
+
const exportRecordsXLS = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fileName, gridColumns, records, schema, schemaStore, }) {
|
|
110
|
+
const ExcelJS = yield Promise.resolve().then(() => __importStar(require('exceljs')));
|
|
111
|
+
const headers = getHeaders(schema, gridColumns, schemaStore);
|
|
112
|
+
const cellData = records.map((item) => {
|
|
113
|
+
return gridColumns.map((column) => {
|
|
114
|
+
const { attribute, value } = extractAttributeData({
|
|
115
|
+
column,
|
|
116
|
+
record: item,
|
|
117
|
+
schema,
|
|
118
|
+
schemaStore,
|
|
119
|
+
});
|
|
120
|
+
if (!value) {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
switch (attribute === null || attribute === void 0 ? void 0 : attribute.type) {
|
|
124
|
+
case 'money':
|
|
125
|
+
case 'number':
|
|
126
|
+
return value;
|
|
127
|
+
case 'date':
|
|
128
|
+
return value ? new Date(value) : undefined;
|
|
129
|
+
default:
|
|
130
|
+
return (0, utils_2.getAttributeFormattedValue)(attribute, value);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
const workbook = new ExcelJS.Workbook();
|
|
135
|
+
const worksheet = workbook.addWorksheet('Sheet1');
|
|
136
|
+
worksheet.addRow(headers);
|
|
137
|
+
const headerRow = worksheet.getRow(1);
|
|
138
|
+
headerRow.font = { bold: true };
|
|
139
|
+
cellData.forEach((row) => {
|
|
140
|
+
worksheet.addRow(row);
|
|
141
|
+
});
|
|
142
|
+
gridColumns.forEach((column, index) => {
|
|
143
|
+
const attribute = getAttribute({ column, schema, schemaStore });
|
|
144
|
+
const sheetColumn = worksheet.getColumn(index + 1);
|
|
145
|
+
let formatFn = (value) => { var _a; return (_a = (0, utils_2.getAttributeFormattedValue)(attribute, value)) !== null && _a !== void 0 ? _a : ''; };
|
|
146
|
+
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'money') {
|
|
147
|
+
sheetColumn.numFmt = '"₹" #,##0.00';
|
|
148
|
+
}
|
|
149
|
+
let maxLength = 0;
|
|
150
|
+
sheetColumn.eachCell((cell) => {
|
|
151
|
+
const length = formatFn(cell.value).length;
|
|
152
|
+
if (length > maxLength) {
|
|
153
|
+
maxLength = length;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
sheetColumn.width = Math.max(maxLength, 10) * 1.2;
|
|
157
|
+
});
|
|
158
|
+
// Generate the Excel file
|
|
159
|
+
const buffer = yield workbook.xlsx.writeBuffer();
|
|
160
|
+
var blob = new Blob([buffer], {
|
|
161
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
162
|
+
});
|
|
163
|
+
var link = document.createElement('a');
|
|
164
|
+
link.href = window.URL.createObjectURL(blob);
|
|
165
|
+
link.download = fileName;
|
|
166
|
+
link.click();
|
|
167
|
+
});
|
|
168
|
+
exports.exportRecordsXLS = exportRecordsXLS;
|
|
169
|
+
function retriveRecords(_a) {
|
|
170
|
+
return __awaiter(this, arguments, void 0, function* ({ gridColumns, dataService, schema, search, view, extraFilter, columnFilters, schemaStore, sorting, skip, limit, }) {
|
|
171
|
+
const expand = (0, utils_1.collectExpandedKeys)(gridColumns);
|
|
172
|
+
const columns = Array.from(new Set([...gridColumns.filter((x) => !x.expandedKey).map((x) => x.name)]));
|
|
173
|
+
const result = yield dataService.retriveRecords({
|
|
174
|
+
logicalName: schema.logicalName,
|
|
175
|
+
search,
|
|
176
|
+
columns: columns,
|
|
177
|
+
expand,
|
|
178
|
+
filter: (0, utils_1.mergeConditions)(schema, view.experience.filter, extraFilter, columnFilters, schemaStore),
|
|
179
|
+
skip,
|
|
180
|
+
limit,
|
|
181
|
+
sort: sorting,
|
|
182
|
+
});
|
|
183
|
+
return result;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useUtility = useUtility;
|
|
4
4
|
exports.useBaseCommandHandlerContext = useBaseCommandHandlerContext;
|
|
5
|
+
const navigation_1 = require("@headless-adminapp/app/navigation");
|
|
5
6
|
const react_query_1 = require("@tanstack/react-query");
|
|
7
|
+
const react_1 = require("react");
|
|
6
8
|
const hooks_1 = require("../../dialog/hooks");
|
|
7
9
|
const locale_1 = require("../../locale");
|
|
8
10
|
const hooks_2 = require("../../metadata/hooks");
|
|
@@ -16,7 +18,7 @@ function useUtility() {
|
|
|
16
18
|
const openErrorDialog = (0, hooks_1.useOpenErrorDialog)();
|
|
17
19
|
const openPromptDialog = (0, hooks_1.useOpenPromptDialog)();
|
|
18
20
|
const openToastNotification = (0, useOpenToastNotification_1.useOpenToastNotification)();
|
|
19
|
-
return {
|
|
21
|
+
return (0, react_1.useMemo)(() => ({
|
|
20
22
|
hideProgressIndicator,
|
|
21
23
|
showProgressIndicator,
|
|
22
24
|
openAlertDialog,
|
|
@@ -24,7 +26,21 @@ function useUtility() {
|
|
|
24
26
|
openErrorDialog,
|
|
25
27
|
openPromptDialog,
|
|
26
28
|
showNotification: openToastNotification,
|
|
27
|
-
}
|
|
29
|
+
}), [
|
|
30
|
+
hideProgressIndicator,
|
|
31
|
+
openAlertDialog,
|
|
32
|
+
openConfirmDialog,
|
|
33
|
+
openErrorDialog,
|
|
34
|
+
openPromptDialog,
|
|
35
|
+
openToastNotification,
|
|
36
|
+
showProgressIndicator,
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
function useNavigation() {
|
|
40
|
+
const openForm = (0, navigation_1.useOpenForm)();
|
|
41
|
+
return (0, react_1.useMemo)(() => ({
|
|
42
|
+
openForm,
|
|
43
|
+
}), [openForm]);
|
|
28
44
|
}
|
|
29
45
|
function useBaseCommandHandlerContext() {
|
|
30
46
|
const dataService = (0, transport_1.useDataService)();
|
|
@@ -32,11 +48,13 @@ function useBaseCommandHandlerContext() {
|
|
|
32
48
|
const stores = (0, hooks_2.useMetadata)();
|
|
33
49
|
const utility = useUtility();
|
|
34
50
|
const locale = (0, locale_1.useLocale)();
|
|
35
|
-
|
|
51
|
+
const navigation = useNavigation();
|
|
52
|
+
return (0, react_1.useMemo)(() => ({
|
|
36
53
|
dataService,
|
|
37
54
|
queryClient,
|
|
38
55
|
utility,
|
|
39
56
|
stores,
|
|
40
57
|
locale,
|
|
41
|
-
|
|
58
|
+
navigation,
|
|
59
|
+
}), [dataService, queryClient, stores, utility, locale, navigation]);
|
|
42
60
|
}
|