@finos/legend-query-builder 4.14.56 → 4.14.57

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,14 @@ import type {
45
45
  export const QUERY_LOADER_TYPEAHEAD_SEARCH_LIMIT = 50;
46
46
  export const QUERY_LOADER_DEFAULT_QUERY_SEARCH_LIMIT = 10;
47
47
 
48
+ export enum SORT_BY_OPTIONS {
49
+ SORT_BY_CREATE = 'Last Created',
50
+ SORT_BY_VIEW = 'Last Viewed',
51
+ SORT_BY_UPDATE = 'Last Updated',
52
+ }
53
+
54
+ export type SortByOption = { label: string; value: string };
55
+
48
56
  export class QueryLoaderState {
49
57
  readonly applicationStore: GenericLegendApplicationStore;
50
58
  readonly graphManagerState: BasicGraphManagerState;
@@ -84,6 +92,7 @@ export class QueryLoaderState {
84
92
  showingDefaultQueries = true;
85
93
  showPreviewViewer = false;
86
94
  queryPreviewContent?: QueryInfo | { name: string; content: string };
95
+ sortBy = '';
87
96
 
88
97
  constructor(
89
98
  applicationStore: GenericLegendApplicationStore,
@@ -115,6 +124,8 @@ export class QueryLoaderState {
115
124
  searchText: observable,
116
125
  isCuratedTemplateToggled: observable,
117
126
  curatedTemplateQuerySepcifications: observable,
127
+ sortBy: observable,
128
+ setSortBy: action,
118
129
  setSearchText: action,
119
130
  setQueryLoaderDialogOpen: action,
120
131
  setQueries: action,
@@ -147,6 +158,10 @@ export class QueryLoaderState {
147
158
  this.isCuratedTemplateToggled = val;
148
159
  }
149
160
 
161
+ setSortBy(val: string): void {
162
+ this.sortBy = val;
163
+ }
164
+
150
165
  setSearchText(val: string): void {
151
166
  this.searchText = val;
152
167
  }
@@ -156,7 +171,7 @@ export class QueryLoaderState {
156
171
  }
157
172
 
158
173
  setQueries(val: LightQuery[]): void {
159
- this.queries = val;
174
+ this.queries = val.sort((a, b) => a.name.localeCompare(b.name));
160
175
  }
161
176
 
162
177
  setShowPreviewViewer(val: boolean): void {
@@ -225,7 +240,9 @@ export class QueryLoaderState {
225
240
  if (!this.fetchDefaultQueries) {
226
241
  return;
227
242
  }
228
- this.queries = (yield this.fetchDefaultQueries()) as LightQuery[];
243
+ this.queries = (
244
+ (yield this.fetchDefaultQueries()) as LightQuery[]
245
+ ).sort((a, b) => a.name.localeCompare(b.name));
229
246
  this.searchQueriesState.pass();
230
247
  } catch (error) {
231
248
  this.searchQueriesState.fail();
@@ -271,9 +288,11 @@ export class QueryLoaderState {
271
288
  searchSpecification =
272
289
  this.decorateSearchSpecification?.(searchSpecification) ??
273
290
  searchSpecification;
274
- this.queries = (yield this.graphManagerState.graphManager.searchQueries(
275
- searchSpecification,
276
- )) as LightQuery[];
291
+ this.queries = (
292
+ (yield this.graphManagerState.graphManager.searchQueries(
293
+ searchSpecification,
294
+ )) as LightQuery[]
295
+ ).sort((a, b) => a.name.localeCompare(b.name));
277
296
  this.searchQueriesState.pass();
278
297
  } catch (error) {
279
298
  assertErrorThrown(error);