@dataloop-ai/components 0.18.122 → 0.18.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.18.122",
3
+ "version": "0.18.124",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -64,7 +64,8 @@
64
64
  </div>
65
65
  <dl-smart-search-json-editor-dialog
66
66
  v-model="showJSONEditor"
67
- :json="stringifiedJSON"
67
+ :json="modelValue"
68
+ :options="selectOptions"
68
69
  @search="handleJSONSearch"
69
70
  @change="handleJSONChange"
70
71
  />
@@ -75,7 +76,7 @@ import { defineComponent, PropType, ref, computed, toRefs } from 'vue-demi'
75
76
  import { DlButton } from '../../../basic'
76
77
  import { DlSmartSearchInput, DlSmartSearchJsonEditorDialog } from './components'
77
78
  import { Schema, Alias } from '../../../../hooks/use-suggestions'
78
- import { Filters, ColorSchema, SearchStatus } from './types'
79
+ import { ColorSchema, SearchStatus, DlSmartSearchFilter } from './types'
79
80
  import { v4 } from 'uuid'
80
81
  import { stateManager } from '../../../../StateManager'
81
82
 
@@ -115,8 +116,8 @@ export default defineComponent({
115
116
  })
116
117
  },
117
118
  filters: {
118
- type: Object as PropType<Filters>,
119
- default: () => ({} as Filters)
119
+ type: Array as PropType<DlSmartSearchFilter[]>,
120
+ default: () => [] as DlSmartSearchFilter[]
120
121
  },
121
122
  disabled: {
122
123
  type: Boolean,
@@ -179,8 +180,6 @@ export default defineComponent({
179
180
  //#endregion
180
181
 
181
182
  //#region computed
182
- const stringifiedJSON = computed(() => JSON.stringify(modelValue.value))
183
-
184
183
  const cssVars = computed(() => ({
185
184
  '--dl-smart-search-max-width': isFocused.value
186
185
  ? '100%'
@@ -196,24 +195,9 @@ export default defineComponent({
196
195
  }
197
196
  })
198
197
 
199
- const selectedOptions = computed(() => {
200
- const options: Record<string, string>[] = [
201
- {
202
- label: 'New Query',
203
- value: '{}'
204
- }
205
- ]
206
-
207
- const queryFilters = filters.value?.saved ?? []
208
- for (const filter of queryFilters) {
209
- options.push({
210
- label: filter.name,
211
- value: filter.query
212
- })
213
- }
214
-
215
- return options
216
- })
198
+ const selectOptions = computed<DlSmartSearchFilter[]>(
199
+ () => filters.value ?? []
200
+ )
217
201
  //#endregion
218
202
 
219
203
  //#region methods
@@ -271,10 +255,9 @@ export default defineComponent({
271
255
  preventUpdate,
272
256
  selectedOption,
273
257
  cssVars,
274
- selectedOptions,
258
+ selectOptions,
275
259
  emitSearchQuery,
276
260
  showJSONEditor,
277
- stringifiedJSON,
278
261
  handleJSONSearch,
279
262
  handleJSONChange
280
263
  }
@@ -1,5 +1,4 @@
1
1
  <template>
2
- <!-- todo: Add support for saved queries-->
3
2
  <div>
4
3
  <dl-dialog-box
5
4
  v-model="isOpen"
@@ -21,10 +20,9 @@
21
20
  style="margin-bottom: 10px"
22
21
  >
23
22
  <dl-select
24
- disabled
25
23
  :model-value="selectedOption"
26
24
  width="200px"
27
- :options="options"
25
+ :options="selectOptions"
28
26
  placeholder="New Query"
29
27
  @update:model-value="onQuerySelect"
30
28
  />
@@ -48,7 +46,7 @@
48
46
  <template #footer>
49
47
  <div class="json-editor-footer">
50
48
  <dl-button
51
- :disabled="true || canDelete"
49
+ :disabled="!hasActiveFilter"
52
50
  icon="icon-dl-delete"
53
51
  label="Delete Query"
54
52
  flat
@@ -58,15 +56,18 @@
58
56
  />
59
57
  <div class="json-editor-footer-actions">
60
58
  <dl-button
61
- disabled
62
59
  style="margin-right: 14px"
63
60
  outlined
64
61
  label="Save As"
65
62
  @click="showSaveDialog = true"
66
63
  />
67
64
  <dl-button
68
- label="Search"
69
- @click="search"
65
+ :label="
66
+ hasActiveFilter ? 'Save & Search' : 'Search'
67
+ "
68
+ @click="
69
+ () => (hasActiveFilter ? saveQuery() : search())
70
+ "
70
71
  />
71
72
  </div>
72
73
  </div>
@@ -97,6 +98,7 @@
97
98
  <dl-button
98
99
  :disabled="!newQueryName"
99
100
  outlined
101
+ style="margin-right: 5px"
100
102
  @click="saveQuery"
101
103
  >
102
104
  Save
@@ -124,7 +126,8 @@
124
126
  size="h3"
125
127
  style="display: flex; justify-content: center"
126
128
  >
127
- Are you sure you want to delete {{ selectedOption.label }}?
129
+ Are you sure you want to delete
130
+ {{ selectedOption.label }}?
128
131
  </dl-typography>
129
132
  </template>
130
133
  <template #footer>
@@ -146,8 +149,6 @@ import {
146
149
  toRefs,
147
150
  computed,
148
151
  nextTick,
149
- onMounted,
150
- getCurrentInstance,
151
152
  watch
152
153
  } from 'vue-demi'
153
154
  import { DlSelect } from '../../../DlSelect'
@@ -158,8 +159,8 @@ import { DlJsonEditor } from '../../../DlJsonEditor'
158
159
  import { DlTypography } from '../../../../essential'
159
160
  import { DlInput } from '../../../DlInput'
160
161
  import { stateManager } from '../../../../../StateManager'
161
- import { isEqual } from 'lodash'
162
- import { registerToWindow } from '../../../../../utils'
162
+ import { cloneDeep, isEqual, uniqBy } from 'lodash'
163
+ import { DlSmartSearchFilter } from '../types'
163
164
 
164
165
  export default defineComponent({
165
166
  components: {
@@ -183,44 +184,105 @@ export default defineComponent({
183
184
  },
184
185
  json: {
185
186
  required: true,
186
- type: String
187
+ type: Object as PropType<Record<string, any>>
187
188
  },
188
189
  options: {
189
190
  required: false,
190
191
  type: Array as PropType<DlSelectOption[]>,
191
192
  default: () => [] as DlSelectOption[]
193
+ },
194
+ selectedFilter: {
195
+ required: false,
196
+ type: String,
197
+ default: null
192
198
  }
193
199
  },
194
- emits: ['update:modelValue', 'search', 'change', 'update:options'],
200
+ emits: [
201
+ 'update:modelValue',
202
+ 'search',
203
+ 'change',
204
+ 'update:options',
205
+ 'save',
206
+ 'delete',
207
+ 'select'
208
+ ],
195
209
  setup(props, { emit }) {
196
- const { modelValue, options, json } = toRefs(props)
210
+ const { modelValue, options, json, selectedFilter } = toRefs(props)
197
211
 
198
212
  const isOpen = computed({
199
213
  get: () => modelValue.value,
200
214
  set: (val) => emit('update:modelValue', val)
201
215
  })
202
216
 
217
+ const currentQuery = ref<{ [key: string]: any }>(cloneDeep(json.value))
203
218
  const jsonEditor = ref<any>(null)
204
219
  const showSaveDialog = ref(false)
205
220
  const showDeleteDialog = ref(false)
206
- const stringifiedJSON = ref(json.value)
207
221
  const newQueryName = ref('')
222
+
223
+ const selectOptions = computed<DlSelectOption[]>(() => {
224
+ return uniqBy(
225
+ [
226
+ {
227
+ label: 'New Query',
228
+ value: cloneDeep(json.value ?? {})
229
+ }
230
+ ].concat(options.value),
231
+ 'label'
232
+ )
233
+ })
208
234
  const selectedOption = ref<DlSelectOption>(
209
- options.value.find((o) => isEqual(o.value, json.value)) ?? {
235
+ options.value.find((o) => isEqual(o.value, currentQuery.value)) ?? {
210
236
  label: 'New Query',
211
- value: json.value
237
+ value: currentQuery.value
212
238
  }
213
239
  )
214
240
 
241
+ watch(
242
+ selectedFilter,
243
+ () => {
244
+ selectedOption.value = options.value.find(
245
+ (o) => o.label === selectedFilter.value
246
+ ) ?? {
247
+ label: 'New Query',
248
+ value: currentQuery.value
249
+ }
250
+
251
+ if (selectedOption.value.label !== 'New Query') {
252
+ currentQuery.value = cloneDeep(selectedOption.value.value)
253
+ }
254
+ },
255
+ { immediate: true }
256
+ )
257
+
215
258
  const alignJSON = () => {
216
- jsonEditor.value.format()
259
+ jsonEditor.value?.format()
217
260
  }
218
261
 
219
262
  const onQuerySelect = (option: DlSelectOption) => {
220
- selectedOption.value = option
221
- stringifiedJSON.value = option.value
263
+ if (option.label === selectedOption.value.label) {
264
+ return
265
+ }
266
+
267
+ selectedOption.value = cloneDeep(option)
268
+ currentQuery.value = cloneDeep(option.value)
269
+ nextTick(() => {
270
+ alignJSON()
271
+ // wtf oa ?
272
+ nextTick(() => {
273
+ alignJSON()
274
+ })
275
+ })
276
+ emit('select', option)
222
277
  }
223
278
 
279
+ const stringifiedJSON = computed<string>({
280
+ get: () => JSON.stringify(currentQuery.value),
281
+ set: (val) => {
282
+ currentQuery.value = toObject(val)
283
+ }
284
+ })
285
+
224
286
  const toObject = (json: string) => {
225
287
  try {
226
288
  return JSON.parse(json)
@@ -231,9 +293,8 @@ export default defineComponent({
231
293
  }
232
294
 
233
295
  const search = () => {
234
- const parsed = toObject(stringifiedJSON.value)
235
- if (!parsed) return
236
- emit('search', parsed)
296
+ if (!currentQuery.value) return
297
+ emit('search', currentQuery.value)
237
298
  isOpen.value = false
238
299
  }
239
300
 
@@ -244,16 +305,23 @@ export default defineComponent({
244
305
  }
245
306
 
246
307
  const saveQuery = (searchAfterSave = false) => {
247
- const newOptions = options.value.concat([
248
- {
249
- label: newQueryName.value,
250
- value: stringifiedJSON.value
251
- }
252
- ])
308
+ let toSave: DlSmartSearchFilter = hasActiveFilter.value
309
+ ? selectedOption.value
310
+ : ({} as DlSmartSearchFilter)
311
+ toSave = Object.assign({}, toSave, {
312
+ label: hasActiveFilter.value
313
+ ? selectedOption.value.label
314
+ : newQueryName.value,
315
+ value: currentQuery.value
316
+ })
317
+
318
+ const newOptions = options.value.concat([toSave])
253
319
 
320
+ emit('save', toSave)
254
321
  emit('update:options', newOptions)
255
322
 
256
323
  showSaveDialog.value = false
324
+ newQueryName.value = ''
257
325
  nextTick(() => {
258
326
  if (searchAfterSave) {
259
327
  search()
@@ -261,25 +329,38 @@ export default defineComponent({
261
329
  })
262
330
  }
263
331
 
264
- const canDelete = computed(
332
+ const hasActiveFilter = computed(
265
333
  () => selectedOption.value.label !== 'New Query'
266
334
  )
267
335
 
268
336
  const deleteQuery = () => {
337
+ const toDelete = options.value.find(
338
+ (o: DlSelectOption) => o.label === selectedOption.value.label
339
+ )
269
340
  const newOptions = options.value.filter(
270
- (o: DlSelectOption) => o.value !== selectedOption.value.label
341
+ (o: DlSelectOption) => o.label !== selectedOption.value.label
271
342
  )
272
343
 
344
+ emit('delete', toDelete)
273
345
  emit('update:options', newOptions)
274
346
  selectedOption.value = {
275
347
  label: 'New Query',
276
- value: '{}'
348
+ value: {}
277
349
  }
350
+ currentQuery.value = {}
278
351
  showDeleteDialog.value = false
279
352
  }
280
353
 
281
354
  watch(json, () => {
282
- stringifiedJSON.value = json.value
355
+ currentQuery.value = cloneDeep(json.value)
356
+ nextTick(() => {
357
+ alignJSON()
358
+ })
359
+ })
360
+ watch(isOpen, () => {
361
+ nextTick(() => {
362
+ alignJSON()
363
+ })
283
364
  })
284
365
 
285
366
  return {
@@ -288,11 +369,12 @@ export default defineComponent({
288
369
  showSaveDialog,
289
370
  stringifiedJSON,
290
371
  selectedOption,
291
- canDelete,
372
+ hasActiveFilter,
292
373
  alignJSON,
293
374
  onQuerySelect,
294
375
  newQueryName,
295
376
  showDeleteDialog,
377
+ selectOptions,
296
378
  search,
297
379
  onChange,
298
380
  saveQuery,
@@ -1,4 +1,4 @@
1
- import { DlSmartSearchInput } from './components'
1
+ import { DlSmartSearchInput, DlSmartSearchJsonEditorDialog } from './components'
2
2
  import DlSmartSearch from './DlSmartSearch.vue'
3
3
 
4
- export { DlSmartSearch, DlSmartSearchInput }
4
+ export { DlSmartSearch, DlSmartSearchInput, DlSmartSearchJsonEditorDialog }
@@ -50,12 +50,14 @@ import {
50
50
  Alias as DlSmartSearchAlias,
51
51
  Schema as DlSmartSearchSchema
52
52
  } from '../../../../hooks/use-suggestions'
53
+ import { DlSelectOption } from '../../types'
53
54
 
54
- type DlSmartSearchFilters = Filters & { [key: string]: any }
55
+ // type DlSmartSearchFilters = Filters & { [key: string]: any }
56
+ type DlSmartSearchFilter = DlSelectOption
55
57
 
56
58
  export type {
57
59
  DlSmartSearchAlias,
58
60
  DlSmartSearchSchema,
59
61
  ColorSchema as DlSmartSearchColorSchema,
60
- DlSmartSearchFilters
62
+ DlSmartSearchFilter
61
63
  }
@@ -740,10 +740,7 @@ export default defineComponent({
740
740
 
741
741
  this.selectedIndex = this.options.findIndex(
742
742
  (option: string | Record<string, string | number> | number) =>
743
- isEqual(
744
- (option as any).value,
745
- (this.modelValue as any).value
746
- )
743
+ isEqual(option, this.modelValue)
747
744
  )
748
745
  },
749
746
  getOptionValue(option: any) {
@@ -200,7 +200,7 @@ export default defineComponent({
200
200
  &__content {
201
201
  color: var(--dl-label-text-color);
202
202
  display: flex;
203
- width: 95%;
203
+ width: 100%;
204
204
  }
205
205
  &__text {
206
206
  overflow: hidden;
@@ -100,7 +100,7 @@ import {
100
100
  DlCheckbox,
101
101
  DlInput
102
102
  } from '../../components'
103
- import { DlSmartSearchFilters, Query } from '../../components/types'
103
+ import { DlSmartSearchFilter, Query } from '../../components/types'
104
104
  import { parseSmartQuery } from '../../utils'
105
105
 
106
106
  export default defineComponent({
@@ -195,29 +195,47 @@ export default defineComponent({
195
195
  key: 'metadata.system.width'
196
196
  }
197
197
  ]
198
+ const filters: DlSmartSearchFilter[] = [
199
+ {
200
+ label: 'Query 1',
201
+ value: { q: 1 }
202
+ },
203
+ {
204
+ label: 'Query 2',
205
+ value: { query2: 'query2' }
206
+ },
207
+ {
208
+ label: 'Query 3',
209
+ value: { query3: 'query3' }
210
+ },
211
+ {
212
+ label: 'Query 4',
213
+ value: { age: 12, name: 'john' }
214
+ }
215
+ ]
198
216
 
199
- const filters: DlSmartSearchFilters = {
200
- saved: [
201
- {
202
- name: 'Query 1',
203
- query: '{"q": 1}'
204
- },
205
- {
206
- name: 'Query 2',
207
- query: '{"query2": "query2"}'
208
- },
209
- {
210
- name: 'Query 3',
211
- query: '{"query3": "query3"}'
212
- },
213
- {
214
- name: 'Query 4',
215
- query: '{"age": 12, "name": "john"}'
216
- }
217
- ],
218
- recent: [],
219
- suggested: []
220
- }
217
+ // const filters: DlSmartSearchFilters = {
218
+ // saved: [
219
+ // {
220
+ // name: 'Query 1',
221
+ // query: {"q": 1}
222
+ // },
223
+ // {
224
+ // name: 'Query 2',
225
+ // query: {"query2": "query2"}
226
+ // },
227
+ // {
228
+ // name: 'Query 3',
229
+ // query: {"query3": "query3"}
230
+ // },
231
+ // {
232
+ // name: 'Query 4',
233
+ // query: {"age": 12, "name": "john"}
234
+ // }
235
+ // ],
236
+ // recent: [],
237
+ // suggested: []
238
+ // }
221
239
 
222
240
  return {
223
241
  schema,
@@ -249,27 +267,33 @@ export default defineComponent({
249
267
  this.isLoading = false
250
268
  }, 2000)
251
269
 
252
- if (this.filters.recent[-1]?.name !== queryString) {
253
- this.filters.recent.push({
254
- name: queryString || query.name,
255
- query: query.query
256
- })
257
- }
270
+ // if (this.filters.recent[-1]?.name !== queryString) {
271
+ // this.filters.recent.push({
272
+ // name: queryString || query.name,
273
+ // query: query.query
274
+ // })
275
+ // }
258
276
  },
259
- handleSaveQuery(query: Query, type: string) {
260
- const saveQueryIndex = this.filters[type].findIndex(
261
- (q: Query) => q.name === query.name || q.query === query.query
262
- )
263
- if (saveQueryIndex !== -1) {
264
- this.filters[type][saveQueryIndex] = query
265
- } else {
266
- this.filters[type].push(query)
267
- }
277
+ // handleSaveQuery(query: Query, type: string) {
278
+ // const saveQueryIndex = this.filters[type].findIndex(
279
+ // (q: Query) => q.name === query.name || q.query === query.query
280
+ // )
281
+ // if (saveQueryIndex !== -1) {
282
+ // this.filters[type][saveQueryIndex] = query
283
+ // } else {
284
+ // this.filters[type].push(query)
285
+ // }
286
+ // },
287
+ // handleRemoveQuery(query: Query, type: string) {
288
+ // this.filters[type] = this.filters[type].filter(
289
+ // (q: Query) => q.name !== query.name
290
+ // )
291
+ // },
292
+ handleSaveQuery(query: DlSmartSearchFilter) {
293
+ this.filters.push(query)
268
294
  },
269
- handleRemoveQuery(query: Query, type: string) {
270
- this.filters[type] = this.filters[type].filter(
271
- (q: Query) => q.name !== query.name
272
- )
295
+ handleRemoveQuery(query: DlSmartSearchFilter) {
296
+ this.filters = this.filters.filter((q) => q.label !== q.label)
273
297
  },
274
298
  onSearchEmitted(query: Query) {
275
299
  this.searchEmitted++