Skip to content

Commit

Permalink
feat: added support for multi-container shell selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen Nijhuis committed Jan 11, 2024
1 parent 3d6d298 commit 2b3d513
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
13 changes: 12 additions & 1 deletion src/components/tables/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
export interface RowAction<T> {
export interface BaseRowAction<T> {
label: string;
}

export interface WithOptions<T> extends BaseRowAction<T> {
options: (row: T) => WithHandler<T>[];
handler?: never;
}

export interface WithHandler<T> extends BaseRowAction<T> {
options?: never;
handler: (row: T) => void;
}

export type RowAction<T> = WithOptions<T> | WithHandler<T>;
29 changes: 23 additions & 6 deletions src/components/ui/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
ContextMenuTrigger,
ContextMenuContent,
ContextMenuItem,
ContextMenuSub,
ContextMenuSubTrigger,
ContextMenuSubContent,
} from "@/components/ui/context-menu";
import {
Expand Down Expand Up @@ -103,12 +106,26 @@ const table = useVueTable({
</TableBody>
</ContextMenuTrigger>
<ContextMenuContent v-if="rowActions && rowActions?.length > 0">
<ContextMenuItem
v-for="(rowAction, index) in rowActions"
:key="index"
@select="rowAction.handler(state.contextMenuSubject as TData)"
>{{ rowAction.label }}</ContextMenuItem
>
<template v-for="(rowAction, index) in rowActions" :key="index">
<ContextMenuItem
v-if="!rowAction.options"
@select="rowAction.handler(state.contextMenuSubject as TData)"
>{{ rowAction.label }}</ContextMenuItem
>
<ContextMenuSub v-else>
<ContextMenuSubTrigger>
{{ rowAction.label }}
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem
v-for="(option, optionIndex) in rowAction.options(state.contextMenuSubject as TData)"
:key="optionIndex"
@select="option.handler(state.contextMenuSubject as TData)"
>{{ option.label }}</ContextMenuItem
>
</ContextMenuSubContent>
</ContextMenuSub>
</template>
</ContextMenuContent>
</ContextMenu>
</Table>
Expand Down
36 changes: 25 additions & 11 deletions src/views/Pods.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,39 @@ const rowActions: RowAction<V1Pod>[] = [
{
label: "Describe",
handler: (row) => {
console.log("Describe", row);
},
},
{
label: "Shell",
handler: (row) => {
console.log(row);
addTab(
`shell_${row.metadata?.name}`,
`Shell for ${row.metadata?.name}`,
defineAsyncComponent(() => import("@/views/Shell.vue")),
`describe_${row.metadata?.name}`,
`Describe ${row.metadata?.name}`,
defineAsyncComponent(() => import("@/views/Describe.vue")),
{
context: context.value,
namespace: namespace.value,
pod: row,
object: `pods/${row.metadata?.name}`,
}
);
},
},
{
label: "Shell",
options: (row) => {
return (row.status?.containerStatuses || []).map((container) => ({
label: container.name,
handler: () => {
addTab(
`shell_${row.metadata?.name}_${container.name}`,
`>_ ${row.metadata?.name}/${container.name}`,
defineAsyncComponent(() => import("@/views/Shell.vue")),
{
context: context.value,
namespace: namespace.value,
pod: row,
container: container,
}
);
},
}));
},
},
{
label: "Logs",
handler: (row) => {
Expand Down

0 comments on commit 2b3d513

Please sign in to comment.