@headless-adminapp/app 1.4.6 → 1.4.9

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.
@@ -119,9 +119,6 @@ var FormCommandBuilder;
119
119
  if (!recordId) {
120
120
  return;
121
121
  }
122
- // if (typeof stringSet === 'function') {
123
- // stringSet = stringSet(context);
124
- // }
125
122
  const localizeSelector = (0, utils_1.createLocalizedSelector)(stringSet, localizedStringSet, context.locale.language);
126
123
  try {
127
124
  const confirmResult = await context.utility.openConfirmDialog({
@@ -76,7 +76,7 @@ function getIsFieldDisabled({ attribute, isFormReadonly, disabledFields, control
76
76
  else if ('disabled' in control && control.disabled !== undefined) {
77
77
  disabled = control.disabled;
78
78
  }
79
- else if (attribute && attribute.readonly !== undefined) {
79
+ else if (attribute?.readonly !== undefined) {
80
80
  disabled = attribute.readonly;
81
81
  }
82
82
  }
@@ -39,21 +39,23 @@ function useFormSave() {
39
39
  const saveRecord = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.saveRecordFn);
40
40
  const client = (0, react_query_1.useQueryClient)();
41
41
  const router = (0, route_1.useRouter)();
42
- function showMessageAfterSave({ isCreatedMode }) {
42
+ function showMessageAfterSave({ mode }) {
43
43
  // Show notification
44
- if (!isCreatedMode) {
45
- openToastNotification({
46
- type: 'success',
47
- title: 'Record updated',
48
- text: 'Record updated successfully',
49
- });
50
- }
51
- else {
52
- openToastNotification({
53
- type: 'success',
54
- title: 'Record created',
55
- text: 'Record created successfully',
56
- });
44
+ switch (mode) {
45
+ case 'create':
46
+ openToastNotification({
47
+ type: 'success',
48
+ title: 'Record created',
49
+ text: 'Record created successfully',
50
+ });
51
+ break;
52
+ case 'update':
53
+ openToastNotification({
54
+ type: 'success',
55
+ title: 'Record updated',
56
+ text: 'Record updated successfully',
57
+ });
58
+ break;
57
59
  }
58
60
  }
59
61
  const _save = async (mode) => {
@@ -107,7 +109,7 @@ function useFormSave() {
107
109
  queryKey: ['data', 'retriveRecords'],
108
110
  });
109
111
  showMessageAfterSave({
110
- isCreatedMode: !record,
112
+ mode: record ? 'update' : 'create',
111
113
  });
112
114
  }
113
115
  catch (err) {
@@ -19,9 +19,7 @@ function useLoadFormGridPage(logicalName, formId) {
19
19
  queryKey: ['experience-schema-form-commands', logicalName],
20
20
  queryFn: async () => {
21
21
  let commands = await experienceStore.getFormCommands(logicalName);
22
- if (!commands) {
23
- commands = formCommands;
24
- }
22
+ commands ??= formCommands;
25
23
  return commands ?? [];
26
24
  },
27
25
  initialData: [],
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getModifiedValues = getModifiedValues;
4
4
  exports.saveRecord = saveRecord;
5
5
  exports.saveEditableGridControl = saveEditableGridControl;
6
- const utils_1 = require("../../dataform/DataFormProvider/utils");
6
+ const utils_1 = require("../DataFormProvider/utils");
7
7
  function getModifiedValues(initialValues, values, exclude) {
8
8
  const keys = Object.keys(values);
9
9
  return keys.reduce((p, c) => {
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDebouncedValue = useDebouncedValue;
4
4
  const react_1 = require("react");
5
5
  function useDebouncedValue(value, wait, options = { leading: false }) {
6
- const [_value, setValue] = (0, react_1.useState)(value);
6
+ const [internalValue, setInternalValue] = (0, react_1.useState)(value);
7
7
  const mountedRef = (0, react_1.useRef)(false);
8
- const timeoutRef = (0, react_1.useRef)(null);
8
+ const timeoutRef = (0, react_1.useRef)();
9
9
  const cooldownRef = (0, react_1.useRef)(false);
10
10
  const cancel = () => window.clearTimeout(timeoutRef.current);
11
11
  (0, react_1.useEffect)(() => {
12
12
  if (mountedRef.current) {
13
13
  if (!cooldownRef.current && options.leading) {
14
14
  cooldownRef.current = true;
15
- setValue(value);
15
+ setInternalValue(value);
16
16
  }
17
17
  else {
18
18
  cancel();
19
19
  timeoutRef.current = window.setTimeout(() => {
20
20
  cooldownRef.current = false;
21
- setValue(value);
21
+ setInternalValue(value);
22
22
  }, wait);
23
23
  }
24
24
  }
@@ -27,5 +27,5 @@ function useDebouncedValue(value, wait, options = { leading: false }) {
27
27
  mountedRef.current = true;
28
28
  return cancel;
29
29
  }, []);
30
- return [_value, cancel];
30
+ return [internalValue, cancel];
31
31
  }
@@ -8,7 +8,7 @@ exports.useIsTablet = useIsTablet;
8
8
  const debounce_1 = __importDefault(require("lodash/debounce"));
9
9
  const react_1 = require("react");
10
10
  function useIsMobile() {
11
- const [isMobile, setIsMobile] = (0, react_1.useState)(false);
11
+ const [isMobile, setIsMobile] = (0, react_1.useState)(window.innerWidth < 768);
12
12
  (0, react_1.useLayoutEffect)(() => {
13
13
  const updateSize = () => {
14
14
  setIsMobile(window.innerWidth < 768);
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const app_1 = require("@headless-adminapp/core/experience/app");
6
6
  const store_1 = require("@headless-adminapp/core/store");
7
7
  const icons_1 = require("@headless-adminapp/icons");
8
+ const react_1 = require("react");
8
9
  const context_1 = require("../mutable/context");
9
10
  const store_2 = require("../store");
10
11
  const context_2 = require("./context");
@@ -32,6 +33,13 @@ const MetadataProvider = ({ children, experienceStore = exports.defaultExperienc
32
33
  appExperience,
33
34
  recentItemStore,
34
35
  });
36
+ (0, react_1.useEffect)(() => {
37
+ contextValue.setValue({
38
+ appExperience,
39
+ experienceStore,
40
+ schemaStore,
41
+ });
42
+ }, [contextValue, appExperience, experienceStore, schemaStore]);
35
43
  return ((0, jsx_runtime_1.jsx)(context_2.MetadataContext.Provider, { value: contextValue, children: children }));
36
44
  };
37
45
  exports.MetadataProvider = MetadataProvider;
@@ -12,9 +12,7 @@ function useExperienceViewCommands(logicalName) {
12
12
  queryKey: ['experience-schema-view-commands', logicalName],
13
13
  queryFn: async () => {
14
14
  let commands = await experienceStore.getViewCommands(logicalName);
15
- if (!commands) {
16
- commands = viewCommands;
17
- }
15
+ commands ??= viewCommands;
18
16
  return commands ?? [];
19
17
  },
20
18
  initialData: [],
@@ -12,9 +12,7 @@ function useExperienceViewSubgridCommands(logicalName) {
12
12
  queryKey: ['experience-schema-view-subgrid-commands', logicalName],
13
13
  queryFn: async () => {
14
14
  let commands = await experienceStore.getSubgridCommands(logicalName);
15
- if (!commands) {
16
- commands = subgridCommands;
17
- }
15
+ commands ??= subgridCommands;
18
16
  return commands ?? [];
19
17
  },
20
18
  initialData: [],
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOpenForm = useOpenForm;
4
4
  const app_1 = require("@headless-adminapp/core/experience/app");
5
5
  const react_1 = require("react");
6
- const hooks_1 = require("../../route/hooks/");
6
+ const hooks_1 = require("../../route/hooks");
7
7
  const useRouteResolver_1 = require("../../route/hooks/useRouteResolver");
8
8
  function useOpenForm() {
9
9
  const routeResolver = (0, useRouteResolver_1.useRouteResolver)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "1.4.6",
3
+ "version": "1.4.9",
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": "89d91fe63da3aae42fc34482cc90c1e12963810b"
41
+ "gitHead": "39e62181f5436c5ceeaca2aa88d132593d53607a"
42
42
  }
@@ -13,12 +13,10 @@ const ProgressIndicatorProvider = ({ children, }) => {
13
13
  setOverlayVisible(true);
14
14
  setMessage(message);
15
15
  if (delay) {
16
- if (!showTimeoutRef.current) {
17
- showTimeoutRef.current = setTimeout(() => {
18
- setVisible(true);
19
- showTimeoutRef.current = undefined;
20
- }, delay);
21
- }
16
+ showTimeoutRef.current ??= setTimeout(() => {
17
+ setVisible(true);
18
+ showTimeoutRef.current = undefined;
19
+ }, delay);
22
20
  }
23
21
  else {
24
22
  if (showTimeoutRef.current) {
@@ -1,7 +1,7 @@
1
- import { SchemaAttributes } from '@headless-adminapp/core/schema';
1
+ import { InferredSchemaType, SchemaAttributes } from '@headless-adminapp/core/schema';
2
2
  export declare function useRecordSetResult(): {
3
3
  isLoading: boolean;
4
- data: import("@headless-adminapp/core/transport").Data<SchemaAttributes>[] | undefined;
4
+ data: import("@headless-adminapp/core/transport").Data<InferredSchemaType<SchemaAttributes>>[] | undefined;
5
5
  cardView: import("@headless-adminapp/core/experience/view").CardView | null;
6
6
  schema: import("@headless-adminapp/core/schema").Schema<SchemaAttributes> | null;
7
7
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SchemaExperienceStore = void 0;
4
4
  exports.getDefaultCardView = getDefaultCardView;
5
+ const utils_1 = require("@headless-adminapp/core/utils");
5
6
  function getDefaultCardView(schema) {
6
7
  return {
7
8
  primaryColumn: schema.primaryAttribute,
@@ -71,9 +72,7 @@ class SchemaExperienceStore {
71
72
  if (!validViewIds.length) {
72
73
  validViewIds = [experience.defaultViewId];
73
74
  }
74
- if (!viewId) {
75
- viewId = experience.defaultViewId;
76
- }
75
+ viewId = (0, utils_1.stringWithDefault)(viewId, experience.defaultViewId);
77
76
  if (!validViewIds.includes(viewId)) {
78
77
  viewId = validViewIds[0];
79
78
  }
@@ -103,9 +102,7 @@ class SchemaExperienceStore {
103
102
  if (!validViewIds.length) {
104
103
  validViewIds = [experience.defaultViewId];
105
104
  }
106
- if (!viewId) {
107
- viewId = experience.defaultAssociatedViewId;
108
- }
105
+ viewId = (0, utils_1.stringWithDefault)(viewId, experience.defaultAssociatedViewId);
109
106
  if (!validViewIds.includes(viewId)) {
110
107
  viewId = validViewIds[0];
111
108
  }
@@ -130,9 +127,7 @@ class SchemaExperienceStore {
130
127
  }
131
128
  async getViewLookupV2(logicalName, viewId) {
132
129
  const experience = await this.getExperience(logicalName);
133
- if (!viewId) {
134
- viewId = experience.defaultLookupId;
135
- }
130
+ viewId = (0, utils_1.stringWithDefault)(viewId, experience.defaultLookupId);
136
131
  const view = experience.lookups.find((v) => v.id === viewId);
137
132
  if (!view) {
138
133
  throw new Error(`Lookup ${viewId} not found`);
@@ -3,9 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileServiceContext = exports.DataServiceContext = void 0;
4
4
  const react_1 = require("react");
5
5
  exports.DataServiceContext = (0, react_1.createContext)(undefined);
6
- // export const noopFileService = {
7
- // uploadFile: async () => {
8
- // throw new Error('File service not implemented');
9
- // },
10
- // } as IFileService;
11
6
  exports.FileServiceContext = (0, react_1.createContext)(null);
package/utils/phone.js CHANGED
@@ -21,7 +21,7 @@ function parsePhoneNumber(input, defaultCountry) {
21
21
  uri: phoneNumber.getURI(),
22
22
  };
23
23
  }
24
- catch (error) {
24
+ catch {
25
25
  return {
26
26
  formattedInternationalValue: input,
27
27
  formattedNationalValue: input,