Skip to content

Commit

Permalink
feat: adds new menu for custom groups
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Jan 25, 2025
1 parent 0216438 commit 05b6715
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 40 deletions.
1 change: 1 addition & 0 deletions assets/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ declare module 'vue' {
EventSource: typeof import('./components/LogViewer/EventSource.vue')['default']
FuzzySearchModal: typeof import('./components/FuzzySearchModal.vue')['default']
GroupedLog: typeof import('./components/GroupedViewer/GroupedLog.vue')['default']
GroupsMenu: typeof import('./components/GroupsMenu.vue')['default']
HostIcon: typeof import('./components/common/HostIcon.vue')['default']
HostList: typeof import('./components/HostList.vue')['default']
HostLog: typeof import('./components/HostViewer/HostLog.vue')['default']
Expand Down
29 changes: 29 additions & 0 deletions assets/components/GroupsMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<ul class="menu w-full p-0 text-[0.95rem]">
<li v-if="customGroups.length > 0">
<details open>
<summary class="text-base-content/80 font-light">
<ph:bounding-box-fill />
{{ $t("label.groups-menu") }}
</summary>
<ul>
<li v-for="group in customGroups" :key="group.name">
<router-link :to="{ name: '/group/[name]', params: { name: group.name } }" active-class="menu-active">
<ph:stack-simple />
<div class="truncate">
{{ group.name }}
</div>
</router-link>
</li>
</ul>
</details>
</li>
</ul>
</template>

<script lang="ts" setup>
const store = useSwarmStore();
const { customGroups } = storeToRefs(store);
</script>
<style scoped></style>
15 changes: 8 additions & 7 deletions assets/components/SideMenu.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<template>
<div v-if="ready" data-testid="side-menu" class="flex min-h-0 flex-col">
<Carousel v-model="selectedCard" class="flex-1">
<CarouselItem title="Hosts and Containers" id="host">
<CarouselItem :title="$t('label.host-menu')" id="host">
<HostMenu />
</CarouselItem>
<CarouselItem title="Services and Stacks" v-if="services.length > 0 || customGroups.length > 0" id="swarm">
<CarouselItem :title="$t('label.groups-menu')" v-if="customGroups.length > 0" id="group">
<GroupsMenu />
</CarouselItem>
<CarouselItem :title="$t('label.swarm-menu')" v-if="services.length > 0" id="swarm">
<SwarmMenu />
</CarouselItem>
</Carousel>
Expand All @@ -21,15 +24,13 @@ const { ready } = storeToRefs(containerStore);
const route = useRoute();
const swarmStore = useSwarmStore();
const { services, customGroups } = storeToRefs(swarmStore);
const selectedCard = ref<"host" | "swarm">("host");
const selectedCard = ref<"host" | "swarm" | "group">("host");
watch(
route,
() => {
if (route.meta.swarmMode) {
selectedCard.value = "swarm";
} else if (route.meta.containerMode) {
selectedCard.value = "host";
if (route.meta.menu && ["host", "swarm", "group"].includes(route.meta.menu as string)) {
selectedCard.value = route.meta.menu as "host" | "swarm" | "group";
}
},
{ immediate: true },
Expand Down
26 changes: 1 addition & 25 deletions assets/components/SwarmMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,13 @@
</ul>
</details>
</li>

<li v-if="customGroups.length > 0">
<details open>
<summary class="text-base-content/80 font-light">
<ph:bounding-box-fill />
{{ $t("label.custom-groups") }}
</summary>
<ul>
<li v-for="group in customGroups" :key="group.name">
<router-link :to="{ name: '/group/[name]', params: { name: group.name } }" active-class="menu-active">
<ph:stack-simple />
<div class="truncate">
{{ group.name }}
</div>
</router-link>
</li>
</ul>
</details>
</li>
</ul>
</template>

<script lang="ts" setup>
const store = useSwarmStore();
const { stacks, services, customGroups } = storeToRefs(store);
const { stacks, services } = storeToRefs(store);
const servicesWithoutStacks = computed(() => services.value.filter((service) => !service.stack));
</script>
<style scoped>
.menu {
@apply text-[0.95rem];
}
</style>
2 changes: 1 addition & 1 deletion assets/pages/container/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ watchEffect(() => {
</script>
<route lang="yaml">
meta:
containerMode: true
menu: "host"
</route>
2 changes: 1 addition & 1 deletion assets/pages/group/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ watchEffect(() => {
</script>
<route lang="yaml">
meta:
swarmMode: true
menu: group
</route>
2 changes: 1 addition & 1 deletion assets/pages/host/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ watchEffect(() => {
</script>
<route lang="yaml">
meta:
containerMode: true
menu: host
</route>
2 changes: 1 addition & 1 deletion assets/pages/merged/[ids].vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ watchEffect(() => {
</script>
<route lang="yaml">
meta:
containerMode: true
menu: host
</route>
2 changes: 1 addition & 1 deletion assets/pages/service/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ watchEffect(() => {
</script>
<route lang="yaml">
meta:
swarmMode: true
menu: swarm
</route>
2 changes: 1 addition & 1 deletion assets/pages/stack/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ watchEffect(() => {
</script>
<route lang="yaml">
meta:
swarmMode: true
menu: swarm
</route>
5 changes: 3 additions & 2 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ label:
avg-mem: Avg. MEM (%)
pinned: Pinned
per-page: Rows per page
swarm-mode: Swarm Mode
custom-groups: Custom Groups
host-menu: Hosts and Containers
swarm-menu: Services and Stacks
groups-menu: Custom Groups
tooltip:
search: Search containers (⌘ + k, ⌃k)
pin-column: Pin as column
Expand Down

0 comments on commit 05b6715

Please sign in to comment.