Skip to content

Commit d904204

Browse files
adityathebemoshloop
authored andcommitted
fix(playbooks): handle filtered dropdown specs
The playbook list endpoint can return playbooks that are not visible through the DB playbooks API for the current user. The dropdown merged list results by assuming every listed playbook had a matching spec, which threw and silently hid the menu.\n\nBuild dropdown entries from the DB playbooks response and merge in list metadata only for matching IDs. Surface query errors instead of returning null so failures are visible.
1 parent f77ede4 commit d904204

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/api/query-hooks/playbooks.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ export function useGetPlaybooksToRun(
7272
// this is a bit of a hack, but we need to get the specs because that's
7373
// where the icon is stored
7474
const specs = await getPlaybookSpecsByIDs(ids);
75-
return res.map((playbook) => ({
76-
...playbook,
77-
title: specs.find((spec) => spec.id === playbook.id)!.title,
78-
spec: specs.find((spec) => spec.id === playbook.id)!.spec
75+
const playbooksByID = new Map(
76+
res.map((playbook) => [playbook.id, playbook])
77+
);
78+
79+
return specs.map((playbookSpec) => ({
80+
...playbooksByID.get(playbookSpec.id),
81+
title: playbookSpec.title,
82+
spec: playbookSpec.spec
7983
})) as (RunnablePlaybook & {
8084
spec: any;
8185
})[];

src/components/Playbooks/Runs/Submit/PlaybooksDropdownMenu.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getErrorMessage } from "@flanksource-ui/api/types/error";
12
import { Icon } from "@flanksource-ui/ui/Icons/Icon";
23
import {
34
Menu,
@@ -47,7 +48,15 @@ export default function PlaybooksDropdownMenu({
4748
config_id
4849
});
4950

50-
if (error || playbooks?.length === 0 || isLoading) {
51+
if (error) {
52+
return (
53+
<div className={clsx(containerClassName, "text-sm text-red-600")}>
54+
Failed to load playbooks: {getErrorMessage(error)}
55+
</div>
56+
);
57+
}
58+
59+
if (playbooks?.length === 0 || isLoading) {
5160
return null;
5261
}
5362

0 commit comments

Comments
 (0)