@admin-layout/gluestack-ui-mobile 12.2.4-alpha.81 → 12.2.4-alpha.86
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/CHANGELOG.md +8 -0
- package/lib/components/usePermissionAutoFetch.d.ts +4 -56
- package/lib/components/usePermissionAutoFetch.js +7 -19
- package/lib/components/usePermissionAutoFetch.js.map +1 -1
- package/lib/components/useSetting.d.ts +11 -6
- package/lib/components/useSetting.js +10 -75
- package/lib/components/useSetting.js.map +1 -1
- package/package.json +4 -4
- package/src/components/usePermissionAutoFetch.tsx +7 -22
- package/src/components/useSetting.tsx +22 -100
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [12.2.4-alpha.86](https://github.com/CDEBase/admin-layout/compare/v12.2.4-alpha.85...v12.2.4-alpha.86) (2026-07-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @admin-layout/gluestack-ui-mobile
|
|
9
|
+
|
|
10
|
+
## [12.2.4-alpha.85](https://github.com/CDEBase/admin-layout/compare/v12.2.4-alpha.84...v12.2.4-alpha.85) (2026-07-01)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @admin-layout/gluestack-ui-mobile
|
|
13
|
+
|
|
6
14
|
## [12.2.4-alpha.81](https://github.com/CDEBase/admin-layout/compare/v12.2.4-alpha.80...v12.2.4-alpha.81) (2026-06-29)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @admin-layout/gluestack-ui-mobile
|
|
@@ -2,62 +2,10 @@ interface userPermissionAutoFetchProps {
|
|
|
2
2
|
configKey?: string;
|
|
3
3
|
}
|
|
4
4
|
export declare const usePermissionAutoFetch: (options?: userPermissionAutoFetchProps) => {
|
|
5
|
+
permissions: any;
|
|
6
|
+
data: {
|
|
7
|
+
resolveConfiguration: any;
|
|
8
|
+
};
|
|
5
9
|
loading: boolean;
|
|
6
|
-
preferencesInput?: import("common").IPreferencesInput;
|
|
7
|
-
updateConfiguration?: ({ updateKey, value, updateOverrides, target, }: {
|
|
8
|
-
updateKey?: string;
|
|
9
|
-
value: string | boolean | number;
|
|
10
|
-
updateOverrides?: import("common").IConfigurationOverridesInput;
|
|
11
|
-
target?: import("common").ConfigurationTarget;
|
|
12
|
-
}) => Promise<import("graphql").ExecutionResult<import("common").IUpdateConfigurationMutation>>;
|
|
13
|
-
client: import("@apollo/client").ApolloClient<any>;
|
|
14
|
-
observable: import("@apollo/client").ObservableQuery<import("common").IResolveConfigurationQuery, import("common").Exact<{
|
|
15
|
-
input: import("common").IPreferencesInputInput;
|
|
16
|
-
key?: import("common").InputMaybe<import("common").Scalars["String"]["input"]>;
|
|
17
|
-
overrides?: import("common").InputMaybe<import("common").IConfigurationOverridesInput>;
|
|
18
|
-
}>>;
|
|
19
|
-
data: import("common").IResolveConfigurationQuery;
|
|
20
|
-
previousData?: import("common").IResolveConfigurationQuery;
|
|
21
|
-
error?: import("@apollo/client").ApolloError;
|
|
22
|
-
errors?: ReadonlyArray<import("graphql").GraphQLFormattedError>;
|
|
23
|
-
networkStatus: import("@apollo/client").NetworkStatus;
|
|
24
|
-
called: boolean;
|
|
25
|
-
startPolling: (pollInterval: number) => void;
|
|
26
|
-
stopPolling: () => void;
|
|
27
|
-
subscribeToMore: import("@apollo/client").SubscribeToMoreFunction<import("common").IResolveConfigurationQuery, import("common").Exact<{
|
|
28
|
-
input: import("common").IPreferencesInputInput;
|
|
29
|
-
key?: import("common").InputMaybe<import("common").Scalars["String"]["input"]>;
|
|
30
|
-
overrides?: import("common").InputMaybe<import("common").IConfigurationOverridesInput>;
|
|
31
|
-
}>>;
|
|
32
|
-
updateQuery: (mapFn: import("@apollo/client").UpdateQueryMapFn<import("common").IResolveConfigurationQuery, import("common").Exact<{
|
|
33
|
-
input: import("common").IPreferencesInputInput;
|
|
34
|
-
key?: import("common").InputMaybe<import("common").Scalars["String"]["input"]>;
|
|
35
|
-
overrides?: import("common").InputMaybe<import("common").IConfigurationOverridesInput>;
|
|
36
|
-
}>>) => void;
|
|
37
|
-
refetch: (variables?: Partial<import("common").Exact<{
|
|
38
|
-
input: import("common").IPreferencesInputInput;
|
|
39
|
-
key?: import("common").InputMaybe<import("common").Scalars["String"]["input"]>;
|
|
40
|
-
overrides?: import("common").InputMaybe<import("common").IConfigurationOverridesInput>;
|
|
41
|
-
}>>) => Promise<import("@apollo/client").ApolloQueryResult<import("common").IResolveConfigurationQuery>>;
|
|
42
|
-
reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<import("common").Exact<{
|
|
43
|
-
input: import("common").IPreferencesInputInput;
|
|
44
|
-
key?: import("common").InputMaybe<import("common").Scalars["String"]["input"]>;
|
|
45
|
-
overrides?: import("common").InputMaybe<import("common").IConfigurationOverridesInput>;
|
|
46
|
-
}>, import("common").IResolveConfigurationQuery>>, newNetworkStatus?: import("@apollo/client").NetworkStatus) => Promise<import("@apollo/client").ApolloQueryResult<import("common").IResolveConfigurationQuery>>;
|
|
47
|
-
variables: import("common").Exact<{
|
|
48
|
-
input: import("common").IPreferencesInputInput;
|
|
49
|
-
key?: import("common").InputMaybe<import("common").Scalars["String"]["input"]>;
|
|
50
|
-
overrides?: import("common").InputMaybe<import("common").IConfigurationOverridesInput>;
|
|
51
|
-
}>;
|
|
52
|
-
fetchMore: <TFetchData = import("common").IResolveConfigurationQuery, TFetchVars extends import("@apollo/client").OperationVariables = import("common").Exact<{
|
|
53
|
-
input: import("common").IPreferencesInputInput;
|
|
54
|
-
key?: import("common").InputMaybe<import("common").Scalars["String"]["input"]>;
|
|
55
|
-
overrides?: import("common").InputMaybe<import("common").IConfigurationOverridesInput>;
|
|
56
|
-
}>>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & {
|
|
57
|
-
updateQuery?: (previousQueryResult: import("common").IResolveConfigurationQuery, options: {
|
|
58
|
-
fetchMoreResult: import("@apollo/client").Unmasked<TFetchData>;
|
|
59
|
-
variables: TFetchVars;
|
|
60
|
-
}) => import("common").IResolveConfigurationQuery;
|
|
61
|
-
}) => Promise<import("@apollo/client").ApolloQueryResult<TFetchData>>;
|
|
62
10
|
};
|
|
63
11
|
export {};
|
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { generateUserUri } from '@adminide-stack/core';
|
|
3
|
-
import { useGetContextDataQuery } from 'common/lib/generated/generated.js';
|
|
4
|
-
import { useSetting } from './useSetting';
|
|
1
|
+
import { usePermissionAutoFetch as usePlatformPermissionAutoFetch } from '@adminide-stack/platform-client';
|
|
5
2
|
export const usePermissionAutoFetch = (options) => {
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
resource: resource,
|
|
13
|
-
},
|
|
14
|
-
options: {
|
|
15
|
-
forceExist: false,
|
|
16
|
-
authority: ResourceAuthority.Defaultpermissions,
|
|
17
|
-
fragment: ConfigFragmentName.Roles,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
return { ...remaining, loading: loading || settingLoading };
|
|
3
|
+
const { permissions, loading } = usePlatformPermissionAutoFetch(options);
|
|
4
|
+
return {
|
|
5
|
+
permissions,
|
|
6
|
+
data: permissions === undefined ? undefined : { resolveConfiguration: permissions },
|
|
7
|
+
loading,
|
|
8
|
+
};
|
|
21
9
|
};
|
|
22
10
|
// import React from 'react';
|
|
23
11
|
// import { ResourceAuthority, ConfigFragmentName } from '@adminide-stack/core';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePermissionAutoFetch.js","sourceRoot":"","sources":["../../src/components/usePermissionAutoFetch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"usePermissionAutoFetch.js","sourceRoot":"","sources":["../../src/components/usePermissionAutoFetch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,IAAI,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAK3G,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAsC,EAAE,EAAE;IAC7E,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC;IAEzE,OAAO;QACH,WAAW;QACX,IAAI,EAAE,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,WAAW,EAAE;QACnF,OAAO;KACV,CAAC;AACN,CAAC,CAAC;AAEF,6BAA6B;AAC7B,gFAAgF;AAChF,4EAA4E;AAC5E,mFAAmF;AACnF,6CAA6C;AAC7C,8DAA8D;AAC9D,6CAA6C;AAE7C,2CAA2C;AAC3C,0BAA0B;AAC1B,IAAI;AACJ,sFAAsF;AACtF,+DAA+D;AAC/D,6DAA6D;AAC7D,6EAA6E;AAC7E,mGAAmG;AACnG,0DAA0D;AAC1D,0EAA0E;AAC1E,8BAA8B;AAC9B,yEAAyE;AACzE,mFAAmF;AACnF,qCAAqC;AACrC,mCAAmC;AACnC,gBAAgB;AAChB,YAAY;AACZ,yBAAyB;AACzB,mFAAmF;AACnF,iCAAiC;AACjC,YAAY;AACZ,kDAAkD;AAElD,qEAAqE;AACrE,+CAA+C;AAC/C,uBAAuB;AACvB,qDAAqD;AACrD,aAAa;AACb,qBAAqB;AACrB,iCAAiC;AACjC,+DAA+D;AAC/D,kDAAkD;AAClD,aAAa;AACb,UAAU;AACV,mEAAmE;AACnE,KAAK"}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IConfigurationsFlattenedKeys, IPreferencesInput, IPreferencesOpenOptionsInput, IConfigurationOverridesInput } from 'common';
|
|
2
2
|
import { ConfigurationTarget } from 'common';
|
|
3
|
-
import { QueryResult } from '@apollo/client/react';
|
|
4
|
-
import { ExecutionResult } from 'graphql';
|
|
5
3
|
export interface ISettingsVariable {
|
|
6
4
|
overrides?: IConfigurationOverridesInput;
|
|
7
|
-
configKey:
|
|
5
|
+
configKey: IConfigurationsFlattenedKeys;
|
|
8
6
|
options?: IPreferencesOpenOptionsInput;
|
|
9
7
|
skip?: boolean;
|
|
10
8
|
}
|
|
11
|
-
interface IResponse
|
|
9
|
+
interface IResponse {
|
|
10
|
+
data?: {
|
|
11
|
+
resolveConfiguration?: unknown;
|
|
12
|
+
};
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error?: unknown;
|
|
12
15
|
preferencesInput?: IPreferencesInput;
|
|
13
16
|
updateConfiguration?: ({ updateKey, value, updateOverrides, target, }: {
|
|
14
17
|
updateKey?: string;
|
|
15
18
|
value: string | boolean | number;
|
|
16
19
|
updateOverrides?: IConfigurationOverridesInput;
|
|
17
20
|
target?: ConfigurationTarget;
|
|
18
|
-
}) => Promise<
|
|
21
|
+
}) => Promise<unknown>;
|
|
22
|
+
refetch?: Function;
|
|
23
|
+
[key: string]: unknown;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Provides configuration for Organization and OrganizationResources. By default, it provides Organization configuration.
|
|
@@ -1,87 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { omitBy, isNil } from 'lodash-es';
|
|
3
|
-
import { useResolveConfigurationQuery, useOpenPreferencesSettingsQuery, useUpdateConfigurationMutation, } from 'common/lib/generated/generated.js';
|
|
1
|
+
import { useSetting as usePlatformSetting } from '@adminide-stack/platform-client';
|
|
4
2
|
/**
|
|
5
3
|
* Provides configuration for Organization and OrganizationResources. By default, it provides Organization configuration.
|
|
6
4
|
* If you need `resource` level configuration then, you need to provide resource URI in `overrides`.
|
|
7
5
|
* @param baseOptions
|
|
8
6
|
*/
|
|
9
7
|
export const useSetting = (settingsVariable) => {
|
|
10
|
-
const {
|
|
11
|
-
const targetResource = overrides?.resource ?? null;
|
|
12
|
-
let prefLoaded = false;
|
|
13
|
-
const { data: prefData, error: prefError, loading: perfLoading, refetch: refetchPrefData, } = useOpenPreferencesSettingsQuery({
|
|
14
|
-
variables: { resource: targetResource, options },
|
|
15
|
-
fetchPolicy: 'cache-first', // to make `{always: true}` to work
|
|
16
|
-
skip: prefLoaded,
|
|
17
|
-
});
|
|
18
|
-
React.useEffect(() => {
|
|
19
|
-
refetchPrefData({ resource: targetResource, options });
|
|
20
|
-
}, [targetResource]);
|
|
21
|
-
prefLoaded = perfLoading || skip;
|
|
22
|
-
const [updateConfigurationMutation] = useUpdateConfigurationMutation();
|
|
23
|
-
const modifiedOverrides = {
|
|
24
|
-
...overrides,
|
|
25
|
-
resource: targetResource ? prefData?.openPreferencesSettings?.editableSettingsInput ?? null : null,
|
|
26
|
-
};
|
|
27
|
-
const defaultOverrides = omitBy(modifiedOverrides, isNil);
|
|
28
|
-
let { data: settingsData, error: settingError, loading: settingLoading, ...remaining } = useResolveConfigurationQuery({
|
|
29
|
-
variables: {
|
|
30
|
-
input: prefData?.openPreferencesSettings ?? null,
|
|
31
|
-
key: configKey,
|
|
32
|
-
overrides: defaultOverrides,
|
|
33
|
-
},
|
|
34
|
-
fetchPolicy: 'cache-and-network', // to make `{always: true}` to work
|
|
35
|
-
skip: prefLoaded || !!prefError || !prefData?.openPreferencesSettings?.editableSettingsInput,
|
|
36
|
-
});
|
|
37
|
-
React.useEffect(() => {
|
|
38
|
-
remaining?.refetch({
|
|
39
|
-
input: prefData?.openPreferencesSettings ?? null,
|
|
40
|
-
key: configKey,
|
|
41
|
-
overrides: defaultOverrides,
|
|
42
|
-
});
|
|
43
|
-
}, [prefData]);
|
|
44
|
-
let loading = true;
|
|
45
|
-
if (!settingLoading && !prefLoaded) {
|
|
46
|
-
loading = false;
|
|
47
|
-
}
|
|
48
|
-
const error = settingError || prefError;
|
|
49
|
-
if (error) {
|
|
50
|
-
return {
|
|
51
|
-
error,
|
|
52
|
-
data: undefined,
|
|
53
|
-
loading: false,
|
|
54
|
-
...remaining,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (loading) {
|
|
58
|
-
return {
|
|
59
|
-
error,
|
|
60
|
-
data: undefined,
|
|
61
|
-
loading,
|
|
62
|
-
...remaining,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const updateConfiguration = ({ value, updateKey, updateOverrides, target }) => {
|
|
66
|
-
return updateConfigurationMutation({
|
|
67
|
-
variables: {
|
|
68
|
-
key: updateKey || configKey,
|
|
69
|
-
value,
|
|
70
|
-
target,
|
|
71
|
-
overrides: updateOverrides || defaultOverrides,
|
|
72
|
-
input: prefData?.openPreferencesSettings,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
};
|
|
8
|
+
const { data, updateConfiguration, ...remaining } = usePlatformSetting(settingsVariable);
|
|
76
9
|
return {
|
|
77
|
-
data:
|
|
78
|
-
loading,
|
|
79
|
-
error,
|
|
10
|
+
data: data === undefined ? undefined : { resolveConfiguration: data },
|
|
80
11
|
...remaining,
|
|
81
|
-
|
|
82
|
-
|
|
12
|
+
updateConfiguration: ({ value, updateKey, updateOverrides, target }) => {
|
|
13
|
+
return updateConfiguration?.({
|
|
14
|
+
value,
|
|
15
|
+
updateKey,
|
|
16
|
+
updateOverrides,
|
|
17
|
+
target,
|
|
18
|
+
});
|
|
83
19
|
},
|
|
84
|
-
updateConfiguration,
|
|
85
20
|
};
|
|
86
21
|
};
|
|
87
22
|
//# sourceMappingURL=useSetting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSetting.js","sourceRoot":"","sources":["../../src/components/useSetting.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSetting.js","sourceRoot":"","sources":["../../src/components/useSetting.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AA+BnF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,gBAAmC,EAAa,EAAE;IACzE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,GAAG,SAAS,EAAE,GAAG,kBAAkB,CAAC,gBAAuB,CAAC,CAAC;IAEhG,OAAO;QACH,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,IAAI,EAAE;QACrE,GAAG,SAAS;QACZ,mBAAmB,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,EAAE,EAAE;YACnE,OAAO,mBAAmB,EAAE,CAAC;gBACzB,KAAK;gBACL,SAAS;gBACT,eAAe;gBACf,MAAM;aACT,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;AACN,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@admin-layout/gluestack-ui-mobile",
|
|
3
|
-
"version": "12.2.4-alpha.
|
|
3
|
+
"version": "12.2.4-alpha.86",
|
|
4
4
|
"description": "Glustack-ui for mobile component layout",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"watch": "npm run build:lib:watch"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@admin-layout/client": "12.2.4-alpha.
|
|
26
|
+
"@admin-layout/client": "12.2.4-alpha.85",
|
|
27
27
|
"@gluestack-style/react": "^1.0.53",
|
|
28
28
|
"@gluestack-ui/config": "^1.1.18",
|
|
29
29
|
"@gluestack-ui/nativewind-utils": "^1.0.26",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/react-window": "^1.8.8",
|
|
39
|
-
"common": "12.2.4-alpha.
|
|
39
|
+
"common": "12.2.4-alpha.85"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@common-stack/remix-router-redux": "^6.0.2-alpha.2",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "353b0d63c41114c730dd0d71276341dcff4f0c7c",
|
|
51
51
|
"typescript": {
|
|
52
52
|
"definition": "lib/index.d.ts"
|
|
53
53
|
}
|
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { generateUserUri } from '@adminide-stack/core';
|
|
3
|
-
import { useGetContextDataQuery } from 'common/lib/generated/generated.js';
|
|
4
|
-
import { useSetting } from './useSetting';
|
|
5
|
-
import type { URI } from '@vscode-alt/monaco-editor/esm/vs/base/common/uri.js';
|
|
1
|
+
import { usePermissionAutoFetch as usePlatformPermissionAutoFetch } from '@adminide-stack/platform-client';
|
|
6
2
|
|
|
7
3
|
interface userPermissionAutoFetchProps {
|
|
8
4
|
configKey?: string;
|
|
9
5
|
}
|
|
10
6
|
export const usePermissionAutoFetch = (options?: userPermissionAutoFetchProps) => {
|
|
11
|
-
const {
|
|
12
|
-
const { orgResource, userId } = (data?.getContextData as IContext) || {};
|
|
7
|
+
const { permissions, loading } = usePlatformPermissionAutoFetch(options);
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
resource: resource as unknown as URI,
|
|
20
|
-
},
|
|
21
|
-
options: {
|
|
22
|
-
forceExist: false,
|
|
23
|
-
authority: ResourceAuthority.Defaultpermissions,
|
|
24
|
-
fragment: ConfigFragmentName.Roles,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return { ...remaining, loading: loading || settingLoading };
|
|
9
|
+
return {
|
|
10
|
+
permissions,
|
|
11
|
+
data: permissions === undefined ? undefined : { resolveConfiguration: permissions },
|
|
12
|
+
loading,
|
|
13
|
+
};
|
|
29
14
|
};
|
|
30
15
|
|
|
31
16
|
// import React from 'react';
|
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
IResolveConfigurationQueryVariables,
|
|
2
|
+
IConfigurationsFlattenedKeys,
|
|
5
3
|
IPreferencesInput,
|
|
6
4
|
IPreferencesOpenOptionsInput,
|
|
7
|
-
IUpdateConfigurationMutation,
|
|
8
5
|
IConfigurationOverridesInput,
|
|
9
6
|
} from 'common';
|
|
10
7
|
import { ConfigurationTarget } from 'common';
|
|
11
|
-
import {
|
|
12
|
-
import { omitBy, isNil } from 'lodash-es';
|
|
13
|
-
import { ExecutionResult } from 'graphql';
|
|
14
|
-
import {
|
|
15
|
-
useResolveConfigurationQuery,
|
|
16
|
-
useOpenPreferencesSettingsQuery,
|
|
17
|
-
useUpdateConfigurationMutation,
|
|
18
|
-
} from 'common/lib/generated/generated.js';
|
|
8
|
+
import { useSetting as usePlatformSetting } from '@adminide-stack/platform-client';
|
|
19
9
|
|
|
20
10
|
export interface ISettingsVariable {
|
|
21
11
|
overrides?: IConfigurationOverridesInput;
|
|
22
|
-
configKey:
|
|
12
|
+
configKey: IConfigurationsFlattenedKeys;
|
|
23
13
|
options?: IPreferencesOpenOptionsInput;
|
|
24
14
|
skip?: boolean;
|
|
25
15
|
}
|
|
26
16
|
|
|
27
|
-
interface IResponse
|
|
17
|
+
interface IResponse {
|
|
18
|
+
data?: {
|
|
19
|
+
resolveConfiguration?: unknown;
|
|
20
|
+
};
|
|
21
|
+
loading: boolean;
|
|
22
|
+
error?: unknown;
|
|
28
23
|
preferencesInput?: IPreferencesInput;
|
|
29
24
|
updateConfiguration?: ({
|
|
30
25
|
updateKey,
|
|
@@ -36,7 +31,9 @@ interface IResponse extends QueryResult<IResolveConfigurationQuery, IResolveConf
|
|
|
36
31
|
value: string | boolean | number;
|
|
37
32
|
updateOverrides?: IConfigurationOverridesInput;
|
|
38
33
|
target?: ConfigurationTarget;
|
|
39
|
-
}) => Promise<
|
|
34
|
+
}) => Promise<unknown>;
|
|
35
|
+
refetch?: Function;
|
|
36
|
+
[key: string]: unknown;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
/**
|
|
@@ -45,93 +42,18 @@ interface IResponse extends QueryResult<IResolveConfigurationQuery, IResolveConf
|
|
|
45
42
|
* @param baseOptions
|
|
46
43
|
*/
|
|
47
44
|
export const useSetting = (settingsVariable: ISettingsVariable): IResponse => {
|
|
48
|
-
const {
|
|
49
|
-
const targetResource = overrides?.resource ?? null;
|
|
50
|
-
let prefLoaded = false;
|
|
51
|
-
const {
|
|
52
|
-
data: prefData,
|
|
53
|
-
error: prefError,
|
|
54
|
-
loading: perfLoading,
|
|
55
|
-
refetch: refetchPrefData,
|
|
56
|
-
} = useOpenPreferencesSettingsQuery({
|
|
57
|
-
variables: { resource: targetResource, options },
|
|
58
|
-
fetchPolicy: 'cache-first', // to make `{always: true}` to work
|
|
59
|
-
skip: prefLoaded,
|
|
60
|
-
});
|
|
61
|
-
React.useEffect(() => {
|
|
62
|
-
refetchPrefData({ resource: targetResource, options });
|
|
63
|
-
}, [targetResource]);
|
|
64
|
-
prefLoaded = perfLoading || skip;
|
|
65
|
-
const [updateConfigurationMutation] = useUpdateConfigurationMutation();
|
|
66
|
-
const modifiedOverrides = {
|
|
67
|
-
...overrides,
|
|
68
|
-
resource: targetResource ? prefData?.openPreferencesSettings?.editableSettingsInput ?? null : null,
|
|
69
|
-
};
|
|
70
|
-
const defaultOverrides = omitBy(modifiedOverrides, isNil);
|
|
71
|
-
let {
|
|
72
|
-
data: settingsData,
|
|
73
|
-
error: settingError,
|
|
74
|
-
loading: settingLoading,
|
|
75
|
-
...remaining
|
|
76
|
-
} = useResolveConfigurationQuery({
|
|
77
|
-
variables: {
|
|
78
|
-
input: prefData?.openPreferencesSettings ?? null,
|
|
79
|
-
key: configKey,
|
|
80
|
-
overrides: defaultOverrides,
|
|
81
|
-
},
|
|
82
|
-
fetchPolicy: 'cache-and-network', // to make `{always: true}` to work
|
|
83
|
-
skip: prefLoaded || !!prefError || !prefData?.openPreferencesSettings?.editableSettingsInput,
|
|
84
|
-
});
|
|
85
|
-
React.useEffect(() => {
|
|
86
|
-
remaining?.refetch({
|
|
87
|
-
input: prefData?.openPreferencesSettings ?? null,
|
|
88
|
-
key: configKey,
|
|
89
|
-
overrides: defaultOverrides,
|
|
90
|
-
});
|
|
91
|
-
}, [prefData]);
|
|
92
|
-
|
|
93
|
-
let loading = true;
|
|
94
|
-
if (!settingLoading && !prefLoaded) {
|
|
95
|
-
loading = false;
|
|
96
|
-
}
|
|
97
|
-
const error = settingError || prefError;
|
|
98
|
-
if (error) {
|
|
99
|
-
return {
|
|
100
|
-
error,
|
|
101
|
-
data: undefined,
|
|
102
|
-
loading: false,
|
|
103
|
-
...remaining,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (loading) {
|
|
107
|
-
return {
|
|
108
|
-
error,
|
|
109
|
-
data: undefined,
|
|
110
|
-
loading,
|
|
111
|
-
...remaining,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const updateConfiguration = ({ value, updateKey, updateOverrides, target }) => {
|
|
116
|
-
return updateConfigurationMutation({
|
|
117
|
-
variables: {
|
|
118
|
-
key: updateKey || configKey,
|
|
119
|
-
value,
|
|
120
|
-
target,
|
|
121
|
-
overrides: updateOverrides || defaultOverrides,
|
|
122
|
-
input: prefData?.openPreferencesSettings,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
};
|
|
45
|
+
const { data, updateConfiguration, ...remaining } = usePlatformSetting(settingsVariable as any);
|
|
126
46
|
|
|
127
47
|
return {
|
|
128
|
-
data:
|
|
129
|
-
loading,
|
|
130
|
-
error,
|
|
48
|
+
data: data === undefined ? undefined : { resolveConfiguration: data },
|
|
131
49
|
...remaining,
|
|
132
|
-
|
|
133
|
-
|
|
50
|
+
updateConfiguration: ({ value, updateKey, updateOverrides, target }) => {
|
|
51
|
+
return updateConfiguration?.({
|
|
52
|
+
value,
|
|
53
|
+
updateKey,
|
|
54
|
+
updateOverrides,
|
|
55
|
+
target,
|
|
56
|
+
});
|
|
134
57
|
},
|
|
135
|
-
|
|
136
|
-
} as any;
|
|
58
|
+
};
|
|
137
59
|
};
|