@headless-adminapp/app 1.4.10 → 1.4.12
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/SubgridCommandBuilder.js +2 -2
- package/builders/CommandBuilder/ViewCommandBuilder.js +2 -2
- package/builders/utils.d.ts +4 -4
- package/builders/utils.js +24 -16
- package/hooks/useStorageState.js +2 -1
- package/package.json +2 -2
- package/store/RecentItemStore.d.ts +1 -0
- package/store/RecentItemStore.js +4 -2
- package/utils/getAttributeFormattedValue.d.ts +1 -1
- package/utils/getAttributeFormattedValue.js +9 -1
- package/utils/localStorage.d.ts +1 -0
- package/utils/localStorage.js +29 -0
|
@@ -206,7 +206,7 @@ var SubgridCommandBuilder;
|
|
|
206
206
|
fileName: context.secondaryControl.view.name + '.xlsx',
|
|
207
207
|
gridColumns: context.secondaryControl.gridColumns,
|
|
208
208
|
records: result.records,
|
|
209
|
-
|
|
209
|
+
attributes: context.secondaryControl.schema.attributes,
|
|
210
210
|
schemaStore: context.stores.schemaStore,
|
|
211
211
|
locale: context.locale,
|
|
212
212
|
});
|
|
@@ -240,7 +240,7 @@ var SubgridCommandBuilder;
|
|
|
240
240
|
fileName: context.secondaryControl.view.name + '.csv',
|
|
241
241
|
gridColumns: context.secondaryControl.gridColumns,
|
|
242
242
|
records: result.records,
|
|
243
|
-
|
|
243
|
+
attributes: context.secondaryControl.schema.attributes,
|
|
244
244
|
schemaStore: context.stores.schemaStore,
|
|
245
245
|
locale: context.locale,
|
|
246
246
|
});
|
|
@@ -308,7 +308,7 @@ async function exportRecordsToExcel(context) {
|
|
|
308
308
|
fileName: context.primaryControl.view.name + '.xlsx',
|
|
309
309
|
gridColumns: context.primaryControl.gridColumns,
|
|
310
310
|
records: result.records,
|
|
311
|
-
|
|
311
|
+
attributes: context.primaryControl.schema.attributes,
|
|
312
312
|
schemaStore: context.stores.schemaStore,
|
|
313
313
|
locale: context.locale,
|
|
314
314
|
});
|
|
@@ -325,7 +325,7 @@ async function exportRecordsToCSV(context) {
|
|
|
325
325
|
fileName: context.primaryControl.view.name + '.csv',
|
|
326
326
|
gridColumns: context.primaryControl.gridColumns,
|
|
327
327
|
records: result.records,
|
|
328
|
-
|
|
328
|
+
attributes: context.primaryControl.schema.attributes,
|
|
329
329
|
schemaStore: context.stores.schemaStore,
|
|
330
330
|
locale: context.locale,
|
|
331
331
|
});
|
package/builders/utils.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp
|
|
|
4
4
|
import { ISchemaStore } from '@headless-adminapp/core/store';
|
|
5
5
|
import { Filter, IDataService } from '@headless-adminapp/core/transport';
|
|
6
6
|
import { TransformedViewColumn } from '../datagrid';
|
|
7
|
-
type
|
|
8
|
-
|
|
7
|
+
export type ExportColumn<S extends SchemaAttributes = SchemaAttributes> = Omit<TransformedViewColumn<S>, 'id' | 'component' | 'width' | 'maxWidth'>;
|
|
8
|
+
export type ExportFn<S extends SchemaAttributes = SchemaAttributes> = (option: {
|
|
9
|
+
attributes: S;
|
|
9
10
|
records: unknown[];
|
|
10
|
-
gridColumns:
|
|
11
|
+
gridColumns: ExportColumn<S>[];
|
|
11
12
|
schemaStore: ISchemaStore;
|
|
12
13
|
fileName: string;
|
|
13
14
|
locale: Locale;
|
|
@@ -27,4 +28,3 @@ export declare function retriveRecords<S extends SchemaAttributes = SchemaAttrib
|
|
|
27
28
|
skip: number;
|
|
28
29
|
limit: number;
|
|
29
30
|
}): Promise<import("@headless-adminapp/core/transport").RetriveRecordsResult<InferredSchemaType<S>>>;
|
|
30
|
-
export {};
|
package/builders/utils.js
CHANGED
|
@@ -27,34 +27,38 @@ exports.exportRecordsXLS = exports.exportRecordsCSV = void 0;
|
|
|
27
27
|
exports.retriveRecords = retriveRecords;
|
|
28
28
|
const utils_1 = require("../datagrid/DataGridProvider/utils");
|
|
29
29
|
const utils_2 = require("../utils");
|
|
30
|
-
const getHeaders = (
|
|
30
|
+
const getHeaders = (attributes, gridColumns, schemaStore) => {
|
|
31
31
|
const headers = gridColumns.map((column) => {
|
|
32
32
|
if (column.name.indexOf('.') !== -1) {
|
|
33
33
|
const [lookup, field] = column.name.split('.');
|
|
34
|
-
const entity =
|
|
34
|
+
const entity = attributes[lookup].entity;
|
|
35
35
|
const lookupSchema = schemaStore.getSchema(entity);
|
|
36
|
-
return `${lookupSchema.attributes[field]?.label} (${
|
|
36
|
+
return `${lookupSchema.attributes[field]?.label} (${attributes[lookup]?.label})`;
|
|
37
37
|
}
|
|
38
|
-
return column.label ??
|
|
38
|
+
return column.label ?? attributes[column.name]?.label;
|
|
39
39
|
});
|
|
40
40
|
return headers;
|
|
41
41
|
};
|
|
42
|
-
function getAttribute({ column,
|
|
42
|
+
function getAttribute({ column, attributes, schemaStore, }) {
|
|
43
43
|
let attribute;
|
|
44
44
|
if (column.expandedKey) {
|
|
45
45
|
const lookup = column.name;
|
|
46
46
|
const field = column.expandedKey;
|
|
47
|
-
const entity =
|
|
47
|
+
const entity = attributes[lookup].entity;
|
|
48
48
|
const lookupSchema = schemaStore.getSchema(entity);
|
|
49
49
|
attribute = lookupSchema.attributes[field];
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
|
-
attribute =
|
|
52
|
+
attribute = attributes[column.name];
|
|
53
53
|
}
|
|
54
54
|
return attribute;
|
|
55
55
|
}
|
|
56
|
-
function extractAttributeData({ column, record,
|
|
57
|
-
const attribute = getAttribute({
|
|
56
|
+
function extractAttributeData({ column, record, attributes, schemaStore, }) {
|
|
57
|
+
const attribute = getAttribute({
|
|
58
|
+
column,
|
|
59
|
+
attributes,
|
|
60
|
+
schemaStore,
|
|
61
|
+
});
|
|
58
62
|
let value;
|
|
59
63
|
if (column.expandedKey) {
|
|
60
64
|
const lookup = column.name;
|
|
@@ -69,15 +73,15 @@ function extractAttributeData({ column, record, schema, schemaStore, }) {
|
|
|
69
73
|
value,
|
|
70
74
|
};
|
|
71
75
|
}
|
|
72
|
-
const exportRecordsCSV = async ({
|
|
76
|
+
const exportRecordsCSV = async ({ attributes, records, gridColumns, schemaStore, fileName, locale, }) => {
|
|
73
77
|
const csvDownload = await Promise.resolve().then(() => __importStar(require('json-to-csv-export')));
|
|
74
|
-
const headers = getHeaders(
|
|
78
|
+
const headers = getHeaders(attributes, gridColumns, schemaStore);
|
|
75
79
|
const cellData = records.map((record) => {
|
|
76
80
|
return gridColumns.map((column) => {
|
|
77
81
|
const { attribute, value } = extractAttributeData({
|
|
78
82
|
column,
|
|
79
83
|
record,
|
|
80
|
-
|
|
84
|
+
attributes,
|
|
81
85
|
schemaStore,
|
|
82
86
|
});
|
|
83
87
|
if (attribute.type === 'money' || attribute.type === 'number') {
|
|
@@ -94,15 +98,15 @@ const exportRecordsCSV = async ({ schema, records, gridColumns, schemaStore, fil
|
|
|
94
98
|
});
|
|
95
99
|
};
|
|
96
100
|
exports.exportRecordsCSV = exportRecordsCSV;
|
|
97
|
-
const exportRecordsXLS = async ({ fileName, gridColumns, records,
|
|
101
|
+
const exportRecordsXLS = async ({ fileName, gridColumns, records, attributes, schemaStore, locale, }) => {
|
|
98
102
|
const ExcelJS = await Promise.resolve().then(() => __importStar(require('exceljs')));
|
|
99
|
-
const headers = getHeaders(
|
|
103
|
+
const headers = getHeaders(attributes, gridColumns, schemaStore);
|
|
100
104
|
const cellData = records.map((item) => {
|
|
101
105
|
return gridColumns.map((column) => {
|
|
102
106
|
const { attribute, value } = extractAttributeData({
|
|
103
107
|
column,
|
|
104
108
|
record: item,
|
|
105
|
-
|
|
109
|
+
attributes,
|
|
106
110
|
schemaStore,
|
|
107
111
|
});
|
|
108
112
|
if (!value) {
|
|
@@ -128,7 +132,11 @@ const exportRecordsXLS = async ({ fileName, gridColumns, records, schema, schema
|
|
|
128
132
|
worksheet.addRow(row);
|
|
129
133
|
});
|
|
130
134
|
gridColumns.forEach((column, index) => {
|
|
131
|
-
const attribute = getAttribute({
|
|
135
|
+
const attribute = getAttribute({
|
|
136
|
+
column,
|
|
137
|
+
attributes: attributes,
|
|
138
|
+
schemaStore,
|
|
139
|
+
});
|
|
132
140
|
const sheetColumn = worksheet.getColumn(index + 1);
|
|
133
141
|
let formatFn = (value) => (0, utils_2.getAttributeFormattedValue)(attribute, value, locale) ?? '';
|
|
134
142
|
if (attribute?.type === 'money') {
|
package/hooks/useStorageState.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useStorageState = useStorageState;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const localStorage_1 = require("../utils/localStorage");
|
|
5
6
|
function getStorageValue(key, store) {
|
|
6
7
|
const value = store.getItem(key);
|
|
7
8
|
if (value) {
|
|
@@ -12,7 +13,7 @@ function getStorageValue(key, store) {
|
|
|
12
13
|
function setStorageValue(key, value, store) {
|
|
13
14
|
store.setItem(key, JSON.stringify(value));
|
|
14
15
|
}
|
|
15
|
-
function useStorageState(initialState, key, store =
|
|
16
|
+
function useStorageState(initialState, key, store = localStorage_1.safeLocalStorage) {
|
|
16
17
|
const [state, setState] = (0, react_1.useState)(getStorageValue(key, store) ?? initialState);
|
|
17
18
|
const setStoredState = (0, react_1.useCallback)((value) => {
|
|
18
19
|
setState((prevState) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"uuid": "11.0.3",
|
|
39
39
|
"yup": "^1.4.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ff83d8ca2e616d6125781975cfc1dde6a1fc05c3"
|
|
42
42
|
}
|
package/store/RecentItemStore.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RecentItemStore = void 0;
|
|
4
|
+
const localStorage_1 = require("../utils/localStorage");
|
|
4
5
|
class RecentItemStore {
|
|
5
6
|
data = {};
|
|
6
7
|
storageKey = 'recent_items';
|
|
7
8
|
maxItems = 5;
|
|
8
9
|
listeners = {};
|
|
10
|
+
localStorage = localStorage_1.safeLocalStorage;
|
|
9
11
|
constructor() {
|
|
10
12
|
this.init();
|
|
11
13
|
}
|
|
12
14
|
init() {
|
|
13
|
-
const _data = localStorage.getItem(this.storageKey);
|
|
15
|
+
const _data = this.localStorage.getItem(this.storageKey);
|
|
14
16
|
if (_data) {
|
|
15
17
|
this.data = JSON.parse(_data);
|
|
16
18
|
}
|
|
@@ -19,7 +21,7 @@ class RecentItemStore {
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
sync() {
|
|
22
|
-
localStorage.setItem(this.storageKey, JSON.stringify(this.data));
|
|
24
|
+
this.localStorage.setItem(this.storageKey, JSON.stringify(this.data));
|
|
23
25
|
}
|
|
24
26
|
getItems(cacheKey, limit) {
|
|
25
27
|
if (!this.data[cacheKey]) {
|
|
@@ -8,7 +8,7 @@ interface AttributeFormattedValueStringsSet {
|
|
|
8
8
|
export declare function getAttributeLookupsFormattedValue(value: unknown, options?: {
|
|
9
9
|
maxCount?: number;
|
|
10
10
|
}): string;
|
|
11
|
-
export declare function getAttributeAttachmentFormattedValue(value: unknown): string;
|
|
11
|
+
export declare function getAttributeAttachmentFormattedValue(value: unknown): string | null;
|
|
12
12
|
export declare function getAttributeDateFormattedValue(attribute: DateAttribute, value: unknown, locale: Locale): string;
|
|
13
13
|
export declare function getAttributeDateRangeFormattedValue(value: unknown, locale: Locale): string;
|
|
14
14
|
export declare function getAttributeBooleanFormattedValue(attribute: BooleanAttribute, value: unknown, options?: {
|
|
@@ -35,7 +35,15 @@ function getAttributeLookupsFormattedValue(value, options) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
function getAttributeAttachmentFormattedValue(value) {
|
|
38
|
-
|
|
38
|
+
const name = value?.name;
|
|
39
|
+
const url = value?.url;
|
|
40
|
+
if (name) {
|
|
41
|
+
return name;
|
|
42
|
+
}
|
|
43
|
+
if (url) {
|
|
44
|
+
return url;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
39
47
|
}
|
|
40
48
|
function getAttributeDateFormattedValue(attribute, value, locale) {
|
|
41
49
|
if (attribute.format === 'datetime') {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const safeLocalStorage: Storage;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeLocalStorage = void 0;
|
|
4
|
+
function getLocalStorage() {
|
|
5
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
6
|
+
return window.localStorage;
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
exports.safeLocalStorage = {
|
|
11
|
+
clear: () => {
|
|
12
|
+
getLocalStorage()?.clear();
|
|
13
|
+
},
|
|
14
|
+
get length() {
|
|
15
|
+
return getLocalStorage()?.length || 0;
|
|
16
|
+
},
|
|
17
|
+
getItem: (key) => {
|
|
18
|
+
return getLocalStorage()?.getItem(key) || null;
|
|
19
|
+
},
|
|
20
|
+
setItem: (key, value) => {
|
|
21
|
+
getLocalStorage()?.setItem(key, value);
|
|
22
|
+
},
|
|
23
|
+
removeItem: (key) => {
|
|
24
|
+
getLocalStorage()?.removeItem(key);
|
|
25
|
+
},
|
|
26
|
+
key: (index) => {
|
|
27
|
+
return getLocalStorage()?.key(index) || null;
|
|
28
|
+
},
|
|
29
|
+
};
|