-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(workspace): add dropdown #123
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cabb03a
feat(workspace): add workspace dropdown selection
peppescg 5a7016c
fix: invalidate cache should be called only for alerts event
peppescg b0d16f0
fix: sse api path
peppescg 7dbc6b6
fix: close dialog
peppescg 4c12354
fix: mock workspaces api
peppescg 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 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 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
92 changes: 92 additions & 0 deletions
92
src/features/workspace/components/workspaces-selection.tsx
This file contains 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,92 @@ | ||
import { useWorkspacesData } from "@/hooks/useWorkspacesData"; | ||
import { | ||
Button, | ||
DialogTrigger, | ||
Input, | ||
ListBox, | ||
ListBoxItem, | ||
Popover, | ||
SearchField, | ||
Separator, | ||
} from "@stacklok/ui-kit"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import clsx from "clsx"; | ||
import { ChevronDown, Search, Settings } from "lucide-react"; | ||
import { useState } from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export function WorkspacesSelection() { | ||
const queryClient = useQueryClient(); | ||
const { data } = useWorkspacesData(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [searchWorkspace, setSearchWorkspace] = useState(""); | ||
const workspaces = data?.workspaces ?? []; | ||
const filteredWorkspaces = workspaces.filter((workspace) => | ||
workspace.name.toLowerCase().includes(searchWorkspace.toLowerCase()), | ||
); | ||
const activeWorkspace = workspaces.find((workspace) => workspace.is_active); | ||
|
||
const handleWorkspaceClick = () => { | ||
queryClient.invalidateQueries({ refetchType: "all" }); | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<DialogTrigger isOpen={isOpen} onOpenChange={(test) => setIsOpen(test)}> | ||
<Button variant="tertiary" className="flex cursor-pointer"> | ||
Workspace {activeWorkspace?.name ?? "default"} | ||
<ChevronDown /> | ||
</Button> | ||
|
||
<Popover className="w-1/4 p-4" placement="bottom left"> | ||
<div> | ||
<div> | ||
<SearchField | ||
onChange={setSearchWorkspace} | ||
autoFocus | ||
aria-label="search" | ||
> | ||
<Input icon={<Search />} /> | ||
</SearchField> | ||
</div> | ||
|
||
<ListBox | ||
className="pb-2 pt-3" | ||
aria-label="Workspaces" | ||
items={filteredWorkspaces} | ||
selectedKeys={activeWorkspace?.name ?? []} | ||
renderEmptyState={() => ( | ||
<p className="text-center">No workspaces found</p> | ||
)} | ||
> | ||
{(item) => ( | ||
<ListBoxItem | ||
id={item.name} | ||
onAction={() => handleWorkspaceClick()} | ||
className={clsx( | ||
"cursor-pointer py-2 m-1 text-base hover:bg-gray-300", | ||
{ | ||
"bg-gray-900 text-white hover:text-secondary": | ||
item.is_active, | ||
}, | ||
)} | ||
key={item.name} | ||
> | ||
{item.name} | ||
</ListBoxItem> | ||
)} | ||
</ListBox> | ||
<Separator className="" /> | ||
<Link | ||
to="/workspaces" | ||
onClick={() => setIsOpen(false)} | ||
className="text-secondary pt-3 px-2 gap-2 flex" | ||
> | ||
<Settings /> | ||
Manage Workspaces | ||
</Link> | ||
</div> | ||
</Popover> | ||
</DialogTrigger> | ||
); | ||
} |
This file contains 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 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,10 @@ | ||
[ | ||
{ | ||
"name": "workspace-1", | ||
"is_active": true | ||
}, | ||
{ | ||
"name": "workspace-2", | ||
"is_active": false | ||
} | ||
] |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to refetch for the all events, but only for the alerts one