Skip to content

Commit fcfa5cc

Browse files
committed
fix: paginate nodes list page
Enable search for the `ClusterMachineHostname`. Disable filtering by the node status, as it's not going to work in paginated mode for the data pulled from Kubernetes. Signed-off-by: Artem Chernyshev <[email protected]>
1 parent 725584c commit fcfa5cc

File tree

3 files changed

+31
-70
lines changed

3 files changed

+31
-70
lines changed

client/pkg/omni/resources/omni/cluster_machine_status.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package omni
66

77
import (
8+
"strings"
9+
810
"github.com/cosi-project/runtime/pkg/resource"
911
"github.com/cosi-project/runtime/pkg/resource/meta"
1012
"github.com/cosi-project/runtime/pkg/resource/protobuf"
@@ -58,3 +60,21 @@ func (ClusterMachineStatusExtension) ResourceDefinition() meta.ResourceDefinitio
5860
},
5961
}
6062
}
63+
64+
// Make implements [typed.Maker] interface.
65+
func (ClusterMachineStatusExtension) Make(md *resource.Metadata, _ *ClusterMachineStatusSpec) any {
66+
return &clusterMachineStatusAux{md: md}
67+
}
68+
69+
type clusterMachineStatusAux struct {
70+
md *resource.Metadata
71+
}
72+
73+
func (m *clusterMachineStatusAux) Match(searchFor string) bool {
74+
val, ok := m.md.Labels().Get(ClusterMachineStatusLabelNodeName)
75+
if ok && strings.Contains(val, searchFor) {
76+
return true
77+
}
78+
79+
return false
80+
}

frontend/src/components/common/List/TList.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const sortByState = computed(() => {
138138
if (opt.desc === selectedSortOption?.value) {
139139
return {
140140
sortByField: opt.id,
141-
sortDescending: opt.descending,
141+
sortDescending: opt.descending
142142
};
143143
}
144144
}
@@ -311,7 +311,7 @@ const openPage = (page: number | string) => {
311311
if (page === dots) {
312312
return;
313313
}
314-
314+
315315
currentPage.value = page as number;
316316
};
317317
</script>

frontend/src/views/cluster/Nodes/NodesList.vue

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,8 @@ included in the LICENSE file.
77
<template>
88
<div class="flex flex-col w-full gap-4">
99
<page-header title="All Nodes"/>
10-
<div class="flex gap-2">
11-
<t-input
12-
primary
13-
class="flex-1"
14-
placeholder="Search..."
15-
v-model="searchOption"
16-
/>
17-
<t-select-list
18-
title="Status"
19-
:defaultValue="NodesViewFilterOptions.ALL"
20-
:values="filterOptions"
21-
@checkedValue="setFilterOption"
22-
/>
23-
</div>
24-
<watch :opts="opts" spinner noRecordsAlert errorsAlert>
25-
<template #default="{ items }">
10+
<t-list :opts="opts" search pagination>
11+
<template #default="{ items, searchQuery }">
2612
<div class="nodes-list">
2713
<div class="nodes-list-heading">
2814
<p>Name</p>
@@ -33,45 +19,32 @@ included in the LICENSE file.
3319
</div>
3420
<t-group-animation>
3521
<nodes-item
36-
v-for="item in filterItems(items)"
22+
v-for="item in items"
3723
:key="item.metadata.id!"
3824
:item="item"
39-
:searchOption="searchOption"
25+
:searchOption="searchQuery"
4026
/>
4127
</t-group-animation>
4228
</div>
4329
</template>
44-
</watch>
30+
</t-list>
4531
</div>
4632
</template>
4733

4834
<script setup lang="ts">
4935
import { getContext } from "@/context";
5036
import { kubernetes, ClusterMachineStatusType, LabelCluster, ClusterMachineStatusLabelNodeName, TalosMemberType, TalosClusterNamespace } from "@/api/resources";
5137
import { Runtime } from "@/api/common/omni.pb";
52-
import { Resource, ResourceTyped } from "@/api/grpc";
5338
import { ClusterMachineStatusSpec } from "@/api/omni/specs/omni.pb";
5439
import { useRoute } from "vue-router";
5540
import { DefaultNamespace } from "@/api/resources";
56-
import { Node, NodeSpec, NodeStatus } from "kubernetes-types/core/v1";
57-
import { NodesViewFilterOptions } from "@/constants";
58-
import { ref } from "vue";
59-
import { getStatus } from "@/methods";
41+
import { Node } from "kubernetes-types/core/v1";
6042
61-
import Watch from "@/components/common/Watch/Watch.vue";
43+
import TList from "@/components/common/List/TList.vue";
6244
import PageHeader from "@/components/common/PageHeader.vue";
6345
import NodesItem from "@/views/cluster/Nodes/components/NodesItem.vue";
6446
import TGroupAnimation from "@/components/common/Animation/TGroupAnimation.vue";
65-
import TInput from "@/components/common/TInput/TInput.vue";
66-
import TSelectList from "@/components/common/SelectList/TSelectList.vue";
67-
68-
const filterOption = ref("All");
69-
const searchOption = ref("");
70-
const setFilterOption = (data: string) => {
71-
filterOption.value = data;
72-
};
73-
74-
const filterOptions = Object.keys(NodesViewFilterOptions).map(key => NodesViewFilterOptions[key]);
47+
import { Resource } from "@/api/v1alpha1/resource.pb";
7548
7649
const route = useRoute();
7750
const context = getContext();
@@ -86,7 +59,7 @@ const opts = [
8659
selectors: [
8760
`${LabelCluster}=${route.params.cluster}`
8861
],
89-
idFunc: (item: ResourceTyped<ClusterMachineStatusSpec>): string => {
62+
idFunc: (item: Resource<ClusterMachineStatusSpec>): string => {
9063
return (item?.metadata?.labels ?? {})[ClusterMachineStatusLabelNodeName] ?? item.metadata.id;
9164
}
9265
},
@@ -111,38 +84,6 @@ const opts = [
11184
return item.metadata.id;
11285
}
11386
}];
114-
115-
type MemberSpec = {
116-
operatingSystem: string,
117-
addresses: string[],
118-
}
119-
120-
const filterItems = (items: Resource<ClusterMachineStatusSpec & NodeSpec & MemberSpec, NodeStatus>[]) => {
121-
return items.filter((elem: any) => {
122-
const searchFields = [
123-
(elem?.metadata.labels || {})[ClusterMachineStatusLabelNodeName],
124-
elem?.metadata.id,
125-
elem?.spec.operatingSystem,
126-
(elem?.spec?.addresses ?? {})[0] ?? ""
127-
];
128-
129-
if (getStatus(elem) !== filterOption?.value && filterOption?.value !== NodesViewFilterOptions.ALL) {
130-
return false;
131-
}
132-
133-
if (searchOption?.value === "") {
134-
return true;
135-
}
136-
137-
for (const value of searchFields) {
138-
if (value.includes(searchOption?.value)) {
139-
return true;
140-
}
141-
}
142-
143-
return false;
144-
})
145-
};
14687
</script>
14788

14889
<style scoped>

0 commit comments

Comments
 (0)