@headless-adminapp/app 1.4.11 → 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.
@@ -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
- schema: context.secondaryControl.schema,
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
- schema: context.secondaryControl.schema,
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
- schema: context.primaryControl.schema,
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
- schema: context.primaryControl.schema,
328
+ attributes: context.primaryControl.schema.attributes,
329
329
  schemaStore: context.stores.schemaStore,
330
330
  locale: context.locale,
331
331
  });
@@ -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 ExportFn<S extends SchemaAttributes = SchemaAttributes> = (option: {
8
- schema: Schema<S>;
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: TransformedViewColumn<SchemaAttributes>[];
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 = (schema, gridColumns, schemaStore) => {
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 = schema.attributes[lookup].entity;
34
+ const entity = attributes[lookup].entity;
35
35
  const lookupSchema = schemaStore.getSchema(entity);
36
- return `${lookupSchema.attributes[field]?.label} (${schema.attributes[lookup]?.label})`;
36
+ return `${lookupSchema.attributes[field]?.label} (${attributes[lookup]?.label})`;
37
37
  }
38
- return column.label ?? schema.attributes[column.name]?.label;
38
+ return column.label ?? attributes[column.name]?.label;
39
39
  });
40
40
  return headers;
41
41
  };
42
- function getAttribute({ column, schema, schemaStore, }) {
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 = schema.attributes[lookup].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 = schema.attributes[column.name];
52
+ attribute = attributes[column.name];
53
53
  }
54
54
  return attribute;
55
55
  }
56
- function extractAttributeData({ column, record, schema, schemaStore, }) {
57
- const attribute = getAttribute({ column, schema, schemaStore });
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 ({ schema, records, gridColumns, schemaStore, fileName, locale, }) => {
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(schema, gridColumns, schemaStore);
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
- schema,
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, schema, schemaStore, locale, }) => {
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(schema, gridColumns, schemaStore);
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
- schema,
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({ column, schema, schemaStore });
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "1.4.11",
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": "a021ad89086df820727f8dc87e57a039b0126bf2"
41
+ "gitHead": "ff83d8ca2e616d6125781975cfc1dde6a1fc05c3"
42
42
  }
@@ -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
- return value?.url ?? null;
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') {