@finos/legend-application-query 8.1.2 → 9.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/lib/application/LegendQuery.d.ts.map +1 -1
- package/lib/application/LegendQuery.js +7 -9
- package/lib/application/LegendQuery.js.map +1 -1
- package/lib/application/LegendQueryApplicationConfig.d.ts +4 -0
- package/lib/application/LegendQueryApplicationConfig.d.ts.map +1 -1
- package/lib/application/LegendQueryApplicationConfig.js +4 -0
- package/lib/application/LegendQueryApplicationConfig.js.map +1 -1
- package/lib/components/{QuerySetupStoreProvider.d.ts → CloneQueryServiceSetup.d.ts} +2 -7
- package/lib/components/CloneQueryServiceSetup.d.ts.map +1 -0
- package/lib/components/CloneQueryServiceSetup.js +137 -0
- package/lib/components/CloneQueryServiceSetup.js.map +1 -0
- package/lib/components/Core_LegendQueryApplicationPlugin.d.ts +24 -0
- package/lib/components/Core_LegendQueryApplicationPlugin.d.ts.map +1 -0
- package/lib/components/Core_LegendQueryApplicationPlugin.js +144 -0
- package/lib/components/Core_LegendQueryApplicationPlugin.js.map +1 -0
- package/lib/components/CreateMappingQuerySetup.d.ts +18 -0
- package/lib/components/CreateMappingQuerySetup.d.ts.map +1 -0
- package/lib/components/CreateMappingQuerySetup.js +160 -0
- package/lib/components/CreateMappingQuerySetup.js.map +1 -0
- package/lib/components/EditExistingQuerySetup.d.ts +18 -0
- package/lib/components/EditExistingQuerySetup.d.ts.map +1 -0
- package/lib/components/EditExistingQuerySetup.js +107 -0
- package/lib/components/EditExistingQuerySetup.js.map +1 -0
- package/lib/components/LegendQueryApplication.d.ts.map +1 -1
- package/lib/components/LegendQueryApplication.js +4 -2
- package/lib/components/LegendQueryApplication.js.map +1 -1
- package/lib/components/LoadProjectServiceQuerySetup.d.ts +18 -0
- package/lib/components/LoadProjectServiceQuerySetup.d.ts.map +1 -0
- package/lib/components/LoadProjectServiceQuerySetup.js +63 -0
- package/lib/components/LoadProjectServiceQuerySetup.js.map +1 -0
- package/lib/components/QueryEditor.d.ts.map +1 -1
- package/lib/components/QueryEditor.js +31 -33
- package/lib/components/QueryEditor.js.map +1 -1
- package/lib/components/QueryProductionizerSetup.d.ts +18 -0
- package/lib/components/QueryProductionizerSetup.d.ts.map +1 -0
- package/lib/components/QueryProductionizerSetup.js +85 -0
- package/lib/components/QueryProductionizerSetup.js.map +1 -0
- package/lib/components/QuerySetup.d.ts +20 -5
- package/lib/components/QuerySetup.d.ts.map +1 -1
- package/lib/components/QuerySetup.js +69 -473
- package/lib/components/QuerySetup.js.map +1 -1
- package/lib/components/UpdateExistingServiceQuerySetup.d.ts +18 -0
- package/lib/components/UpdateExistingServiceQuerySetup.d.ts.map +1 -0
- package/lib/components/UpdateExistingServiceQuerySetup.js +69 -0
- package/lib/components/UpdateExistingServiceQuerySetup.js.map +1 -0
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/package.json +5 -8
- package/lib/stores/CloneServiceQuerySetupStore.d.ts +41 -0
- package/lib/stores/CloneServiceQuerySetupStore.d.ts.map +1 -0
- package/lib/stores/CloneServiceQuerySetupStore.js +98 -0
- package/lib/stores/CloneServiceQuerySetupStore.js.map +1 -0
- package/lib/stores/CreateMappingQuerySetupStore.d.ts +40 -0
- package/lib/stores/CreateMappingQuerySetupStore.d.ts.map +1 -0
- package/lib/stores/CreateMappingQuerySetupStore.js +97 -0
- package/lib/stores/CreateMappingQuerySetupStore.js.map +1 -0
- package/lib/stores/EditExistingQuerySetupStore.d.ts +33 -0
- package/lib/stores/EditExistingQuerySetupStore.d.ts.map +1 -0
- package/lib/stores/EditExistingQuerySetupStore.js +85 -0
- package/lib/stores/EditExistingQuerySetupStore.js.map +1 -0
- package/lib/stores/LegendQueryApplicationPlugin.d.ts +21 -16
- package/lib/stores/LegendQueryApplicationPlugin.d.ts.map +1 -1
- package/lib/stores/LegendQueryApplicationPlugin.js +4 -0
- package/lib/stores/LegendQueryApplicationPlugin.js.map +1 -1
- package/lib/stores/LegendQueryRouter.d.ts +28 -1
- package/lib/stores/LegendQueryRouter.d.ts.map +1 -1
- package/lib/stores/LegendQueryRouter.js +33 -3
- package/lib/stores/LegendQueryRouter.js.map +1 -1
- package/lib/stores/LoadProjectServiceQuerySetupStore.d.ts +27 -0
- package/lib/stores/LoadProjectServiceQuerySetupStore.d.ts.map +1 -0
- package/lib/stores/LoadProjectServiceQuerySetupStore.js +61 -0
- package/lib/stores/LoadProjectServiceQuerySetupStore.js.map +1 -0
- package/lib/stores/QueryEditorStore.d.ts +6 -2
- package/lib/stores/QueryEditorStore.d.ts.map +1 -1
- package/lib/stores/QueryEditorStore.js +35 -17
- package/lib/stores/QueryEditorStore.js.map +1 -1
- package/lib/stores/QueryEditorStoreTestUtils.d.ts.map +1 -1
- package/lib/stores/QueryEditorStoreTestUtils.js +3 -0
- package/lib/stores/QueryEditorStoreTestUtils.js.map +1 -1
- package/lib/stores/QueryProductionizerSetupStore.d.ts +32 -0
- package/lib/stores/QueryProductionizerSetupStore.d.ts.map +1 -0
- package/lib/stores/QueryProductionizerSetupStore.js +101 -0
- package/lib/stores/QueryProductionizerSetupStore.js.map +1 -0
- package/lib/stores/QuerySetupStore.d.ts +22 -85
- package/lib/stores/QuerySetupStore.d.ts.map +1 -1
- package/lib/stores/QuerySetupStore.js +78 -408
- package/lib/stores/QuerySetupStore.js.map +1 -1
- package/lib/stores/UpdateExistingServiceQuerySetupStore.d.ts +28 -0
- package/lib/stores/UpdateExistingServiceQuerySetupStore.d.ts.map +1 -0
- package/lib/stores/UpdateExistingServiceQuerySetupStore.js +73 -0
- package/lib/stores/UpdateExistingServiceQuerySetupStore.js.map +1 -0
- package/package.json +13 -16
- package/src/application/LegendQuery.tsx +7 -8
- package/src/application/LegendQueryApplicationConfig.ts +14 -0
- package/src/components/CloneQueryServiceSetup.tsx +312 -0
- package/src/components/Core_LegendQueryApplicationPlugin.tsx +184 -0
- package/src/components/CreateMappingQuerySetup.tsx +352 -0
- package/src/components/EditExistingQuerySetup.tsx +280 -0
- package/src/components/LegendQueryApplication.tsx +14 -2
- package/src/components/LoadProjectServiceQuerySetup.tsx +131 -0
- package/src/components/QueryEditor.tsx +127 -81
- package/src/components/QueryProductionizerSetup.tsx +206 -0
- package/src/components/QuerySetup.tsx +285 -1183
- package/src/components/UpdateExistingServiceQuerySetup.tsx +153 -0
- package/src/index.ts +3 -2
- package/src/stores/CloneServiceQuerySetupStore.ts +151 -0
- package/src/stores/CreateMappingQuerySetupStore.ts +155 -0
- package/src/stores/EditExistingQuerySetupStore.ts +111 -0
- package/src/stores/LegendQueryApplicationPlugin.ts +27 -27
- package/src/stores/LegendQueryRouter.ts +95 -12
- package/src/stores/LoadProjectServiceQuerySetupStore.ts +87 -0
- package/src/stores/QueryEditorStore.ts +90 -24
- package/src/stores/QueryEditorStoreTestUtils.ts +3 -0
- package/src/stores/QueryProductionizerSetupStore.ts +143 -0
- package/src/stores/QuerySetupStore.ts +111 -604
- package/src/stores/UpdateExistingServiceQuerySetupStore.ts +118 -0
- package/tsconfig.json +13 -1
- package/lib/components/QuerySetupStoreProvider.d.ts.map +0 -1
- package/lib/components/QuerySetupStoreProvider.js +0 -34
- package/lib/components/QuerySetupStoreProvider.js.map +0 -1
- package/src/components/QuerySetupStoreProvider.tsx +0 -56
@@ -0,0 +1,118 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
import {
|
18
|
+
DEFAULT_TYPEAHEAD_SEARCH_LIMIT,
|
19
|
+
DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH,
|
20
|
+
} from '@finos/legend-application';
|
21
|
+
import { CORE_PURE_PATH } from '@finos/legend-graph';
|
22
|
+
import {
|
23
|
+
extractServiceInfo,
|
24
|
+
type ServiceInfo,
|
25
|
+
} from '@finos/legend-query-builder';
|
26
|
+
import {
|
27
|
+
DepotScope,
|
28
|
+
ProjectData,
|
29
|
+
type DepotServerClient,
|
30
|
+
type StoredEntity,
|
31
|
+
} from '@finos/legend-server-depot';
|
32
|
+
import {
|
33
|
+
ActionState,
|
34
|
+
assertErrorThrown,
|
35
|
+
type GeneratorFn,
|
36
|
+
} from '@finos/legend-shared';
|
37
|
+
import { parseProjectIdentifier } from '@finos/legend-storage';
|
38
|
+
import { flow, makeObservable, observable } from 'mobx';
|
39
|
+
import type { LegendQueryApplicationStore } from './LegendQueryBaseStore.js';
|
40
|
+
import { EXTERNAL_APPLICATION_NAVIGATION__generateStudioUpdateExistingServiceQueryUrl } from './LegendQueryRouter.js';
|
41
|
+
import { BaseQuerySetupStore } from './QuerySetupStore.js';
|
42
|
+
|
43
|
+
export class UpdateExistingServiceQuerySetupStore extends BaseQuerySetupStore {
|
44
|
+
readonly loadServicesState = ActionState.create();
|
45
|
+
services: ServiceInfo[] = [];
|
46
|
+
|
47
|
+
constructor(
|
48
|
+
applicationStore: LegendQueryApplicationStore,
|
49
|
+
depotServerClient: DepotServerClient,
|
50
|
+
) {
|
51
|
+
super(applicationStore, depotServerClient);
|
52
|
+
|
53
|
+
makeObservable(this, {
|
54
|
+
services: observable,
|
55
|
+
loadServices: flow,
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
async loadServiceUpdater(serviceInfo: ServiceInfo): Promise<void> {
|
60
|
+
// fetch project data
|
61
|
+
const project = ProjectData.serialization.fromJson(
|
62
|
+
await this.depotServerClient.getProject(
|
63
|
+
serviceInfo.groupId,
|
64
|
+
serviceInfo.artifactId,
|
65
|
+
),
|
66
|
+
);
|
67
|
+
|
68
|
+
// find the matching SDLC instance
|
69
|
+
const projectIDPrefix = parseProjectIdentifier(project.projectId).prefix;
|
70
|
+
const matchingSDLCEntry = this.applicationStore.config.studioInstances.find(
|
71
|
+
(entry) => entry.sdlcProjectIDPrefix === projectIDPrefix,
|
72
|
+
);
|
73
|
+
if (matchingSDLCEntry) {
|
74
|
+
this.applicationStore.setBlockingAlert({
|
75
|
+
message: `Loading service...`,
|
76
|
+
prompt: 'Please do not close the application',
|
77
|
+
showLoading: true,
|
78
|
+
});
|
79
|
+
this.applicationStore.navigator.goToAddress(
|
80
|
+
EXTERNAL_APPLICATION_NAVIGATION__generateStudioUpdateExistingServiceQueryUrl(
|
81
|
+
matchingSDLCEntry.url,
|
82
|
+
serviceInfo.groupId,
|
83
|
+
serviceInfo.artifactId,
|
84
|
+
serviceInfo.path,
|
85
|
+
),
|
86
|
+
);
|
87
|
+
} else {
|
88
|
+
this.applicationStore.notifyWarning(
|
89
|
+
`Can't find the corresponding SDLC instance to update the service`,
|
90
|
+
);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
*loadServices(searchText: string): GeneratorFn<void> {
|
95
|
+
const isValidSearchString =
|
96
|
+
searchText.length >= DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH;
|
97
|
+
this.loadServicesState.inProgress();
|
98
|
+
try {
|
99
|
+
this.services = (
|
100
|
+
(yield this.depotServerClient.getEntitiesByClassifierPath(
|
101
|
+
CORE_PURE_PATH.SERVICE,
|
102
|
+
{
|
103
|
+
search: isValidSearchString ? searchText : undefined,
|
104
|
+
// NOTE: since this mode is meant for contribution, we want to load services
|
105
|
+
// on the snapshot version (i.e. merged to the default branch on the projects)
|
106
|
+
scope: DepotScope.SNAPSHOT,
|
107
|
+
limit: DEFAULT_TYPEAHEAD_SEARCH_LIMIT,
|
108
|
+
},
|
109
|
+
)) as StoredEntity[]
|
110
|
+
).map((storedEntity) => extractServiceInfo(storedEntity));
|
111
|
+
this.loadServicesState.pass();
|
112
|
+
} catch (error) {
|
113
|
+
assertErrorThrown(error);
|
114
|
+
this.applicationStore.notifyError(error);
|
115
|
+
this.loadServicesState.fail();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
package/tsconfig.json
CHANGED
@@ -37,21 +37,33 @@
|
|
37
37
|
"./src/index.ts",
|
38
38
|
"./src/application/LegendQueryApplicationConfig.ts",
|
39
39
|
"./src/application/LegendQueryPluginManager.ts",
|
40
|
+
"./src/stores/CloneServiceQuerySetupStore.ts",
|
41
|
+
"./src/stores/CreateMappingQuerySetupStore.ts",
|
42
|
+
"./src/stores/EditExistingQuerySetupStore.ts",
|
40
43
|
"./src/stores/LegendQueryApplicationPlugin.ts",
|
41
44
|
"./src/stores/LegendQueryBaseStore.ts",
|
42
45
|
"./src/stores/LegendQueryEventService.ts",
|
43
46
|
"./src/stores/LegendQueryRouter.ts",
|
47
|
+
"./src/stores/LoadProjectServiceQuerySetupStore.ts",
|
44
48
|
"./src/stores/QueryEditorStore.ts",
|
45
49
|
"./src/stores/QueryEditorStoreTestUtils.ts",
|
50
|
+
"./src/stores/QueryProductionizerSetupStore.ts",
|
46
51
|
"./src/stores/QuerySetupStore.ts",
|
52
|
+
"./src/stores/UpdateExistingServiceQuerySetupStore.ts",
|
47
53
|
"./src/application/LegendQuery.tsx",
|
54
|
+
"./src/components/CloneQueryServiceSetup.tsx",
|
55
|
+
"./src/components/Core_LegendQueryApplicationPlugin.tsx",
|
56
|
+
"./src/components/CreateMappingQuerySetup.tsx",
|
57
|
+
"./src/components/EditExistingQuerySetup.tsx",
|
48
58
|
"./src/components/LegendQueryApplication.tsx",
|
49
59
|
"./src/components/LegendQueryBaseStoreProvider.tsx",
|
60
|
+
"./src/components/LoadProjectServiceQuerySetup.tsx",
|
50
61
|
"./src/components/QueryEditor.tsx",
|
51
62
|
"./src/components/QueryEditorComponentTestUtils.tsx",
|
52
63
|
"./src/components/QueryEditorStoreProvider.tsx",
|
64
|
+
"./src/components/QueryProductionizerSetup.tsx",
|
53
65
|
"./src/components/QuerySetup.tsx",
|
54
|
-
"./src/components/
|
66
|
+
"./src/components/UpdateExistingServiceQuerySetup.tsx"
|
55
67
|
],
|
56
68
|
"include": [
|
57
69
|
"src/**/*.ts",
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"QuerySetupStoreProvider.d.ts","sourceRoot":"","sources":["../../src/components/QuerySetupStoreProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAS/D,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAWA,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,eAInC,CAAC;AAEJ,eAAO,MAAM,mBAAmB,qBAAsB,MAAM,EAAE,KAAG,MAAM,EAOpE,CAAC"}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
/**
|
3
|
-
* Copyright (c) 2020-present, Goldman Sachs
|
4
|
-
*
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
* you may not use this file except in compliance with the License.
|
7
|
-
* You may obtain a copy of the License at
|
8
|
-
*
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
*
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
* See the License for the specific language governing permissions and
|
15
|
-
* limitations under the License.
|
16
|
-
*/
|
17
|
-
import { createContext, useContext } from 'react';
|
18
|
-
import { useLocalObservable } from 'mobx-react-lite';
|
19
|
-
import { QuerySetupStore } from '../stores/QuerySetupStore.js';
|
20
|
-
import { guaranteeNonNullable } from '@finos/legend-shared';
|
21
|
-
import { useDepotServerClient } from '@finos/legend-server-depot';
|
22
|
-
import { useLegendQueryApplicationStore } from './LegendQueryBaseStoreProvider.js';
|
23
|
-
const QuerySetupStoreContext = createContext(undefined);
|
24
|
-
export const QuerySetupStoreProvider = ({ children }) => {
|
25
|
-
const applicationStore = useLegendQueryApplicationStore();
|
26
|
-
const depotServerClient = useDepotServerClient();
|
27
|
-
const store = useLocalObservable(() => new QuerySetupStore(applicationStore, depotServerClient));
|
28
|
-
return (_jsx(QuerySetupStoreContext.Provider, { value: store, children: children }));
|
29
|
-
};
|
30
|
-
export const useQuerySetupStore = () => guaranteeNonNullable(useContext(QuerySetupStoreContext), `Can't find query setup store in context`);
|
31
|
-
export const withQuerySetupStore = (WrappedComponent) => function WithQuerySetupStore() {
|
32
|
-
return (_jsx(QuerySetupStoreProvider, { children: _jsx(WrappedComponent, {}) }));
|
33
|
-
};
|
34
|
-
//# sourceMappingURL=QuerySetupStoreProvider.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"QuerySetupStoreProvider.js","sourceRoot":"","sources":["../../src/components/QuerySetupStoreProvider.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AAEnF,MAAM,sBAAsB,GAAG,aAAa,CAC1C,SAAS,CACV,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAE/B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACpB,MAAM,gBAAgB,GAAG,8BAA8B,EAAE,CAAC;IAC1D,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,kBAAkB,CAC9B,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAC/D,CAAC;IACF,OAAO,CACL,KAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC1C,QAAQ,GACuB,CACnC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAoB,EAAE,CACtD,oBAAoB,CAClB,UAAU,CAAC,sBAAsB,CAAC,EAClC,yCAAyC,CAC1C,CAAC;AAEJ,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,gBAA0B,EAAY,EAAE,CAC1E,SAAS,mBAAmB;IAC1B,OAAO,CACL,KAAC,uBAAuB,cACtB,KAAC,gBAAgB,KAAG,GACI,CAC3B,CAAC;AACJ,CAAC,CAAC"}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2020-present, Goldman Sachs
|
3
|
-
*
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
* you may not use this file except in compliance with the License.
|
6
|
-
* You may obtain a copy of the License at
|
7
|
-
*
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
*
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
* See the License for the specific language governing permissions and
|
14
|
-
* limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
import { createContext, useContext } from 'react';
|
18
|
-
import { useLocalObservable } from 'mobx-react-lite';
|
19
|
-
import { QuerySetupStore } from '../stores/QuerySetupStore.js';
|
20
|
-
import { guaranteeNonNullable } from '@finos/legend-shared';
|
21
|
-
import { useDepotServerClient } from '@finos/legend-server-depot';
|
22
|
-
import { useLegendQueryApplicationStore } from './LegendQueryBaseStoreProvider.js';
|
23
|
-
|
24
|
-
const QuerySetupStoreContext = createContext<QuerySetupStore | undefined>(
|
25
|
-
undefined,
|
26
|
-
);
|
27
|
-
|
28
|
-
export const QuerySetupStoreProvider: React.FC<{
|
29
|
-
children: React.ReactNode;
|
30
|
-
}> = ({ children }) => {
|
31
|
-
const applicationStore = useLegendQueryApplicationStore();
|
32
|
-
const depotServerClient = useDepotServerClient();
|
33
|
-
const store = useLocalObservable(
|
34
|
-
() => new QuerySetupStore(applicationStore, depotServerClient),
|
35
|
-
);
|
36
|
-
return (
|
37
|
-
<QuerySetupStoreContext.Provider value={store}>
|
38
|
-
{children}
|
39
|
-
</QuerySetupStoreContext.Provider>
|
40
|
-
);
|
41
|
-
};
|
42
|
-
|
43
|
-
export const useQuerySetupStore = (): QuerySetupStore =>
|
44
|
-
guaranteeNonNullable(
|
45
|
-
useContext(QuerySetupStoreContext),
|
46
|
-
`Can't find query setup store in context`,
|
47
|
-
);
|
48
|
-
|
49
|
-
export const withQuerySetupStore = (WrappedComponent: React.FC): React.FC =>
|
50
|
-
function WithQuerySetupStore() {
|
51
|
-
return (
|
52
|
-
<QuerySetupStoreProvider>
|
53
|
-
<WrappedComponent />
|
54
|
-
</QuerySetupStoreProvider>
|
55
|
-
);
|
56
|
-
};
|