@headless-adminapp/app 1.2.3 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -208,6 +208,7 @@ var SubgridCommandBuilder;
208
208
  records: result.records,
209
209
  schema: context.secondaryControl.schema,
210
210
  schemaStore: context.stores.schemaStore,
211
+ locale: context.locale,
211
212
  });
212
213
  }
213
214
  finally {
@@ -241,6 +242,7 @@ var SubgridCommandBuilder;
241
242
  records: result.records,
242
243
  schema: context.secondaryControl.schema,
243
244
  schemaStore: context.stores.schemaStore,
245
+ locale: context.locale,
244
246
  });
245
247
  }
246
248
  finally {
@@ -310,6 +310,7 @@ async function exportRecordsToExcel(context) {
310
310
  records: result.records,
311
311
  schema: context.primaryControl.schema,
312
312
  schemaStore: context.stores.schemaStore,
313
+ locale: context.locale,
313
314
  });
314
315
  }
315
316
  finally {
@@ -326,6 +327,7 @@ async function exportRecordsToCSV(context) {
326
327
  records: result.records,
327
328
  schema: context.primaryControl.schema,
328
329
  schemaStore: context.stores.schemaStore,
330
+ locale: context.locale,
329
331
  });
330
332
  }
331
333
  finally {
@@ -1,3 +1,4 @@
1
+ import { Locale } from '@headless-adminapp/core/experience/locale';
1
2
  import { ColumnCondition, SortingState, View } from '@headless-adminapp/core/experience/view';
2
3
  import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
3
4
  import { ISchemaStore } from '@headless-adminapp/core/store';
@@ -9,6 +10,7 @@ type ExportFn<S extends SchemaAttributes = SchemaAttributes> = (option: {
9
10
  gridColumns: TransformedViewColumn<SchemaAttributes>[];
10
11
  schemaStore: ISchemaStore;
11
12
  fileName: string;
13
+ locale: Locale;
12
14
  }) => Promise<void>;
13
15
  export declare const exportRecordsCSV: ExportFn;
14
16
  export declare const exportRecordsXLS: ExportFn;
package/builders/utils.js CHANGED
@@ -69,7 +69,7 @@ function extractAttributeData({ column, record, schema, schemaStore, }) {
69
69
  value,
70
70
  };
71
71
  }
72
- const exportRecordsCSV = async ({ schema, records, gridColumns, schemaStore, fileName, }) => {
72
+ const exportRecordsCSV = async ({ schema, records, gridColumns, schemaStore, fileName, locale, }) => {
73
73
  const csvDownload = await Promise.resolve().then(() => __importStar(require('json-to-csv-export')));
74
74
  const headers = getHeaders(schema, gridColumns, schemaStore);
75
75
  const cellData = records.map((record) => {
@@ -83,7 +83,7 @@ const exportRecordsCSV = async ({ schema, records, gridColumns, schemaStore, fil
83
83
  if (attribute.type === 'money' || attribute.type === 'number') {
84
84
  return value?.toString() ?? '';
85
85
  }
86
- return (0, utils_2.getAttributeFormattedValue)(attribute, value) ?? '';
86
+ return (0, utils_2.getAttributeFormattedValue)(attribute, value, locale) ?? '';
87
87
  });
88
88
  });
89
89
  csvDownload.default({
@@ -94,7 +94,7 @@ const exportRecordsCSV = async ({ schema, records, gridColumns, schemaStore, fil
94
94
  });
95
95
  };
96
96
  exports.exportRecordsCSV = exportRecordsCSV;
97
- const exportRecordsXLS = async ({ fileName, gridColumns, records, schema, schemaStore, }) => {
97
+ const exportRecordsXLS = async ({ fileName, gridColumns, records, schema, schemaStore, locale, }) => {
98
98
  const ExcelJS = await Promise.resolve().then(() => __importStar(require('exceljs')));
99
99
  const headers = getHeaders(schema, gridColumns, schemaStore);
100
100
  const cellData = records.map((item) => {
@@ -115,7 +115,7 @@ const exportRecordsXLS = async ({ fileName, gridColumns, records, schema, schema
115
115
  case 'date':
116
116
  return value ? new Date(value) : undefined;
117
117
  default:
118
- return (0, utils_2.getAttributeFormattedValue)(attribute, value);
118
+ return (0, utils_2.getAttributeFormattedValue)(attribute, value, locale);
119
119
  }
120
120
  });
121
121
  });
@@ -130,9 +130,9 @@ const exportRecordsXLS = async ({ fileName, gridColumns, records, schema, schema
130
130
  gridColumns.forEach((column, index) => {
131
131
  const attribute = getAttribute({ column, schema, schemaStore });
132
132
  const sheetColumn = worksheet.getColumn(index + 1);
133
- let formatFn = (value) => (0, utils_2.getAttributeFormattedValue)(attribute, value) ?? '';
133
+ let formatFn = (value) => (0, utils_2.getAttributeFormattedValue)(attribute, value, locale) ?? '';
134
134
  if (attribute?.type === 'money') {
135
- sheetColumn.numFmt = '"₹" #,##0.00';
135
+ sheetColumn.numFmt = `"₹" #,##0.00`;
136
136
  }
137
137
  let maxLength = 0;
138
138
  sheetColumn.eachCell((cell) => {
@@ -8,9 +8,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const clsx_1 = __importDefault(require("clsx"));
9
9
  const react_1 = require("react");
10
10
  const react_custom_scrollbars_2_1 = require("react-custom-scrollbars-2");
11
- function getReaminingSpace(div) {
12
- return div.scrollHeight - div.scrollTop - div.clientHeight;
13
- }
14
11
  const ScrollView = ({ children, className, rtl, autoHide, onScroll, shadowEffect = false, }) => {
15
12
  const [isTop, setIsTop] = (0, react_1.useState)(true);
16
13
  const [isBottom, setIsBottom] = (0, react_1.useState)(false);
@@ -286,21 +286,6 @@ const dateOperatorOptions = [
286
286
  labelKey: 'nextXDays',
287
287
  controls: [],
288
288
  },
289
- {
290
- value: 'next-x-weeks',
291
- labelKey: 'nextXWeeks',
292
- controls: [],
293
- },
294
- {
295
- value: 'next-x-months',
296
- labelKey: 'nextXMonths',
297
- controls: [],
298
- },
299
- {
300
- value: 'next-x-years',
301
- labelKey: 'nextXYears',
302
- controls: [],
303
- },
304
289
  {
305
290
  value: 'last-week',
306
291
  labelKey: 'lastWeek',
@@ -336,21 +321,6 @@ const dateOperatorOptions = [
336
321
  labelKey: 'lastXDays',
337
322
  controls: ['number'],
338
323
  },
339
- {
340
- value: 'last-x-weeks',
341
- labelKey: 'lastXWeeks',
342
- controls: ['number'],
343
- },
344
- {
345
- value: 'last-x-months',
346
- labelKey: 'lastXMonths',
347
- controls: ['number'],
348
- },
349
- {
350
- value: 'last-x-years',
351
- labelKey: 'lastXYears',
352
- controls: ['number'],
353
- },
354
324
  {
355
325
  value: 'olderthan-x-hours',
356
326
  labelKey: 'olderthanXHours',
@@ -361,25 +331,10 @@ const dateOperatorOptions = [
361
331
  labelKey: 'olderthanXDays',
362
332
  controls: ['number'],
363
333
  },
364
- {
365
- value: 'olderthan-x-weeks',
366
- labelKey: 'olderthanXWeeks',
367
- controls: ['number'],
368
- },
369
- {
370
- value: 'olderthan-x-months',
371
- labelKey: 'olderthanXMonths',
372
- controls: ['number'],
373
- },
374
- {
375
- value: 'olderthan-x-years',
376
- labelKey: 'olderthanXYears',
377
- controls: ['number'],
378
- },
379
334
  {
380
335
  value: 'in-fiscal-year',
381
336
  labelKey: 'inFiscalYear',
382
- controls: [],
337
+ controls: ['number'],
383
338
  },
384
339
  {
385
340
  value: 'between',
@@ -6,6 +6,7 @@ export interface LocaleProviderProps {
6
6
  options?: {
7
7
  direction?: Locale['direction'];
8
8
  dateFormats?: Locale['dateFormats'];
9
+ dateRangeFormats?: Locale['dateRangeFormats'];
9
10
  timeFormats?: Locale['timeFormats'];
10
11
  currency?: Partial<Locale['currency']>;
11
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "1.2.3",
3
+ "version": "1.3.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -37,5 +37,5 @@
37
37
  "uuid": "11.0.3",
38
38
  "yup": "^1.4.0"
39
39
  },
40
- "gitHead": "8d3c42183ed245a59d5200b4f0d4d271ebfe2160"
40
+ "gitHead": "019339a44fae0fcce5466041f922710b08b79172"
41
41
  }
@@ -1,19 +1,26 @@
1
- import { Attribute, InferredAttributeType } from '@headless-adminapp/core/attributes';
1
+ import { Attribute, BooleanAttribute, DateAttribute, InferredAttributeType } from '@headless-adminapp/core/attributes';
2
+ import { ChoicesAttribute } from '@headless-adminapp/core/attributes/ChoiceAttribute';
3
+ import { Locale } from '@headless-adminapp/core/experience/locale/types';
2
4
  interface AttributeFormattedValueStringsSet {
3
5
  yes: string;
4
6
  no: string;
5
7
  }
8
+ export declare function getAttributeLookupsFormattedValue(value: unknown, options?: {
9
+ maxCount?: number;
10
+ }): string;
11
+ export declare function getAttributeAttachmentFormattedValue(value: unknown): string;
12
+ export declare function getAttributeDateFormattedValue(attribute: DateAttribute, value: unknown, locale: Locale): string;
13
+ export declare function getAttributeDateRangeFormattedValue(value: unknown, locale: Locale): string;
14
+ export declare function getAttributeBooleanFormattedValue(attribute: BooleanAttribute, value: unknown, options?: {
15
+ strings?: AttributeFormattedValueStringsSet;
16
+ }): string;
17
+ export declare function getAttributeChoicesFormattedValue(attribute: ChoicesAttribute<string | number>, value: unknown): string;
18
+ export declare function getAttributeLookupFormattedValue(value: unknown): string;
19
+ export declare function getAttributeRegardingFormattedValue(value: unknown): string;
20
+ export declare function getAttributeMoneyFormattedValue(value: unknown, locale: Locale): string;
6
21
  export declare function formatDuration(value: number | null): string;
7
- export declare function getAttributeFormattedValue<A extends Attribute = Attribute>(attribute: Attribute, value: InferredAttributeType<A> | null | undefined, options?: {
22
+ export declare function getAttributeFormattedValue<A extends Attribute = Attribute>(attribute: Attribute, value: InferredAttributeType<A> | null | undefined, locale: Locale, options?: {
8
23
  maxCount?: number;
9
24
  strings?: AttributeFormattedValueStringsSet;
10
- dateFormat?: string;
11
- timeFormat?: string;
12
- locale?: string;
13
- currency?: string;
14
- currencySign?: 'accounting' | 'standard';
15
- currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code';
16
- timezone?: string;
17
- region?: string;
18
25
  }): string | null;
19
26
  export {};
@@ -3,6 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getAttributeLookupsFormattedValue = getAttributeLookupsFormattedValue;
7
+ exports.getAttributeAttachmentFormattedValue = getAttributeAttachmentFormattedValue;
8
+ exports.getAttributeDateFormattedValue = getAttributeDateFormattedValue;
9
+ exports.getAttributeDateRangeFormattedValue = getAttributeDateRangeFormattedValue;
10
+ exports.getAttributeBooleanFormattedValue = getAttributeBooleanFormattedValue;
11
+ exports.getAttributeChoicesFormattedValue = getAttributeChoicesFormattedValue;
12
+ exports.getAttributeLookupFormattedValue = getAttributeLookupFormattedValue;
13
+ exports.getAttributeRegardingFormattedValue = getAttributeRegardingFormattedValue;
14
+ exports.getAttributeMoneyFormattedValue = getAttributeMoneyFormattedValue;
6
15
  exports.formatDuration = formatDuration;
7
16
  exports.getAttributeFormattedValue = getAttributeFormattedValue;
8
17
  const dayjs_1 = __importDefault(require("dayjs"));
@@ -15,12 +24,6 @@ const defaultAttributeFormattedValueStrings = {
15
24
  yes: 'Yes',
16
25
  no: 'No',
17
26
  };
18
- const defaultDateFormat = 'YYYY-MM-DD';
19
- const defaultTimeFormat = 'HH:mm';
20
- const defaultLocale = 'en-US';
21
- const defaultCurrency = 'USD';
22
- const defaultCurrencySign = 'accounting';
23
- const defaultCurrencyDisplay = 'symbol';
24
27
  function getAttributeLookupsFormattedValue(value, options) {
25
28
  const items = value?.map((v) => v.name);
26
29
  if (options?.maxCount && items?.length > options.maxCount) {
@@ -34,41 +37,50 @@ function getAttributeLookupsFormattedValue(value, options) {
34
37
  function getAttributeAttachmentFormattedValue(value) {
35
38
  return value?.url ?? null;
36
39
  }
37
- function getAttributeDateFormattedValue(attribute, value, options) {
38
- const dateFormat = options?.dateFormat ?? defaultDateFormat;
39
- const timeFormat = options?.timeFormat ?? defaultTimeFormat;
40
+ function getAttributeDateFormattedValue(attribute, value, locale) {
40
41
  if (attribute.format === 'datetime') {
41
42
  return (0, dayjs_1.default)(value)
42
- .tz(options?.timezone)
43
- .format(dateFormat + ' ' + timeFormat);
43
+ .tz(locale?.timezone)
44
+ .format(locale.dateFormats.short + ' ' + locale.timeFormats.short);
44
45
  }
45
46
  else {
46
- return (0, dayjs_1.default)(value)
47
- .tz(options?.timezone)
48
- .format(dateFormat);
47
+ return (0, dayjs_1.default)(value).format(locale.dateFormats.short);
49
48
  }
50
49
  }
51
- function getAttributeDateRangeFormattedValue(value, options) {
52
- if (!value)
53
- return null;
54
- const dateFormat = options?.dateFormat ?? defaultDateFormat;
55
- const from = value[0];
56
- const to = value[1];
57
- if (!from && !to) {
58
- return null;
50
+ function getAttributeDateRangeFormattedValue(value, locale) {
51
+ if (!value) {
52
+ return '';
59
53
  }
60
- if (from && to) {
61
- return ((0, dayjs_1.default)(from).tz(options?.timezone).format(dateFormat) +
62
- ' - ' +
63
- (0, dayjs_1.default)(to).tz(options?.timezone).format(dateFormat));
54
+ if (!Array.isArray(value) || value.length !== 2) {
55
+ return '';
64
56
  }
65
- if (from) {
66
- return 'After ' + (0, dayjs_1.default)(from).tz(options?.timezone).format(dateFormat);
57
+ if (!value[0] || !value[1]) {
58
+ return '';
67
59
  }
68
- if (to) {
69
- return 'Before ' + (0, dayjs_1.default)(to).tz(options?.timezone).format(dateFormat);
60
+ const dateRangeFormat = locale.dateRangeFormats.short;
61
+ const [start, end] = value.map((date) => (0, dayjs_1.default)(date));
62
+ if (start.isSame(end, 'year')) {
63
+ if (start.isSame(end, 'month')) {
64
+ if (start.isSame(end, 'day')) {
65
+ return start.format(dateRangeFormat.date);
66
+ }
67
+ else {
68
+ return (start.format(dateRangeFormat.sameMonth[0]) +
69
+ dateRangeFormat.separator +
70
+ end.format(dateRangeFormat.sameMonth[1]));
71
+ }
72
+ }
73
+ else {
74
+ return (start.format(dateRangeFormat.sameYear[0]) +
75
+ dateRangeFormat.separator +
76
+ end.format(dateRangeFormat.sameYear[1]));
77
+ }
78
+ }
79
+ else {
80
+ return (start.format(dateRangeFormat.date) +
81
+ dateRangeFormat.separator +
82
+ end.format(dateRangeFormat.date));
70
83
  }
71
- return null;
72
84
  }
73
85
  function getAttributeBooleanFormattedValue(attribute, value, options) {
74
86
  const strings = options?.strings ?? defaultAttributeFormattedValueStrings;
@@ -96,19 +108,15 @@ function getAttributeLookupFormattedValue(value) {
96
108
  function getAttributeRegardingFormattedValue(value) {
97
109
  return value?.name;
98
110
  }
99
- function getAttributeMoneyFormattedValue(value, options) {
100
- const locale = options?.locale ?? defaultLocale;
101
- const currency = options?.currency ?? defaultCurrency;
102
- const currencySign = options?.currencySign ?? defaultCurrencySign;
103
- const currencyDisplay = options?.currencyDisplay ?? defaultCurrencyDisplay;
104
- return new Intl.NumberFormat(locale, {
111
+ function getAttributeMoneyFormattedValue(value, locale) {
112
+ return new Intl.NumberFormat(locale.locale, {
105
113
  style: 'currency',
106
- currency,
107
- currencySign,
108
- currencyDisplay,
114
+ currency: locale.currency.currency,
115
+ currencySign: locale.currency.currencySign,
116
+ currencyDisplay: locale.currency.currencyDisplay,
109
117
  }).format(value);
110
118
  }
111
- function getAttributeNumberFormattedValue(attribute, value, options) {
119
+ function getAttributeNumberFormattedValue(attribute, value, locale) {
112
120
  if (attribute.format === 'duration') {
113
121
  return formatDuration(value);
114
122
  }
@@ -116,9 +124,9 @@ function getAttributeNumberFormattedValue(attribute, value, options) {
116
124
  return (0, dayjs_1.default)()
117
125
  .startOf('day')
118
126
  .add(value, 'minutes')
119
- .format(options?.timeFormat ?? defaultTimeFormat);
127
+ .format(locale.timeFormats.short);
120
128
  }
121
- return new Intl.NumberFormat(options?.locale).format(value);
129
+ return new Intl.NumberFormat(locale.locale).format(value);
122
130
  }
123
131
  function formatDuration(value) {
124
132
  if (!value) {
@@ -154,11 +162,11 @@ function formatDuration(value) {
154
162
  }
155
163
  return `${Number((value / 1440).toFixed(2))} days`;
156
164
  }
157
- function getAttributeFormattedValue(attribute, value, options) {
165
+ function getAttributeFormattedValue(attribute, value, locale, options) {
158
166
  if (value === null || value === undefined) {
159
167
  return null;
160
168
  }
161
- const region = options?.region ?? 'US';
169
+ const region = locale.region;
162
170
  switch (attribute.type) {
163
171
  case 'boolean':
164
172
  return getAttributeBooleanFormattedValue(attribute, value, options);
@@ -167,9 +175,9 @@ function getAttributeFormattedValue(attribute, value, options) {
167
175
  case 'choices':
168
176
  return getAttributeChoicesFormattedValue(attribute, value);
169
177
  case 'date':
170
- return getAttributeDateFormattedValue(attribute, value, options);
178
+ return getAttributeDateFormattedValue(attribute, value, locale);
171
179
  case 'daterange':
172
- return getAttributeDateRangeFormattedValue(value, options);
180
+ return getAttributeDateRangeFormattedValue(value, locale);
173
181
  case 'lookup':
174
182
  return getAttributeLookupFormattedValue(value);
175
183
  case 'lookups':
@@ -177,9 +185,9 @@ function getAttributeFormattedValue(attribute, value, options) {
177
185
  case 'regarding':
178
186
  return getAttributeRegardingFormattedValue(value);
179
187
  case 'money':
180
- return getAttributeMoneyFormattedValue(value, options);
188
+ return getAttributeMoneyFormattedValue(value, locale);
181
189
  case 'number':
182
- return getAttributeNumberFormattedValue(attribute, value, options);
190
+ return getAttributeNumberFormattedValue(attribute, value, locale);
183
191
  case 'attachment':
184
192
  return getAttributeAttachmentFormattedValue(value);
185
193
  case 'string':