Skip to content

Commit

Permalink
feat: added tab icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen Nijhuis committed Jan 11, 2024
1 parent bb25c35 commit 995aa1f
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/assets/icons/describe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/logs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/shell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/components/TabIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script setup lang="ts">
import { defineAsyncComponent } from "vue";
const props = defineProps({
name: {
type: String,
required: true,
},
});
const icon = defineAsyncComponent(
() => import(`@/assets/icons/${props.name}.svg`)
);
</script>

<template>
<component :is="icon" class="w-[14px] min-w-[14px] content-center" />
</template>
2 changes: 2 additions & 0 deletions src/components/TabOrchestrator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
TabProviderCloseTabKey,
} from "@/providers/TabProvider";
import { injectStrict } from "@/lib/utils";
import TabIcon from "@/components/TabIcon.vue";
import Expand from "@/assets/icons/expand.svg";
import Close from "@/assets/icons/close.svg";
import { SettingsContextStateKey } from "@/providers/SettingsContextProvider";
Expand Down Expand Up @@ -99,6 +100,7 @@ const closeAndSetActiveTab = (id: string) => {
@click="setActiveTab(tab.id)"
:title="tab.title"
>
<tab-icon :name="tab.icon" class="mr-1" />
<span class="truncate">{{ tab.title }}</span>
<div
@click="closeAndSetActiveTab(tab.id)"
Expand Down
18 changes: 16 additions & 2 deletions src/providers/TabProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ import {
export const TabProviderStateKey: InjectionKey<ToRefs<TabProviderState>> =
Symbol("TabProviderState");
export const TabProviderAddTabKey: InjectionKey<
(id: string, title: string, component: any, props?: any) => void
(
id: string,
title: string,
component: any,
props?: any,
icon?: string
) => void
> = Symbol("TabProviderAddTab");
export const TabProviderCloseTabKey: InjectionKey<(id: string) => void> =
Symbol("TabProviderCloseTab");

export interface Tab {
id: string;
icon: string;
title: string;
component: any;
props?: any;
Expand All @@ -37,14 +44,21 @@ export default {

provide(TabProviderStateKey, toRefs(state));

const addTab = (id: string, title: string, component: any, props?: any) => {
const addTab = (
id: string,
title: string,
component: any,
props?: any,
icon: string = "tab"
) => {
if (state.tabs.find((tab) => tab.id === id)) {
state.activeTabId = id;
return;
}

state.tabs.push({
id,
icon,
title,
component: shallowRef(component),
props,
Expand Down
20 changes: 12 additions & 8 deletions src/views/Pods.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ const rowActions: RowAction<V1Pod>[] = [
handler: (row) => {
addTab(
`edit_${row.metadata?.name}`,
`Edit ${row.metadata?.name}`,
`${row.metadata?.name}`,
defineAsyncComponent(() => import("@/views/ObjectEditor.vue")),
{
context: context.value,
namespace: namespace.value,
object: `pods/${row.metadata?.name}`,
}
},
"edit"
);
},
},
Expand All @@ -43,13 +44,14 @@ const rowActions: RowAction<V1Pod>[] = [
handler: (row) => {
addTab(
`describe_${row.metadata?.name}`,
`Describe ${row.metadata?.name}`,
`${row.metadata?.name}`,
defineAsyncComponent(() => import("@/views/Describe.vue")),
{
context: context.value,
namespace: namespace.value,
object: `pods/${row.metadata?.name}`,
}
},
"describe"
);
},
},
Expand All @@ -61,14 +63,15 @@ const rowActions: RowAction<V1Pod>[] = [
handler: () => {
addTab(
`shell_${row.metadata?.name}_${container.name}`,
`>_ ${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,
}
},
"shell"
);
},
}));
Expand All @@ -79,13 +82,14 @@ const rowActions: RowAction<V1Pod>[] = [
handler: (row) => {
addTab(
`logs_${row.metadata?.name}`,
`Logs for ${row.metadata?.name}`,
`${row.metadata?.name}`,
defineAsyncComponent(() => import("@/views/LogViewer.vue")),
{
context: context.value,
namespace: namespace.value,
pod: row.metadata?.name,
}
},
"logs"
);
},
},
Expand Down

0 comments on commit 995aa1f

Please sign in to comment.