@headless-adminapp/app 0.0.17-alpha.4 → 0.0.17-alpha.7
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/builders/CommandBuilder.js +106 -13
- package/builders/utils.d.ts +28 -0
- package/builders/utils.js +185 -0
- package/command/hooks/useBaseCommandHandlerContext.js +9 -0
- package/dataform/DataFormProvider/DataResolver.js +4 -4
- package/dataform/DataFormProvider/index.js +3 -3
- package/dataform/hooks/useFormSave.js +2 -2
- package/dataform/utils/index.d.ts +4 -3
- package/dataform/utils/index.js +4 -4
- package/datagrid/DataGridProvider/DataResolver.js +3 -48
- package/datagrid/DataGridProvider/utils.d.ts +7 -2
- package/datagrid/DataGridProvider/utils.js +52 -2
- package/datagrid/context.d.ts +3 -5
- package/datagrid/hooks/useMainGridCommands.d.ts +1 -13
- package/datagrid/hooks/useMainGridCommands.js +11 -21
- package/datagrid/hooks/useOpenRecord.d.ts +1 -0
- package/datagrid/hooks/useOpenRecord.js +34 -0
- package/datagrid/hooks/useSubGridCommands.js +3 -24
- package/locale/LocaleProvider.js +1 -1
- package/metadata/hooks/useMetadata.d.ts +1 -0
- package/metadata/hooks/useMetadata.js +2 -0
- package/metadata/hooks/useSchema.js +2 -2
- package/mutable/context.js +1 -1
- package/navigation/hooks/index.d.ts +1 -0
- package/navigation/hooks/index.js +17 -0
- package/navigation/hooks/useOpenForm.d.ts +2 -4
- package/navigation/hooks/useOpenForm.js +7 -3
- package/navigation/index.d.ts +1 -0
- package/navigation/index.js +17 -0
- package/package.json +11 -3
- package/recordset/RecordSetProvider.js +1 -1
- package/recordset/hooks/useRecordSetResult.js +1 -1
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CommandBuilder = void 0;
|
|
13
13
|
exports.localizedLabel = localizedLabel;
|
|
14
14
|
exports.createLocalizedSelector = createLocalizedSelector;
|
|
15
|
+
const utils_1 = require("./utils");
|
|
15
16
|
function localizedLabel(language, value, fallback) {
|
|
16
17
|
var _a, _b, _c, _d, _e;
|
|
17
18
|
return ((_e = (_d = (_b = (_a = value.localizedLabels) === null || _a === void 0 ? void 0 : _a[language]) !== null && _b !== void 0 ? _b : (_c = fallback === null || fallback === void 0 ? void 0 : fallback.localizedLabels) === null || _c === void 0 ? void 0 : _c[language]) !== null && _d !== void 0 ? _d : value.label) !== null && _e !== void 0 ? _e : fallback === null || fallback === void 0 ? void 0 : fallback.label);
|
|
@@ -28,6 +29,32 @@ var CommandBuilder;
|
|
|
28
29
|
(function (CommandBuilder) {
|
|
29
30
|
let View;
|
|
30
31
|
(function (View) {
|
|
32
|
+
let EnabledRules;
|
|
33
|
+
(function (EnabledRules) {
|
|
34
|
+
function HasCreatePermisssion(context) {
|
|
35
|
+
var _a;
|
|
36
|
+
return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableCreate);
|
|
37
|
+
}
|
|
38
|
+
EnabledRules.HasCreatePermisssion = HasCreatePermisssion;
|
|
39
|
+
function HasUpdatePermission(context) {
|
|
40
|
+
var _a;
|
|
41
|
+
return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableUpdate);
|
|
42
|
+
}
|
|
43
|
+
EnabledRules.HasUpdatePermission = HasUpdatePermission;
|
|
44
|
+
function HasDeletePermission(context) {
|
|
45
|
+
var _a;
|
|
46
|
+
return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableDelete);
|
|
47
|
+
}
|
|
48
|
+
EnabledRules.HasDeletePermission = HasDeletePermission;
|
|
49
|
+
function HasSingleRecordSelected(context) {
|
|
50
|
+
return context.primaryControl.selectedIds.length === 1;
|
|
51
|
+
}
|
|
52
|
+
EnabledRules.HasSingleRecordSelected = HasSingleRecordSelected;
|
|
53
|
+
function HasAtLeastOneRecordSelected(context) {
|
|
54
|
+
return context.primaryControl.selectedIds.length > 0;
|
|
55
|
+
}
|
|
56
|
+
EnabledRules.HasAtLeastOneRecordSelected = HasAtLeastOneRecordSelected;
|
|
57
|
+
})(EnabledRules || (EnabledRules = {}));
|
|
31
58
|
function createNewRecordCommand({ Icon, text, localizedTexts, }) {
|
|
32
59
|
return {
|
|
33
60
|
type: 'button',
|
|
@@ -35,11 +62,14 @@ var CommandBuilder;
|
|
|
35
62
|
text,
|
|
36
63
|
localizedText: localizedTexts,
|
|
37
64
|
onClick: (context) => {
|
|
38
|
-
|
|
65
|
+
context.navigation.openForm({
|
|
66
|
+
logicalName: context.primaryControl.schema.logicalName,
|
|
67
|
+
});
|
|
39
68
|
},
|
|
40
69
|
hidden: (context) => {
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
if (!EnabledRules.HasCreatePermisssion(context)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
43
73
|
return false;
|
|
44
74
|
},
|
|
45
75
|
};
|
|
@@ -53,9 +83,17 @@ var CommandBuilder;
|
|
|
53
83
|
localizedText: localizedTexts,
|
|
54
84
|
isContextMenu: true,
|
|
55
85
|
onClick: (context) => {
|
|
56
|
-
|
|
86
|
+
context.primaryControl.openRecord(context.primaryControl.selectedIds[0]);
|
|
87
|
+
},
|
|
88
|
+
hidden: (context) => {
|
|
89
|
+
if (!EnabledRules.HasUpdatePermission(context)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (!EnabledRules.HasSingleRecordSelected(context)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
57
96
|
},
|
|
58
|
-
hidden: (context) => context.primaryControl.selectedIds.length !== 1, // TODO: check permissions
|
|
59
97
|
};
|
|
60
98
|
}
|
|
61
99
|
View.createEditRecordCommand = createEditRecordCommand;
|
|
@@ -97,7 +135,6 @@ var CommandBuilder;
|
|
|
97
135
|
localizedText,
|
|
98
136
|
danger: true,
|
|
99
137
|
isContextMenu: true,
|
|
100
|
-
hidden: [(context) => context.primaryControl.selectedIds.length === 0], // TODO: check permissions
|
|
101
138
|
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
102
139
|
const recordIds = context.primaryControl.selectedIds;
|
|
103
140
|
if (!recordIds.length) {
|
|
@@ -115,7 +152,9 @@ var CommandBuilder;
|
|
|
115
152
|
return;
|
|
116
153
|
}
|
|
117
154
|
context.utility.showProgressIndicator(plurialize(recordIds.length, localizeSelector((s) => s.status.deleting)) + '...');
|
|
118
|
-
|
|
155
|
+
for (const recordId of recordIds) {
|
|
156
|
+
yield context.dataService.deleteRecord(context.primaryControl.logicalName, recordId);
|
|
157
|
+
}
|
|
119
158
|
context.utility.showNotification({
|
|
120
159
|
title: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.title)),
|
|
121
160
|
text: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.text)),
|
|
@@ -134,6 +173,10 @@ var CommandBuilder;
|
|
|
134
173
|
context.utility.hideProgressIndicator();
|
|
135
174
|
}
|
|
136
175
|
}),
|
|
176
|
+
hidden: [
|
|
177
|
+
(context) => !EnabledRules.HasAtLeastOneRecordSelected(context),
|
|
178
|
+
(context) => !EnabledRules.HasDeletePermission(context),
|
|
179
|
+
],
|
|
137
180
|
};
|
|
138
181
|
}
|
|
139
182
|
View.createDeleteRecordCommand = createDeleteRecordCommand;
|
|
@@ -161,17 +204,67 @@ var CommandBuilder;
|
|
|
161
204
|
Icon: excel.Icon,
|
|
162
205
|
text: excel.text,
|
|
163
206
|
localizedTexts: excel.localizedTexts,
|
|
164
|
-
onClick: (context) => {
|
|
165
|
-
|
|
166
|
-
|
|
207
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
context.utility.showProgressIndicator('Exporting to Excel...');
|
|
209
|
+
try {
|
|
210
|
+
const result = yield (0, utils_1.retriveRecords)({
|
|
211
|
+
columnFilters: context.primaryControl.columnFilter,
|
|
212
|
+
dataService: context.dataService,
|
|
213
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
214
|
+
schema: context.primaryControl.schema,
|
|
215
|
+
schemaStore: context.stores.schemaStore,
|
|
216
|
+
view: context.primaryControl.view,
|
|
217
|
+
search: context.primaryControl.searchText,
|
|
218
|
+
extraFilter: context.primaryControl.extraFilter,
|
|
219
|
+
sorting: context.primaryControl.sorting,
|
|
220
|
+
skip: 0,
|
|
221
|
+
limit: 5000,
|
|
222
|
+
});
|
|
223
|
+
yield (0, utils_1.exportRecordsXLS)({
|
|
224
|
+
fileName: context.primaryControl.view.name + '.xlsx',
|
|
225
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
226
|
+
records: result.records,
|
|
227
|
+
schema: context.primaryControl.schema,
|
|
228
|
+
schemaStore: context.stores.schemaStore,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
context.utility.hideProgressIndicator();
|
|
233
|
+
}
|
|
234
|
+
}),
|
|
167
235
|
},
|
|
168
236
|
{
|
|
169
237
|
Icon: csv.Icon,
|
|
170
238
|
text: csv.text,
|
|
171
239
|
localizedTexts: csv.localizedTexts,
|
|
172
|
-
onClick: (context) => {
|
|
173
|
-
|
|
174
|
-
|
|
240
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
context.utility.showProgressIndicator('Exporting to Excel...');
|
|
242
|
+
try {
|
|
243
|
+
const result = yield (0, utils_1.retriveRecords)({
|
|
244
|
+
columnFilters: context.primaryControl.columnFilter,
|
|
245
|
+
dataService: context.dataService,
|
|
246
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
247
|
+
schema: context.primaryControl.schema,
|
|
248
|
+
schemaStore: context.stores.schemaStore,
|
|
249
|
+
view: context.primaryControl.view,
|
|
250
|
+
search: context.primaryControl.searchText,
|
|
251
|
+
extraFilter: context.primaryControl.extraFilter,
|
|
252
|
+
sorting: context.primaryControl.sorting,
|
|
253
|
+
skip: 0,
|
|
254
|
+
limit: 5000,
|
|
255
|
+
});
|
|
256
|
+
yield (0, utils_1.exportRecordsCSV)({
|
|
257
|
+
fileName: context.primaryControl.view.name + '.csv',
|
|
258
|
+
gridColumns: context.primaryControl.gridColumns,
|
|
259
|
+
records: result.records,
|
|
260
|
+
schema: context.primaryControl.schema,
|
|
261
|
+
schemaStore: context.stores.schemaStore,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
context.utility.hideProgressIndicator();
|
|
266
|
+
}
|
|
267
|
+
}),
|
|
175
268
|
},
|
|
176
269
|
],
|
|
177
270
|
],
|
|
@@ -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,6 +2,7 @@
|
|
|
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");
|
|
6
7
|
const hooks_1 = require("../../dialog/hooks");
|
|
7
8
|
const locale_1 = require("../../locale");
|
|
@@ -26,17 +27,25 @@ function useUtility() {
|
|
|
26
27
|
showNotification: openToastNotification,
|
|
27
28
|
};
|
|
28
29
|
}
|
|
30
|
+
function useNavigation() {
|
|
31
|
+
const openForm = (0, navigation_1.useOpenForm)();
|
|
32
|
+
return {
|
|
33
|
+
openForm,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
29
36
|
function useBaseCommandHandlerContext() {
|
|
30
37
|
const dataService = (0, transport_1.useDataService)();
|
|
31
38
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
32
39
|
const stores = (0, hooks_2.useMetadata)();
|
|
33
40
|
const utility = useUtility();
|
|
34
41
|
const locale = (0, locale_1.useLocale)();
|
|
42
|
+
const navigation = useNavigation();
|
|
35
43
|
return {
|
|
36
44
|
dataService,
|
|
37
45
|
queryClient,
|
|
38
46
|
utility,
|
|
39
47
|
stores,
|
|
40
48
|
locale,
|
|
49
|
+
navigation,
|
|
41
50
|
};
|
|
42
51
|
}
|
|
@@ -39,7 +39,7 @@ function getColumns(form) {
|
|
|
39
39
|
return columns;
|
|
40
40
|
}
|
|
41
41
|
function getRecord(_a) {
|
|
42
|
-
return __awaiter(this, arguments, void 0, function* ({ recordId, dataService, form, schema, columns,
|
|
42
|
+
return __awaiter(this, arguments, void 0, function* ({ recordId, dataService, form, schema, columns, schemaStore, }) {
|
|
43
43
|
var _b;
|
|
44
44
|
let record = null;
|
|
45
45
|
try {
|
|
@@ -60,7 +60,7 @@ function getRecord(_a) {
|
|
|
60
60
|
if (control.type !== 'editablegrid') {
|
|
61
61
|
continue;
|
|
62
62
|
}
|
|
63
|
-
const controlSchema = getSchema(control.logicalName);
|
|
63
|
+
const controlSchema = schemaStore.getSchema(control.logicalName);
|
|
64
64
|
const records = yield dataService.retriveRecords({
|
|
65
65
|
logicalName: controlSchema.logicalName,
|
|
66
66
|
filter: {
|
|
@@ -97,7 +97,7 @@ function DataResolver() {
|
|
|
97
97
|
const form = (0, hooks_2.useSelectedForm)();
|
|
98
98
|
const dataService = (0, transport_2.useDataService)();
|
|
99
99
|
const recordId = (0, hooks_2.useRecordId)();
|
|
100
|
-
const {
|
|
100
|
+
const { schemaStore } = (0, hooks_1.useMetadata)();
|
|
101
101
|
const setState = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
102
102
|
const columns = (0, react_1.useMemo)(() => getColumns(form), [form]);
|
|
103
103
|
const queryKey = (0, react_1.useMemo)(() => ['data', 'retriveRecord', schema.logicalName, recordId, columns], [columns, recordId, schema.logicalName]);
|
|
@@ -113,7 +113,7 @@ function DataResolver() {
|
|
|
113
113
|
form,
|
|
114
114
|
recordId,
|
|
115
115
|
schema,
|
|
116
|
-
|
|
116
|
+
schemaStore,
|
|
117
117
|
});
|
|
118
118
|
return record;
|
|
119
119
|
}),
|
|
@@ -23,7 +23,7 @@ const DataResolver_1 = require("./DataResolver");
|
|
|
23
23
|
const InitialValueResolver_1 = require("./InitialValueResolver");
|
|
24
24
|
const ReadonlyInfoResolver_1 = require("./ReadonlyInfoResolver");
|
|
25
25
|
function DataFormProvider(props) {
|
|
26
|
-
const {
|
|
26
|
+
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
27
27
|
const { language } = (0, useLocale_1.useLocale)();
|
|
28
28
|
const formValidationStrings = (0, FormValidationStringContext_1.useFormValidationStrings)();
|
|
29
29
|
const [formReadOnly, setFormReadOnly] = (0, react_1.useState)(false); // A trick to provide readOnly info to formInstance
|
|
@@ -32,7 +32,7 @@ function DataFormProvider(props) {
|
|
|
32
32
|
defaultValues: {},
|
|
33
33
|
resolver: (0, utils_1.formValidator)({
|
|
34
34
|
form: props.form,
|
|
35
|
-
|
|
35
|
+
schemaStore,
|
|
36
36
|
language,
|
|
37
37
|
schema: props.schema,
|
|
38
38
|
strings: formValidationStrings,
|
|
@@ -65,7 +65,7 @@ function DataFormProvider(props) {
|
|
|
65
65
|
props.schema,
|
|
66
66
|
props.recordId,
|
|
67
67
|
contextValue,
|
|
68
|
-
|
|
68
|
+
schemaStore,
|
|
69
69
|
props.commands,
|
|
70
70
|
]);
|
|
71
71
|
return ((0, jsx_runtime_1.jsx)(context_1.DataFormContext.Provider, { value: contextValue, children: (0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider, Object.assign({}, formInstance, { children: [(0, jsx_runtime_1.jsx)(DataResolver_1.DataResolver, {}), (0, jsx_runtime_1.jsx)(InitialValueResolver_1.InitialValueResolver, {}), (0, jsx_runtime_1.jsx)(ReadonlyInfoResolver_1.ReadonlyInfoResolver, { setFormReadOnly: setFormReadOnly }), props.children] })) }));
|
|
@@ -34,7 +34,7 @@ function useFormSave() {
|
|
|
34
34
|
const form = (0, useSelectedForm_1.useSelectedForm)();
|
|
35
35
|
const formInstance = (0, react_hook_form_1.useFormContext)();
|
|
36
36
|
const record = (0, useFormRecord_1.useFormRecord)();
|
|
37
|
-
const {
|
|
37
|
+
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
38
38
|
const schema = (0, useFormSchema_1.useDataFormSchema)();
|
|
39
39
|
const initialValues = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.initialValues);
|
|
40
40
|
const refresh = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.refresh);
|
|
@@ -76,7 +76,7 @@ function useFormSave() {
|
|
|
76
76
|
initialValues: initialValues,
|
|
77
77
|
dataService,
|
|
78
78
|
schema: schema,
|
|
79
|
-
|
|
79
|
+
schemaStore,
|
|
80
80
|
});
|
|
81
81
|
if (!result.success) {
|
|
82
82
|
openToastNotification({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Attribute } from '@headless-adminapp/core/attributes';
|
|
2
2
|
import { Form } from '@headless-adminapp/core/experience/form';
|
|
3
3
|
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
4
|
+
import { ISchemaStore } from '@headless-adminapp/core/store';
|
|
4
5
|
import { IDataService } from '@headless-adminapp/core/transport';
|
|
5
6
|
import { Nullable } from '@headless-adminapp/core/types';
|
|
6
7
|
import { MemoizedFunction } from 'lodash';
|
|
@@ -17,14 +18,14 @@ type SaveRecordResult = {
|
|
|
17
18
|
message: string;
|
|
18
19
|
isError: boolean;
|
|
19
20
|
};
|
|
20
|
-
export declare function saveRecord({ values, form, schema, dataService, initialValues, record,
|
|
21
|
+
export declare function saveRecord({ values, form, schema, dataService, initialValues, record, schemaStore, }: {
|
|
21
22
|
values: any;
|
|
22
23
|
form: Form<SchemaAttributes>;
|
|
23
24
|
record: InferredSchemaType<SchemaAttributes> | undefined;
|
|
24
25
|
initialValues: Nullable<InferredSchemaType<SchemaAttributes>>;
|
|
25
26
|
schema: Schema<SchemaAttributes>;
|
|
26
27
|
dataService: IDataService;
|
|
27
|
-
|
|
28
|
+
schemaStore: ISchemaStore;
|
|
28
29
|
}): Promise<SaveRecordResult>;
|
|
29
30
|
export declare function getInitialValues({ cloneRecord, form, record, recordId, defaultParameters, }: {
|
|
30
31
|
cloneRecord: InferredSchemaType<SchemaAttributes> | undefined;
|
|
@@ -41,7 +42,7 @@ interface FormValidatorOptions<A extends SchemaAttributes = SchemaAttributes> {
|
|
|
41
42
|
formReadOnly?: boolean;
|
|
42
43
|
readonlyAttributes?: string[];
|
|
43
44
|
strings: FormValidationStringSet;
|
|
44
|
-
|
|
45
|
+
schemaStore: ISchemaStore;
|
|
45
46
|
}
|
|
46
47
|
type FormValidator = (<A extends SchemaAttributes = SchemaAttributes>(options: FormValidatorOptions<A>) => (values: Record<string, any>, context: any, options: any) => Promise<ResolverResult<{}>>) & MemoizedFunction;
|
|
47
48
|
export declare const formValidator: FormValidator;
|
package/dataform/utils/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function getModifiedValues(initialValues, values, exclude) {
|
|
|
57
57
|
}, {});
|
|
58
58
|
}
|
|
59
59
|
function saveRecord(_a) {
|
|
60
|
-
return __awaiter(this, arguments, void 0, function* ({ values, form, schema, dataService, initialValues, record,
|
|
60
|
+
return __awaiter(this, arguments, void 0, function* ({ values, form, schema, dataService, initialValues, record, schemaStore, }) {
|
|
61
61
|
const controls = (0, DataResolver_1.getControls)(form);
|
|
62
62
|
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
63
63
|
const modifiedValues = getModifiedValues(initialValues, values, editableGridControls.map((x) => x.attributeName));
|
|
@@ -74,7 +74,7 @@ function saveRecord(_a) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
for (const control of editableGridControls) {
|
|
77
|
-
const gridSchema = getSchema(control.logicalName);
|
|
77
|
+
const gridSchema = schemaStore.getSchema(control.logicalName);
|
|
78
78
|
const gridRows = values[control.attributeName];
|
|
79
79
|
const initialGridRows = initialValues[control.attributeName];
|
|
80
80
|
const newRows = gridRows.filter((x) => !x[gridSchema.idAttribute]);
|
|
@@ -212,7 +212,7 @@ function getInitialValues({ cloneRecord, form, record, recordId, defaultParamete
|
|
|
212
212
|
return Object.assign(Object.assign({}, acc), { [column]: value });
|
|
213
213
|
}, {});
|
|
214
214
|
}
|
|
215
|
-
exports.formValidator = (0, lodash_1.memoize)(function formValidator({ form, schema, readonlyAttributes, formReadOnly,
|
|
215
|
+
exports.formValidator = (0, lodash_1.memoize)(function formValidator({ form, schema, readonlyAttributes, formReadOnly, schemaStore, language, strings, }) {
|
|
216
216
|
return (values, context, options) => __awaiter(this, void 0, void 0, function* () {
|
|
217
217
|
let validator = yup.object().shape({});
|
|
218
218
|
if (!formReadOnly) {
|
|
@@ -243,7 +243,7 @@ exports.formValidator = (0, lodash_1.memoize)(function formValidator({ form, sch
|
|
|
243
243
|
if (control.type !== 'editablegrid') {
|
|
244
244
|
throw new Error('Invalid control type');
|
|
245
245
|
}
|
|
246
|
-
const schema = getSchema(control.logicalName);
|
|
246
|
+
const schema = schemaStore.getSchema(control.logicalName);
|
|
247
247
|
return {
|
|
248
248
|
columns: control.attributes,
|
|
249
249
|
schema: schema,
|
|
@@ -21,41 +21,6 @@ const hooks_1 = require("../hooks");
|
|
|
21
21
|
const utils_1 = require("./utils");
|
|
22
22
|
const ROWS_PER_PAGE = 100;
|
|
23
23
|
const MAX_RECORDS = 10000;
|
|
24
|
-
function mergeConditions(schema, filter, extraFilter, columnFilters, getSchema) {
|
|
25
|
-
const conditions = [];
|
|
26
|
-
if (filter) {
|
|
27
|
-
conditions.push(filter);
|
|
28
|
-
}
|
|
29
|
-
if (extraFilter) {
|
|
30
|
-
conditions.push(extraFilter);
|
|
31
|
-
}
|
|
32
|
-
if (columnFilters) {
|
|
33
|
-
const transformedColumnFilters = (0, utils_1.transformColumnFilter)(columnFilters, schema, getSchema);
|
|
34
|
-
if (transformedColumnFilters) {
|
|
35
|
-
conditions.push({
|
|
36
|
-
type: 'and',
|
|
37
|
-
conditions: Object.entries(transformedColumnFilters).map(([field, condition]) => {
|
|
38
|
-
return {
|
|
39
|
-
field,
|
|
40
|
-
operator: condition.operator,
|
|
41
|
-
value: condition.value,
|
|
42
|
-
extendedKey: condition.extendedKey,
|
|
43
|
-
};
|
|
44
|
-
}),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (conditions.length === 0) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
if (conditions.length === 1) {
|
|
52
|
-
return conditions[0];
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
type: 'and',
|
|
56
|
-
conditions,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
24
|
function DataResolver() {
|
|
60
25
|
var _a;
|
|
61
26
|
const schema = (0, hooks_1.useDataGridSchema)();
|
|
@@ -67,24 +32,14 @@ function DataResolver() {
|
|
|
67
32
|
const [columnFilters] = (0, hooks_1.useGridColumnFilter)();
|
|
68
33
|
const gridColumns = (0, hooks_1.useGridColumns)();
|
|
69
34
|
const maxRecords = (_a = (0, hooks_1.useMaxRecords)()) !== null && _a !== void 0 ? _a : MAX_RECORDS;
|
|
70
|
-
const {
|
|
35
|
+
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
71
36
|
const setState = (0, context_1.useContextSetValue)(context_2.GridContext);
|
|
72
37
|
const [search] = (0, useDebouncedValue_1.useDebouncedValue)(searchText, 500);
|
|
73
38
|
const columns = (0, react_1.useMemo)(() => Array.from(new Set([
|
|
74
39
|
...gridColumns.filter((x) => !x.expandedKey).map((x) => x.name),
|
|
75
40
|
schema.primaryAttribute,
|
|
76
41
|
])), [gridColumns, schema.primaryAttribute]);
|
|
77
|
-
const expand = (0, react_1.useMemo)(() => gridColumns
|
|
78
|
-
.filter((x) => x.expandedKey)
|
|
79
|
-
.reduce((acc, x) => {
|
|
80
|
-
if (!acc[x.name]) {
|
|
81
|
-
acc[x.name] = [];
|
|
82
|
-
}
|
|
83
|
-
if (!acc[x.name].includes(x.expandedKey)) {
|
|
84
|
-
acc[x.name].push(x.expandedKey);
|
|
85
|
-
}
|
|
86
|
-
return acc;
|
|
87
|
-
}, {}), [gridColumns]);
|
|
42
|
+
const expand = (0, react_1.useMemo)(() => (0, utils_1.collectExpandedKeys)(gridColumns), [gridColumns]);
|
|
88
43
|
const queryKey = (0, react_1.useMemo)(() => [
|
|
89
44
|
'data',
|
|
90
45
|
'retriveRecords',
|
|
@@ -150,7 +105,7 @@ function DataResolver() {
|
|
|
150
105
|
search,
|
|
151
106
|
columns: columns,
|
|
152
107
|
expand,
|
|
153
|
-
filter: mergeConditions(schema, view.experience.filter, extraFilter, columnFilters,
|
|
108
|
+
filter: (0, utils_1.mergeConditions)(schema, view.experience.filter, extraFilter, columnFilters, schemaStore),
|
|
154
109
|
skip,
|
|
155
110
|
limit,
|
|
156
111
|
sort: sorting,
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { ColumnCondition } from '@headless-adminapp/core/experience/view';
|
|
2
|
-
import { Schema } from '@headless-adminapp/core/schema';
|
|
3
|
-
|
|
2
|
+
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
+
import { ISchemaStore } from '@headless-adminapp/core/store';
|
|
4
|
+
import { Filter } from '@headless-adminapp/core/transport';
|
|
5
|
+
import { TransformedViewColumn } from '../context';
|
|
6
|
+
export declare function transformColumnFilter<S extends SchemaAttributes = SchemaAttributes>(filter: Partial<Record<string, ColumnCondition>>, schema: Schema<S>, schemaStore: ISchemaStore): Record<string, ColumnCondition> | null;
|
|
7
|
+
export declare function mergeConditions<S extends SchemaAttributes = SchemaAttributes>(schema: Schema<S>, filter: Filter | null | undefined, extraFilter: Filter | null | undefined, columnFilters: Partial<Record<string, ColumnCondition>> | undefined, schemaStore: ISchemaStore): Filter | null;
|
|
8
|
+
export declare function collectExpandedKeys(columns: TransformedViewColumn<SchemaAttributes>[]): Record<string, string[]>;
|
|
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.transformColumnFilter = transformColumnFilter;
|
|
7
|
+
exports.mergeConditions = mergeConditions;
|
|
8
|
+
exports.collectExpandedKeys = collectExpandedKeys;
|
|
7
9
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
-
function transformColumnFilter(filter, schema,
|
|
10
|
+
function transformColumnFilter(filter, schema, schemaStore) {
|
|
9
11
|
const transformedResult = Object.entries(filter).reduce((acc, [id, value]) => {
|
|
10
12
|
const [key, extendedKey] = id.split('.');
|
|
11
13
|
let attribute = schema.attributes[key];
|
|
@@ -16,7 +18,7 @@ function transformColumnFilter(filter, schema, getSchema) {
|
|
|
16
18
|
if (attribute.type !== 'lookup') {
|
|
17
19
|
throw new Error(`Invalid column filter key: ${id}. Key ${key} is not a lookup column.`);
|
|
18
20
|
}
|
|
19
|
-
const lookupSchema = getSchema(attribute.entity);
|
|
21
|
+
const lookupSchema = schemaStore.getSchema(attribute.entity);
|
|
20
22
|
attribute = lookupSchema.attributes[extendedKey];
|
|
21
23
|
}
|
|
22
24
|
if (!attribute) {
|
|
@@ -72,3 +74,51 @@ function transformColumnFilter(filter, schema, getSchema) {
|
|
|
72
74
|
}
|
|
73
75
|
return transformedResult;
|
|
74
76
|
}
|
|
77
|
+
function mergeConditions(schema, filter, extraFilter, columnFilters, schemaStore) {
|
|
78
|
+
const conditions = [];
|
|
79
|
+
if (filter) {
|
|
80
|
+
conditions.push(filter);
|
|
81
|
+
}
|
|
82
|
+
if (extraFilter) {
|
|
83
|
+
conditions.push(extraFilter);
|
|
84
|
+
}
|
|
85
|
+
if (columnFilters) {
|
|
86
|
+
const transformedColumnFilters = transformColumnFilter(columnFilters, schema, schemaStore);
|
|
87
|
+
if (transformedColumnFilters) {
|
|
88
|
+
conditions.push({
|
|
89
|
+
type: 'and',
|
|
90
|
+
conditions: Object.entries(transformedColumnFilters).map(([field, condition]) => {
|
|
91
|
+
return {
|
|
92
|
+
field,
|
|
93
|
+
operator: condition.operator,
|
|
94
|
+
value: condition.value,
|
|
95
|
+
extendedKey: condition.extendedKey,
|
|
96
|
+
};
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (conditions.length === 0) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (conditions.length === 1) {
|
|
105
|
+
return conditions[0];
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
type: 'and',
|
|
109
|
+
conditions,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function collectExpandedKeys(columns) {
|
|
113
|
+
return columns
|
|
114
|
+
.filter((x) => x.expandedKey)
|
|
115
|
+
.reduce((acc, x) => {
|
|
116
|
+
if (!acc[x.name]) {
|
|
117
|
+
acc[x.name] = [];
|
|
118
|
+
}
|
|
119
|
+
if (!acc[x.name].includes(x.expandedKey)) {
|
|
120
|
+
acc[x.name].push(x.expandedKey);
|
|
121
|
+
}
|
|
122
|
+
return acc;
|
|
123
|
+
}, {});
|
|
124
|
+
}
|
package/datagrid/context.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { LocalizedDataLookup } from '@headless-adminapp/core/attributes';
|
|
2
2
|
import { CommandItemExperience } from '@headless-adminapp/core/experience/command';
|
|
3
|
-
import { ColumnCondition, EntityMainGridCommandContext, EntitySubGridCommandContext, SortingState, View
|
|
3
|
+
import { ColumnCondition, EntityMainGridCommandContext, EntitySubGridCommandContext, SortingState, View } from '@headless-adminapp/core/experience/view';
|
|
4
|
+
import { type TransformedViewColumn } from '@headless-adminapp/core/experience/view/ViewColumn';
|
|
4
5
|
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
5
6
|
import { Filter, RetriveRecordsResult } from '@headless-adminapp/core/transport';
|
|
6
|
-
export
|
|
7
|
-
id: string;
|
|
8
|
-
label: string;
|
|
9
|
-
}
|
|
7
|
+
export { type TransformedViewColumn } from '@headless-adminapp/core/experience/view/ViewColumn';
|
|
10
8
|
export interface GridContextState<S extends SchemaAttributes = SchemaAttributes, CommandContext extends EntityMainGridCommandContext | EntitySubGridCommandContext = EntityMainGridCommandContext> {
|
|
11
9
|
schema: Schema<S>;
|
|
12
10
|
view: View<S>;
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
import { EntityMainGridCommandContext } from '@headless-adminapp/core/experience/view';
|
|
2
2
|
import { CommandItemState, MenuItemCommandState, UtilityContextState } from '../../command/types';
|
|
3
3
|
export declare function useUtility(): UtilityContextState;
|
|
4
|
-
export declare function useGridControlContext():
|
|
5
|
-
data: import("@headless-adminapp/core/transport").RetriveRecordsResult<import("@headless-adminapp/core/schema").InferredSchemaType<import("@headless-adminapp/core/schema").SchemaAttributes>> | null;
|
|
6
|
-
logicalName: string;
|
|
7
|
-
schema: import("@headless-adminapp/core/schema").Schema<import("@headless-adminapp/core/schema").SchemaAttributes>;
|
|
8
|
-
refresh: () => void;
|
|
9
|
-
searchText: string;
|
|
10
|
-
selectedIds: string[];
|
|
11
|
-
selectedRecords: import("@headless-adminapp/core/transport").Data<import("@headless-adminapp/core/schema").InferredSchemaType<import("@headless-adminapp/core/schema").SchemaAttributes>>[];
|
|
12
|
-
view: import("@headless-adminapp/core/experience/view").View<import("@headless-adminapp/core/schema").SchemaAttributes>;
|
|
13
|
-
viewId: string;
|
|
14
|
-
columnFilter: Partial<Record<string, import("@headless-adminapp/core/experience/view").ColumnCondition>>;
|
|
15
|
-
extraFilter: import("@headless-adminapp/core/transport").Filter | undefined;
|
|
16
|
-
};
|
|
4
|
+
export declare function useGridControlContext(): EntityMainGridCommandContext['primaryControl'];
|
|
17
5
|
export declare function useMainGridCommandHandlerContext(): EntityMainGridCommandContext;
|
|
18
6
|
export declare function useMainGridCommands(): CommandItemState[][];
|
|
19
7
|
export declare function useMainGridContextCommands(): MenuItemCommandState[][];
|
|
@@ -5,22 +5,21 @@ exports.useGridControlContext = useGridControlContext;
|
|
|
5
5
|
exports.useMainGridCommandHandlerContext = useMainGridCommandHandlerContext;
|
|
6
6
|
exports.useMainGridCommands = useMainGridCommands;
|
|
7
7
|
exports.useMainGridContextCommands = useMainGridContextCommands;
|
|
8
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
9
8
|
const react_1 = require("react");
|
|
10
9
|
const command_1 = require("../../command");
|
|
11
10
|
const hooks_1 = require("../../dialog/hooks");
|
|
12
|
-
const useLocale_1 = require("../../locale/useLocale");
|
|
13
|
-
const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
14
11
|
const useProgressIndicator_1 = require("../../progress-indicator/hooks/useProgressIndicator");
|
|
15
12
|
const useOpenToastNotification_1 = require("../../toast-notification/hooks/useOpenToastNotification");
|
|
16
|
-
const transport_1 = require("../../transport");
|
|
17
13
|
const useGridColumnFilter_1 = require("./useGridColumnFilter");
|
|
14
|
+
const useGridColumns_1 = require("./useGridColumns");
|
|
18
15
|
const useGridCommands_1 = require("./useGridCommands");
|
|
19
16
|
const useGridData_1 = require("./useGridData");
|
|
20
17
|
const useGridExtraFilter_1 = require("./useGridExtraFilter");
|
|
21
18
|
const useGridRefresh_1 = require("./useGridRefresh");
|
|
22
19
|
const useGridSchema_1 = require("./useGridSchema");
|
|
23
20
|
const useGridSelection_1 = require("./useGridSelection");
|
|
21
|
+
const useGridSorting_1 = require("./useGridSorting");
|
|
22
|
+
const useOpenRecord_1 = require("./useOpenRecord");
|
|
24
23
|
const useSearchText_1 = require("./useSearchText");
|
|
25
24
|
const useSelectedView_1 = require("./useSelectedView");
|
|
26
25
|
function useUtility() {
|
|
@@ -49,6 +48,9 @@ function useGridControlContext() {
|
|
|
49
48
|
const [columnFilter] = (0, useGridColumnFilter_1.useGridColumnFilter)();
|
|
50
49
|
const extraFilter = (0, useGridExtraFilter_1.useGridExtraFilter)();
|
|
51
50
|
const refresh = (0, useGridRefresh_1.useGridRefresh)();
|
|
51
|
+
const openRecord = (0, useOpenRecord_1.useOpenRecord)();
|
|
52
|
+
const gridColumns = (0, useGridColumns_1.useGridColumns)();
|
|
53
|
+
const [sorting] = (0, useGridSorting_1.useGridSorting)();
|
|
52
54
|
const selectedIdsObj = (0, react_1.useMemo)(() => {
|
|
53
55
|
const obj = {};
|
|
54
56
|
selectedIds.forEach((id) => {
|
|
@@ -72,27 +74,15 @@ function useGridControlContext() {
|
|
|
72
74
|
viewId: view.id,
|
|
73
75
|
columnFilter,
|
|
74
76
|
extraFilter,
|
|
77
|
+
openRecord,
|
|
78
|
+
gridColumns,
|
|
79
|
+
sorting,
|
|
75
80
|
};
|
|
76
81
|
}
|
|
77
82
|
function useMainGridCommandHandlerContext() {
|
|
78
|
-
const
|
|
79
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
80
|
-
const { appStore, experienceStore, schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
81
|
-
const utility = useUtility();
|
|
82
|
-
const locale = (0, useLocale_1.useLocale)();
|
|
83
|
+
const baseHandlerContext = (0, command_1.useBaseCommandHandlerContext)();
|
|
83
84
|
const primaryControl = useGridControlContext();
|
|
84
|
-
return {
|
|
85
|
-
dataService,
|
|
86
|
-
queryClient,
|
|
87
|
-
utility,
|
|
88
|
-
primaryControl,
|
|
89
|
-
stores: {
|
|
90
|
-
appStore,
|
|
91
|
-
experienceStore,
|
|
92
|
-
schemaStore,
|
|
93
|
-
},
|
|
94
|
-
locale,
|
|
95
|
-
};
|
|
85
|
+
return Object.assign(Object.assign({}, baseHandlerContext), { primaryControl });
|
|
96
86
|
}
|
|
97
87
|
function useMainGridCommands() {
|
|
98
88
|
const commands = (0, useGridCommands_1.useGridCommands)();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useOpenRecord(): (id: string) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useOpenRecord = useOpenRecord;
|
|
4
|
+
const recordset_1 = require("@headless-adminapp/app/recordset");
|
|
5
|
+
const route_1 = require("@headless-adminapp/app/route");
|
|
6
|
+
const app_1 = require("@headless-adminapp/core/experience/app");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const useGridData_1 = require("./useGridData");
|
|
9
|
+
const useGridSchema_1 = require("./useGridSchema");
|
|
10
|
+
function useOpenRecord() {
|
|
11
|
+
const data = (0, useGridData_1.useGridData)();
|
|
12
|
+
const schema = (0, useGridSchema_1.useDataGridSchema)();
|
|
13
|
+
const routeResolver = (0, route_1.useRouteResolver)();
|
|
14
|
+
const router = (0, route_1.useRouter)();
|
|
15
|
+
const recordSetSetter = (0, recordset_1.useRecordSetSetter)();
|
|
16
|
+
const dataRef = (0, react_1.useRef)(data);
|
|
17
|
+
dataRef.current = data;
|
|
18
|
+
return (0, react_1.useCallback)((id) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const path = routeResolver({
|
|
21
|
+
logicalName: schema.logicalName,
|
|
22
|
+
type: app_1.PageType.EntityForm,
|
|
23
|
+
id,
|
|
24
|
+
});
|
|
25
|
+
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 : []);
|
|
26
|
+
router.push(path);
|
|
27
|
+
}, [
|
|
28
|
+
recordSetSetter,
|
|
29
|
+
routeResolver,
|
|
30
|
+
router,
|
|
31
|
+
schema.idAttribute,
|
|
32
|
+
schema.logicalName,
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
@@ -3,13 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useSubGridCommandHandlerContext = useSubGridCommandHandlerContext;
|
|
4
4
|
exports.useSubGridCommands = useSubGridCommands;
|
|
5
5
|
exports.useSubGridContextCommands = useSubGridContextCommands;
|
|
6
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
7
6
|
const react_1 = require("react");
|
|
8
7
|
const command_1 = require("../../command");
|
|
9
8
|
const useMainFormCommands_1 = require("../../dataform/hooks/useMainFormCommands");
|
|
10
|
-
const useLocale_1 = require("../../locale/useLocale");
|
|
11
|
-
const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
12
|
-
const transport_1 = require("../../transport");
|
|
13
9
|
const useGridColumnFilter_1 = require("./useGridColumnFilter");
|
|
14
10
|
const useGridCommands_1 = require("./useGridCommands");
|
|
15
11
|
const useGridData_1 = require("./useGridData");
|
|
@@ -17,13 +13,10 @@ const useGridExtraFilter_1 = require("./useGridExtraFilter");
|
|
|
17
13
|
const useGridRefresh_1 = require("./useGridRefresh");
|
|
18
14
|
const useGridSchema_1 = require("./useGridSchema");
|
|
19
15
|
const useGridSelection_1 = require("./useGridSelection");
|
|
20
|
-
const useMainGridCommands_1 = require("./useMainGridCommands");
|
|
21
16
|
const useSearchText_1 = require("./useSearchText");
|
|
22
17
|
const useSelectedView_1 = require("./useSelectedView");
|
|
23
18
|
function useSubGridCommandHandlerContext() {
|
|
24
|
-
const
|
|
25
|
-
const queryClient = (0, react_query_1.useQueryClient)();
|
|
26
|
-
const { appStore, experienceStore, schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
19
|
+
const baseHandlerContext = (0, command_1.useBaseCommandHandlerContext)();
|
|
27
20
|
const data = (0, useGridData_1.useGridData)();
|
|
28
21
|
const schema = (0, useGridSchema_1.useDataGridSchema)();
|
|
29
22
|
const view = (0, useSelectedView_1.useSelectedView)();
|
|
@@ -43,15 +36,8 @@ function useSubGridCommandHandlerContext() {
|
|
|
43
36
|
const [columnFilter] = (0, useGridColumnFilter_1.useGridColumnFilter)();
|
|
44
37
|
const extraFilter = (0, useGridExtraFilter_1.useGridExtraFilter)();
|
|
45
38
|
const refresh = (0, useGridRefresh_1.useGridRefresh)();
|
|
46
|
-
const utility = (0, useMainGridCommands_1.useUtility)();
|
|
47
|
-
const locale = (0, useLocale_1.useLocale)();
|
|
48
39
|
const mainFormHandlerContext = (0, useMainFormCommands_1.useMainFormCommandHandlerContext)();
|
|
49
|
-
return {
|
|
50
|
-
dataService,
|
|
51
|
-
queryClient,
|
|
52
|
-
utility,
|
|
53
|
-
primaryControl: mainFormHandlerContext.primaryControl,
|
|
54
|
-
secondaryControl: {
|
|
40
|
+
return Object.assign(Object.assign({}, baseHandlerContext), { primaryControl: mainFormHandlerContext.primaryControl, secondaryControl: {
|
|
55
41
|
data,
|
|
56
42
|
logicalName: schema.logicalName,
|
|
57
43
|
schema,
|
|
@@ -63,14 +49,7 @@ function useSubGridCommandHandlerContext() {
|
|
|
63
49
|
viewId: view.id,
|
|
64
50
|
columnFilter,
|
|
65
51
|
extraFilter,
|
|
66
|
-
}
|
|
67
|
-
stores: {
|
|
68
|
-
appStore,
|
|
69
|
-
experienceStore,
|
|
70
|
-
schemaStore,
|
|
71
|
-
},
|
|
72
|
-
locale,
|
|
73
|
-
};
|
|
52
|
+
} });
|
|
74
53
|
}
|
|
75
54
|
function useSubGridCommands() {
|
|
76
55
|
const commands = (0, useGridCommands_1.useGridCommands)();
|
package/locale/LocaleProvider.js
CHANGED
|
@@ -8,7 +8,7 @@ const context_1 = require("./context");
|
|
|
8
8
|
const LocaleProvider = ({ children, locale, options, }) => {
|
|
9
9
|
const localeState = (0, react_1.useMemo)(() => {
|
|
10
10
|
return (0, locale_1.getLocale)(locale, options);
|
|
11
|
-
}, [locale]);
|
|
11
|
+
}, [locale, options]);
|
|
12
12
|
return ((0, jsx_runtime_1.jsx)(context_1.LocaleContext.Provider, { value: localeState, children: children }));
|
|
13
13
|
};
|
|
14
14
|
exports.LocaleProvider = LocaleProvider;
|
|
@@ -2,6 +2,7 @@ import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
|
2
2
|
export declare function useMetadata(): {
|
|
3
3
|
schemas: Record<string, import("@headless-adminapp/core/schema").Schema<SchemaAttributes>>;
|
|
4
4
|
schemaLoading: boolean;
|
|
5
|
+
/*** @deprecated */
|
|
5
6
|
getSchema: <S extends SchemaAttributes = SchemaAttributes>(logicalName: string) => import("@headless-adminapp/core/schema").Schema<S>;
|
|
6
7
|
schemaStore: import("@headless-adminapp/core/store").ISchemaStore<SchemaAttributes>;
|
|
7
8
|
appStore: import("@headless-adminapp/core/store").IClientAppStore;
|
|
@@ -14,12 +14,14 @@ function useMetadata() {
|
|
|
14
14
|
// );
|
|
15
15
|
const schemaLoading = false;
|
|
16
16
|
const schemas = schemaStore.getAllSchema();
|
|
17
|
+
/*** @deprecated */
|
|
17
18
|
const getSchema = (0, react_1.useCallback)((logicalName) => {
|
|
18
19
|
return schemaStore.getSchema(logicalName);
|
|
19
20
|
}, [schemaStore]);
|
|
20
21
|
return {
|
|
21
22
|
schemas,
|
|
22
23
|
schemaLoading,
|
|
24
|
+
/*** @deprecated */
|
|
23
25
|
getSchema,
|
|
24
26
|
schemaStore,
|
|
25
27
|
appStore,
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useSchema = useSchema;
|
|
4
4
|
const useMetadata_1 = require("./useMetadata");
|
|
5
5
|
function useSchema(logicalName) {
|
|
6
|
-
const {
|
|
7
|
-
return getSchema(logicalName);
|
|
6
|
+
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
7
|
+
return schemaStore.getSchema(logicalName);
|
|
8
8
|
}
|
package/mutable/context.js
CHANGED
|
@@ -41,6 +41,6 @@ function useContextValueSetter(context, setter) {
|
|
|
41
41
|
setterRef.current = setter;
|
|
42
42
|
const setterWrapper = (0, react_1.useCallback)((...args) => {
|
|
43
43
|
return setterRef.current(contextValue.setValue)(...args);
|
|
44
|
-
}, []);
|
|
44
|
+
}, [contextValue.setValue]);
|
|
45
45
|
return setterWrapper;
|
|
46
46
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useOpenForm';
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useOpenForm"), exports);
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function useOpenForm(): (
|
|
3
|
-
replace?: boolean;
|
|
4
|
-
}) => void;
|
|
1
|
+
import { OpenFormOptions } from '@headless-adminapp/core/experience/command';
|
|
2
|
+
export declare function useOpenForm(): (options: OpenFormOptions) => void;
|
|
@@ -8,9 +8,13 @@ const useRouteResolver_1 = require("../../route/hooks/useRouteResolver");
|
|
|
8
8
|
function useOpenForm() {
|
|
9
9
|
const routeResolver = (0, useRouteResolver_1.useRouteResolver)();
|
|
10
10
|
const router = (0, hooks_1.useRouter)();
|
|
11
|
-
return (0, react_1.useCallback)((
|
|
12
|
-
const path = routeResolver(
|
|
13
|
-
|
|
11
|
+
return (0, react_1.useCallback)((options) => {
|
|
12
|
+
const path = routeResolver({
|
|
13
|
+
logicalName: options.logicalName,
|
|
14
|
+
type: app_1.PageType.EntityForm,
|
|
15
|
+
id: options.id,
|
|
16
|
+
});
|
|
17
|
+
if (options.replace) {
|
|
14
18
|
router.replace(path);
|
|
15
19
|
}
|
|
16
20
|
else {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks';
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./hooks"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "0.0.17-alpha.
|
|
3
|
+
"version": "0.0.17-alpha.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,8 +27,16 @@
|
|
|
27
27
|
"author": "",
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@hookform/resolvers": "^3.9.0",
|
|
31
|
+
"@tanstack/react-query": "5.51.1",
|
|
30
32
|
"clsx": "2.1.1",
|
|
31
|
-
"
|
|
33
|
+
"dayjs": "^1.11.13",
|
|
34
|
+
"exceljs": "^4.4.0",
|
|
35
|
+
"json-to-csv-export": "^2.1.1",
|
|
36
|
+
"lodash": "^4.17.21",
|
|
37
|
+
"react-custom-scrollbars-2": "^4.5.0",
|
|
38
|
+
"react-hook-form": "7.52.2",
|
|
39
|
+
"yup": "^1.4.0"
|
|
32
40
|
},
|
|
33
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "5b53560e1c0b20e0bb0e74e820a96c7c75e2c43b"
|
|
34
42
|
}
|
|
@@ -26,7 +26,7 @@ function useRecordSetResult() {
|
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
28
|
return schemaStore.getSchema(context.logicalName);
|
|
29
|
-
}, [context.logicalName]);
|
|
29
|
+
}, [context.logicalName, schemaStore]);
|
|
30
30
|
const cardView = context.cardView;
|
|
31
31
|
const columns = (0, react_1.useMemo)(() => {
|
|
32
32
|
var _a;
|