-
Notifications
You must be signed in to change notification settings - Fork 25
feat/playbooks panel #2774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adityathebe
wants to merge
4
commits into
main
Choose a base branch
from
feat/playbooks-panel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat/playbooks panel #2774
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/pages/audit-report/components/View/panels/PanelWrapper.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import React, { ReactNode } from "react"; | ||
|
|
||
| interface PanelWrapperProps { | ||
| title: string; | ||
| description?: string; | ||
| className?: string; | ||
| titleClassName?: string; | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| /** | ||
| * Common wrapper component for all panel types. | ||
| * Provides consistent styling for the panel container, header, and description. | ||
| */ | ||
| const PanelWrapper: React.FC<PanelWrapperProps> = ({ | ||
| title, | ||
| description, | ||
| className = "", | ||
| titleClassName = "", | ||
| children | ||
| }) => { | ||
| return ( | ||
| <div | ||
| className={`flex h-full w-full flex-col overflow-hidden rounded-lg border border-gray-200 bg-white p-4 ${className}`} | ||
| > | ||
| <h4 | ||
| className={`mb-2 text-sm font-medium text-gray-600 ${titleClassName}`} | ||
| > | ||
| {title} | ||
| </h4> | ||
| {description && ( | ||
| <p className="mb-3 text-xs text-gray-500">{description}</p> | ||
| )} | ||
| {children} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default PanelWrapper; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
src/pages/audit-report/components/View/panels/PlaybooksPanel.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| import { useMemo, useState, useRef, useEffect } from "react"; | ||
| import { Loader2, ChevronDown, Workflow } from "lucide-react"; | ||
| import { useGetPlaybookSpecsDetails } from "@flanksource-ui/api/query-hooks/playbooks"; | ||
| import { SubmitPlaybookRunFormValues } from "@flanksource-ui/components/Playbooks/Runs/Submit/SubmitPlaybookRunForm"; | ||
| import SubmitPlaybookRunForm from "@flanksource-ui/components/Playbooks/Runs/Submit/SubmitPlaybookRunForm"; | ||
| import { Icon } from "@flanksource-ui/ui/Icons/Icon"; | ||
| import EmptyState from "@flanksource-ui/components/EmptyState"; | ||
| import { PanelResult } from "../../../types"; | ||
| import mixins from "@flanksource-ui/utils/mixins.module.css"; | ||
| import { Button } from "@flanksource-ui/components/ui/button"; | ||
| import PanelWrapper from "./PanelWrapper"; | ||
|
|
||
| type PlaybookRunRow = { | ||
| id: string; | ||
| title?: string; | ||
| name?: string; | ||
| description?: string; | ||
| icon?: string; | ||
| component_id?: string; | ||
| config_id?: string; | ||
| check_id?: string; | ||
| params?: SubmitPlaybookRunFormValues["params"]; | ||
| }; | ||
|
|
||
| type PlaybookRunPanelProps = { | ||
| summary: PanelResult; | ||
| }; | ||
|
|
||
| /** | ||
| * A panel that lists playbooks with inline Run buttons and opens the existing | ||
| * SubmitPlaybookRunForm modal when a playbook is selected. | ||
| */ | ||
| export default function PlaybooksPanel({ summary }: PlaybookRunPanelProps) { | ||
| const rows = useMemo( | ||
| () => | ||
| (summary.rows || []).filter( | ||
| (row): row is PlaybookRunRow => | ||
| typeof row === "object" && | ||
| row !== null && | ||
| typeof row.id === "string" && | ||
| row.id.length > 0 | ||
| ), | ||
| [summary.rows] | ||
| ); | ||
| const [selected, setSelected] = useState<PlaybookRunRow | null>(null); | ||
| const [showScrollIndicator, setShowScrollIndicator] = useState(false); | ||
| const scrollContainerRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const { data: playbookSpec, isLoading } = useGetPlaybookSpecsDetails( | ||
| selected?.id ?? "", | ||
| { | ||
| enabled: !!selected?.id | ||
| } | ||
| ); | ||
|
|
||
| const handleCloseModal = () => { | ||
| setSelected(null); | ||
| }; | ||
|
|
||
| // Check scroll position to show/hide indicator | ||
| const checkScrollPosition = () => { | ||
| const container = scrollContainerRef.current; | ||
| if (!container) return; | ||
|
|
||
| const { scrollTop, scrollHeight, clientHeight } = container; | ||
| const isScrollable = scrollHeight > clientHeight; | ||
| const isAtBottom = scrollHeight - scrollTop - clientHeight < 10; // 10px threshold | ||
|
|
||
| setShowScrollIndicator(isScrollable && !isAtBottom); | ||
| }; | ||
|
|
||
| // Set up scroll listener and check initial state | ||
| useEffect(() => { | ||
| const container = scrollContainerRef.current; | ||
| if (!container) return; | ||
|
|
||
| checkScrollPosition(); | ||
|
|
||
| container.addEventListener("scroll", checkScrollPosition); | ||
| return () => container.removeEventListener("scroll", checkScrollPosition); | ||
| }, [rows]); // Re-check when rows change | ||
|
|
||
| return ( | ||
| <PanelWrapper title={summary.name} description={summary.description}> | ||
| <div className="flex flex-1 flex-col overflow-hidden"> | ||
| {/* Playbook List */} | ||
| <div className="relative min-h-0 flex-1"> | ||
| <div | ||
| ref={scrollContainerRef} | ||
| className={`h-full overflow-y-auto ${mixins.hoverScrollbar}`} | ||
| > | ||
| {(!rows || rows.length === 0) && ( | ||
| <EmptyState title="No playbooks" /> | ||
| )} | ||
|
|
||
| {rows && rows.length > 0 && ( | ||
| <div className="space-y-1"> | ||
| {rows.map((row) => { | ||
| const title = row.title || row.name || "Playbook"; | ||
| const isCurrentlyLoading = | ||
| isLoading && selected?.id === row.id; | ||
|
|
||
| return ( | ||
| <div | ||
| key={row.id} | ||
| className="group rounded-lg border border-transparent px-3 py-2 transition-all hover:border-gray-200 hover:bg-gray-50" | ||
| > | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <div className="flex min-w-0 flex-1 items-center gap-2"> | ||
| <div className="flex-shrink-0"> | ||
| {row.icon ? ( | ||
| <Icon | ||
| name={row.icon} | ||
| className="h-4 w-4 text-gray-600" | ||
| /> | ||
| ) : ( | ||
| <Workflow className="h-4 w-4 text-gray-600" /> | ||
| )} | ||
| </div> | ||
| <div className="min-w-0 flex-1"> | ||
| <p className="text-sm font-medium text-foreground"> | ||
| {title} | ||
| </p> | ||
| {row.description && ( | ||
| <p className="mt-0.5 text-xs text-muted-foreground"> | ||
| {row.description} | ||
| </p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <Button | ||
| size="sm" | ||
| variant="outline" | ||
| onClick={() => setSelected(row)} | ||
| disabled={isCurrentlyLoading} | ||
| className="h-7 flex-shrink-0 gap-1.5 px-4" | ||
| > | ||
| {isCurrentlyLoading ? ( | ||
| <> | ||
| <Loader2 className="h-4 w-4 animate-spin" /> | ||
| <span className="text-xs">Loading</span> | ||
| </> | ||
| ) : ( | ||
| <span className="text-xs font-medium">Run</span> | ||
| )} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Scroll Indicator */} | ||
| {showScrollIndicator && ( | ||
| <div className="pointer-events-none absolute bottom-0 left-0 right-0 flex justify-center pb-2"> | ||
| <div className="flex flex-col items-center gap-1 rounded-full bg-gradient-to-t from-white via-white to-transparent px-3 py-2"> | ||
| <ChevronDown className="h-4 w-4 text-muted-foreground" /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| {playbookSpec && selected && playbookSpec.id === selected.id && ( | ||
| <SubmitPlaybookRunForm | ||
| isOpen={!!selected} | ||
| onClose={handleCloseModal} | ||
| playbook={playbookSpec} | ||
| componentId={selected.component_id} | ||
| configId={selected.config_id} | ||
| checkId={selected.check_id} | ||
| params={selected.params} | ||
| /> | ||
| )} | ||
| </PanelWrapper> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.