@headless-adminapp/app 0.0.17-alpha.23 → 0.0.17-alpha.25

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.
@@ -8,7 +8,7 @@ import { RouteProviderProps } from '../route/RouteProvider';
8
8
  export interface LayoutProviderProps {
9
9
  routeProps: RouteProviderProps;
10
10
  queryClient: QueryClient;
11
- localeProps?: LocaleProviderProps;
11
+ localeProps: LocaleProviderProps;
12
12
  dataService: IDataService;
13
13
  authProps?: AuthProviderProps;
14
14
  authPlaceholder?: FC<AuthProviderPlaceholderProps>;
@@ -17,6 +17,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.useFormSave = useFormSave;
20
+ // Wrapper - Loader, response message
21
+ // Core - Extract modified fields, prepare operations, perform operations
22
+ const route_1 = require("@headless-adminapp/app/route");
20
23
  const react_query_1 = require("@tanstack/react-query");
21
24
  const react_1 = require("react");
22
25
  const react_hook_form_1 = require("react-hook-form");
@@ -42,6 +45,7 @@ function useFormSave() {
42
45
  const { showProgressIndicator, hideProgressIndicator } = (0, useProgressIndicator_1.useProgressIndicator)();
43
46
  const openToastNotification = (0, useOpenToastNotification_1.useOpenToastNotification)();
44
47
  const client = (0, react_query_1.useQueryClient)();
48
+ const router = (0, route_1.useRouter)();
45
49
  function showMessageAfterSave({ isCreatedMode }) {
46
50
  // Show notification
47
51
  if (!isCreatedMode) {
@@ -97,6 +101,9 @@ function useFormSave() {
97
101
  yield client.invalidateQueries({
98
102
  queryKey: ['data', 'retriveRecord'],
99
103
  });
104
+ if (mode === 'saveandclose') {
105
+ router.back();
106
+ }
100
107
  }
101
108
  yield client.invalidateQueries({
102
109
  queryKey: ['data', 'retriveRecords'],
@@ -32,7 +32,10 @@ function DataResolver() {
32
32
  const [columnFilters] = (0, hooks_1.useGridColumnFilter)();
33
33
  const gridColumns = (0, hooks_1.useGridColumns)();
34
34
  const maxRecords = (_a = (0, hooks_1.useMaxRecords)()) !== null && _a !== void 0 ? _a : MAX_RECORDS;
35
+ const [selectedIds] = (0, hooks_1.useGridSelection)();
35
36
  const { schemaStore } = (0, useMetadata_1.useMetadata)();
37
+ const selectedIdsRef = (0, react_1.useRef)(selectedIds);
38
+ selectedIdsRef.current = selectedIds;
36
39
  const setState = (0, context_1.useContextSetValue)(context_2.GridContext);
37
40
  const [search] = (0, useDebouncedValue_1.useDebouncedValue)(searchText, 500);
38
41
  const columns = (0, react_1.useMemo)(() => Array.from(new Set([
@@ -146,10 +149,12 @@ function DataResolver() {
146
149
  count: (_c = (_b = data === null || data === void 0 ? void 0 : data.pages) === null || _b === void 0 ? void 0 : _b[0].data.count) !== null && _c !== void 0 ? _c : 0,
147
150
  records: (_d = data === null || data === void 0 ? void 0 : data.pages.map((x) => x.data.records).flat()) !== null && _d !== void 0 ? _d : [],
148
151
  };
152
+ const selectedIds = selectedIdsRef.current.filter((x) => finalData.records.some((y) => y[schema.idAttribute] === x));
149
153
  setState({
150
154
  data: finalData,
155
+ selectedIds,
151
156
  });
152
- }, [data, setState]);
157
+ }, [data, setState, schema.idAttribute]);
153
158
  (0, react_1.useEffect)(() => {
154
159
  setState({
155
160
  dataState: {
@@ -0,0 +1 @@
1
+ export declare function DataSelectionResolver(): null;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataSelectionResolver = DataSelectionResolver;
4
+ const react_1 = require("react");
5
+ const hooks_1 = require("../hooks");
6
+ function DataSelectionResolver() {
7
+ const data = (0, hooks_1.useGridData)();
8
+ const [selectedIds] = (0, hooks_1.useGridSelection)();
9
+ const selectedIdsRef = (0, react_1.useRef)(selectedIds);
10
+ selectedIdsRef.current = selectedIds;
11
+ (0, react_1.useEffect)(() => { }, [data]);
12
+ return null;
13
+ }
@@ -1,7 +1,8 @@
1
1
  import { Locale } from '@headless-adminapp/core/experience/locale';
2
2
  import { FC, PropsWithChildren } from 'react';
3
3
  export interface LocaleProviderProps {
4
- locale?: string;
4
+ locale: string;
5
+ timezone: string;
5
6
  options?: {
6
7
  direction?: Locale['direction'];
7
8
  dateFormats?: Locale['dateFormats'];
@@ -5,10 +5,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const locale_1 = require("@headless-adminapp/core/experience/locale");
6
6
  const react_1 = require("react");
7
7
  const context_1 = require("./context");
8
- const LocaleProvider = ({ children, locale = 'en-US', options, }) => {
8
+ const LocaleProvider = ({ children, locale, timezone, options, }) => {
9
9
  const localeState = (0, react_1.useMemo)(() => {
10
- return (0, locale_1.getLocale)(locale, options);
11
- }, [locale, options]);
10
+ return (0, locale_1.getLocale)(locale, timezone, options);
11
+ }, [locale, timezone, options]);
12
12
  return ((0, jsx_runtime_1.jsx)(context_1.LocaleContext.Provider, { value: localeState, children: children }));
13
13
  };
14
14
  exports.LocaleProvider = LocaleProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "0.0.17-alpha.23",
3
+ "version": "0.0.17-alpha.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -39,5 +39,5 @@
39
39
  "react-hook-form": "7.52.2",
40
40
  "yup": "^1.4.0"
41
41
  },
42
- "gitHead": "ff177d1491eff81fa8ab0cdfc7e5e1d1b3edc18b"
42
+ "gitHead": "0a42b982d6113067cd2f9739ec646d138c1a5274"
43
43
  }
@@ -3,11 +3,11 @@ import { RetriveRecordsFnOptions, RetriveRecordsResult } from '@headless-adminap
3
3
  interface RestDataServiceOptions {
4
4
  endpoint: string;
5
5
  }
6
+ export declare function handleResponseError(response: Response): Promise<void>;
6
7
  export declare class RestDataService implements IDataService {
7
8
  protected readonly options: RestDataServiceOptions;
8
9
  constructor(options: RestDataServiceOptions);
9
10
  protected readonly headers: Record<string, string>;
10
- protected handleResponseError(response: Response): Promise<void>;
11
11
  private getHeaders;
12
12
  setHeader(name: string, value: string): void;
13
13
  removeHeader(name: string): void;
@@ -10,27 +10,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RestDataService = void 0;
13
+ exports.handleResponseError = handleResponseError;
13
14
  const transport_1 = require("@headless-adminapp/core/transport");
15
+ function handleResponseError(response) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ var _a;
18
+ if (response.ok) {
19
+ return;
20
+ }
21
+ if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
22
+ const data = yield response.json();
23
+ if (data.error) {
24
+ throw new transport_1.HttpError(response.status, data.error);
25
+ }
26
+ }
27
+ throw new transport_1.HttpError(response.status, response.statusText);
28
+ });
29
+ }
14
30
  class RestDataService {
15
31
  constructor(options) {
16
32
  this.options = options;
17
33
  this.headers = {};
18
34
  }
19
- handleResponseError(response) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- var _a;
22
- if (response.ok) {
23
- return;
24
- }
25
- if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
26
- const data = yield response.json();
27
- if (data.error) {
28
- throw new transport_1.HttpError(response.status, data.error);
29
- }
30
- }
31
- throw new transport_1.HttpError(response.status, response.statusText);
32
- });
33
- }
34
35
  getHeaders() {
35
36
  return Object.assign({ 'content-type': 'application/json' }, this.headers);
36
37
  }
@@ -47,7 +48,7 @@ class RestDataService {
47
48
  method: 'POST',
48
49
  body: JSON.stringify(data),
49
50
  });
50
- yield this.handleResponseError(response);
51
+ yield handleResponseError(response);
51
52
  return response.json();
52
53
  });
53
54
  }
@@ -11,5 +11,6 @@ export declare function getAttributeFormattedValue<A extends Attribute = Attribu
11
11
  currency?: string;
12
12
  currencySign?: 'accounting' | 'standard';
13
13
  currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code';
14
+ timezone?: string;
14
15
  }): string | null | undefined;
15
16
  export {};
@@ -5,6 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getAttributeFormattedValue = getAttributeFormattedValue;
7
7
  const dayjs_1 = __importDefault(require("dayjs"));
8
+ const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
9
+ const utc_1 = __importDefault(require("dayjs/plugin/utc"));
10
+ dayjs_1.default.extend(utc_1.default);
11
+ dayjs_1.default.extend(timezone_1.default);
8
12
  const defaultAttributeFormattedValueStrings = {
9
13
  yes: 'Yes',
10
14
  no: 'No',
@@ -44,7 +48,9 @@ function getAttributeFormattedValue(attribute, value, options) {
44
48
  })
45
49
  .join(', ');
46
50
  case 'date':
47
- return (0, dayjs_1.default)(value).format(dateFormat);
51
+ return (0, dayjs_1.default)(value)
52
+ .tz(options === null || options === void 0 ? void 0 : options.timezone)
53
+ .format(dateFormat);
48
54
  case 'daterange':
49
55
  if (!value)
50
56
  return null;
@@ -54,13 +60,15 @@ function getAttributeFormattedValue(attribute, value, options) {
54
60
  return null;
55
61
  }
56
62
  if (from && to) {
57
- return ((0, dayjs_1.default)(from).format(dateFormat) + ' - ' + (0, dayjs_1.default)(to).format(dateFormat));
63
+ return ((0, dayjs_1.default)(from).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat) +
64
+ ' - ' +
65
+ (0, dayjs_1.default)(to).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat));
58
66
  }
59
67
  if (from) {
60
- return 'After ' + (0, dayjs_1.default)(from).format(dateFormat);
68
+ return 'After ' + (0, dayjs_1.default)(from).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat);
61
69
  }
62
70
  if (to) {
63
- return 'Before ' + (0, dayjs_1.default)(to).format(dateFormat);
71
+ return 'Before ' + (0, dayjs_1.default)(to).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat);
64
72
  }
65
73
  return null;
66
74
  case 'lookup':