Skip to content

Commit 3026838

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

File tree

3 files changed

+77
-59
lines changed

3 files changed

+77
-59
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: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<template>
2-
<KTable
2+
<KTableView
3+
ref="$ref"
34
data-testid="app-collection"
45
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) => ({
6+
:headers="props.headers.map((item) => {
7+
if (item.key === 'actions') {
8+
item.key = '_actions'
9+
}
10+
return item
11+
})"
12+
:data="typeof props.items === 'undefined' ? [] : props.items"
13+
:cell-attrs="({ headerKey }) => ({
1114
class: `${headerKey}-column`,
1215
})"
1316
:row-attrs="getRowAttributes"
14-
:disable-sorting="true"
15-
:disable-pagination="true"
17+
:hide-pagination="true"
1618
:resize-columns="true"
1719
:table-preferences="{
1820
columnWidths: props.headers.reduce<Record<string, number>>((prev, value) => {
19-
if(typeof value.width !== 'undefined') {
21+
if (typeof value.width !== 'undefined') {
2022
prev[value.key] = value.width
2123
}
2224
return prev
@@ -27,39 +29,35 @@
2729
@update:table-preferences="resize"
2830
>
2931
<template
30-
v-for="key in Object.keys(slots)"
32+
v-for="key in Object.keys(slots).map((item) => item === 'actions' ? '_actions' : item)"
3133
:key="key"
3234
#[key]="{ row }"
3335
>
3436
<slot
3537
v-if="(props.items ?? []).length > 0"
36-
:name="key"
38+
:name="key === '_actions' ? 'actions' : key"
3739
:row="row as Row"
3840
/>
3941
</template>
40-
</KTable>
42+
</KTableView>
4143
</template>
4244

4345
<script lang="ts" setup generic="Row extends {}">
44-
import { KTable } from '@kong/kongponents'
45-
import { ref, watch, Ref, inject } from 'vue'
46+
import { KTableView } from '@kong/kongponents'
47+
import { ref, inject, onMounted } from 'vue'
48+
4649
4750
import { runInDebug } from '../../'
48-
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-
}
51+
import type { TableViewHeader as KTableViewHeader, TablePreferences } from '@kong/kongponents'
5552
type ResizeValue = {
5653
headers: Record<string, { width: number }>
5754
}
5855
59-
type TableHeader = KTableHeader & {
56+
type TableHeader = KTableViewHeader & {
6057
width?: number
6158
}
6259
60+
6361
// when we are inside of a DataLoader make sure its using the `variant="list"`
6462
// but only error in dev mode, if this fails in production we don't want things
6563
// to blow up
@@ -90,9 +88,6 @@ const slots = defineSlots<{
9088
}) => any
9189
}>()
9290
93-
const items = ref(props.items) as Ref<typeof props.items>
94-
const cacheKey = ref<number>(0)
95-
9691
const resize = (args: TablePreferences) => {
9792
const headers = Object.entries(args.columnWidths ?? {}).reduce<Record<string, { width: number }>>((prev, [key, value]) => {
9893
prev[key] = {
@@ -106,27 +101,20 @@ const resize = (args: TablePreferences) => {
106101
})
107102
}
108103
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> {
104+
function getRowAttributes(row: Record<string, any>): Record<string, any> {
117105
if (!row) {
118106
return {}
119107
}
120108
121109
const attributes: Record<string, string> = {}
122110
123-
if (typeof props.isSelectedRow !== 'undefined' && props.isSelectedRow(row)) {
111+
if (typeof props.isSelectedRow !== 'undefined' && props.isSelectedRow(row as Row)) {
124112
attributes.class = 'is-selected'
125113
}
126114
127115
return attributes
128116
}
129-
const click = (e: MouseEvent) => {
117+
const click = (e: Event) => {
130118
const $tr = (e.target as HTMLElement).closest('tr')
131119
if ($tr) {
132120
const $a: HTMLAnchorElement | null = ['td:first-child a', '[data-action]'].reduce<HTMLAnchorElement | null>((prev, item) => {
@@ -141,6 +129,18 @@ const click = (e: MouseEvent) => {
141129
}
142130
}
143131
}
132+
const $ref = ref<InstanceType<typeof KTableView> | null>(null)
133+
const rewrite = () => {
134+
const $el = $ref.value?.$el
135+
if (
136+
((el: any | HTMLElement): el is HTMLElement => el && typeof el.querySelectorAll === 'function')($el)
137+
) {
138+
const $trs = $el.querySelectorAll('tr[tabindex="0"]')
139+
;['tabindex'].forEach(attr => Array.from($trs).forEach(item => item.removeAttribute(attr)))
140+
}
141+
}
142+
onMounted(rewrite)
143+
144144
</script>
145145

146146
<style lang="scss" scoped>
@@ -149,20 +149,22 @@ const click = (e: MouseEvent) => {
149149
font-weight: $kui-font-weight-semibold;
150150
text-decoration: none;
151151
}
152+
152153
.app-collection :deep(td:first-child li a) {
153154
color: $kui-color-text-primary;
154155
font-weight: $kui-font-weight-regular;
155156
}
157+
156158
.app-collection :deep(td:first-child li a:hover) {
157159
text-decoration: underline;
158160
}
159161
</style>
160162

161163
<style lang="scss">
162-
163-
.app-collection .actions-column {
164+
.app-collection ._actions-column {
164165
width: 48px;
165166
}
167+
166168
.app-collection .is-selected {
167169
background-color: $kui-color-background-neutral-weakest;
168170
}

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)