Skip to content

Commit

Permalink
fix(ktable): init col visibility [khcp-11730] (#2169)
Browse files Browse the repository at this point in the history
Fix an issue where initial provided visibility preferences were immediately cleared for [KHCP-11730](https://konghq.atlassian.net/browse/KHCP-11730).
  • Loading branch information
kaiarrowood authored and adamdehaven committed Jun 15, 2024
1 parent 3d3edcb commit e87426e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/KTable/ColumnVisibilityMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const setOverflowClass = (el: HTMLDivElement) => {
watch(() => props.visibilityPreferences, () => {
initVisibilityMap()
})
}, { immediate: true })
onMounted(() => {
if (menuItemsRef.value) {
Expand Down
5 changes: 3 additions & 2 deletions src/components/KTable/KTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ const resizerHoveredColumn = ref('')
const currentHoveredColumn = ref('')
const hasColumnVisibilityMenu = computed((): boolean => {
// has hidable columns, no error/loading/empty state
return !!(tableHeaders.value.filter((header: TableHeader) => header.hidable).length > 0 &&
return !!(hasHidableColumns.value &&
!props.hasError && !isTableLoading.value && !props.isLoading && (data.value && data.value.length))
})
// columns whose visibility can be toggled
Expand Down Expand Up @@ -1034,13 +1034,14 @@ const scrollHandler = (event: any): void => {
}
}
const hasHidableColumns = computed((): boolean => tableHeaders.value.filter((header: TableHeader) => header.hidable).length > 0)
// Store the tablePreferences in a computed property to utilize in the watcher
const tablePreferences = computed((): TablePreferences => ({
pageSize: pageSize.value,
sortColumnKey: sortColumnKey.value,
sortColumnOrder: sortColumnOrder.value as 'asc' | 'desc',
...(props.resizeColumns ? { columnWidths: columnWidths.value } : {}),
...(hasColumnVisibilityMenu.value ? { columnVisibility: columnVisibility.value } : {}),
...(hasHidableColumns.value ? { columnVisibility: columnVisibility.value } : {}),
}))
const emitTablePreferences = (): void => {
Expand Down

0 comments on commit e87426e

Please sign in to comment.