Skip to content

Commit

Permalink
fix(ktable): disable column visibility dropdown [KHCP-13248]
Browse files Browse the repository at this point in the history
  • Loading branch information
portikM committed Sep 13, 2024
1 parent e41db18 commit ef108c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/components/KTable/ColumnVisibilityMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="table-column-visibility-menu">
<KDropdown
data-testid="table-column-visibility-menu"
:disabled="disabled"
:kpop-attributes="{ placement: 'bottom-end' }"
@toggle-dropdown="handleDropdownToggle"
>
Expand All @@ -14,6 +15,7 @@
aria-label="Show/Hide Columns"
class="menu-button"
data-testid="column-visibility-menu-button"
:disabled="disabled"
icon
size="large"
>
Expand Down Expand Up @@ -91,6 +93,10 @@ const props = defineProps({
type: Object as PropType<Record<string, boolean>>,
default: () => ({}),
},
disabled: {
type: Boolean,
default: false,
},
})
const isDropdownOpen = ref<boolean>(false)
Expand Down
17 changes: 13 additions & 4 deletions src/components/KTable/KTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
name="toolbar"
:state="stateData"
/>

<ColumnVisibilityMenu
v-if="hasColumnVisibilityMenu"
:columns="visibilityColumns"
:disabled="columnVisibilityDisabled"
:table-id="tableId"
:visibility-preferences="visibilityPreferences"
@update="(columnMap: Record<string, boolean>) => columnVisibility = columnMap"
Expand Down Expand Up @@ -530,10 +531,18 @@ const resizerHoveredColumn = ref('')
const currentHoveredColumn = ref('')
const hasHidableColumns = computed((): boolean => tableHeaders.value.filter((header: TableHeader) => header.hidable).length > 0)
const hasColumnVisibilityMenu = computed((): boolean => {
// has hidable columns, no error/loading/empty state
return !!(hasHidableColumns.value &&
!props.error && !isTableLoading.value && !props.loading && (data.value && data.value.length))
if (!hasHidableColumns.value || props.error) {
return false
}
if (slots.toolbar) {
// when toolbar slot is present, we want to disable column visibility menu rather than hide it in certain states
return true
}
return !isTableLoading.value && !props.loading && data.value && !!data.value.length
})
const columnVisibilityDisabled = computed((): boolean => isTableLoading.value || props.loading || !(data.value && data.value.length))
// columns whose visibility can be toggled
const visibilityColumns = computed((): TableHeader[] => tableHeaders.value.filter((header: TableHeader) => header.hidable))
// visibility preferences from the host app (initialized by app)
Expand Down

0 comments on commit ef108c9

Please sign in to comment.