Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wiki
Manage
Activity
Members
Labels
Plan
Issues
53
Issue boards
Milestones
Wiki
Code
Merge requests
6
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MDM Lab
Wiki
Commits
f389aaf0
Commit
f389aaf0
authored
1 year ago
by
Remi PLANEL
Browse files
Options
Downloads
Patches
Plain Diff
WIP: use array to generate meilifilter and wrap or with parenthesis
parent
e188ef32
No related branches found
No related tags found
2 merge requests
!203
Foldseek pages
,
!186
Refactor facet autocomplete
Pipeline
#120390
passed with stages
in 6 minutes and 19 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
components/AutocompleteMeiliFacets.vue
+1
-1
1 addition, 1 deletion
components/AutocompleteMeiliFacets.vue
components/ServerDbTable.vue
+11
-1
11 additions, 1 deletion
components/ServerDbTable.vue
composables/useMeiliFilters.ts
+88
-0
88 additions, 0 deletions
composables/useMeiliFilters.ts
with
100 additions
and
2 deletions
components/AutocompleteMeiliFacets.vue
+
1
−
1
View file @
f389aaf0
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
{
filter
}
from
'
@observablehq/plot
'
import
{
filter
}
from
'
@observablehq/plot
'
export
interface
FilterItem
{
export
interface
FilterItem
{
type
:
'
facet
'
|
'
innerOperator
'
|
'
outerOperator
'
|
'
value
'
|
'
text
'
type
:
'
facet
'
|
'
innerOperator
'
|
'
outerOperator
'
|
'
value
'
value
:
string
value
:
string
title
:
string
title
:
string
count
?:
number
count
?:
number
...
...
This diff is collapsed.
Click to expand it.
components/ServerDbTable.vue
+
11
−
1
View file @
f389aaf0
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
// import type { FacetDistribution } from "meilisearch";
// import type { FacetDistribution } from "meilisearch";
import
{
useCsvDownload
}
from
"
@/composables/useCsvDownload
"
import
{
useCsvDownload
}
from
"
@/composables/useCsvDownload
"
import
{
useMeiliFilters
}
from
"
@/composables/useMeiliFilters
"
import
{
useSlots
}
from
'
vue
'
import
{
useSlots
}
from
'
vue
'
import
{
useDisplay
}
from
"
vuetify
"
;
import
{
useDisplay
}
from
"
vuetify
"
;
import
{
useThrottleFn
}
from
'
@vueuse/core
'
import
{
useThrottleFn
}
from
'
@vueuse/core
'
...
@@ -141,7 +142,7 @@ onBeforeMount(async () => {
...
@@ -141,7 +142,7 @@ onBeforeMount(async () => {
const
msFilterCompo
=
ref
<
FilterItem
[]
|
undefined
>
(
undefined
)
const
msFilterCompo
=
ref
<
FilterItem
[]
|
undefined
>
(
undefined
)
const
computedFilter
=
computed
(()
=>
{
const
computedFilter
Str
=
computed
(()
=>
{
const
toValFilters
=
toValue
(
msFilterCompo
)
const
toValFilters
=
toValue
(
msFilterCompo
)
let
filtersStr
:
string
|
undefined
=
undefined
let
filtersStr
:
string
|
undefined
=
undefined
if
(
toValFilters
!==
undefined
&&
toValFilters
.
length
>
0
)
{
if
(
toValFilters
!==
undefined
&&
toValFilters
.
length
>
0
)
{
...
@@ -169,6 +170,15 @@ const computedFilter = computed(() => {
...
@@ -169,6 +170,15 @@ const computedFilter = computed(() => {
})
})
const
{
arrayFilters
:
computedFilter
}
=
useMeiliFilters
(
msFilterCompo
)
// const computedFilter = computed(() => {
// const toValFilters = toValue(msFilterCompo)
// if (toValFilters !== undefined && toValFilters.length > 0) {
// meiliFilterAsArray
// }
// })
watch
(
computedFilter
,
()
=>
{
watch
(
computedFilter
,
()
=>
{
if
(
toValue
(
isValidFilters
)
&&
(
toValue
(
computedFilter
)
!==
undefined
||
toValue
(
filterInputValues
)
===
null
))
{
if
(
toValue
(
isValidFilters
)
&&
(
toValue
(
computedFilter
)
!==
undefined
||
toValue
(
filterInputValues
)
===
null
))
{
searchOrFilter
()
searchOrFilter
()
...
...
This diff is collapsed.
Click to expand it.
composables/useMeiliFilters.ts
0 → 100644
+
88
−
0
View file @
f389aaf0
import
type
{
FilterItem
}
from
'
@/components/AutocompleteMeiliFacets.vue
'
export
function
useMeiliFilters
(
filters
:
MaybeRef
<
FilterItem
[]
|
undefined
>
)
{
const
arrayFilters
=
computed
(()
=>
{
const
toValFilters
=
toValue
(
filters
)
if
(
toValFilters
!==
undefined
&&
toValFilters
.
length
>=
3
)
{
const
cachedFilters
=
[...
toValFilters
]
// Remove last element if it is an outerOperator
if
(
cachedFilters
.
length
%
4
===
0
&&
cachedFilters
.
slice
(
-
1
)[
0
].
type
===
'
outerOperator
'
)
{
cachedFilters
.
splice
(
-
1
)
}
let
previousOperator
:
'
AND
'
|
'
OR
'
|
undefined
=
undefined
const
arrayFilters
=
cachedFilters
.
reduce
((
acc
,
curr
,
index
)
=>
{
const
sanitizedValue
=
curr
.
value
.
split
(
"
-
"
).
slice
(
0
,
-
1
).
join
(
"
-
"
)
const
position
=
index
+
1
switch
(
position
%
4
)
{
case
0
:
if
(
previousOperator
===
undefined
)
{
const
newFilter
=
acc
.
splice
(
-
3
).
join
(
""
)
if
(
sanitizedValue
===
'
AND
'
)
{
acc
.
push
(
newFilter
)
}
else
{
acc
.
push
([
newFilter
])
}
}
previousOperator
=
sanitizedValue
break
;
case
3
:
// if last element
acc
.
push
(
`'
${
sanitizedValue
}
'`
)
if
(
previousOperator
===
undefined
)
{
const
newFilter
=
acc
.
splice
(
-
3
).
join
(
""
)
acc
.
push
(
newFilter
)
}
else
{
const
newFilter
=
acc
.
splice
(
-
3
).
join
(
""
)
console
.
log
(
"
new filter:
"
,
newFilter
)
if
(
previousOperator
===
'
AND
'
)
{
acc
.
push
(
newFilter
)
}
else
{
console
.
log
(
"
previous operator is OR
"
)
const
previousElem
=
acc
.
slice
(
-
1
)[
0
]
console
.
log
(
previousElem
)
if
(
Array
.
isArray
(
previousElem
))
{
acc
.
slice
(
-
1
)[
0
].
push
(
newFilter
)
}
else
{
const
previousElem
=
acc
.
splice
(
-
1
)[
0
]
console
.
log
(
previousElem
)
console
.
log
([...
acc
])
acc
.
push
([
previousElem
,
newFilter
])
}
}
}
break
default
:
acc
.
push
(
sanitizedValue
)
break
;
}
console
.
log
(
position
)
console
.
log
([...
acc
])
return
acc
},
[])
console
.
log
(
arrayFilters
)
return
arrayFilters
}
else
{
return
undefined
}
})
return
{
arrayFilters
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment