@dataloop-ai/components 0.19.106 → 0.19.108
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 +1 -1
- package/src/components/compound/DlSearches/DlSmartSearch/components/DlSmartSearchInput.vue +9 -3
- package/src/components/compound/DlSearches/DlSmartSearch/utils/index.ts +57 -0
- package/src/demos/SmartSearchDemo/DlSmartSearchDemo.vue +7 -0
- package/src/hooks/use-suggestions.ts +43 -15
package/package.json
CHANGED
|
@@ -124,7 +124,9 @@ import {
|
|
|
124
124
|
replaceJSDatesWithStringifiedDates,
|
|
125
125
|
replaceStringifiedDatesWithJSDates,
|
|
126
126
|
setAliases,
|
|
127
|
-
revertAliases
|
|
127
|
+
revertAliases,
|
|
128
|
+
setValueAliases,
|
|
129
|
+
revertValueAliases
|
|
128
130
|
} from '../utils'
|
|
129
131
|
import { v4 } from 'uuid'
|
|
130
132
|
import {
|
|
@@ -569,7 +571,9 @@ export default defineComponent({
|
|
|
569
571
|
const replacedDate = replaceStringifiedDatesWithJSDates(value)
|
|
570
572
|
const json = parseSmartQuery(replacedDate ?? searchQuery.value)
|
|
571
573
|
|
|
572
|
-
return isValidJSON(json)
|
|
574
|
+
return isValidJSON(json)
|
|
575
|
+
? revertValueAliases(json, schema.value)
|
|
576
|
+
: searchQuery.value
|
|
573
577
|
}
|
|
574
578
|
|
|
575
579
|
const fromJSON = (value: { [key: string]: any }) => {
|
|
@@ -579,7 +583,9 @@ export default defineComponent({
|
|
|
579
583
|
dateKeys.value
|
|
580
584
|
)
|
|
581
585
|
|
|
582
|
-
const stringQuery = stringifySmartQuery(
|
|
586
|
+
const stringQuery = stringifySmartQuery(
|
|
587
|
+
setValueAliases(replacedDate, schema.value)
|
|
588
|
+
)
|
|
583
589
|
const aliased = setAliases(stringQuery, aliases.value)
|
|
584
590
|
return aliased
|
|
585
591
|
} catch (e) {
|
|
@@ -5,6 +5,7 @@ import { ColorSchema, SyntaxColorSchema, Filters } from '../types'
|
|
|
5
5
|
import {
|
|
6
6
|
operators,
|
|
7
7
|
Alias,
|
|
8
|
+
Data,
|
|
8
9
|
datePattern,
|
|
9
10
|
datePatternNoBrackets,
|
|
10
11
|
removeBrackets
|
|
@@ -187,6 +188,62 @@ export function setAliases(str: string, aliases: Alias[]) {
|
|
|
187
188
|
return str.replace(regex, replacement)
|
|
188
189
|
}
|
|
189
190
|
|
|
191
|
+
function valueAliases(schema: Data, field: string) {
|
|
192
|
+
let aliases: Data = {}
|
|
193
|
+
const type: any = schema[field]
|
|
194
|
+
if (Array.isArray(type)) {
|
|
195
|
+
for (const element of type) {
|
|
196
|
+
if (typeof element === 'object')
|
|
197
|
+
aliases = Object.assign(aliases, element)
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
if (typeof type === 'object') aliases = Object.assign(aliases, type)
|
|
201
|
+
}
|
|
202
|
+
return aliases
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function revertValueAliases(json: Data, schema: Data) {
|
|
206
|
+
const clone = cloneDeep(json)
|
|
207
|
+
const replaceAliases = (where: Data) => {
|
|
208
|
+
for (const key in where) {
|
|
209
|
+
if (typeof where[key] === 'object') {
|
|
210
|
+
replaceAliases(where[key])
|
|
211
|
+
} else {
|
|
212
|
+
const aliases = valueAliases(schema, key)
|
|
213
|
+
const value = aliases[where[key] as string]
|
|
214
|
+
if (value) {
|
|
215
|
+
where[key] = value
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
replaceAliases(clone)
|
|
222
|
+
return clone
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function setValueAliases(json: Data, schema: Data) {
|
|
226
|
+
const clone = cloneDeep(json)
|
|
227
|
+
const replaceValues = (where: Data) => {
|
|
228
|
+
for (const key in where) {
|
|
229
|
+
if (typeof where[key] === 'object') {
|
|
230
|
+
replaceValues(where[key])
|
|
231
|
+
} else {
|
|
232
|
+
const aliases = valueAliases(schema, key)
|
|
233
|
+
for (const alias in aliases) {
|
|
234
|
+
if (where[key] === aliases[alias]) {
|
|
235
|
+
where[key] = alias
|
|
236
|
+
break
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
replaceValues(clone)
|
|
244
|
+
return clone
|
|
245
|
+
}
|
|
246
|
+
|
|
190
247
|
export function createColorSchema(
|
|
191
248
|
colorSchema: ColorSchema,
|
|
192
249
|
aliases: Alias[]
|
|
@@ -3,12 +3,16 @@ import { splitByQuotes } from '../utils/splitByQuotes'
|
|
|
3
3
|
import { flatten } from 'flat'
|
|
4
4
|
import { isObject } from 'lodash'
|
|
5
5
|
|
|
6
|
+
export type Data = {
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
export type Schema = {
|
|
7
11
|
[key: string]:
|
|
8
12
|
| string
|
|
9
13
|
| number
|
|
10
14
|
| boolean
|
|
11
|
-
| (number | boolean | string)[]
|
|
15
|
+
| (number | boolean | string | Data)[]
|
|
12
16
|
| Schema
|
|
13
17
|
}
|
|
14
18
|
|
|
@@ -245,8 +249,10 @@ export const useSuggestions = (
|
|
|
245
249
|
|
|
246
250
|
if (Array.isArray(dataType)) {
|
|
247
251
|
localSuggestions = dataType.filter(
|
|
248
|
-
(type) =>
|
|
249
|
-
|
|
252
|
+
(type) =>
|
|
253
|
+
typeof type === 'string' &&
|
|
254
|
+
!knownDataTypes.includes(type)
|
|
255
|
+
) as string[]
|
|
250
256
|
|
|
251
257
|
if (!value) continue
|
|
252
258
|
|
|
@@ -357,7 +363,9 @@ const getError = (
|
|
|
357
363
|
for (const key of Object.keys(schema)) {
|
|
358
364
|
if (isObject(schema[key]) && !Array.isArray(schema[key])) {
|
|
359
365
|
const flattened = flatten({ [key]: schema[key] })
|
|
360
|
-
|
|
366
|
+
for (const k of Object.keys(flattened)) {
|
|
367
|
+
keys.push(k)
|
|
368
|
+
}
|
|
361
369
|
} else {
|
|
362
370
|
keys.push(key)
|
|
363
371
|
}
|
|
@@ -402,7 +410,7 @@ const getError = (
|
|
|
402
410
|
|
|
403
411
|
const isValidByDataType = (
|
|
404
412
|
str: string | string[],
|
|
405
|
-
dataType: string | string[],
|
|
413
|
+
dataType: string | (string | Data)[],
|
|
406
414
|
operator: string
|
|
407
415
|
): boolean => {
|
|
408
416
|
if (dataType === 'any') {
|
|
@@ -423,9 +431,16 @@ const isValidByDataType = (
|
|
|
423
431
|
*/
|
|
424
432
|
|
|
425
433
|
if (Array.isArray(dataType)) {
|
|
426
|
-
let isOneOf = !!getValueMatch(
|
|
434
|
+
let isOneOf = !!getValueMatch(
|
|
435
|
+
dataType.filter((type) => typeof type !== 'object') as string[],
|
|
436
|
+
str
|
|
437
|
+
)
|
|
427
438
|
for (const type of dataType) {
|
|
428
|
-
|
|
439
|
+
if (typeof type === 'object') {
|
|
440
|
+
isOneOf = isOneOf || !!getValueMatch(Object.keys(type), str)
|
|
441
|
+
} else {
|
|
442
|
+
isOneOf = isOneOf || isValidByDataType(str, type, operator)
|
|
443
|
+
}
|
|
429
444
|
}
|
|
430
445
|
return isOneOf
|
|
431
446
|
}
|
|
@@ -507,7 +522,7 @@ const getDataType = (
|
|
|
507
522
|
schema: Schema,
|
|
508
523
|
aliases: Alias[],
|
|
509
524
|
key: string
|
|
510
|
-
): string | string[] | null => {
|
|
525
|
+
): string | (string | Data)[] | null => {
|
|
511
526
|
const aliasedKey = getAliasObjByAlias(aliases, key)?.key ?? key
|
|
512
527
|
|
|
513
528
|
const nestedKey = aliasedKey.split('.').filter((el) => el)
|
|
@@ -529,7 +544,7 @@ const getDataType = (
|
|
|
529
544
|
return 'object'
|
|
530
545
|
}
|
|
531
546
|
|
|
532
|
-
return value as unknown as string | string[] | null
|
|
547
|
+
return value as unknown as string | (string | Data)[] | null
|
|
533
548
|
}
|
|
534
549
|
|
|
535
550
|
const getAliasObjByAlias = (aliases: Alias[], alias: string): Alias | null => {
|
|
@@ -666,14 +681,24 @@ export const removeLeadingExpression = (str: string) => {
|
|
|
666
681
|
return str.match(/\s+(.*)$/)?.[1] || ''
|
|
667
682
|
}
|
|
668
683
|
|
|
669
|
-
const getValueSuggestions = (
|
|
670
|
-
|
|
684
|
+
const getValueSuggestions = (
|
|
685
|
+
dataType: string | (string | Data)[],
|
|
686
|
+
operator: string
|
|
687
|
+
) => {
|
|
688
|
+
const types: (string | Data)[] = Array.isArray(dataType)
|
|
689
|
+
? dataType
|
|
690
|
+
: [dataType]
|
|
671
691
|
const suggestion: string[] = []
|
|
672
692
|
|
|
673
693
|
if (Array.isArray(dataType)) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
694
|
+
for (const type of dataType) {
|
|
695
|
+
if (
|
|
696
|
+
!knownDataTypes.includes(type as string) &&
|
|
697
|
+
typeof type !== 'object'
|
|
698
|
+
) {
|
|
699
|
+
suggestion.push(type)
|
|
700
|
+
}
|
|
701
|
+
}
|
|
677
702
|
}
|
|
678
703
|
|
|
679
704
|
for (const type of types) {
|
|
@@ -688,7 +713,10 @@ const getValueSuggestions = (dataType: string | string[], operator: string) => {
|
|
|
688
713
|
case 'datetime':
|
|
689
714
|
suggestion.push(dateSuggestionPattern)
|
|
690
715
|
default:
|
|
691
|
-
|
|
716
|
+
if (typeof type === 'object') {
|
|
717
|
+
// value aliases: key is the alias, value is the actual value
|
|
718
|
+
for (const key in type) suggestion.push(key)
|
|
719
|
+
}
|
|
692
720
|
break
|
|
693
721
|
}
|
|
694
722
|
}
|