@finos/legend-application-query 12.0.9 → 13.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.
Files changed (51) hide show
  1. package/lib/__lib__/LegendQueryEvent.d.ts +1 -0
  2. package/lib/__lib__/LegendQueryEvent.d.ts.map +1 -1
  3. package/lib/__lib__/LegendQueryEvent.js +1 -0
  4. package/lib/__lib__/LegendQueryEvent.js.map +1 -1
  5. package/lib/__lib__/LegendQueryTelemetryHelper.d.ts +7 -6
  6. package/lib/__lib__/LegendQueryTelemetryHelper.d.ts.map +1 -1
  7. package/lib/__lib__/LegendQueryTelemetryHelper.js +15 -12
  8. package/lib/__lib__/LegendQueryTelemetryHelper.js.map +1 -1
  9. package/lib/__lib__/LegendQueryUserDataHelper.d.ts +27 -0
  10. package/lib/__lib__/LegendQueryUserDataHelper.d.ts.map +1 -0
  11. package/lib/__lib__/LegendQueryUserDataHelper.js +63 -0
  12. package/lib/__lib__/LegendQueryUserDataHelper.js.map +1 -0
  13. package/lib/components/EditExistingQuerySetup.d.ts.map +1 -1
  14. package/lib/components/EditExistingQuerySetup.js +7 -71
  15. package/lib/components/EditExistingQuerySetup.js.map +1 -1
  16. package/lib/components/QueryEditor.d.ts.map +1 -1
  17. package/lib/components/QueryEditor.js +15 -72
  18. package/lib/components/QueryEditor.js.map +1 -1
  19. package/lib/components/QueryProductionizerSetup.d.ts.map +1 -1
  20. package/lib/components/QueryProductionizerSetup.js +6 -47
  21. package/lib/components/QueryProductionizerSetup.js.map +1 -1
  22. package/lib/index.css +2 -2
  23. package/lib/index.css.map +1 -1
  24. package/lib/package.json +1 -1
  25. package/lib/stores/EditExistingQuerySetupStore.d.ts +3 -12
  26. package/lib/stores/EditExistingQuerySetupStore.d.ts.map +1 -1
  27. package/lib/stores/EditExistingQuerySetupStore.js +27 -64
  28. package/lib/stores/EditExistingQuerySetupStore.js.map +1 -1
  29. package/lib/stores/LegendQueryApplicationPlugin.d.ts +4 -3
  30. package/lib/stores/LegendQueryApplicationPlugin.d.ts.map +1 -1
  31. package/lib/stores/LegendQueryApplicationPlugin.js.map +1 -1
  32. package/lib/stores/QueryEditorStore.d.ts +5 -18
  33. package/lib/stores/QueryEditorStore.d.ts.map +1 -1
  34. package/lib/stores/QueryEditorStore.js +34 -62
  35. package/lib/stores/QueryEditorStore.js.map +1 -1
  36. package/lib/stores/QueryProductionizerSetupStore.d.ts +4 -10
  37. package/lib/stores/QueryProductionizerSetupStore.d.ts.map +1 -1
  38. package/lib/stores/QueryProductionizerSetupStore.js +29 -62
  39. package/lib/stores/QueryProductionizerSetupStore.js.map +1 -1
  40. package/package.json +9 -9
  41. package/src/__lib__/LegendQueryEvent.ts +1 -0
  42. package/src/__lib__/LegendQueryTelemetryHelper.ts +19 -26
  43. package/src/__lib__/LegendQueryUserDataHelper.ts +92 -0
  44. package/src/components/EditExistingQuerySetup.tsx +10 -204
  45. package/src/components/QueryEditor.tsx +36 -251
  46. package/src/components/QueryProductionizerSetup.tsx +9 -124
  47. package/src/stores/EditExistingQuerySetupStore.ts +54 -87
  48. package/src/stores/LegendQueryApplicationPlugin.ts +4 -3
  49. package/src/stores/QueryEditorStore.ts +66 -73
  50. package/src/stores/QueryProductionizerSetupStore.ts +55 -84
  51. package/tsconfig.json +1 -0
@@ -0,0 +1,92 @@
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 type { UserDataService } from '@finos/legend-application';
18
+ import { returnUndefOnError } from '@finos/legend-shared';
19
+ import { createSimpleSchema, deserialize, list, primitive } from 'serializr';
20
+
21
+ export enum LEGEND_QUERY_USER_DATA_KEY {
22
+ RECENTLY_VIEWED_QUERIES = 'query-editor.recent-queries',
23
+ }
24
+
25
+ const USER_DATA_RECENTLY_VIEWED_QUERIES_LIMIT = 10;
26
+ type RecentlyViewedQueriesData = string[];
27
+
28
+ export class LegendQueryUserDataHelper {
29
+ static getRecentlyViewedQueries(
30
+ service: UserDataService,
31
+ ): RecentlyViewedQueriesData {
32
+ const data = service.getObjectValue(
33
+ LEGEND_QUERY_USER_DATA_KEY.RECENTLY_VIEWED_QUERIES,
34
+ );
35
+ return (
36
+ // TODO: think of a better way to deserialize this data, maybe like settings, use JSON schema
37
+ // See https://github.com/finos/legend-studio/issues/407
38
+ returnUndefOnError(
39
+ () =>
40
+ (
41
+ deserialize(
42
+ createSimpleSchema({
43
+ data: list(primitive()),
44
+ }),
45
+ {
46
+ data,
47
+ },
48
+ ) as { data: RecentlyViewedQueriesData }
49
+ ).data,
50
+ ) ?? []
51
+ );
52
+ }
53
+
54
+ static removeRecentlyViewedQuery(
55
+ service: UserDataService,
56
+ queryId: string,
57
+ ): void {
58
+ const queries = LegendQueryUserDataHelper.getRecentlyViewedQueries(service);
59
+ const idx = queries.findIndex((query) => query === queryId);
60
+ if (idx !== -1) {
61
+ return;
62
+ }
63
+ queries.splice(idx, 1);
64
+ service.persistValue(
65
+ LEGEND_QUERY_USER_DATA_KEY.RECENTLY_VIEWED_QUERIES,
66
+ queries,
67
+ );
68
+ }
69
+
70
+ static addRecentlyViewedQuery(
71
+ service: UserDataService,
72
+ queryId: string,
73
+ ): void {
74
+ const queries = LegendQueryUserDataHelper.getRecentlyViewedQueries(service);
75
+ const idx = queries.findIndex((query) => query === queryId);
76
+ if (idx === -1) {
77
+ if (queries.length < USER_DATA_RECENTLY_VIEWED_QUERIES_LIMIT) {
78
+ queries.unshift(queryId);
79
+ } else {
80
+ queries.pop();
81
+ queries.unshift(queryId);
82
+ }
83
+ } else {
84
+ queries.splice(idx, 1);
85
+ queries.unshift(queryId);
86
+ }
87
+ service.persistValue(
88
+ LEGEND_QUERY_USER_DATA_KEY.RECENTLY_VIEWED_QUERIES,
89
+ queries,
90
+ );
91
+ }
92
+ }
@@ -14,40 +14,19 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import {
18
- type SelectComponent,
19
- ArrowLeftIcon,
20
- ArrowRightIcon,
21
- BlankPanelContent,
22
- clsx,
23
- CustomSelectorInput,
24
- PanelLoadingIndicator,
25
- SearchIcon,
26
- UserIcon,
27
- } from '@finos/legend-art';
28
- import { debounce, guaranteeType } from '@finos/legend-shared';
29
- import { flowResult } from 'mobx';
17
+ import { ArrowLeftIcon } from '@finos/legend-art';
18
+ import { guaranteeType } from '@finos/legend-shared';
30
19
  import { observer, useLocalObservable } from 'mobx-react-lite';
31
- import { useContext, useEffect, useMemo, useRef, useState } from 'react';
32
- import {
33
- generateExistingQueryEditorRoute,
34
- generateQuerySetupRoute,
35
- } from '../__lib__/LegendQueryNavigation.js';
20
+ import { useContext } from 'react';
21
+ import { generateQuerySetupRoute } from '../__lib__/LegendQueryNavigation.js';
36
22
  import { useApplicationStore } from '@finos/legend-application';
37
- import {
38
- type QueryOption,
39
- buildQueryOption,
40
- } from '@finos/legend-query-builder';
41
23
  import {
42
24
  useLegendQueryApplicationStore,
43
25
  useLegendQueryBaseStore,
44
26
  } from './LegendQueryFrameworkProvider.js';
45
27
  import { EditExistingQuerySetupStore } from '../stores/EditExistingQuerySetupStore.js';
46
28
  import { BaseQuerySetup, BaseQuerySetupStoreContext } from './QuerySetup.js';
47
- import {
48
- CODE_EDITOR_LANGUAGE,
49
- CodeEditor,
50
- } from '@finos/legend-lego/code-editor';
29
+ import { QueryLoader } from '@finos/legend-query-builder';
51
30
 
52
31
  const EditExistingQuerySetupStoreProvider: React.FC<{
53
32
  children: React.ReactNode;
@@ -78,8 +57,6 @@ const useEditExistingQuerySetupStore = (): EditExistingQuerySetupStore =>
78
57
  const EditExistingQuerySetupContent = observer(() => {
79
58
  const setupStore = useEditExistingQuerySetupStore();
80
59
  const applicationStore = useApplicationStore();
81
- const querySearchRef = useRef<SelectComponent>(null);
82
- const [searchText, setSearchText] = useState('');
83
60
 
84
61
  // actions
85
62
  const back = (): void => {
@@ -87,112 +64,6 @@ const EditExistingQuerySetupContent = observer(() => {
87
64
  generateQuerySetupRoute(),
88
65
  );
89
66
  };
90
- const next = (): void => {
91
- if (setupStore.currentQuery) {
92
- applicationStore.navigationService.navigator.goToLocation(
93
- generateExistingQueryEditorRoute(setupStore.currentQuery.id),
94
- );
95
- }
96
- };
97
- const canProceed = setupStore.currentQuery;
98
-
99
- // query
100
- const queryOptions = setupStore.queries.map(buildQueryOption);
101
- const selectedQueryOption = setupStore.currentQuery
102
- ? buildQueryOption(setupStore.currentQuery)
103
- : null;
104
- const onQueryOptionChange = (option: QueryOption | null): void => {
105
- if (option?.value !== setupStore.currentQuery) {
106
- setupStore.setCurrentQuery(option?.value.id);
107
- }
108
- };
109
- const formatQueryOptionLabel = (option: QueryOption): React.ReactNode => {
110
- const deleteQuery: React.MouseEventHandler<HTMLButtonElement> = (event) => {
111
- event.preventDefault();
112
- event.stopPropagation();
113
- setupStore.graphManagerState.graphManager
114
- .deleteQuery(option.value.id)
115
- .then(() =>
116
- flowResult(setupStore.loadQueries('')).catch(
117
- applicationStore.alertUnhandledError,
118
- ),
119
- )
120
- .catch(applicationStore.alertUnhandledError);
121
- };
122
- if (option.value.id === setupStore.currentQuery?.id) {
123
- return option.label;
124
- }
125
- return (
126
- <div className="query-setup__existing-query__query-option">
127
- <div
128
- className="query-setup__existing-query__query-option__label"
129
- title={option.label}
130
- >
131
- {option.label}
132
- </div>
133
- {setupStore.showCurrentUserQueriesOnly && (
134
- <button
135
- className="query-setup__existing-query__query-option__action"
136
- tabIndex={-1}
137
- onClick={deleteQuery}
138
- >
139
- Delete
140
- </button>
141
- )}
142
- {!setupStore.showCurrentUserQueriesOnly &&
143
- Boolean(option.value.owner) && (
144
- <div
145
- className={clsx(
146
- 'query-setup__existing-query__query-option__user',
147
- {
148
- 'query-setup__existing-query__query-option__user--mine':
149
- option.value.isCurrentUserQuery,
150
- },
151
- )}
152
- >
153
- {option.value.isCurrentUserQuery ? 'mine' : option.value.owner}
154
- </div>
155
- )}
156
- </div>
157
- );
158
- };
159
-
160
- // search text
161
- const debouncedLoadQueries = useMemo(
162
- () =>
163
- debounce((input: string): void => {
164
- flowResult(setupStore.loadQueries(input)).catch(
165
- applicationStore.alertUnhandledError,
166
- );
167
- }, 500),
168
- [applicationStore, setupStore],
169
- );
170
- const onSearchTextChange = (value: string): void => {
171
- if (value !== searchText) {
172
- setSearchText(value);
173
- debouncedLoadQueries.cancel();
174
- debouncedLoadQueries(value);
175
- }
176
- };
177
-
178
- // show current user queries only
179
- const toggleShowCurrentUserQueriesOnly = (): void => {
180
- setupStore.setShowCurrentUserQueriesOnly(
181
- !setupStore.showCurrentUserQueriesOnly,
182
- );
183
- debouncedLoadQueries.cancel();
184
- debouncedLoadQueries(searchText);
185
- };
186
-
187
- useEffect(() => {
188
- flowResult(setupStore.loadQueries('')).catch(
189
- applicationStore.alertUnhandledError,
190
- );
191
- }, [setupStore, applicationStore]);
192
-
193
- useEffect(() => {
194
- querySearchRef.current?.focus();
195
- }, []);
196
67
 
197
68
  return (
198
69
  <div className="query-setup__wizard query-setup__existing-query">
@@ -207,77 +78,12 @@ const EditExistingQuerySetupContent = observer(() => {
207
78
  <div className="query-setup__wizard__header__title">
208
79
  Loading an existing query...
209
80
  </div>
210
- <button
211
- className={clsx('query-setup__wizard__header__btn', {
212
- 'query-setup__wizard__header__btn--ready': canProceed,
213
- })}
214
- onClick={next}
215
- disabled={!canProceed}
216
- title="Edit query"
217
- >
218
- <ArrowRightIcon />
219
- </button>
220
81
  </div>
221
- <div className="query-setup__wizard__content">
222
- <div className="query-setup__wizard__group query-setup__wizard__group--inline">
223
- <div className="query-setup__wizard__group__title">
224
- <SearchIcon />
225
- </div>
226
- <div className="query-setup__existing-query__input">
227
- <CustomSelectorInput
228
- ref={querySearchRef}
229
- className="query-setup__wizard__selector"
230
- options={queryOptions}
231
- isLoading={setupStore.loadQueriesState.isInProgress}
232
- onInputChange={onSearchTextChange}
233
- inputValue={searchText}
234
- onChange={onQueryOptionChange}
235
- value={selectedQueryOption}
236
- placeholder="Search for query by name..."
237
- isClearable={true}
238
- escapeClearsValue={true}
239
- darkMode={true}
240
- formatOptionLabel={formatQueryOptionLabel}
241
- />
242
- <button
243
- className={clsx('query-setup__existing-query__btn', {
244
- 'query-setup__existing-query__btn--active':
245
- setupStore.showCurrentUserQueriesOnly,
246
- })}
247
- tabIndex={-1}
248
- title={`[${
249
- setupStore.showCurrentUserQueriesOnly ? 'on' : 'off'
250
- }] Toggle show only queries of current user`}
251
- onClick={toggleShowCurrentUserQueriesOnly}
252
- >
253
- <UserIcon />
254
- </button>
255
- </div>
256
- </div>
257
- <div className="query-setup__existing-query__preview">
258
- <PanelLoadingIndicator
259
- isLoading={setupStore.loadQueryState.isInProgress}
260
- />
261
- {setupStore.currentQuery && (
262
- <>
263
- {!setupStore.currentQueryInfo && (
264
- <BlankPanelContent>{`Can't preview query`}</BlankPanelContent>
265
- )}
266
- {setupStore.currentQueryInfo && (
267
- <CodeEditor
268
- inputValue={setupStore.currentQueryInfo.content}
269
- isReadOnly={true}
270
- language={CODE_EDITOR_LANGUAGE.PURE}
271
- showMiniMap={false}
272
- hideGutter={true}
273
- />
274
- )}
275
- </>
276
- )}
277
- {!setupStore.currentQuery && (
278
- <BlankPanelContent>No query to preview</BlankPanelContent>
279
- )}
280
- </div>
82
+ <div className="query-setup__existing-query__content">
83
+ <QueryLoader
84
+ queryLoaderState={setupStore.queryLoaderState}
85
+ loadActionLabel="load query"
86
+ />
281
87
  </div>
282
88
  </div>
283
89
  );