Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
0b6daa34
Unverified
Commit
0b6daa34
authored
1 year ago
by
Cal Herries
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Rank models over non-models in autocomplete (#31064)
parent
e2d46e21
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/database.clj
+2
-1
2 additions, 1 deletion
src/metabase/api/database.clj
test/metabase/api/database_test.clj
+19
-14
19 additions, 14 deletions
test/metabase/api/database_test.clj
with
21 additions
and
15 deletions
src/metabase/api/database.clj
+
2
−
1
View file @
0b6daa34
...
...
@@ -518,7 +518,8 @@
(
and
(
empty?
search-id
)
(
not-empty
search-name
))
[
:like
[
:lower
:report_card.name
]
(
str
"%"
search-name
"%"
)])]
:left-join
[[
:collection
:collection
]
[
:=
:collection.id
:report_card.collection_id
]]
:order-by
[[
:report_card.id
:desc
]]
:order-by
[[
:dataset
:desc
]
; prioritize models
[
:report_card.id
:desc
]]
; then most recently created
:limit
50
})))
(
defn-
autocomplete-fields
[
db-id
search-string
limit
]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/database_test.clj
+
19
−
14
View file @
0b6daa34
...
...
@@ -523,26 +523,31 @@
(
deftest
card-autocomplete-suggestions-test
(
testing
"GET /api/database/:id/card_autocomplete_suggestions"
(
mt/with-temp*
[
Collection
[
collection
{
:name
"Maz Analytics"
}]
Card
[
card-1
(
card-with-native-query
"Maz Quote Views Per Month"
)]
Card
[
card-2
(
card-with-native-query
"Maz Quote Views Per Day"
:collection_id
(
:id
collection
))]]
(
let
[
card->result
{
card-1
(
assoc
(
select-keys
card-1
[
:id
:name
:dataset
])
:collection_name
nil
)
card-2
(
assoc
(
select-keys
card-2
[
:id
:name
:dataset
])
:collection_name
(
:name
collection
))}]
Card
[
card-1
(
card-with-native-query
"Maz Quote Views Per Month"
:collection_id
(
:id
collection
))]
Card
[
card-2
(
card-with-native-query
"Maz Quote Views Per Day"
:dataset
true
)]
Card
[
card-3
(
card-with-native-query
"Maz Quote Views Per Day"
)]]
(
let
[
card->result
{
card-1
(
assoc
(
select-keys
card-1
[
:id
:name
:dataset
])
:collection_name
(
:name
collection
))
card-2
(
assoc
(
select-keys
card-2
[
:id
:name
:dataset
])
:collection_name
nil
)
card-3
(
assoc
(
select-keys
card-3
[
:id
:name
:dataset
])
:collection_name
nil
)}]
(
testing
"exclude cards without perms"
(
mt/with-non-admin-groups-no-root-collection-perms
(
is
(
=
[(
card->result
card-
2
)]
(
is
(
=
[(
card->result
card-
1
)]
(
mt/user-http-request
:rasta
:get
200
(
format
"database/%d/card_autocomplete_suggestions"
(
mt/id
))
:query
"maz"
))))
(
testing
"cards should match the query"
(
doseq
[[
query
expected-cards
]
{
"QUOTE-views"
[
card-2
card-1
]
"per-day"
[
card-2
]
(
str
(
:id
card-1
))
[
card-1
]
(
str
(
:id
card-2
)
"-maz"
)
[
card-2
]
(
str
(
:id
card-2
)
"-kyle"
)
[]}]
(
is
(
=
(
map
card->result
expected-cards
)
(
mt/user-http-request
:rasta
:get
200
(
format
"database/%d/card_autocomplete_suggestions"
(
mt/id
))
:query
query
)))))))
(
doseq
[[
query
expected-cards
]
[
; in all these queries, card-2 should be first because it's a model,
; followed by card-3 because it's created more recently than card-1
[
"QUOTE-views"
[
card-2
card-3
card-1
]]
[
"per-day"
[
card-2
card-3
]]
[(
str
(
:id
card-1
))
[
card-1
]]
[(
str
(
:id
card-2
)
"-maz"
)
[
card-2
]]
[(
str
(
:id
card-2
)
"-kyle"
)
[]]]]
(
testing
(
format
"query = %s"
query
)
(
is
(
=
(
map
card->result
expected-cards
)
(
mt/user-http-request
:rasta
:get
200
(
format
"database/%d/card_autocomplete_suggestions"
(
mt/id
))
:query
query
))))))))
(
testing
"should reject requests for databases for which the user has no perms"
(
mt/with-temp*
[
Database
[{
database-id
:id
}]
Card
[
_
(
card-with-native-query
"Maz Quote Views Per Month"
:database_id
database-id
)]]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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