@headless-adminapp/app 0.0.17-alpha.8 → 1.0.0
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/app/AppProvider.d.ts +0 -3
- package/app/AppProvider.js +10 -33
- package/app/AuthWrapper.d.ts +1 -1
- package/app/AuthWrapper.js +4 -1
- package/app/LayoutProvider.d.ts +8 -7
- package/app/LayoutProvider.js +28 -2
- package/app/context.d.ts +1 -1
- package/auth/AuthProvider.d.ts +1 -1
- package/auth/AuthProvider.js +30 -23
- package/auth/context.d.ts +2 -0
- package/auth/hooks/useIsSkipAuthCheck.d.ts +1 -0
- package/auth/hooks/useIsSkipAuthCheck.js +8 -0
- package/auth/hooks/useLogout.js +1 -1
- package/board/BoardColumnDataResolver.d.ts +1 -0
- package/board/BoardColumnDataResolver.js +64 -0
- package/board/BoardColumnProvider.d.ts +7 -0
- package/board/BoardColumnProvider.js +36 -0
- package/board/context.d.ts +19 -0
- package/board/context.js +6 -0
- package/board/hooks/index.d.ts +6 -0
- package/board/hooks/index.js +15 -0
- package/board/hooks/useBoardColumnConfig.d.ts +2 -0
- package/board/hooks/useBoardColumnConfig.js +8 -0
- package/board/hooks/useBoardColumnData.d.ts +3 -0
- package/board/hooks/useBoardColumnData.js +9 -0
- package/board/hooks/useBoardColumnDataState.d.ts +5 -0
- package/board/hooks/useBoardColumnDataState.js +9 -0
- package/board/hooks/useBoardConfig.d.ts +3 -0
- package/board/hooks/useBoardConfig.js +8 -0
- package/board/hooks/useBoardSchema.d.ts +2 -0
- package/board/hooks/useBoardSchema.js +7 -0
- package/board/hooks/useSearchText.d.ts +1 -0
- package/board/hooks/useSearchText.js +14 -0
- package/board/types.d.ts +47 -0
- package/board/utils.d.ts +3 -0
- package/board/utils.js +6 -0
- package/builders/CommandBuilder/DefaultCommandBuilder.d.ts +15 -6
- package/builders/CommandBuilder/DefaultCommandBuilder.js +42 -20
- package/builders/CommandBuilder/FormCommandBuilder.d.ts +14 -13
- package/builders/CommandBuilder/FormCommandBuilder.js +66 -52
- package/builders/CommandBuilder/SubgridCommandBuilder.d.ts +8 -27
- package/builders/CommandBuilder/SubgridCommandBuilder.js +115 -57
- package/builders/CommandBuilder/ViewCommandBuilder.js +32 -52
- package/builders/CommandBuilder/utils.js +1 -1
- package/builders/DefineFormExperience.d.ts +27 -0
- package/builders/DefineFormExperience.js +99 -0
- package/builders/DefineViewExperience.d.ts +13 -0
- package/builders/DefineViewExperience.js +33 -0
- package/builders/SchemaExperienceBuilder.d.ts +9 -7
- package/builders/SchemaExperienceBuilder.js +62 -40
- package/builders/utils.js +30 -44
- package/calendar/baseEventAttributes.d.ts +35 -0
- package/calendar/baseEventAttributes.js +38 -0
- package/calendar/context.d.ts +6 -0
- package/calendar/context.js +5 -0
- package/calendar/hooks/index.d.ts +1 -0
- package/{appearance → calendar}/hooks/index.js +1 -1
- package/calendar/hooks/useConfig.d.ts +3 -0
- package/calendar/hooks/useConfig.js +8 -0
- package/calendar/types.d.ts +41 -0
- package/calendar/types.js +2 -0
- package/calendar/utils.d.ts +3 -0
- package/calendar/utils.js +6 -0
- package/command/hooks/useBaseCommandHandlerContext.js +15 -6
- package/command/hooks/useCommands.js +1 -1
- package/command/utils/index.js +34 -9
- package/components/ScrollView/index.d.ts +1 -1
- package/components/ScrollView/index.js +2 -2
- package/components/ScrollbarWithMoreDataRequest/index.d.ts +9 -0
- package/components/ScrollbarWithMoreDataRequest/index.js +32 -0
- package/dataform/DataFormProvider/CustomHookExecuter.d.ts +5 -0
- package/dataform/DataFormProvider/CustomHookExecuter.js +14 -0
- package/dataform/DataFormProvider/DataResolver.d.ts +6 -4
- package/dataform/DataFormProvider/DataResolver.js +11 -94
- package/dataform/DataFormProvider/InitialValueResolver.js +3 -2
- package/dataform/DataFormProvider/ReadonlyInfoResolver.js +2 -3
- package/dataform/DataFormProvider/getRecord.d.ts +3 -0
- package/dataform/DataFormProvider/getRecord.js +56 -0
- package/dataform/DataFormProvider/index.d.ts +4 -0
- package/dataform/DataFormProvider/index.js +34 -12
- package/dataform/DataFormProvider/types.d.ts +13 -0
- package/dataform/DataFormProvider/types.js +2 -0
- package/dataform/DataFormProvider/utils.d.ts +23 -0
- package/dataform/DataFormProvider/utils.js +105 -0
- package/dataform/FormManager.d.ts +57 -0
- package/dataform/FormManager.js +247 -0
- package/dataform/constants.d.ts +1 -0
- package/dataform/constants.js +4 -0
- package/dataform/context.d.ts +26 -1
- package/dataform/hooks/index.d.ts +11 -0
- package/dataform/hooks/index.js +11 -0
- package/dataform/hooks/useContextKey.d.ts +1 -0
- package/dataform/hooks/useContextKey.js +8 -0
- package/dataform/hooks/useDisabledControlsManager.d.ts +6 -0
- package/dataform/hooks/useDisabledControlsManager.js +46 -0
- package/dataform/hooks/useEventManager.d.ts +1 -0
- package/dataform/hooks/useEventManager.js +8 -0
- package/dataform/hooks/useFormManager.d.ts +2 -0
- package/dataform/hooks/useFormManager.js +13 -0
- package/dataform/hooks/useFormNotifications.js +2 -2
- package/dataform/hooks/useFormSave.js +28 -31
- package/dataform/hooks/useHiddenControlsManager.d.ts +7 -0
- package/dataform/hooks/useHiddenControlsManager.js +50 -0
- package/dataform/hooks/useIsControlDisabled.d.ts +1 -0
- package/dataform/hooks/useIsControlDisabled.js +27 -0
- package/dataform/hooks/useIsControlHiddenByAttributeName.d.ts +1 -0
- package/dataform/hooks/useIsControlHiddenByAttributeName.js +17 -0
- package/dataform/hooks/useIsControlHiddenByKey.d.ts +1 -0
- package/dataform/hooks/useIsControlHiddenByKey.js +17 -0
- package/dataform/hooks/useIsFieldRequired.d.ts +1 -0
- package/dataform/hooks/useIsFieldRequired.js +25 -0
- package/dataform/hooks/useLoadFormGridPage.js +8 -17
- package/dataform/hooks/useMainFormCommands.d.ts +1 -12
- package/dataform/hooks/useMainFormCommands.js +13 -3
- package/dataform/hooks/useOnFieldValueChangeListener.d.ts +1 -0
- package/dataform/hooks/useOnFieldValueChangeListener.js +30 -0
- package/dataform/hooks/useProcessFlowSteps.d.ts +1 -0
- package/dataform/hooks/useProcessFlowSteps.js +45 -0
- package/dataform/hooks/useRecordTitle.d.ts +3 -1
- package/dataform/hooks/useRecordTitle.js +12 -5
- package/dataform/hooks/useRequiredFieldManager.d.ts +6 -0
- package/dataform/hooks/useRequiredFieldManager.js +49 -0
- package/dataform/test.d.ts +57 -0
- package/dataform/test.js +247 -0
- package/dataform/utils/defaultParameters.d.ts +6 -0
- package/dataform/utils/defaultParameters.js +54 -0
- package/dataform/utils/index.d.ts +6 -24
- package/dataform/utils/index.js +164 -190
- package/dataform/utils/saveRecord.d.ts +27 -0
- package/dataform/utils/saveRecord.js +163 -0
- package/datagrid/DataGridProvider/DataResolver.js +38 -109
- package/datagrid/DataGridProvider/index.d.ts +6 -0
- package/datagrid/DataGridProvider/index.js +18 -8
- package/datagrid/DataGridProvider/transformViewColumns.js +10 -2
- package/datagrid/DataGridProvider/utils.js +8 -8
- package/datagrid/column-filter/constants.js +38 -3
- package/datagrid/column-filter/utils.js +7 -1
- package/datagrid/context.d.ts +6 -0
- package/datagrid/hooks/useChangeView.js +1 -1
- package/datagrid/hooks/useGridColumnFilter.js +4 -1
- package/datagrid/hooks/useGridDisabled.d.ts +1 -0
- package/datagrid/hooks/useGridDisabled.js +8 -0
- package/datagrid/hooks/useLoadMainGridPage.js +1 -1
- package/datagrid/hooks/useMainGridCommands.js +23 -9
- package/datagrid/hooks/useOpenRecord.js +2 -2
- package/datagrid/hooks/useSubGridCommands.js +23 -45
- package/defaults.d.ts +2 -0
- package/defaults.js +5 -0
- package/dialog/hooks/useCloseDialog.js +17 -15
- package/dialog/hooks/useOpenAlertDialog.js +8 -3
- package/dialog/hooks/useOpenConfirmDialog.js +10 -4
- package/dialog/hooks/useOpenDialog.js +7 -5
- package/dialog/hooks/useOpenErrorDialog.js +8 -3
- package/dialog/hooks/useOpenPromptDialog.js +10 -4
- package/form/FormValidationStringContext.d.ts +1 -0
- package/form/FormValidationStringContext.js +1 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +3 -0
- package/hooks/useDebouncedValue.js +0 -1
- package/hooks/useElementLayout.js +1 -1
- package/hooks/useIsMobile.js +0 -1
- package/hooks/useItemsWithKey.d.ts +7 -0
- package/hooks/useItemsWithKey.js +13 -0
- package/hooks/useStorageState.js +1 -2
- package/hooks/useSystemColorScheme.d.ts +1 -1
- package/hooks/useSystemColorScheme.js +0 -1
- package/insights/InsightsProvider.d.ts +8 -0
- package/insights/InsightsProvider.js +27 -0
- package/locale/LocaleProvider.d.ts +2 -1
- package/locale/LocaleProvider.js +3 -3
- package/locale/index.d.ts +1 -0
- package/locale/index.js +1 -0
- package/locale/useCurrencySymbol.d.ts +1 -0
- package/locale/useCurrencySymbol.js +12 -0
- package/locale/utils.js +4 -2
- package/metadata/MetadataProvider.d.ts +8 -4
- package/metadata/MetadataProvider.js +23 -17
- package/metadata/context.d.ts +3 -2
- package/metadata/hooks/index.d.ts +1 -1
- package/metadata/hooks/index.js +1 -1
- package/metadata/hooks/useAppExperience.d.ts +1 -0
- package/metadata/hooks/useAppExperience.js +8 -0
- package/metadata/hooks/useAppStore.d.ts +1 -1
- package/metadata/hooks/useAppStore.js +3 -3
- package/metadata/hooks/useExperienceView.js +2 -11
- package/metadata/hooks/useExperienceViewCommands.d.ts +1 -1
- package/metadata/hooks/useExperienceViewCommands.js +5 -14
- package/metadata/hooks/useExperienceViewLookup.js +2 -11
- package/metadata/hooks/useExperienceViewSubgridCommands.d.ts +1 -1
- package/metadata/hooks/useExperienceViewSubgridCommands.js +5 -14
- package/metadata/hooks/useMetadata.d.ts +11 -10
- package/metadata/hooks/useMetadata.js +4 -16
- package/metadata/hooks/useSchema.d.ts +1 -1
- package/metadata/hooks/useSchema.js +3 -0
- package/mutable/context.d.ts +3 -0
- package/mutable/context.js +8 -0
- package/mutable/utils.js +5 -12
- package/navigation/hooks/useOpenForm.js +4 -0
- package/package.json +6 -10
- package/providers/PageEntityFormProvider/index.d.ts +5 -1
- package/providers/PageEntityFormProvider/index.js +2 -2
- package/recordset/hooks/useRecordSetResult.js +4 -14
- package/route/RouteProvider.d.ts +2 -2
- package/route/RouteProvider.js +4 -1
- package/store/ClientAppStore.js +7 -20
- package/store/ComponentStore.d.ts +1 -1
- package/store/ComponentStore.js +6 -12
- package/store/EventManager.d.ts +2 -2
- package/store/EventManager.js +13 -29
- package/store/SchemaExperienceStore.js +179 -215
- package/store/index.d.ts +0 -1
- package/store/index.js +0 -1
- package/toast-notification/hooks/useCloseToastNotification.js +17 -15
- package/toast-notification/hooks/useOpenToastNotification.js +7 -5
- package/transport/InMemoryDataService/index.js +54 -77
- package/transport/RestDataService/index.d.ts +3 -3
- package/transport/RestDataService/index.js +68 -91
- package/transport/context.d.ts +2 -1
- package/transport/context.js +7 -1
- package/transport/hooks/index.d.ts +1 -0
- package/transport/hooks/index.js +1 -0
- package/transport/hooks/useFileService.d.ts +1 -0
- package/transport/hooks/useFileService.js +9 -0
- package/transport/hooks/useRetriveRecords.d.ts +33 -0
- package/transport/hooks/useRetriveRecords.js +110 -0
- package/utils/calculateColumnWidths.js +1 -1
- package/utils/color.d.ts +1 -0
- package/utils/color.js +14 -0
- package/utils/getAttributeFormattedValue.d.ts +4 -1
- package/utils/getAttributeFormattedValue.js +109 -54
- package/utils/phone.d.ts +13 -0
- package/utils/phone.js +33 -0
- package/appearance/context.d.ts +0 -7
- package/appearance/context.js +0 -5
- package/appearance/hooks/index.d.ts +0 -1
- package/appearance/hooks/useAppearanceContext.d.ts +0 -1
- package/appearance/hooks/useAppearanceContext.js +0 -12
- package/appearance/index.d.ts +0 -2
- package/appearance/index.js +0 -20
- package/builders/CommandBuilder.d.ts +0 -176
- package/builders/CommandBuilder.js +0 -567
- package/locale/types.d.ts +0 -2
- /package/{locale → board}/types.js +0 -0
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.InMemoryDataService = void 0;
|
|
13
4
|
class InMemoryDataService {
|
|
5
|
+
options;
|
|
14
6
|
// , IActionService, IReportService
|
|
15
7
|
constructor(options) {
|
|
16
8
|
this.options = options;
|
|
@@ -28,85 +20,70 @@ class InMemoryDataService {
|
|
|
28
20
|
}
|
|
29
21
|
return this.options.data[logicalName];
|
|
30
22
|
}
|
|
31
|
-
retriveRecord(logicalName, id) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return record[schema.idAttribute] === id;
|
|
37
|
-
});
|
|
38
|
-
if (!record) {
|
|
39
|
-
throw new Error(`Record with id ${id} not found`);
|
|
40
|
-
}
|
|
41
|
-
return record;
|
|
23
|
+
async retriveRecord(logicalName, id) {
|
|
24
|
+
const schema = this.getSchema(logicalName);
|
|
25
|
+
const records = this.getCollection(logicalName);
|
|
26
|
+
const record = records.find((record) => {
|
|
27
|
+
return record[schema.idAttribute] === id;
|
|
42
28
|
});
|
|
29
|
+
if (!record) {
|
|
30
|
+
throw new Error(`Record with id ${id} not found`);
|
|
31
|
+
}
|
|
32
|
+
return record;
|
|
43
33
|
}
|
|
44
|
-
retriveRecords(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
});
|
|
34
|
+
async retriveRecords({ logicalName, }) {
|
|
35
|
+
const records = this.getCollection(logicalName);
|
|
36
|
+
return {
|
|
37
|
+
logicalName,
|
|
38
|
+
records: records,
|
|
39
|
+
count: records.length,
|
|
40
|
+
};
|
|
53
41
|
}
|
|
54
|
-
createRecord(logicalName, data) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
async createRecord(logicalName, data) {
|
|
43
|
+
const schema = this.getSchema(logicalName);
|
|
44
|
+
const records = this.getCollection(logicalName);
|
|
45
|
+
const newId = this.options.idGenerator(logicalName, records);
|
|
46
|
+
const newRecord = {
|
|
47
|
+
...data,
|
|
48
|
+
[schema.idAttribute]: newId,
|
|
49
|
+
};
|
|
50
|
+
records.push(newRecord);
|
|
51
|
+
return { id: newId };
|
|
63
52
|
}
|
|
64
|
-
updateRecord(logicalName, id, data) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return record[schema.idAttribute] === id;
|
|
70
|
-
});
|
|
71
|
-
if (!record) {
|
|
72
|
-
throw new Error(`Record with id ${id} not found`);
|
|
73
|
-
}
|
|
74
|
-
Object.assign(record, data);
|
|
75
|
-
return { id };
|
|
53
|
+
async updateRecord(logicalName, id, data) {
|
|
54
|
+
const schema = this.getSchema(logicalName);
|
|
55
|
+
const records = this.getCollection(logicalName);
|
|
56
|
+
const record = records.find((record) => {
|
|
57
|
+
return record[schema.idAttribute] === id;
|
|
76
58
|
});
|
|
59
|
+
if (!record) {
|
|
60
|
+
throw new Error(`Record with id ${id} not found`);
|
|
61
|
+
}
|
|
62
|
+
Object.assign(record, data);
|
|
63
|
+
return { id };
|
|
77
64
|
}
|
|
78
|
-
deleteRecord(logicalName, id) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return record[schema.idAttribute] === id;
|
|
84
|
-
});
|
|
85
|
-
if (index === -1) {
|
|
86
|
-
throw new Error(`Record with id ${id} not found`);
|
|
87
|
-
}
|
|
88
|
-
records.splice(index, 1);
|
|
65
|
+
async deleteRecord(logicalName, id) {
|
|
66
|
+
const schema = this.getSchema(logicalName);
|
|
67
|
+
const records = this.getCollection(logicalName);
|
|
68
|
+
const index = records.findIndex((record) => {
|
|
69
|
+
return record[schema.idAttribute] === id;
|
|
89
70
|
});
|
|
71
|
+
if (index === -1) {
|
|
72
|
+
throw new Error(`Record with id ${id} not found`);
|
|
73
|
+
}
|
|
74
|
+
records.splice(index, 1);
|
|
90
75
|
}
|
|
91
|
-
executeAction() {
|
|
92
|
-
return
|
|
93
|
-
return {};
|
|
94
|
-
});
|
|
76
|
+
async executeAction() {
|
|
77
|
+
return {};
|
|
95
78
|
}
|
|
96
|
-
getReportData() {
|
|
97
|
-
return
|
|
98
|
-
return {};
|
|
99
|
-
});
|
|
79
|
+
async getReportData() {
|
|
80
|
+
return {};
|
|
100
81
|
}
|
|
101
|
-
retriveAggregate() {
|
|
102
|
-
return
|
|
103
|
-
return [];
|
|
104
|
-
});
|
|
82
|
+
async retriveAggregate() {
|
|
83
|
+
return [];
|
|
105
84
|
}
|
|
106
|
-
customAction() {
|
|
107
|
-
return
|
|
108
|
-
return {};
|
|
109
|
-
});
|
|
85
|
+
async customAction() {
|
|
86
|
+
return {};
|
|
110
87
|
}
|
|
111
88
|
}
|
|
112
89
|
exports.InMemoryDataService = InMemoryDataService;
|
|
@@ -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;
|
|
@@ -16,8 +16,8 @@ export declare class RestDataService implements IDataService {
|
|
|
16
16
|
[key in keyof T]?: string[];
|
|
17
17
|
}): Promise<Data<T>>;
|
|
18
18
|
retriveRecords<T = unknown>(params: RetriveRecordsFnOptions<T>): Promise<RetriveRecordsResult<T>>;
|
|
19
|
-
createRecord<T>(logicalName: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core
|
|
20
|
-
updateRecord<T>(logicalName: string, id: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core
|
|
19
|
+
createRecord<T>(logicalName: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core").Id>>;
|
|
20
|
+
updateRecord<T>(logicalName: string, id: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core").Id>>;
|
|
21
21
|
deleteRecord(logicalName: string, id: string): Promise<void>;
|
|
22
22
|
retriveAggregate<Q extends Record<string, AggregateAttribute> = Record<string, AggregateAttribute>>(query: AggregateQuery<Q>): Promise<InferredAggregateQueryResult<Q>[]>;
|
|
23
23
|
customAction<T = unknown>(_actionName: string, _payload: unknown): Promise<T>;
|
|
@@ -1,38 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.RestDataService = void 0;
|
|
4
|
+
exports.handleResponseError = handleResponseError;
|
|
13
5
|
const transport_1 = require("@headless-adminapp/core/transport");
|
|
6
|
+
async function handleResponseError(response) {
|
|
7
|
+
if (response.ok) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
11
|
+
const data = await response.json();
|
|
12
|
+
if (data.error) {
|
|
13
|
+
throw new transport_1.HttpError(response.status, data.error);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
throw new transport_1.HttpError(response.status, response.statusText);
|
|
17
|
+
}
|
|
14
18
|
class RestDataService {
|
|
19
|
+
options;
|
|
15
20
|
constructor(options) {
|
|
16
21
|
this.options = options;
|
|
17
|
-
this.headers = {};
|
|
18
|
-
}
|
|
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
22
|
}
|
|
23
|
+
headers = {};
|
|
34
24
|
getHeaders() {
|
|
35
|
-
return
|
|
25
|
+
return {
|
|
26
|
+
'content-type': 'application/json',
|
|
27
|
+
...this.headers,
|
|
28
|
+
};
|
|
36
29
|
}
|
|
37
30
|
setHeader(name, value) {
|
|
38
31
|
this.headers[name] = value;
|
|
@@ -40,85 +33,69 @@ class RestDataService {
|
|
|
40
33
|
removeHeader(name) {
|
|
41
34
|
delete this.headers[name];
|
|
42
35
|
}
|
|
43
|
-
execute(data) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
body: JSON.stringify(data),
|
|
49
|
-
});
|
|
50
|
-
yield this.handleResponseError(response);
|
|
51
|
-
return response.json();
|
|
36
|
+
async execute(data) {
|
|
37
|
+
const response = await fetch(this.options.endpoint, {
|
|
38
|
+
headers: this.getHeaders(),
|
|
39
|
+
method: 'POST',
|
|
40
|
+
body: JSON.stringify(data),
|
|
52
41
|
});
|
|
42
|
+
await handleResponseError(response);
|
|
43
|
+
return response.json();
|
|
53
44
|
}
|
|
54
|
-
retriveRecord(logicalName, id, columns, expand) {
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
});
|
|
45
|
+
async retriveRecord(logicalName, id, columns, expand) {
|
|
46
|
+
return this.execute({
|
|
47
|
+
type: 'retriveRecord',
|
|
48
|
+
payload: {
|
|
49
|
+
logicalName,
|
|
50
|
+
id,
|
|
51
|
+
columns,
|
|
52
|
+
expand,
|
|
53
|
+
},
|
|
65
54
|
});
|
|
66
55
|
}
|
|
67
|
-
retriveRecords(params) {
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
payload: params,
|
|
72
|
-
});
|
|
56
|
+
async retriveRecords(params) {
|
|
57
|
+
return this.execute({
|
|
58
|
+
type: 'retriveRecords',
|
|
59
|
+
payload: params,
|
|
73
60
|
});
|
|
74
61
|
}
|
|
75
|
-
createRecord(logicalName, data) {
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
});
|
|
62
|
+
async createRecord(logicalName, data) {
|
|
63
|
+
return this.execute({
|
|
64
|
+
type: 'createRecord',
|
|
65
|
+
payload: {
|
|
66
|
+
logicalName,
|
|
67
|
+
data,
|
|
68
|
+
},
|
|
84
69
|
});
|
|
85
70
|
}
|
|
86
|
-
updateRecord(logicalName, id, data) {
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
});
|
|
71
|
+
async updateRecord(logicalName, id, data) {
|
|
72
|
+
return this.execute({
|
|
73
|
+
type: 'updateRecord',
|
|
74
|
+
payload: {
|
|
75
|
+
logicalName,
|
|
76
|
+
id,
|
|
77
|
+
data,
|
|
78
|
+
},
|
|
96
79
|
});
|
|
97
80
|
}
|
|
98
|
-
deleteRecord(logicalName, id) {
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
},
|
|
106
|
-
});
|
|
81
|
+
async deleteRecord(logicalName, id) {
|
|
82
|
+
return this.execute({
|
|
83
|
+
type: 'deleteRecord',
|
|
84
|
+
payload: {
|
|
85
|
+
logicalName,
|
|
86
|
+
id,
|
|
87
|
+
},
|
|
107
88
|
});
|
|
108
89
|
}
|
|
109
|
-
retriveAggregate(query) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
payload: query,
|
|
114
|
-
});
|
|
115
|
-
return result;
|
|
90
|
+
async retriveAggregate(query) {
|
|
91
|
+
const result = await this.execute({
|
|
92
|
+
type: 'retriveAggregate',
|
|
93
|
+
payload: query,
|
|
116
94
|
});
|
|
95
|
+
return result;
|
|
117
96
|
}
|
|
118
|
-
customAction(_actionName, _payload) {
|
|
119
|
-
|
|
120
|
-
throw new Error('Custom action not implemented in RestDataService, to use custom actions, define a custom data service extending RestDataService');
|
|
121
|
-
});
|
|
97
|
+
async customAction(_actionName, _payload) {
|
|
98
|
+
throw new Error('Custom action not implemented in RestDataService, to use custom actions, define a custom data service extending RestDataService');
|
|
122
99
|
}
|
|
123
100
|
}
|
|
124
101
|
exports.RestDataService = RestDataService;
|
package/transport/context.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { IDataService } from '@headless-adminapp/core/transport';
|
|
1
|
+
import { IDataService, IFileService } from '@headless-adminapp/core/transport';
|
|
2
2
|
export declare const DataServiceContext: import("react").Context<IDataService | undefined>;
|
|
3
|
+
export declare const FileServiceContext: import("react").Context<IFileService | null>;
|
package/transport/context.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataServiceContext = void 0;
|
|
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
|
+
exports.FileServiceContext = (0, react_1.createContext)(null);
|
package/transport/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useFileService(): import("@headless-adminapp/core/transport").IFileService | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFileService = useFileService;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
function useFileService() {
|
|
7
|
+
const context = (0, react_1.useContext)(context_1.FileServiceContext);
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SortingState } from '@headless-adminapp/core/experience/view';
|
|
2
|
+
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
+
import { Filter } from '@headless-adminapp/core/transport';
|
|
4
|
+
import { QueryKey } from '@tanstack/react-query';
|
|
5
|
+
interface UseRetriveRecordProps<S extends SchemaAttributes = SchemaAttributes> {
|
|
6
|
+
schema: Schema<S>;
|
|
7
|
+
search: string;
|
|
8
|
+
filter: Filter | null;
|
|
9
|
+
sorting: SortingState<S>;
|
|
10
|
+
columns: string[];
|
|
11
|
+
expand?: Partial<Record<string, string[]>>;
|
|
12
|
+
maxRecords: number;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function useRetrieveRecordsKey<S extends SchemaAttributes = SchemaAttributes>({ schema, search, filter, sorting, columns, expand, maxRecords, }: UseRetriveRecordProps<S>): (string | number | string[] | Filter | Partial<Record<string, string[]>> | SortingState<S> | null | undefined)[];
|
|
16
|
+
export declare function useClearDataExceptFirstPage(queryKey: QueryKey): void;
|
|
17
|
+
export declare function useRetriveRecords<S extends SchemaAttributes = SchemaAttributes>(queryKey: QueryKey, { columns, expand, filter, maxRecords, schema, search, sorting, disabled, }: UseRetriveRecordProps): {
|
|
18
|
+
data: {
|
|
19
|
+
logicalName: string;
|
|
20
|
+
count: number;
|
|
21
|
+
records: import("@headless-adminapp/core/transport").Data<InferredSchemaType<S>>[];
|
|
22
|
+
} | null;
|
|
23
|
+
isFetching: boolean;
|
|
24
|
+
hasNextPage: boolean;
|
|
25
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<import("@tanstack/react-query").InfiniteData<{
|
|
26
|
+
params: {
|
|
27
|
+
pageIndex: number;
|
|
28
|
+
};
|
|
29
|
+
data: import("@headless-adminapp/core/transport").RetriveRecordsResult<InferredSchemaType<S>>;
|
|
30
|
+
}, unknown>, Error>>;
|
|
31
|
+
isFetchingNextPage: boolean;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRetrieveRecordsKey = useRetrieveRecordsKey;
|
|
4
|
+
exports.useClearDataExceptFirstPage = useClearDataExceptFirstPage;
|
|
5
|
+
exports.useRetriveRecords = useRetriveRecords;
|
|
6
|
+
const transport_1 = require("@headless-adminapp/app/transport");
|
|
7
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const ROWS_PER_PAGE = 100;
|
|
10
|
+
function useRetrieveRecordsKey({ schema, search, filter, sorting, columns, expand, maxRecords, }) {
|
|
11
|
+
const queryKey = (0, react_1.useMemo)(() => [
|
|
12
|
+
'data',
|
|
13
|
+
'retriveRecords',
|
|
14
|
+
schema.logicalName,
|
|
15
|
+
search,
|
|
16
|
+
filter,
|
|
17
|
+
sorting,
|
|
18
|
+
columns,
|
|
19
|
+
expand,
|
|
20
|
+
maxRecords,
|
|
21
|
+
], [schema.logicalName, search, filter, sorting, columns, expand, maxRecords]);
|
|
22
|
+
return queryKey;
|
|
23
|
+
}
|
|
24
|
+
function useClearDataExceptFirstPage(queryKey) {
|
|
25
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
return () => {
|
|
28
|
+
// Clear all pages except the first one when the component is unmounted
|
|
29
|
+
queryClient.setQueryData(queryKey, (oldData) => {
|
|
30
|
+
if (!oldData) {
|
|
31
|
+
return oldData;
|
|
32
|
+
}
|
|
33
|
+
if (!oldData.pageParams.length || !oldData.pages.length) {
|
|
34
|
+
return oldData;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
pageParams: [oldData.pageParams[0]],
|
|
38
|
+
pages: [oldData.pages[0]],
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}, [queryClient, queryKey]);
|
|
43
|
+
}
|
|
44
|
+
function useRetriveRecords(queryKey, { columns, expand, filter, maxRecords, schema, search, sorting, disabled, }) {
|
|
45
|
+
const dataService = (0, transport_1.useDataService)();
|
|
46
|
+
const { data, isFetching, hasNextPage, fetchNextPage, isFetchingNextPage } = (0, react_query_1.useInfiniteQuery)({
|
|
47
|
+
queryKey: queryKey,
|
|
48
|
+
queryFn: async (queryContext) => {
|
|
49
|
+
const params = queryContext.pageParam ?? {
|
|
50
|
+
pageIndex: 0,
|
|
51
|
+
};
|
|
52
|
+
const skip = params.pageIndex * ROWS_PER_PAGE;
|
|
53
|
+
const limit = Math.min(ROWS_PER_PAGE, Math.max(0, maxRecords - skip));
|
|
54
|
+
if (limit <= 0) {
|
|
55
|
+
return {
|
|
56
|
+
params: params,
|
|
57
|
+
data: {
|
|
58
|
+
logicalName: schema.logicalName,
|
|
59
|
+
count: 0,
|
|
60
|
+
records: [],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const result = await dataService.retriveRecords({
|
|
65
|
+
logicalName: schema.logicalName,
|
|
66
|
+
search,
|
|
67
|
+
columns: columns,
|
|
68
|
+
expand,
|
|
69
|
+
filter,
|
|
70
|
+
skip,
|
|
71
|
+
limit,
|
|
72
|
+
sort: sorting,
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
params: params,
|
|
76
|
+
data: result,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
getNextPageParam: (lastPage) => {
|
|
80
|
+
if (lastPage.data.count <
|
|
81
|
+
ROWS_PER_PAGE * (lastPage.params.pageIndex + 1)) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
pageIndex: lastPage.params.pageIndex + 1,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
initialPageParam: {
|
|
89
|
+
pageIndex: 0,
|
|
90
|
+
},
|
|
91
|
+
enabled: !disabled,
|
|
92
|
+
});
|
|
93
|
+
const finalData = (0, react_1.useMemo)(() => {
|
|
94
|
+
if (!data?.pages.length) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
logicalName: data?.pages?.[0].data.logicalName,
|
|
99
|
+
count: data?.pages?.[0].data.count ?? 0,
|
|
100
|
+
records: data?.pages.map((x) => x.data.records).flat() ?? [],
|
|
101
|
+
};
|
|
102
|
+
}, [data]);
|
|
103
|
+
return {
|
|
104
|
+
data: finalData,
|
|
105
|
+
isFetching,
|
|
106
|
+
hasNextPage,
|
|
107
|
+
fetchNextPage,
|
|
108
|
+
isFetchingNextPage,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -39,7 +39,7 @@ function extendValues(values, maxValues, available) {
|
|
|
39
39
|
if (maxValue && value >= maxValue)
|
|
40
40
|
continue;
|
|
41
41
|
const newValue = value + value * ratio;
|
|
42
|
-
values[i] = Math.min(newValue, maxValue
|
|
42
|
+
values[i] = Math.min(newValue, maxValue ?? newValue);
|
|
43
43
|
}
|
|
44
44
|
} while (true);
|
|
45
45
|
return values;
|
package/utils/color.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isColorDark(color: string): boolean;
|
package/utils/color.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isColorDark = isColorDark;
|
|
4
|
+
function isColorDark(color) {
|
|
5
|
+
if (color.startsWith('#')) {
|
|
6
|
+
color = color.substring(1);
|
|
7
|
+
}
|
|
8
|
+
const rgb = parseInt(color, 16);
|
|
9
|
+
const r = (rgb >> 16) & 0xff;
|
|
10
|
+
const g = (rgb >> 8) & 0xff;
|
|
11
|
+
const b = (rgb >> 0) & 0xff;
|
|
12
|
+
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
13
|
+
return luma < 128;
|
|
14
|
+
}
|
|
@@ -7,9 +7,12 @@ export declare function getAttributeFormattedValue<A extends Attribute = Attribu
|
|
|
7
7
|
maxCount?: number;
|
|
8
8
|
strings?: AttributeFormattedValueStringsSet;
|
|
9
9
|
dateFormat?: string;
|
|
10
|
+
timeFormat?: string;
|
|
10
11
|
locale?: string;
|
|
11
12
|
currency?: string;
|
|
12
13
|
currencySign?: 'accounting' | 'standard';
|
|
13
14
|
currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code';
|
|
14
|
-
|
|
15
|
+
timezone?: string;
|
|
16
|
+
region?: string;
|
|
17
|
+
}): string | null;
|
|
15
18
|
export {};
|