@finos/legend-application-data-cube 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/lib/__lib__/LegendDataCubeNavigation.d.ts +5 -5
  2. package/lib/__lib__/LegendDataCubeNavigation.d.ts.map +1 -1
  3. package/lib/__lib__/LegendDataCubeNavigation.js +5 -5
  4. package/lib/__lib__/LegendDataCubeNavigation.js.map +1 -1
  5. package/lib/{stores/source/CubeInputSource.js → __lib__/LegendDataCubeSetting.d.ts} +6 -14
  6. package/lib/__lib__/LegendDataCubeSetting.d.ts.map +1 -0
  7. package/lib/__lib__/LegendDataCubeSetting.js +25 -0
  8. package/lib/__lib__/LegendDataCubeSetting.js.map +1 -0
  9. package/lib/{stores/model/DataCubeQueryContent.js → __lib__/LegendDataCubeUserData.d.ts} +4 -5
  10. package/lib/__lib__/LegendDataCubeUserData.d.ts.map +1 -0
  11. package/lib/__lib__/LegendDataCubeUserData.js +21 -0
  12. package/lib/__lib__/LegendDataCubeUserData.js.map +1 -0
  13. package/lib/application/LegendDataCube.d.ts.map +1 -1
  14. package/lib/application/LegendDataCube.js.map +1 -1
  15. package/lib/application/LegendDataCubeApplicationConfig.d.ts +1 -1
  16. package/lib/application/LegendDataCubeApplicationConfig.d.ts.map +1 -1
  17. package/lib/application/LegendDataCubeApplicationConfig.js +3 -1
  18. package/lib/application/LegendDataCubeApplicationConfig.js.map +1 -1
  19. package/lib/application/LegendDataCubePluginManager.d.ts.map +1 -1
  20. package/lib/application/LegendDataCubePluginManager.js.map +1 -1
  21. package/lib/components/LegendDataCubeFrameworkProvider.d.ts +2 -2
  22. package/lib/components/LegendDataCubeFrameworkProvider.d.ts.map +1 -1
  23. package/lib/components/LegendDataCubeFrameworkProvider.js +5 -5
  24. package/lib/components/LegendDataCubeFrameworkProvider.js.map +1 -1
  25. package/lib/components/LegendDataCubeWebApplication.d.ts.map +1 -1
  26. package/lib/components/LegendDataCubeWebApplication.js +25 -6
  27. package/lib/components/LegendDataCubeWebApplication.js.map +1 -1
  28. package/lib/{stores/model/DataCubeGenericSource.d.ts → components/query-builder/LegendDataCubeNewQueryBuilder.d.ts} +4 -3
  29. package/lib/components/query-builder/LegendDataCubeNewQueryBuilder.d.ts.map +1 -0
  30. package/lib/components/query-builder/LegendDataCubeNewQueryBuilder.js +46 -0
  31. package/lib/components/query-builder/LegendDataCubeNewQueryBuilder.js.map +1 -0
  32. package/{src/stores/model/DataCubeGenericSource.ts → lib/components/query-builder/LegendDataCubeQueryBuilder.d.ts} +2 -2
  33. package/lib/components/query-builder/LegendDataCubeQueryBuilder.d.ts.map +1 -0
  34. package/lib/components/query-builder/LegendDataCubeQueryBuilder.js +79 -0
  35. package/lib/components/query-builder/LegendDataCubeQueryBuilder.js.map +1 -0
  36. package/lib/components/query-builder/LegendDataCubeQueryBuilderStoreProvider.d.ts +19 -0
  37. package/lib/components/query-builder/LegendDataCubeQueryBuilderStoreProvider.d.ts.map +1 -0
  38. package/lib/components/query-builder/LegendDataCubeQueryBuilderStoreProvider.js +33 -0
  39. package/lib/components/query-builder/LegendDataCubeQueryBuilderStoreProvider.js.map +1 -0
  40. package/lib/components/{source/ExistingDataCubeQuery.d.ts → query-builder/LegendDataCubeQueryLoader.d.ts} +2 -2
  41. package/lib/components/query-builder/LegendDataCubeQueryLoader.d.ts.map +1 -0
  42. package/lib/components/query-builder/LegendDataCubeQueryLoader.js +97 -0
  43. package/lib/components/query-builder/LegendDataCubeQueryLoader.js.map +1 -0
  44. package/lib/components/{DataCubeEditor.d.ts → query-builder/LegendDataCubeQuerySaver.d.ts} +2 -2
  45. package/lib/components/query-builder/LegendDataCubeQuerySaver.d.ts.map +1 -0
  46. package/lib/components/query-builder/LegendDataCubeQuerySaver.js +49 -0
  47. package/lib/components/query-builder/LegendDataCubeQuerySaver.js.map +1 -0
  48. package/lib/components/{source/DataCubeSourceEditor.d.ts → query-builder/source-builder/AdhocQueryDataCubeSourceBuilder.d.ts} +4 -4
  49. package/lib/components/query-builder/source-builder/AdhocQueryDataCubeSourceBuilder.d.ts.map +1 -0
  50. package/lib/components/query-builder/source-builder/AdhocQueryDataCubeSourceBuilder.js +22 -0
  51. package/lib/components/query-builder/source-builder/AdhocQueryDataCubeSourceBuilder.js.map +1 -0
  52. package/lib/components/{source/SavedQuerySourceEditor.d.ts → query-builder/source-builder/LegendQueryDataCubeSourceBuilder.d.ts} +4 -4
  53. package/lib/components/query-builder/source-builder/LegendQueryDataCubeSourceBuilder.d.ts.map +1 -0
  54. package/lib/components/query-builder/source-builder/LegendQueryDataCubeSourceBuilder.js +97 -0
  55. package/lib/components/query-builder/source-builder/LegendQueryDataCubeSourceBuilder.js.map +1 -0
  56. package/lib/index.css +2 -2
  57. package/lib/index.css.map +1 -1
  58. package/lib/package.json +2 -2
  59. package/lib/stores/LegendDataCubeBaseStore.d.ts +43 -0
  60. package/lib/stores/LegendDataCubeBaseStore.d.ts.map +1 -0
  61. package/lib/stores/LegendDataCubeBaseStore.js +130 -0
  62. package/lib/stores/LegendDataCubeBaseStore.js.map +1 -0
  63. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts +57 -0
  64. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts.map +1 -0
  65. package/lib/stores/LegendDataCubeDataCubeEngine.js +250 -0
  66. package/lib/stores/LegendDataCubeDataCubeEngine.js.map +1 -0
  67. package/lib/stores/model/LegendQueryDataCubeSource.d.ts +32 -0
  68. package/lib/stores/model/LegendQueryDataCubeSource.d.ts.map +1 -0
  69. package/lib/stores/model/LegendQueryDataCubeSource.js +35 -0
  70. package/lib/stores/model/LegendQueryDataCubeSource.js.map +1 -0
  71. package/lib/stores/query-builder/LegendDataCubeNewQueryState.d.ts +33 -0
  72. package/lib/stores/query-builder/LegendDataCubeNewQueryState.d.ts.map +1 -0
  73. package/lib/stores/query-builder/LegendDataCubeNewQueryState.js +94 -0
  74. package/lib/stores/query-builder/LegendDataCubeNewQueryState.js.map +1 -0
  75. package/lib/stores/query-builder/LegendDataCubeQueryBuilderStore.d.ts +59 -0
  76. package/lib/stores/query-builder/LegendDataCubeQueryBuilderStore.d.ts.map +1 -0
  77. package/lib/stores/query-builder/LegendDataCubeQueryBuilderStore.js +219 -0
  78. package/lib/stores/query-builder/LegendDataCubeQueryBuilderStore.js.map +1 -0
  79. package/lib/stores/query-builder/LegendDataCubeQueryLoaderState.d.ts +53 -0
  80. package/lib/stores/query-builder/LegendDataCubeQueryLoaderState.d.ts.map +1 -0
  81. package/lib/stores/query-builder/LegendDataCubeQueryLoaderState.js +198 -0
  82. package/lib/stores/query-builder/LegendDataCubeQueryLoaderState.js.map +1 -0
  83. package/lib/stores/{model/DataCubeQueryContent.d.ts → query-builder/source-builder/AdhocQueryDataCubeSourceBuilderState.d.ts} +7 -7
  84. package/lib/stores/query-builder/source-builder/AdhocQueryDataCubeSourceBuilderState.d.ts.map +1 -0
  85. package/lib/stores/{model/LegendSavedQuerySource.js → query-builder/source-builder/AdhocQueryDataCubeSourceBuilderState.js} +12 -7
  86. package/lib/stores/query-builder/source-builder/AdhocQueryDataCubeSourceBuilderState.js.map +1 -0
  87. package/lib/stores/query-builder/source-builder/LegendDataCubeSourceBuilderState.d.ts +32 -0
  88. package/lib/stores/query-builder/source-builder/LegendDataCubeSourceBuilderState.d.ts.map +1 -0
  89. package/lib/stores/query-builder/source-builder/LegendDataCubeSourceBuilderState.js +31 -0
  90. package/lib/stores/query-builder/source-builder/LegendDataCubeSourceBuilderState.js.map +1 -0
  91. package/lib/stores/query-builder/source-builder/LegendQueryDataCubeSourceBuilderState.d.ts +36 -0
  92. package/lib/stores/query-builder/source-builder/LegendQueryDataCubeSourceBuilderState.d.ts.map +1 -0
  93. package/lib/stores/query-builder/source-builder/LegendQueryDataCubeSourceBuilderState.js +90 -0
  94. package/lib/stores/query-builder/source-builder/LegendQueryDataCubeSourceBuilderState.js.map +1 -0
  95. package/package.json +11 -11
  96. package/src/__lib__/LegendDataCubeNavigation.ts +7 -7
  97. package/src/{stores/model/DataCubeQueryContent.ts → __lib__/LegendDataCubeSetting.ts} +6 -6
  98. package/{lib/stores/model/DataCubeGenericSource.js → src/__lib__/LegendDataCubeUserData.ts} +5 -2
  99. package/src/application/LegendDataCube.tsx +1 -0
  100. package/src/application/LegendDataCubeApplicationConfig.ts +6 -4
  101. package/src/application/LegendDataCubePluginManager.ts +1 -0
  102. package/src/components/LegendDataCubeFrameworkProvider.tsx +7 -7
  103. package/src/components/LegendDataCubeWebApplication.tsx +48 -12
  104. package/src/components/query-builder/LegendDataCubeNewQueryBuilder.tsx +112 -0
  105. package/src/components/query-builder/LegendDataCubeQueryBuilder.tsx +148 -0
  106. package/src/components/query-builder/LegendDataCubeQueryBuilderStoreProvider.tsx +56 -0
  107. package/src/components/query-builder/LegendDataCubeQueryLoader.tsx +309 -0
  108. package/src/components/query-builder/LegendDataCubeQuerySaver.tsx +112 -0
  109. package/src/{stores/source/CubeInputSource.ts → components/query-builder/source-builder/AdhocQueryDataCubeSourceBuilder.tsx} +14 -19
  110. package/src/components/query-builder/source-builder/LegendQueryDataCubeSourceBuilder.tsx +315 -0
  111. package/src/stores/LegendDataCubeBaseStore.ts +217 -0
  112. package/src/stores/LegendDataCubeDataCubeEngine.ts +489 -0
  113. package/src/stores/model/LegendQueryDataCubeSource.ts +46 -0
  114. package/src/stores/query-builder/LegendDataCubeNewQueryState.tsx +153 -0
  115. package/src/stores/query-builder/LegendDataCubeQueryBuilderStore.tsx +307 -0
  116. package/src/stores/query-builder/LegendDataCubeQueryLoaderState.tsx +260 -0
  117. package/src/stores/{source/LegendCubeViewer.ts → query-builder/source-builder/AdhocQueryDataCubeSourceBuilderState.ts} +15 -8
  118. package/src/stores/query-builder/source-builder/LegendDataCubeSourceBuilderState.ts +43 -0
  119. package/src/stores/query-builder/source-builder/LegendQueryDataCubeSourceBuilderState.ts +143 -0
  120. package/tsconfig.json +18 -15
  121. package/lib/components/DataCubeEditor.d.ts.map +0 -1
  122. package/lib/components/DataCubeEditor.js +0 -59
  123. package/lib/components/DataCubeEditor.js.map +0 -1
  124. package/lib/components/source/DataCubeSourceEditor.d.ts.map +0 -1
  125. package/lib/components/source/DataCubeSourceEditor.js +0 -43
  126. package/lib/components/source/DataCubeSourceEditor.js.map +0 -1
  127. package/lib/components/source/ExistingDataCubeQuery.d.ts.map +0 -1
  128. package/lib/components/source/ExistingDataCubeQuery.js +0 -36
  129. package/lib/components/source/ExistingDataCubeQuery.js.map +0 -1
  130. package/lib/components/source/SavedQuerySourceEditor.d.ts.map +0 -1
  131. package/lib/components/source/SavedQuerySourceEditor.js +0 -25
  132. package/lib/components/source/SavedQuerySourceEditor.js.map +0 -1
  133. package/lib/stores/LegendDataCubeEditorStore.d.ts +0 -50
  134. package/lib/stores/LegendDataCubeEditorStore.d.ts.map +0 -1
  135. package/lib/stores/LegendDataCubeEditorStore.js +0 -153
  136. package/lib/stores/LegendDataCubeEditorStore.js.map +0 -1
  137. package/lib/stores/engine/LegendExecutionDataCubeEngine.d.ts +0 -52
  138. package/lib/stores/engine/LegendExecutionDataCubeEngine.d.ts.map +0 -1
  139. package/lib/stores/engine/LegendExecutionDataCubeEngine.js +0 -149
  140. package/lib/stores/engine/LegendExecutionDataCubeEngine.js.map +0 -1
  141. package/lib/stores/model/DataCubeGenericSource.d.ts.map +0 -1
  142. package/lib/stores/model/DataCubeGenericSource.js.map +0 -1
  143. package/lib/stores/model/DataCubeGenericSourceHelper.d.ts +0 -24
  144. package/lib/stores/model/DataCubeGenericSourceHelper.d.ts.map +0 -1
  145. package/lib/stores/model/DataCubeGenericSourceHelper.js +0 -58
  146. package/lib/stores/model/DataCubeGenericSourceHelper.js.map +0 -1
  147. package/lib/stores/model/DataCubeQueryContent.d.ts.map +0 -1
  148. package/lib/stores/model/DataCubeQueryContent.js.map +0 -1
  149. package/lib/stores/model/LegendSavedQuerySource.d.ts +0 -21
  150. package/lib/stores/model/LegendSavedQuerySource.d.ts.map +0 -1
  151. package/lib/stores/model/LegendSavedQuerySource.js.map +0 -1
  152. package/lib/stores/source/CubeInputSource.d.ts +0 -32
  153. package/lib/stores/source/CubeInputSource.d.ts.map +0 -1
  154. package/lib/stores/source/CubeInputSource.js.map +0 -1
  155. package/lib/stores/source/CubeInputSourceLoader.d.ts +0 -37
  156. package/lib/stores/source/CubeInputSourceLoader.d.ts.map +0 -1
  157. package/lib/stores/source/CubeInputSourceLoader.js +0 -39
  158. package/lib/stores/source/CubeInputSourceLoader.js.map +0 -1
  159. package/lib/stores/source/LegendCubeViewer.d.ts +0 -23
  160. package/lib/stores/source/LegendCubeViewer.d.ts.map +0 -1
  161. package/lib/stores/source/LegendCubeViewer.js +0 -24
  162. package/lib/stores/source/LegendCubeViewer.js.map +0 -1
  163. package/lib/stores/source/LegendDataCubeSourceBuilder.d.ts +0 -34
  164. package/lib/stores/source/LegendDataCubeSourceBuilder.d.ts.map +0 -1
  165. package/lib/stores/source/LegendDataCubeSourceBuilder.js +0 -70
  166. package/lib/stores/source/LegendDataCubeSourceBuilder.js.map +0 -1
  167. package/lib/stores/source/SavedQueryInputSourceState.d.ts +0 -35
  168. package/lib/stores/source/SavedQueryInputSourceState.d.ts.map +0 -1
  169. package/lib/stores/source/SavedQueryInputSourceState.js +0 -81
  170. package/lib/stores/source/SavedQueryInputSourceState.js.map +0 -1
  171. package/src/components/DataCubeEditor.tsx +0 -190
  172. package/src/components/source/DataCubeSourceEditor.tsx +0 -133
  173. package/src/components/source/ExistingDataCubeQuery.tsx +0 -101
  174. package/src/components/source/SavedQuerySourceEditor.tsx +0 -62
  175. package/src/stores/LegendDataCubeEditorStore.ts +0 -237
  176. package/src/stores/engine/LegendExecutionDataCubeEngine.ts +0 -267
  177. package/src/stores/model/DataCubeGenericSourceHelper.ts +0 -97
  178. package/src/stores/model/LegendSavedQuerySource.ts +0 -26
  179. package/src/stores/source/CubeInputSourceLoader.ts +0 -56
  180. package/src/stores/source/LegendDataCubeSourceBuilder.ts +0 -98
  181. package/src/stores/source/SavedQueryInputSourceState.ts +0 -142
@@ -0,0 +1,307 @@
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 { action, makeObservable, observable } from 'mobx';
18
+ import type {
19
+ LegendDataCubeApplicationStore,
20
+ LegendDataCubeBaseStore,
21
+ } from '../LegendDataCubeBaseStore.js';
22
+ import {
23
+ type DataCubeAlertService,
24
+ type DataCubeAPI,
25
+ type DataCubeLayoutService,
26
+ type DataCubeTaskService,
27
+ DataCubeQuery,
28
+ DEFAULT_ALERT_WINDOW_CONFIG,
29
+ type DisplayState,
30
+ } from '@finos/legend-data-cube';
31
+ import { LegendDataCubeNewQueryState } from './LegendDataCubeNewQueryState.js';
32
+ import {
33
+ PersistentDataCubeQuery,
34
+ type V1_EngineServerClient,
35
+ type V1_PureGraphManager,
36
+ } from '@finos/legend-graph';
37
+ import {
38
+ ActionState,
39
+ assertErrorThrown,
40
+ formatDate,
41
+ isString,
42
+ uuid,
43
+ } from '@finos/legend-shared';
44
+ import type { LegendDataCubeDataCubeEngine } from '../LegendDataCubeDataCubeEngine.js';
45
+ import { LegendDataCubeQuerySaver } from '../../components/query-builder/LegendDataCubeQuerySaver.js';
46
+ import { generateQueryBuilderRoute } from '../../__lib__/LegendDataCubeNavigation.js';
47
+ import { LegendDataCubeQueryLoaderState } from './LegendDataCubeQueryLoaderState.js';
48
+ import {
49
+ LegendDataCubeUserDataKey,
50
+ RECENTLY_VIEWED_QUERIES_LIMIT,
51
+ } from '../../__lib__/LegendDataCubeUserData.js';
52
+ import type { DepotServerClient } from '@finos/legend-server-depot';
53
+
54
+ export class LegendDataCubeQueryBuilderState {
55
+ uuid = uuid();
56
+ startTime = Date.now();
57
+ query!: DataCubeQuery;
58
+ persistentQuery?: PersistentDataCubeQuery | undefined;
59
+ dataCube?: DataCubeAPI | undefined;
60
+
61
+ constructor(
62
+ query: DataCubeQuery,
63
+ persistentQuery?: PersistentDataCubeQuery | undefined,
64
+ ) {
65
+ makeObservable(this, {
66
+ dataCube: observable,
67
+ setDataCube: action,
68
+
69
+ query: observable,
70
+ persistentQuery: observable,
71
+ setPersistentQuery: action,
72
+ });
73
+
74
+ this.query = query;
75
+ this.persistentQuery = persistentQuery;
76
+ }
77
+
78
+ setDataCube(val: DataCubeAPI | undefined) {
79
+ this.dataCube = val;
80
+ }
81
+
82
+ setPersistentQuery(val: PersistentDataCubeQuery) {
83
+ this.persistentQuery = val;
84
+ this.query = DataCubeQuery.serialization.fromJson(val.content);
85
+ this.startTime = Date.now();
86
+ }
87
+ }
88
+
89
+ export class LegendDataCubeQueryBuilderStore {
90
+ readonly application: LegendDataCubeApplicationStore;
91
+ readonly baseStore: LegendDataCubeBaseStore;
92
+ readonly engine: LegendDataCubeDataCubeEngine;
93
+ readonly depotServerClient: DepotServerClient;
94
+ readonly engineServerClient: V1_EngineServerClient;
95
+ readonly graphManager: V1_PureGraphManager;
96
+ readonly taskService: DataCubeTaskService;
97
+ readonly layoutService: DataCubeLayoutService;
98
+ readonly alertService: DataCubeAlertService;
99
+
100
+ readonly newQueryState: LegendDataCubeNewQueryState;
101
+
102
+ readonly saveQueryState = ActionState.create();
103
+ readonly saverDisplay: DisplayState;
104
+
105
+ readonly loadQueryState = ActionState.create();
106
+ loader: LegendDataCubeQueryLoaderState;
107
+ builder?: LegendDataCubeQueryBuilderState | undefined;
108
+
109
+ constructor(baseStore: LegendDataCubeBaseStore) {
110
+ makeObservable(this, {
111
+ builder: observable,
112
+ setBuilder: action,
113
+ });
114
+
115
+ this.application = baseStore.application;
116
+ this.baseStore = baseStore;
117
+ this.engine = baseStore.engine;
118
+ this.depotServerClient = baseStore.depotServerClient;
119
+ this.engineServerClient = baseStore.engineServerClient;
120
+ this.graphManager = baseStore.graphManager;
121
+ this.taskService = baseStore.taskService;
122
+ this.alertService = baseStore.alertService;
123
+ this.layoutService = baseStore.layoutService;
124
+
125
+ this.newQueryState = new LegendDataCubeNewQueryState(this);
126
+ this.loader = new LegendDataCubeQueryLoaderState(this);
127
+ this.saverDisplay = this.layoutService.newDisplay(
128
+ 'Save Query',
129
+ () => <LegendDataCubeQuerySaver />,
130
+ {
131
+ ...DEFAULT_ALERT_WINDOW_CONFIG,
132
+ height: 140,
133
+ },
134
+ );
135
+ }
136
+
137
+ setBuilder(val: LegendDataCubeQueryBuilderState | undefined) {
138
+ this.builder = val;
139
+ }
140
+
141
+ private updateWindowTitle(persistentQuery: PersistentDataCubeQuery) {
142
+ this.application.layoutService.setWindowTitle(
143
+ `\u229E ${persistentQuery.name}${this.builder ? ` - ${formatDate(new Date(this.builder.startTime), 'HH:mm:ss EEE MMM dd yyyy')}` : ''}`,
144
+ );
145
+ }
146
+
147
+ getRecentlyViewedQueries() {
148
+ const data = this.application.userDataService.getObjectValue(
149
+ LegendDataCubeUserDataKey.RECENTLY_VIEWED_QUERIES,
150
+ );
151
+ return data && Array.isArray(data) && data.every((id) => isString(id))
152
+ ? data
153
+ : [];
154
+ }
155
+
156
+ async loadQuery(queryId: string | undefined) {
157
+ if (queryId !== this.builder?.persistentQuery?.id) {
158
+ if (!queryId) {
159
+ this.setBuilder(undefined);
160
+ return;
161
+ }
162
+
163
+ this.loadQueryState.inProgress();
164
+
165
+ try {
166
+ const persistentQuery =
167
+ await this.baseStore.graphManager.getDataCubeQuery(queryId);
168
+ const query = DataCubeQuery.serialization.fromJson(
169
+ persistentQuery.content,
170
+ );
171
+ this.setBuilder(
172
+ new LegendDataCubeQueryBuilderState(query, persistentQuery),
173
+ );
174
+ this.updateWindowTitle(persistentQuery);
175
+
176
+ // update the list of stack of recently viewed queries
177
+ const recentlyViewedQueries = this.getRecentlyViewedQueries();
178
+ const idx = recentlyViewedQueries.findIndex((data) => data === queryId);
179
+ if (idx === -1) {
180
+ if (recentlyViewedQueries.length >= RECENTLY_VIEWED_QUERIES_LIMIT) {
181
+ recentlyViewedQueries.pop();
182
+ }
183
+ recentlyViewedQueries.unshift(queryId);
184
+ } else {
185
+ recentlyViewedQueries.splice(idx, 1);
186
+ recentlyViewedQueries.unshift(queryId);
187
+ }
188
+ this.application.userDataService.persistValue(
189
+ LegendDataCubeUserDataKey.RECENTLY_VIEWED_QUERIES,
190
+ recentlyViewedQueries,
191
+ );
192
+
193
+ this.loadQueryState.pass();
194
+ } catch (error) {
195
+ assertErrorThrown(error);
196
+ this.alertService.alertError(error, {
197
+ message: `Query Load Failure: ${error.message}`,
198
+ });
199
+ this.loadQueryState.fail();
200
+ }
201
+ }
202
+ }
203
+
204
+ private async generatePersistentQuery(
205
+ api: DataCubeAPI,
206
+ name: string,
207
+ existingPersistentQuery?: PersistentDataCubeQuery | undefined,
208
+ ) {
209
+ const query = await api.generateDataCubeQuery();
210
+ let persistentQuery: PersistentDataCubeQuery;
211
+ if (existingPersistentQuery) {
212
+ persistentQuery = existingPersistentQuery.clone();
213
+ } else {
214
+ persistentQuery = new PersistentDataCubeQuery();
215
+ persistentQuery.id = uuid();
216
+ }
217
+ persistentQuery.name = name;
218
+ persistentQuery.content = DataCubeQuery.serialization.toJson(query);
219
+ return persistentQuery;
220
+ }
221
+
222
+ async createQuery(name: string) {
223
+ if (!this.builder?.dataCube || this.saveQueryState.isInProgress) {
224
+ return;
225
+ }
226
+
227
+ this.saveQueryState.inProgress();
228
+ try {
229
+ const persistentQuery = await this.generatePersistentQuery(
230
+ this.builder.dataCube,
231
+ name,
232
+ );
233
+
234
+ const newQuery =
235
+ await this.baseStore.graphManager.createDataCubeQuery(persistentQuery);
236
+ // NOTE: reload is the cleanest, least bug-prone handling here
237
+ // but we can opt for just updating the URL to reflect the new query
238
+ // as an optimization. Also, it helps preserve the edition history
239
+ // on the existing data-cube.
240
+ //
241
+ // Another way to avoid reloading the whole app it to force update
242
+ // the <DataCube/> component using the key prop that ties to an ID
243
+ // of the builder.
244
+ this.application.navigationService.navigator.updateCurrentLocation(
245
+ generateQueryBuilderRoute(newQuery.id),
246
+ );
247
+ this.builder.setPersistentQuery(persistentQuery);
248
+ this.updateWindowTitle(persistentQuery);
249
+
250
+ this.saverDisplay.close();
251
+ this.saveQueryState.pass();
252
+ } catch (error) {
253
+ assertErrorThrown(error);
254
+ this.alertService.alertError(error, {
255
+ message: `Query Creation Failure: ${error.message}`,
256
+ });
257
+ this.saveQueryState.fail();
258
+ }
259
+ }
260
+
261
+ async saveQuery(name: string, saveAsNewQuery: boolean) {
262
+ if (!this.builder?.dataCube || this.saveQueryState.isInProgress) {
263
+ return;
264
+ }
265
+
266
+ this.saveQueryState.inProgress();
267
+ try {
268
+ const persistentQuery = await this.generatePersistentQuery(
269
+ this.builder.dataCube,
270
+ name,
271
+ this.builder.persistentQuery,
272
+ );
273
+
274
+ if (saveAsNewQuery) {
275
+ persistentQuery.id = uuid();
276
+ const newQuery =
277
+ await this.baseStore.graphManager.createDataCubeQuery(
278
+ persistentQuery,
279
+ );
280
+ // NOTE: reload is the cleanest, least bug-prone handling here
281
+ // but we can opt for just updating the URL to reflect the new query
282
+ // as an optimization. Also, it helps preserve the edition history
283
+ // on the existing data-cube.
284
+ //
285
+ // Another way to avoid reloading the whole app it to force update
286
+ // the <DataCube/> component using the key prop that ties to an ID
287
+ // of the builder.
288
+ this.application.navigationService.navigator.updateCurrentLocation(
289
+ generateQueryBuilderRoute(newQuery.id),
290
+ );
291
+ } else {
292
+ await this.baseStore.graphManager.updateDataCubeQuery(persistentQuery);
293
+ }
294
+ this.builder.setPersistentQuery(persistentQuery);
295
+ this.updateWindowTitle(persistentQuery);
296
+
297
+ this.saverDisplay.close();
298
+ this.saveQueryState.pass();
299
+ } catch (error) {
300
+ assertErrorThrown(error);
301
+ this.alertService.alertError(error, {
302
+ message: `Query Update Failure: ${error.message}`,
303
+ });
304
+ this.saveQueryState.fail();
305
+ }
306
+ }
307
+ }
@@ -0,0 +1,260 @@
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
+ APPLICATION_EVENT,
19
+ DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH,
20
+ type GenericLegendApplicationStore,
21
+ } from '@finos/legend-application';
22
+ import {
23
+ type LightPersistentDataCubeQuery,
24
+ QuerySearchSpecification,
25
+ QuerySearchSortBy,
26
+ type V1_PureGraphManager,
27
+ } from '@finos/legend-graph';
28
+ import { ActionState, assertErrorThrown, LogEvent } from '@finos/legend-shared';
29
+ import { makeObservable, observable, action } from 'mobx';
30
+ import type { LegendDataCubeQueryBuilderStore } from './LegendDataCubeQueryBuilderStore.js';
31
+ import { LegendDataCubeUserDataKey } from '../../__lib__/LegendDataCubeUserData.js';
32
+ import {
33
+ type DataCubeAlertService,
34
+ DEFAULT_TOOL_PANEL_WINDOW_CONFIG,
35
+ type DisplayState,
36
+ } from '@finos/legend-data-cube';
37
+ import { LegendDataCubeQueryLoader } from '../../components/query-builder/LegendDataCubeQueryLoader.js';
38
+ import { generateQueryBuilderRoute } from '../../__lib__/LegendDataCubeNavigation.js';
39
+
40
+ export const DATA_CUBE_QUERY_LOADER_TYPEAHEAD_SEARCH_LIMIT = 50;
41
+ export const DATA_CUBE_QUERY_LOADER_DEFAULT_QUERY_SEARCH_LIMIT = 10;
42
+
43
+ export enum DataCubeQuerySortByType {
44
+ LAST_CREATED = 'Last Created',
45
+ LAST_VIEWED = 'Last Viewed',
46
+ LAST_UPDATED = 'Last Updated',
47
+ }
48
+
49
+ export class LegendDataCubeQueryLoaderState {
50
+ private readonly _application: GenericLegendApplicationStore;
51
+ private readonly _store: LegendDataCubeQueryBuilderStore;
52
+ private readonly _graphManager: V1_PureGraphManager;
53
+ private readonly _alertService: DataCubeAlertService;
54
+
55
+ readonly display: DisplayState;
56
+ readonly searchState = ActionState.create();
57
+ readonly finalizeState = ActionState.create();
58
+
59
+ queries: LightPersistentDataCubeQuery[] = [];
60
+ selectedQuery?: LightPersistentDataCubeQuery | undefined;
61
+
62
+ searchText = '';
63
+ showCurrentUserQueriesOnly = false;
64
+ showingDefaultQueries = true;
65
+ sortBy = DataCubeQuerySortByType.LAST_VIEWED;
66
+
67
+ constructor(store: LegendDataCubeQueryBuilderStore) {
68
+ makeObservable(this, {
69
+ showingDefaultQueries: observable,
70
+ setShowingDefaultQueries: action,
71
+
72
+ searchText: observable,
73
+ setSearchText: action,
74
+
75
+ queries: observable,
76
+ setQueries: action,
77
+
78
+ showCurrentUserQueriesOnly: observable,
79
+ setShowCurrentUserQueriesOnly: action,
80
+
81
+ sortBy: observable,
82
+ setSortBy: action,
83
+
84
+ selectedQuery: observable,
85
+ setSelectedQuery: action,
86
+ });
87
+
88
+ this._application = store.application;
89
+ this._store = store;
90
+ this._graphManager = store.graphManager;
91
+ this._alertService = store.alertService;
92
+
93
+ this.display = store.layoutService.newDisplay(
94
+ 'Load Query',
95
+ () => <LegendDataCubeQueryLoader />,
96
+ {
97
+ ...DEFAULT_TOOL_PANEL_WINDOW_CONFIG,
98
+ width: 500,
99
+ minWidth: 500,
100
+ },
101
+ );
102
+ }
103
+
104
+ setSearchText(val: string) {
105
+ this.searchText = val;
106
+ }
107
+
108
+ setQueries(val: LightPersistentDataCubeQuery[]) {
109
+ this.queries = val;
110
+ }
111
+
112
+ setShowingDefaultQueries(val: boolean) {
113
+ this.showingDefaultQueries = val;
114
+ }
115
+
116
+ setShowCurrentUserQueriesOnly(val: boolean): void {
117
+ this.showCurrentUserQueriesOnly = val;
118
+ }
119
+
120
+ setSortBy(val: DataCubeQuerySortByType) {
121
+ this.sortBy = val;
122
+ }
123
+
124
+ private getQuerySearchSortBy(sortByValue: string) {
125
+ switch (sortByValue) {
126
+ case DataCubeQuerySortByType.LAST_CREATED:
127
+ return QuerySearchSortBy.SORT_BY_CREATE;
128
+ case DataCubeQuerySortByType.LAST_UPDATED:
129
+ return QuerySearchSortBy.SORT_BY_UPDATE;
130
+ case DataCubeQuerySortByType.LAST_VIEWED:
131
+ return QuerySearchSortBy.SORT_BY_VIEW;
132
+ default:
133
+ return undefined;
134
+ }
135
+ }
136
+
137
+ setSelectedQuery(query: LightPersistentDataCubeQuery | undefined) {
138
+ this.selectedQuery = query;
139
+ }
140
+
141
+ canPerformAdvancedSearch(searchText: string) {
142
+ return !(
143
+ searchText.length < DEFAULT_TYPEAHEAD_SEARCH_MINIMUM_SEARCH_LENGTH &&
144
+ !this.showCurrentUserQueriesOnly
145
+ );
146
+ }
147
+
148
+ async searchQueries(searchText: string) {
149
+ // for the initial search, i.e. no search config is specified, fetch the default queries if possible
150
+ if (!this.canPerformAdvancedSearch(searchText)) {
151
+ if (!searchText) {
152
+ this.setShowingDefaultQueries(true);
153
+ this.searchState.inProgress();
154
+ this.setQueries([]);
155
+ let defaultQueries: LightPersistentDataCubeQuery[] = [];
156
+ try {
157
+ // first, try to fetch recently viewed queries
158
+ try {
159
+ const recentlyViewedQueryIDs =
160
+ this._store.getRecentlyViewedQueries();
161
+ if (recentlyViewedQueryIDs.length) {
162
+ defaultQueries = await this._graphManager.getDataCubeQueries(
163
+ recentlyViewedQueryIDs,
164
+ );
165
+ }
166
+ } catch (error) {
167
+ assertErrorThrown(error);
168
+ // if there's an error fetching recently viewed queries, most likely because
169
+ // some queries have been removed, just remove them all from the cached user data
170
+ this._application.userDataService.persistValue(
171
+ LegendDataCubeUserDataKey.RECENTLY_VIEWED_QUERIES,
172
+ undefined,
173
+ );
174
+ }
175
+ // if there's no recently viewed queries, just fetch queries of the current user
176
+ if (!defaultQueries.length) {
177
+ const searchSpecification = new QuerySearchSpecification();
178
+ searchSpecification.limit =
179
+ DATA_CUBE_QUERY_LOADER_DEFAULT_QUERY_SEARCH_LIMIT;
180
+ searchSpecification.showCurrentUserQueriesOnly = true;
181
+ defaultQueries =
182
+ await this._graphManager.searchDataCubeQueries(
183
+ searchSpecification,
184
+ );
185
+ }
186
+ this.setQueries(defaultQueries);
187
+ this.searchState.pass();
188
+ } catch (error) {
189
+ assertErrorThrown(error);
190
+ this._application.logService.error(
191
+ LogEvent.create(APPLICATION_EVENT.GENERIC_FAILURE),
192
+ error,
193
+ );
194
+ this.searchState.fail();
195
+ }
196
+ }
197
+ return;
198
+ }
199
+
200
+ this.setShowingDefaultQueries(false);
201
+ this.searchState.inProgress();
202
+
203
+ try {
204
+ const searchSpecification =
205
+ QuerySearchSpecification.createDefault(searchText);
206
+ searchSpecification.limit =
207
+ DATA_CUBE_QUERY_LOADER_TYPEAHEAD_SEARCH_LIMIT + 1;
208
+ searchSpecification.showCurrentUserQueriesOnly =
209
+ this.showCurrentUserQueriesOnly;
210
+ const querySearchSortBy = this.getQuerySearchSortBy(this.sortBy);
211
+ if (querySearchSortBy) {
212
+ searchSpecification.sortByOption = querySearchSortBy;
213
+ }
214
+ this.setQueries(
215
+ await this._graphManager.searchDataCubeQueries(searchSpecification),
216
+ );
217
+
218
+ // if sorting is not configured, sort by name
219
+ if (!querySearchSortBy) {
220
+ this.setQueries(
221
+ this.queries.toSorted((a, b) => a.name.localeCompare(b.name)),
222
+ );
223
+ }
224
+
225
+ this.searchState.pass();
226
+ } catch (error) {
227
+ assertErrorThrown(error);
228
+ this._alertService.alertError(error, {
229
+ message: `Query Search Failure: ${error.message}`,
230
+ });
231
+ this.searchState.fail();
232
+ }
233
+ }
234
+
235
+ async finalize() {
236
+ if (!this.selectedQuery) {
237
+ return;
238
+ }
239
+
240
+ this.finalizeState.inProgress();
241
+ try {
242
+ // just simply change the route here and the new query ID will get picked up
243
+ // and handled by the query builder to load the new query.
244
+ this._application.navigationService.navigator.updateCurrentLocation(
245
+ generateQueryBuilderRoute(this.selectedQuery.id),
246
+ );
247
+
248
+ // reset
249
+ this.setSelectedQuery(undefined);
250
+ this.display.close();
251
+ this.finalizeState.pass();
252
+ } catch (error) {
253
+ assertErrorThrown(error);
254
+ this._alertService.alertError(error, {
255
+ message: `Query Load Failure: ${error.message}`,
256
+ });
257
+ this.finalizeState.fail();
258
+ }
259
+ }
260
+ }
@@ -14,15 +14,22 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import type { DataCubeEngine } from '@finos/legend-data-cube';
18
- import type { DataCubeGenericSource } from '../model/DataCubeGenericSource.js';
17
+ import { type PlainObject } from '@finos/legend-shared';
18
+ import {
19
+ LegendDataCubeSourceBuilderState,
20
+ LegendDataCubeSourceBuilderType,
21
+ } from './LegendDataCubeSourceBuilderState.js';
19
22
 
20
- export class LegendCubeViewer {
21
- source: DataCubeGenericSource;
22
- engine: DataCubeEngine;
23
+ export class AdhocQueryDataCubeSourceBuilderState extends LegendDataCubeSourceBuilderState {
24
+ override get label(): LegendDataCubeSourceBuilderType {
25
+ return LegendDataCubeSourceBuilderType.ADHOC_QUERY;
26
+ }
27
+
28
+ override get isValid(): boolean {
29
+ return false;
30
+ }
23
31
 
24
- constructor(source: DataCubeGenericSource, engine: DataCubeEngine) {
25
- this.source = source;
26
- this.engine = engine;
32
+ override build(): Promise<PlainObject> {
33
+ throw new Error('Method not implemented.');
27
34
  }
28
35
  }
@@ -0,0 +1,43 @@
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 { ActionState, type PlainObject } from '@finos/legend-shared';
18
+ import type { LegendDataCubeApplicationStore } from '../../LegendDataCubeBaseStore.js';
19
+ import type { LegendDataCubeDataCubeEngine } from '../../LegendDataCubeDataCubeEngine.js';
20
+
21
+ export enum LegendDataCubeSourceBuilderType {
22
+ LEGEND_QUERY = 'Legend Query',
23
+ ADHOC_QUERY = 'Ad hoc Query',
24
+ }
25
+
26
+ export abstract class LegendDataCubeSourceBuilderState {
27
+ protected readonly _application: LegendDataCubeApplicationStore;
28
+ protected readonly _engine: LegendDataCubeDataCubeEngine;
29
+
30
+ readonly buildState = ActionState.create();
31
+
32
+ constructor(
33
+ application: LegendDataCubeApplicationStore,
34
+ engine: LegendDataCubeDataCubeEngine,
35
+ ) {
36
+ this._application = application;
37
+ this._engine = engine;
38
+ }
39
+
40
+ abstract get label(): LegendDataCubeSourceBuilderType;
41
+ abstract get isValid(): boolean;
42
+ abstract build(): Promise<PlainObject>;
43
+ }