@headless-adminapp/app 1.4.3 → 1.4.8
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/FormCommandBuilder.js +0 -3
- package/dataform/DataFormProvider/utils.js +1 -1
- package/dataform/hooks/useFormSave.js +17 -15
- package/dataform/hooks/useLoadFormGridPage.js +1 -3
- package/dataform/utils/saveRecord.js +1 -1
- package/datagrid/DataGridProvider/utils.d.ts +1 -0
- package/datagrid/DataGridProvider/utils.js +17 -0
- package/hooks/useDebouncedValue.js +5 -5
- package/metadata/MetadataProvider.d.ts +2 -1
- package/metadata/MetadataProvider.js +11 -1
- package/metadata/context.d.ts +2 -0
- package/metadata/hooks/useExperienceViewCommands.js +1 -3
- package/metadata/hooks/useExperienceViewSubgridCommands.js +1 -3
- package/metadata/hooks/useMetadata.d.ts +2 -0
- package/metadata/hooks/useMetadata.js +3 -1
- package/metadata/hooks/useRecentItemStore.d.ts +2 -0
- package/metadata/hooks/useRecentItemStore.js +8 -0
- package/navigation/hooks/useOpenForm.js +1 -1
- package/package.json +2 -2
- package/progress-indicator/ProgressIndicatorProvider.js +4 -6
- package/recordset/hooks/useRecordSetResult.d.ts +2 -2
- package/store/RecentItemStore.d.ts +25 -0
- package/store/RecentItemStore.js +63 -0
- package/store/SchemaExperienceStore.js +4 -9
- package/store/index.d.ts +1 -1
- package/store/index.js +1 -1
- package/transport/context.js +0 -5
- package/utils/phone.js +1 -1
- package/store/HistoryState.d.ts +0 -7
- package/store/HistoryState.js +0 -32
|
@@ -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
|
|
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({
|
|
42
|
+
function showMessageAfterSave({ mode }) {
|
|
43
43
|
// Show notification
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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("
|
|
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) => {
|
|
@@ -5,6 +5,7 @@ import { Filter } from '@headless-adminapp/core/transport';
|
|
|
5
5
|
import { TransformedViewColumn } from '../context';
|
|
6
6
|
export declare function transformColumnFilter<S extends SchemaAttributes = SchemaAttributes>(filter: Partial<Record<string, ColumnCondition>>, schema: Schema<S>, schemaStore: ISchemaStore): Record<string, ColumnCondition> | null;
|
|
7
7
|
export declare function mergeConditions<S extends SchemaAttributes = SchemaAttributes>(schema: Schema<S>, filter: Filter | null | undefined, extraFilter: Filter | null | undefined, quickFilterResults: Filter | null | undefined, columnFilters: Partial<Record<string, ColumnCondition>> | undefined, schemaStore: ISchemaStore): Filter | null;
|
|
8
|
+
export declare function mergeFilters(...filters: Array<Filter | null | undefined>): Filter | null;
|
|
8
9
|
export declare function simplyfyFilter(filter: Filter): Filter | null;
|
|
9
10
|
export declare function collectExpandedKeys(columns: TransformedViewColumn<SchemaAttributes>[]): Record<string, string[]>;
|
|
10
11
|
export declare function collectGridColumns<S extends SchemaAttributes = SchemaAttributes>({ gridColumns, schema, }: {
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.transformColumnFilter = transformColumnFilter;
|
|
7
7
|
exports.mergeConditions = mergeConditions;
|
|
8
|
+
exports.mergeFilters = mergeFilters;
|
|
8
9
|
exports.simplyfyFilter = simplyfyFilter;
|
|
9
10
|
exports.collectExpandedKeys = collectExpandedKeys;
|
|
10
11
|
exports.collectGridColumns = collectGridColumns;
|
|
@@ -116,6 +117,22 @@ function mergeConditions(schema, filter, extraFilter, quickFilterResults, column
|
|
|
116
117
|
filters: filters,
|
|
117
118
|
});
|
|
118
119
|
}
|
|
120
|
+
function mergeFilters(...filters) {
|
|
121
|
+
if (filters.length === 0) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const nonNullFilters = filters.filter((f) => !!f);
|
|
125
|
+
if (nonNullFilters.length === 0) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (nonNullFilters.length === 1) {
|
|
129
|
+
return nonNullFilters[0];
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
type: 'and',
|
|
133
|
+
filters: nonNullFilters,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
119
136
|
function simplyfyFilter(filter) {
|
|
120
137
|
const conditions = filter.conditions ?? [];
|
|
121
138
|
const filters = [];
|
|
@@ -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 [
|
|
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)(
|
|
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
|
-
|
|
15
|
+
setInternalValue(value);
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
cancel();
|
|
19
19
|
timeoutRef.current = window.setTimeout(() => {
|
|
20
20
|
cooldownRef.current = false;
|
|
21
|
-
|
|
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 [
|
|
30
|
+
return [internalValue, cancel];
|
|
31
31
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
2
|
import { ISchemaExperienceStore, ISchemaStore, SchemaStore } from '@headless-adminapp/core/store';
|
|
3
3
|
import { FC, PropsWithChildren } from 'react';
|
|
4
|
-
import { SchemaExperienceStore } from '../store';
|
|
4
|
+
import { IRecentItemStore, SchemaExperienceStore } from '../store';
|
|
5
5
|
export interface MetadataProviderProps {
|
|
6
6
|
schemaStore?: ISchemaStore;
|
|
7
7
|
experienceStore?: ISchemaExperienceStore;
|
|
8
8
|
appExperience?: AppExperience;
|
|
9
|
+
recentItemStore?: IRecentItemStore;
|
|
9
10
|
}
|
|
10
11
|
export declare const defaultSchemaStore: SchemaStore<import("@headless-adminapp/core/schema").SchemaAttributes>;
|
|
11
12
|
export declare const defaultExperienceStore: SchemaExperienceStore;
|
|
@@ -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");
|
|
@@ -24,12 +25,21 @@ const defaultApp = {
|
|
|
24
25
|
},
|
|
25
26
|
logo: {},
|
|
26
27
|
};
|
|
27
|
-
const
|
|
28
|
+
const defaultRecentItemStore = new store_2.RecentItemStore();
|
|
29
|
+
const MetadataProvider = ({ children, experienceStore = exports.defaultExperienceStore, schemaStore = exports.defaultSchemaStore, appExperience = defaultApp, recentItemStore = defaultRecentItemStore, }) => {
|
|
28
30
|
const contextValue = (0, context_1.useCreateContextStore)({
|
|
29
31
|
experienceStore,
|
|
30
32
|
schemaStore,
|
|
31
33
|
appExperience,
|
|
34
|
+
recentItemStore,
|
|
32
35
|
});
|
|
36
|
+
(0, react_1.useEffect)(() => {
|
|
37
|
+
contextValue.setValue({
|
|
38
|
+
appExperience,
|
|
39
|
+
experienceStore,
|
|
40
|
+
schemaStore,
|
|
41
|
+
});
|
|
42
|
+
}, [contextValue, appExperience, experienceStore, schemaStore]);
|
|
33
43
|
return ((0, jsx_runtime_1.jsx)(context_2.MetadataContext.Provider, { value: contextValue, children: children }));
|
|
34
44
|
};
|
|
35
45
|
exports.MetadataProvider = MetadataProvider;
|
package/metadata/context.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
2
|
import type { ISchemaExperienceStore, ISchemaStore } from '@headless-adminapp/core/store';
|
|
3
|
+
import { IRecentItemStore } from '../store';
|
|
3
4
|
export interface MetadataContextState {
|
|
4
5
|
schemaStore: ISchemaStore;
|
|
5
6
|
experienceStore: ISchemaExperienceStore;
|
|
6
7
|
appExperience: AppExperience;
|
|
8
|
+
recentItemStore: IRecentItemStore;
|
|
7
9
|
}
|
|
8
10
|
export declare const MetadataContext: import("react").Context<import("../mutable/context").ContextValue<MetadataContextState>>;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
16
|
-
commands = subgridCommands;
|
|
17
|
-
}
|
|
15
|
+
commands ??= subgridCommands;
|
|
18
16
|
return commands ?? [];
|
|
19
17
|
},
|
|
20
18
|
initialData: [],
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRecentItemStore } from '@headless-adminapp/app/store';
|
|
1
2
|
import type { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
3
|
import type { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
4
|
import type { ISchemaExperienceStore, ISchemaStore } from '@headless-adminapp/core/store';
|
|
@@ -6,6 +7,7 @@ interface UseMetadataResult {
|
|
|
6
7
|
schemaStore: ISchemaStore<SchemaAttributes>;
|
|
7
8
|
appExperience: AppExperience;
|
|
8
9
|
experienceStore: ISchemaExperienceStore;
|
|
10
|
+
recentItemStore: IRecentItemStore;
|
|
9
11
|
}
|
|
10
12
|
export declare function useMetadata(): UseMetadataResult;
|
|
11
13
|
export {};
|
|
@@ -8,11 +8,13 @@ function useMetadata() {
|
|
|
8
8
|
const schemaStore = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.schemaStore);
|
|
9
9
|
const appExperience = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.appExperience);
|
|
10
10
|
const experienceStore = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.experienceStore);
|
|
11
|
+
const recentItemStore = (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.recentItemStore);
|
|
11
12
|
const schemas = schemaStore.getAllSchema();
|
|
12
13
|
return (0, react_1.useMemo)(() => ({
|
|
13
14
|
schemas,
|
|
14
15
|
schemaStore,
|
|
15
16
|
appExperience,
|
|
16
17
|
experienceStore,
|
|
17
|
-
|
|
18
|
+
recentItemStore,
|
|
19
|
+
}), [schemas, schemaStore, appExperience, experienceStore, recentItemStore]);
|
|
18
20
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRecentItemStore = useRecentItemStore;
|
|
4
|
+
const context_1 = require("../../mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useRecentItemStore() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.recentItemStore);
|
|
8
|
+
}
|
|
@@ -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.
|
|
3
|
+
"version": "1.4.8",
|
|
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": "f25faf823d592f7d9c0356c1ca238e9019b8e7c0"
|
|
42
42
|
}
|
|
@@ -13,12 +13,10 @@ const ProgressIndicatorProvider = ({ children, }) => {
|
|
|
13
13
|
setOverlayVisible(true);
|
|
14
14
|
setMessage(message);
|
|
15
15
|
if (delay) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
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
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Id } from '@headless-adminapp/core';
|
|
2
|
+
export interface IRecentItemStore {
|
|
3
|
+
getItems: <T = unknown>(cacheKey: string, limit?: number) => RecentItem<T>[];
|
|
4
|
+
addItem: <T = unknown>(cacheKey: string, id: Id, value: T, limit?: number) => void;
|
|
5
|
+
addListener: (cacheKey: string, listener: (items: RecentItem<unknown>[]) => void) => void;
|
|
6
|
+
removeListener: (cacheKey: string, listener: (items: RecentItem<unknown>[]) => void) => void;
|
|
7
|
+
}
|
|
8
|
+
export type RecentItem<T> = {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
id: Id;
|
|
11
|
+
value: T;
|
|
12
|
+
};
|
|
13
|
+
export declare class RecentItemStore implements IRecentItemStore {
|
|
14
|
+
private data;
|
|
15
|
+
private readonly storageKey;
|
|
16
|
+
private readonly maxItems;
|
|
17
|
+
private listeners;
|
|
18
|
+
constructor();
|
|
19
|
+
private init;
|
|
20
|
+
private sync;
|
|
21
|
+
getItems<T = unknown>(cacheKey: string, limit?: number): RecentItem<T>[];
|
|
22
|
+
addItem<T = unknown>(cacheKey: string, id: Id, value: T, limit?: number): void;
|
|
23
|
+
addListener(cacheKey: string, listener: (items: RecentItem<unknown>[]) => void): void;
|
|
24
|
+
removeListener(cacheKey: string, listener: (items: RecentItem<unknown>[]) => void): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecentItemStore = void 0;
|
|
4
|
+
class RecentItemStore {
|
|
5
|
+
data = {};
|
|
6
|
+
storageKey = 'recent_items';
|
|
7
|
+
maxItems = 5;
|
|
8
|
+
listeners = {};
|
|
9
|
+
constructor() {
|
|
10
|
+
this.init();
|
|
11
|
+
}
|
|
12
|
+
init() {
|
|
13
|
+
const _data = localStorage.getItem(this.storageKey);
|
|
14
|
+
if (_data) {
|
|
15
|
+
this.data = JSON.parse(_data);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.data = {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
sync() {
|
|
22
|
+
localStorage.setItem(this.storageKey, JSON.stringify(this.data));
|
|
23
|
+
}
|
|
24
|
+
getItems(cacheKey, limit) {
|
|
25
|
+
if (!this.data[cacheKey]) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
if (limit) {
|
|
29
|
+
return this.data[cacheKey].slice(0, limit);
|
|
30
|
+
}
|
|
31
|
+
return this.data[cacheKey];
|
|
32
|
+
}
|
|
33
|
+
addItem(cacheKey, id, value, limit) {
|
|
34
|
+
if (!this.data[cacheKey]) {
|
|
35
|
+
this.data[cacheKey] = [];
|
|
36
|
+
}
|
|
37
|
+
const timestamp = Date.now();
|
|
38
|
+
if (this.data[cacheKey].some((item) => item.id === id)) {
|
|
39
|
+
// Remove existing item with the same ID
|
|
40
|
+
this.data[cacheKey] = this.data[cacheKey].filter((item) => item.id !== id);
|
|
41
|
+
}
|
|
42
|
+
const newItem = { timestamp, id, value };
|
|
43
|
+
this.data[cacheKey].unshift(newItem);
|
|
44
|
+
this.data[cacheKey] = this.data[cacheKey].slice(0, limit ?? this.maxItems); // Limit to max items
|
|
45
|
+
this.sync();
|
|
46
|
+
for (const listener of this.listeners[cacheKey] || []) {
|
|
47
|
+
listener(this.data[cacheKey]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
addListener(cacheKey, listener) {
|
|
51
|
+
if (!this.listeners[cacheKey]) {
|
|
52
|
+
this.listeners[cacheKey] = [];
|
|
53
|
+
}
|
|
54
|
+
this.listeners[cacheKey].push(listener);
|
|
55
|
+
}
|
|
56
|
+
removeListener(cacheKey, listener) {
|
|
57
|
+
if (!this.listeners[cacheKey]) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this.listeners[cacheKey] = this.listeners[cacheKey].filter((l) => l !== listener);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.RecentItemStore = RecentItemStore;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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`);
|
package/store/index.d.ts
CHANGED
package/store/index.js
CHANGED
|
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./ComponentStore"), exports);
|
|
18
18
|
__exportStar(require("./EventManager"), exports);
|
|
19
19
|
__exportStar(require("./SchemaExperienceStore"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./RecentItemStore"), exports);
|
package/transport/context.js
CHANGED
|
@@ -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
package/store/HistoryState.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface HistoryStatePlugin {
|
|
2
|
-
getter: () => Record<string, Record<string, unknown>>;
|
|
3
|
-
setter: (value: Record<string, Record<string, unknown>>) => void;
|
|
4
|
-
}
|
|
5
|
-
export declare function registerHistoryStatePlugin(plugin: HistoryStatePlugin): void;
|
|
6
|
-
export declare function getHistoryState<T extends Record<string, unknown> = Record<string, unknown>>(key: string): Partial<T>;
|
|
7
|
-
export declare function setHistoryState(key: string, value: Record<string, unknown>): void;
|
package/store/HistoryState.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerHistoryStatePlugin = registerHistoryStatePlugin;
|
|
4
|
-
exports.getHistoryState = getHistoryState;
|
|
5
|
-
exports.setHistoryState = setHistoryState;
|
|
6
|
-
let historyStatePlugin = null;
|
|
7
|
-
function registerHistoryStatePlugin(plugin) {
|
|
8
|
-
historyStatePlugin = plugin;
|
|
9
|
-
}
|
|
10
|
-
function getHistoryState(key) {
|
|
11
|
-
if (!historyStatePlugin) {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
|
-
if (!key || typeof key !== 'string' || key.startsWith('~')) {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
const state = historyStatePlugin.getter();
|
|
18
|
-
return (state[key] || {});
|
|
19
|
-
}
|
|
20
|
-
function setHistoryState(key, value) {
|
|
21
|
-
if (!historyStatePlugin) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const currentState = historyStatePlugin.getter();
|
|
25
|
-
historyStatePlugin.setter({
|
|
26
|
-
...currentState,
|
|
27
|
-
[key]: {
|
|
28
|
-
...currentState[key],
|
|
29
|
-
...value,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|