Skip to content

Commit 3c0cb35

Browse files
committed
chore: migrate from KTable to KTableView
Signed-off-by: John Cowen <[email protected]>
1 parent 9ec0df6 commit 3c0cb35

File tree

3 files changed

+55
-54
lines changed

3 files changed

+55
-54
lines changed

packages/kuma-gui/features/mesh/dataplanes/Index.feature

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ Feature: mesh / dataplanes / index
22

33
Background:
44
Given the CSS selectors
5-
| Alias | Selector |
6-
| table | [data-testid='data-plane-collection'] |
7-
| table-header | $table th |
8-
| item | $table tbody tr |
9-
| service-cell | $item:nth-child(1) td:nth-child(3) |
10-
| select-type | [data-testid='select-input'] |
11-
| select-option | .select-item |
12-
| select-standard | [data-testid='select-item-standard'] button |
13-
| select-builtin | [data-testid='select-item-builtin'] button |
14-
| select-delegated | [data-testid='select-item-delegated'] button |
15-
| input-search | [data-testid='filter-bar-filter-input'] |
16-
| button-search | [data-testid='filter-bar-submit-query-button'] |
5+
| Alias | Selector |
6+
| table | [data-testid='data-plane-collection'] |
7+
| table-header | $table th |
8+
| item | $table tbody tr |
9+
| service-cell | $item:nth-child(1) td:nth-child(3) .cell-wrapper |
10+
| select-type | [data-testid='select-input'] |
11+
| select-option | .select-item |
12+
| select-standard | [data-testid='select-item-standard'] button |
13+
| select-builtin | [data-testid='select-item-builtin'] button |
14+
| select-delegated | [data-testid='select-item-delegated'] button |
15+
| input-search | [data-testid='filter-bar-filter-input'] |
16+
| button-search | [data-testid='filter-bar-submit-query-button'] |
1717
And the environment
1818
"""
1919
KUMA_MODE: global

packages/kuma-gui/src/app/application/components/app-collection/AppCollection.vue

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<template>
2-
<KTable
2+
<KTableView
33
data-testid="app-collection"
44
class="app-collection"
5-
:headers="props.headers"
6-
:fetcher-cache-key="String(cacheKey)"
7-
:fetcher="() => {
8-
return { data: props.items }
9-
}"
10-
:cell-attrs="({ headerKey }: CellAttrParams) => ({
5+
:headers="props.headers.map((item) => {
6+
if(item.key === 'actions') {
7+
item.key = '_actions'
8+
}
9+
return item
10+
})"
11+
:data="typeof props.items === 'undefined' ? [] : props.items"
12+
:cell-attrs="({ headerKey }) => ({
1113
class: `${headerKey}-column`,
1214
})"
1315
:row-attrs="getRowAttributes"
14-
:disable-sorting="true"
15-
:disable-pagination="true"
16+
:hide-pagination="true"
1617
:resize-columns="true"
1718
:table-preferences="{
1819
columnWidths: props.headers.reduce<Record<string, number>>((prev, value) => {
@@ -27,31 +28,25 @@
2728
@update:table-preferences="resize"
2829
>
2930
<template
30-
v-for="key in Object.keys(slots)"
31+
v-for="key in Object.keys(slots).map((item) => item === 'actions' ? '_actions' : item)"
3132
:key="key"
3233
#[key]="{ row }"
3334
>
3435
<slot
3536
v-if="(props.items ?? []).length > 0"
36-
:name="key"
37+
:name="key === '_actions' ? 'actions' : key"
3738
:row="row as Row"
3839
/>
3940
</template>
40-
</KTable>
41+
</KTableView>
4142
</template>
4243

4344
<script lang="ts" setup generic="Row extends {}">
44-
import { KTable } from '@kong/kongponents'
45-
import { ref, watch, Ref, inject } from 'vue'
45+
import { KTableView } from '@kong/kongponents'
46+
import { inject } from 'vue'
4647
4748
import { runInDebug } from '../../'
4849
import type { TableHeader as KTableHeader, TablePreferences } from '@kong/kongponents'
49-
type CellAttrParams = {
50-
headerKey: string
51-
row: Row
52-
rowIndex: number
53-
colIndex: number
54-
}
5550
type ResizeValue = {
5651
headers: Record<string, { width: number }>
5752
}
@@ -90,9 +85,6 @@ const slots = defineSlots<{
9085
}) => any
9186
}>()
9287
93-
const items = ref(props.items) as Ref<typeof props.items>
94-
const cacheKey = ref<number>(0)
95-
9688
const resize = (args: TablePreferences) => {
9789
const headers = Object.entries(args.columnWidths ?? {}).reduce<Record<string, { width: number }>>((prev, [key, value]) => {
9890
prev[key] = {
@@ -106,21 +98,14 @@ const resize = (args: TablePreferences) => {
10698
})
10799
}
108100
109-
watch(() => props.items, (newItems, oldItems) => {
110-
if (newItems !== oldItems) {
111-
cacheKey.value++
112-
items.value = props.items
113-
}
114-
})
115-
116-
function getRowAttributes(row: Row): Record<string, string> {
101+
function getRowAttributes(row: Record<string, any>): Record<string, any> {
117102
if (!row) {
118103
return {}
119104
}
120105
121106
const attributes: Record<string, string> = {}
122107
123-
if (typeof props.isSelectedRow !== 'undefined' && props.isSelectedRow(row)) {
108+
if (typeof props.isSelectedRow !== 'undefined' && props.isSelectedRow(row as Row)) {
124109
attributes.class = 'is-selected'
125110
}
126111
@@ -160,7 +145,7 @@ const click = (e: MouseEvent) => {
160145

161146
<style lang="scss">
162147
163-
.app-collection .actions-column {
148+
.app-collection ._actions-column {
164149
width: 48px;
165150
}
166151
.app-collection .is-selected {

packages/kuma-gui/src/app/policies/components/PolicyTypeEntryList.vue

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
<template #accordion-content>
1919
<div class="policy-list">
20-
<KTable
20+
<KTableView
2121
class="policy-type-table"
22-
:fetcher="() => ({ data: policyTypeEntry.connections, total: policyTypeEntry.connections.length })"
22+
:data="policyTypeEntry.connections"
2323
:headers="[
2424
{ label: 'From', key: 'sourceTags' },
2525
{ label: 'To', key: 'destinationTags' },
@@ -28,7 +28,7 @@
2828
{ label: 'Origin policies', key: 'origins' },
2929
]"
3030
:cell-attrs="getCellAttributes"
31-
disable-pagination
31+
hide-pagination
3232
is-clickable
3333
>
3434
<template #sourceTags="{ row }: { row: PolicyTypeEntryConnection }">
@@ -106,7 +106,7 @@
106106
107107
</template>
108108
</template>
109-
</KTable>
109+
</KTableView>
110110
</div>
111111
</template>
112112
</AccordionItem>
@@ -115,6 +115,8 @@
115115

116116
<script lang="ts" setup>
117117
118+
import { KTableView } from '@kong/kongponents'
119+
118120
import type { PolicyResourceType } from '../data'
119121
import { YAML } from '@/app/application'
120122
import AccordionItem from '@/app/common/AccordionItem.vue'
@@ -156,9 +158,23 @@ function getCellAttributes({ headerKey }: any): Record<string, string> {
156158
vertical-align: top;
157159
}
158160
159-
.cell-sourceTags { width: 15%; }
160-
.cell-destinationTags { width: 20%; }
161-
.cell-name { width: 15%; }
162-
.cell-config { width: 35%; }
163-
.cell-origins { width: 15%; }
161+
.cell-sourceTags {
162+
width: 15%;
163+
}
164+
165+
.cell-destinationTags {
166+
width: 20%;
167+
}
168+
169+
.cell-name {
170+
width: 15%;
171+
}
172+
173+
.cell-config {
174+
width: 35%;
175+
}
176+
177+
.cell-origins {
178+
width: 15%;
179+
}
164180
</style>

0 commit comments

Comments
 (0)