@dataloop-ai/components 0.17.80 → 0.17.82

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.17.80",
3
+ "version": "0.17.82",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -102,6 +102,8 @@ export default defineComponent({
102
102
  --jse-background-color: var(--dl-color-tooltip-text);
103
103
  --jse-value-color-boolean: #ae6307;
104
104
  --jse-value-color-string: #337433;
105
+ --jse-panel-background: var(--dl-color-fill);
106
+ --jse-panel-border: var(--dl-color-separator);
105
107
  height: 100%;
106
108
  .jse-error {
107
109
  display: none !important;
@@ -230,7 +230,7 @@ import {
230
230
  } from './utils/utils'
231
231
  import { v4 } from 'uuid'
232
232
  import { parseSmartQuery, stringifySmartQuery } from '../../../../utils'
233
- import { debounce } from 'lodash'
233
+ import { debounce, isEqual } from 'lodash'
234
234
 
235
235
  export default defineComponent({
236
236
  components: {
@@ -376,9 +376,12 @@ export default defineComponent({
376
376
  }
377
377
 
378
378
  const modelRef: any = toRef(props, 'modelValue')
379
-
380
379
  watch(modelRef, (val: any) => {
381
380
  if (val) {
381
+ const currModel = parseSmartQuery(activeQuery.value.query)
382
+ if (isEqual(val, currModel)) {
383
+ return
384
+ }
382
385
  const stringQuery = stringifySmartQuery(val)
383
386
  debouncedInputModel(stringQuery)
384
387
  }
@@ -26,7 +26,7 @@
26
26
  />
27
27
  </template>
28
28
  <template #body>
29
- <div style="height: 200px">
29
+ <div style="height: 350px">
30
30
  <dl-json-editor v-model="dialogJsonModel" />
31
31
  </div>
32
32
  </template>
@@ -12,6 +12,12 @@
12
12
  label="Strict"
13
13
  />
14
14
  </div>
15
+ <dl-input
16
+ v-model="textQuery"
17
+ style="width: 220px"
18
+ placeholder="Select option"
19
+ size="m"
20
+ />
15
21
  <div
16
22
  style="width: 100px"
17
23
  class="props"
@@ -35,14 +41,16 @@
35
41
 
36
42
  <script lang="ts">
37
43
  import { defineComponent } from 'vue-demi'
38
- import { DlSmartSearch, DlCheckbox } from '../../components'
44
+ import { DlSmartSearch, DlCheckbox, DlInput } from '../../components'
39
45
  import { Query } from '../../components/types'
46
+ import { parseSmartQuery } from '../../utils'
40
47
 
41
48
  export default defineComponent({
42
49
  name: 'DlSmartSearchDemo',
43
50
  components: {
44
51
  DlSmartSearch,
45
- DlCheckbox
52
+ DlCheckbox,
53
+ DlInput
46
54
  },
47
55
  data() {
48
56
  const schema: any = {
@@ -98,6 +106,7 @@ export default defineComponent({
98
106
  strictState: false,
99
107
  isLoading: false,
100
108
  queryObject: {},
109
+ textQuery: '',
101
110
  filters: {
102
111
  saved: [
103
112
  {
@@ -122,6 +131,11 @@ export default defineComponent({
122
131
  } as { [key: string]: Query[] }
123
132
  }
124
133
  },
134
+ watch: {
135
+ textQuery(query: string) {
136
+ this.queryObject = parseSmartQuery(query)
137
+ }
138
+ },
125
139
  methods: {
126
140
  handleSearchQuery(query: Query, queryString: string) {
127
141
  this.isLoading = true
@@ -150,6 +150,14 @@ export const useSuggestions = (
150
150
  continue
151
151
  }
152
152
 
153
+ if (operator && (!value || value === '')) {
154
+ const valueSuggestion = getValueSuggestions(dataType, operator)
155
+ if (valueSuggestion) {
156
+ localSuggestions = valueSuggestion
157
+ continue
158
+ }
159
+ }
160
+
153
161
  const ops: string[] = Array.isArray(dataType)
154
162
  ? getGenericOperators()
155
163
  : getOperatorByDataType(dataType)
@@ -480,3 +488,37 @@ export const removeBrackets = (str: string) => {
480
488
  const removeQuotes = (str: string) => {
481
489
  return str.replaceAll('"', '').replaceAll("'", '')
482
490
  }
491
+
492
+ const getValueSuggestions = (dataType: string | string[], operator: string) => {
493
+ const types: string[] = Array.isArray(dataType) ? dataType : [dataType]
494
+ const suggestion: string[] = []
495
+
496
+ if (Array.isArray(dataType)) {
497
+ suggestion.push(
498
+ ...dataType.filter((type) => !knownDataTypes.includes(type))
499
+ )
500
+ }
501
+
502
+ for (const type of types) {
503
+ switch (type) {
504
+ case 'boolean':
505
+ if (operator === '=' || operator === '!=') {
506
+ suggestion.push('true', 'false')
507
+ }
508
+ break
509
+ case 'date':
510
+ case 'time':
511
+ case 'datetime':
512
+ suggestion.push(
513
+ dateIntervalSuggestionString,
514
+ dateStartSuggestionString,
515
+ dateEndSuggestionString
516
+ )
517
+ default:
518
+ // do nothing
519
+ break
520
+ }
521
+ }
522
+
523
+ return suggestion
524
+ }
@@ -3,6 +3,10 @@
3
3
  import { isBoolean, isFinite, isNumber, isObject, isString } from 'lodash'
4
4
 
5
5
  const GeneratePureValue = (value: any) => {
6
+ if (value === '') {
7
+ return null
8
+ }
9
+
6
10
  if (typeof value === 'string') {
7
11
  if (value === 'true') {
8
12
  return true
@@ -40,32 +44,59 @@ export const parseSmartQuery = (query: string) => {
40
44
 
41
45
  let key: string
42
46
  let value: string | number | object
47
+ let pureValue:
48
+ | string
49
+ | number
50
+ | object
51
+ | boolean
52
+ | null
53
+ | (string | number | object | boolean)[]
43
54
 
44
55
  for (const term of andTerms) {
56
+ pureValue = null
57
+
45
58
  switch (true) {
46
59
  case term.includes('>='):
47
60
  [key, value] = term.split('>=').map((x) => x.trim())
48
- andQuery[key] = { $gte: GeneratePureValue(value) }
61
+ pureValue = GeneratePureValue(value)
62
+ if (pureValue) {
63
+ andQuery[key] = { $gte: pureValue }
64
+ }
49
65
  break
50
66
  case term.includes('<='):
51
67
  [key, value] = term.split('<=').map((x) => x.trim())
52
- andQuery[key] = { $lte: GeneratePureValue(value) }
68
+ pureValue = GeneratePureValue(value)
69
+ if (pureValue) {
70
+ andQuery[key] = { $lte: pureValue }
71
+ }
53
72
  break
54
73
  case term.includes('>'):
55
74
  [key, value] = term.split('>').map((x) => x.trim())
56
- andQuery[key] = { $gt: GeneratePureValue(value) }
75
+ pureValue = GeneratePureValue(value)
76
+ if (pureValue) {
77
+ andQuery[key] = { $gt: pureValue }
78
+ }
57
79
  break
58
80
  case term.includes('<'):
59
81
  [key, value] = term.split('<').map((x) => x.trim())
60
- andQuery[key] = { $lt: GeneratePureValue(value) }
82
+ pureValue = GeneratePureValue(value)
83
+ if (pureValue) {
84
+ andQuery[key] = { $lt: pureValue }
85
+ }
61
86
  break
62
87
  case term.includes('!='):
63
88
  [key, value] = term.split('!=').map((x) => x.trim())
64
- andQuery[key] = { $ne: GeneratePureValue(value) }
89
+ pureValue = GeneratePureValue(value)
90
+ if (pureValue) {
91
+ andQuery[key] = { $ne: pureValue }
92
+ }
65
93
  break
66
94
  case term.includes('='):
67
95
  [key, value] = term.split('=').map((x) => x.trim())
68
- andQuery[key] = GeneratePureValue(value)
96
+ pureValue = GeneratePureValue(value)
97
+ if (pureValue) {
98
+ andQuery[key] = pureValue
99
+ }
69
100
  break
70
101
  case term.includes('IN'):
71
102
  [key, value] = term.split('IN').map((x) => x.trim())
@@ -78,14 +109,24 @@ export const parseSmartQuery = (query: string) => {
78
109
  .map((x) => x.trim())[1]
79
110
  .split(',')
80
111
  .map((x) => GeneratePureValue(x.trim()))
81
- andQuery[key] = { $nin: GeneratePureValue(queryValue) }
112
+ .filter((x) => x)
113
+
114
+ pureValue = GeneratePureValue(queryValue)
115
+ if (pureValue && Array.isArray(pureValue)) {
116
+ andQuery[key] = { $nin: pureValue }
117
+ }
82
118
  } else {
83
119
  queryValue = term
84
120
  .split('IN')
85
121
  .map((x) => x.trim())[1]
86
122
  .split(',')
87
123
  .map((x) => GeneratePureValue(x.trim()))
88
- andQuery[key] = { $in: GeneratePureValue(queryValue) }
124
+ .filter((x) => x)
125
+
126
+ pureValue = GeneratePureValue(queryValue)
127
+ if (pureValue && Array.isArray(pureValue)) {
128
+ andQuery[key] = { $in: pureValue }
129
+ }
89
130
  }
90
131
  break
91
132
  }