Filter script kinds in the backend (#2450)

This commit is contained in:
Guillaume Bouvignies
2023-10-13 11:34:39 -07:00
committed by GitHub
parent ad75e78228
commit bcdff7d6f1
8 changed files with 18 additions and 22 deletions
+2 -2
View File
@@ -3820,10 +3820,10 @@ paths:
in: query
schema:
type: boolean
- name: kind
- name: kinds
description: |
(default regardless)
script kind
script kinds to filter, split by comma
in: query
schema:
type: string
+2 -2
View File
@@ -2773,10 +2773,10 @@ paths:
in: query
schema:
type: boolean
- name: kind
- name: kinds
description: |
(default regardless)
script kind
script kinds to filter, split by comma
in: query
schema:
type: string
+9 -2
View File
@@ -218,8 +218,15 @@ async fn list_scripts(
if let Some(it) = &lq.is_template {
sqlb.and_where_eq("is_template", it);
}
if let Some(k) = &lq.kind {
sqlb.and_where_eq("kind", "?".bind(&k.to_lowercase()));
if let Some(kinds_val) = &lq.kinds {
let lowercased_kinds: Vec<String> = kinds_val
.split(",")
.map(&str::to_lowercase)
.map(sql_builder::quote)
.collect();
if lowercased_kinds.len() > 0 {
sqlb.and_where_in("kind", lowercased_kinds.as_slice());
}
}
if lq.starred_only.unwrap_or(false) {
sqlb.and_where_is_not_null("favorite.path");
+1 -1
View File
@@ -231,7 +231,7 @@ pub struct ListScriptQuery {
pub order_by: Option<String>,
pub order_desc: Option<bool>,
pub is_template: Option<bool>,
pub kind: Option<String>,
pub kinds: Option<String>,
pub starred_only: Option<bool>,
}
@@ -169,7 +169,7 @@
<ScriptPicker
disabled={!isEditable}
initialPath={customInitialScriptPath}
kinds={[Script.kind.SCRIPT]}
kinds={[Script.kind.SCRIPT, Script.kind.FAILURE]}
allowFlow={true}
bind:scriptPath={handlerPath}
bind:itemKind={customHandlerKind}
@@ -48,23 +48,12 @@
label: `${flow.path}${flow.summary ? ` | ${truncate(flow.summary, 20)}` : ''}`
}))
} else if (itemKind == 'script') {
if (kinds.length === 1) {
items = (await ScriptService.listScripts({ workspace: $workspaceStore!, kind: kinds[0]})).map(
items = (await ScriptService.listScripts({ workspace: $workspaceStore!, kinds: kinds.join(",")})).map(
(script) => ({
value: script.path,
label: `${script.path}${script.summary ? ` | ${truncate(script.summary, 20)}` : ''}`
})
)
} else {
items = (await ScriptService.listScripts({ workspace: $workspaceStore! })).filter(
(script) => kinds.includes(script.kind)
).map(
(script) => ({
value: script.path,
label: `${script.path}${script.summary ? ` | ${truncate(script.summary, 20)}` : ''}`
})
)
}
} else {
items =
$hubScripts?.map((x) => ({
@@ -14,7 +14,7 @@
const dispatch = createEventDispatcher()
async function loadItems(): Promise<Item[]> {
return await ScriptService.listScripts({ workspace: $workspaceStore!, kind })
return await ScriptService.listScripts({ workspace: $workspaceStore!, kinds: kind })
}
</script>
@@ -29,7 +29,7 @@
$: $workspaceStore && kind && loadItems()
async function loadItems(): Promise<void> {
items = await ScriptService.listScripts({ workspace: $workspaceStore!, kind, isTemplate })
items = await ScriptService.listScripts({ workspace: $workspaceStore!, kinds: kind, isTemplate })
}
let ownerFilter: string | undefined = undefined