Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): add support to EntityBaseTable to use action button outside [KHCP-9618] #913

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
preferences-storage-key="kong-ui-entities-ca-certificates-list"
:query="filterQuery"
:table-headers="tableHeaders"
:use-action-outside="useActionOutside"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mptap Should this line be removed? Because EntityBaseTable does not have the use-action-outside prop.

@clear-search-input="clearFilter"
@click:row="(row: any) => rowClick(row as EntityRow)"
@sort="resetPagination"
Expand All @@ -26,16 +27,23 @@
</template>
<!-- Create action -->
<template #toolbar-button>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
appearance="primary"
data-testid="toolbar-add-ca-certificate"
icon="plus"
:to="config.createRoute"
>
{{ t('ca-certificates.list.toolbar_actions.new_ca_certificate') }}
</KButton>
</PermissionsWrapper>
<!-- Hide Create button if table is empty -->
<Teleport
:disabled="!useActionOutside"
to="#kong-ui-app-page-header-action-button"
>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
v-show="hasData"
appearance="primary"
data-testid="toolbar-add-ca-certificate"
icon="plus"
:to="config.createRoute"
>
{{ t('ca-certificates.list.toolbar_actions.new_ca_certificate') }}
</KButton>
</PermissionsWrapper>
</Teleport>
</template>

<!-- Column Formatting -->
Expand Down Expand Up @@ -215,6 +223,11 @@ const props = defineProps({
required: false,
default: async () => true,
},
/** default to false, setting to true will teleport the toolbar button to the destination in the consuming app */
useActionOutside: {
type: Boolean,
default: false,
},
})

const { i18n: { t, formatUnixTimeStamp }, i18nT } = composables.useI18n()
Expand Down Expand Up @@ -415,10 +428,17 @@ const confirmDelete = async (): Promise<void> => {
}
}

const hasData = ref(true)

/**
* Watchers
*/
watch(fetcherState, (state) => {
// if table is empty, hide the teleported Create button
if (state?.response?.data?.length === 0) {
hasData.value = false
}

if (state.status === FetcherStatus.Error) {
errorMessage.value = {
title: t('ca-certificates.errors.general'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
preferences-storage-key="kong-ui-entities-certificates-list"
:query="filterQuery"
:table-headers="tableHeaders"
:use-action-outside="useActionOutside"
@clear-search-input="clearFilter"
@click:row="(row: any) => rowClick(row as EntityRow)"
@sort="resetPagination"
Expand All @@ -26,16 +27,23 @@
</template>
<!-- Create action -->
<template #toolbar-button>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
appearance="primary"
data-testid="toolbar-add-certificate"
icon="plus"
:to="config.createRoute"
>
{{ t('certificates.list.toolbar_actions.new_certificate') }}
</KButton>
</PermissionsWrapper>
<!-- Hide Create button if table is empty -->
<Teleport
:disabled="!useActionOutside"
to="#kong-ui-app-page-header-action-button"
>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
v-show="hasData"
appearance="primary"
data-testid="toolbar-add-certificate"
icon="plus"
:to="config.createRoute"
>
{{ t('certificates.list.toolbar_actions.new_certificate') }}
</KButton>
</PermissionsWrapper>
</Teleport>
</template>

<!-- Column Formatting -->
Expand Down Expand Up @@ -249,6 +257,11 @@ const props = defineProps({
required: false,
default: async () => true,
},
/** default to false, setting to true will teleport the toolbar button to the destination in the consuming app */
useActionOutside: {
type: Boolean,
default: false,
},
})

const { i18n: { t, formatUnixTimeStamp }, i18nT } = composables.useI18n()
Expand Down Expand Up @@ -482,10 +495,17 @@ const confirmDelete = async (): Promise<void> => {
}
}

const hasData = ref(true)

/**
* Watchers
*/
watch(fetcherState, (state) => {
// if table is empty, hide the teleported Create button
if (state?.response?.data?.length === 0) {
hasData.value = false
}

if (state.status === FetcherStatus.Error) {
errorMessage.value = {
title: t('certificates.errors.general'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@
pagination-type="offset"
preferences-storage-key="kong-ui-entities-consumer-credentials-list"
:table-headers="tableHeaders"
:use-action-outside="useActionOutside"
@sort="resetPagination"
>
<!-- Create action -->
<template #toolbar-button>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
appearance="primary"
data-testid="toolbar-add-credential"
icon="plus"
:to="config.createRoute"
>
{{ t(`credentials.list.toolbar_actions.${config.plugin}.new`) }}
</KButton>
</PermissionsWrapper>
<!-- Hide Create button if table is empty -->
<Teleport
:disabled="!useActionOutside"
to="#kong-ui-app-page-header-action-button"
>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
v-show="hasData"
appearance="primary"
data-testid="toolbar-add-credential"
icon="plus"
:to="config.createRoute"
>
{{ t(`credentials.list.toolbar_actions.${config.plugin}.new`) }}
</KButton>
</PermissionsWrapper>
</Teleport>
</template>

<!-- Column Formatting -->
Expand Down Expand Up @@ -251,6 +259,11 @@ const props = defineProps({
required: false,
default: async () => true,
},
/** default to false, setting to true will teleport the toolbar button to the destination in the consuming app */
useActionOutside: {
type: Boolean,
default: false,
},
})

const { i18n: { t, formatUnixTimeStamp } } = composables.useI18n()
Expand Down Expand Up @@ -443,10 +456,18 @@ const confirmDelete = async (): Promise<void> => {
}
}

// Remount the table when hasData changes
const hasData = ref(true)

/**
* Watchers
*/
watch(fetcherState, (state) => {
// if table is empty, hide the teleported Create button
if (state?.response?.data?.length === 0) {
hasData.value = false
}

if (state.status === FetcherStatus.Error) {
errorMessage.value = {
title: t('credentials.error.general'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:query="filterQuery"
:row-attributes="rowAttributes"
:table-headers="tableHeaders"
:use-action-outside="useActionOutside"
@clear-search-input="clearFilter"
@click:row="(row: any) => rowClick(row as EntityRow)"
@empty-state-cta-clicked="handleEmptyStateCtaClicked"
Expand All @@ -30,17 +31,24 @@
</template>
<!-- Create action -->
<template #toolbar-button>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
appearance="primary"
data-testid="toolbar-add-consumer-group"
icon="plus"
:to="config.consumerId ? undefined : config.createRoute"
@click="() => config.consumerId ? handleAddToGroupClick() : undefined"
>
{{ config.consumerId ? t('consumer_groups.actions.add_to_group') : t('consumer_groups.list.toolbar_actions.new_consumer_group') }}
</KButton>
</PermissionsWrapper>
<!-- Hide Create button if table is empty -->
<Teleport
:disabled="!useActionOutside"
to="#kong-ui-app-page-header-action-button"
>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
v-show="hasData"
appearance="primary"
data-testid="toolbar-add-consumer-group"
icon="plus"
:to="config.consumerId ? undefined : config.createRoute"
@click="() => config.consumerId ? handleAddToGroupClick() : undefined"
>
{{ config.consumerId ? t('consumer_groups.actions.add_to_group') : t('consumer_groups.list.toolbar_actions.new_consumer_group') }}
</KButton>
</PermissionsWrapper>
</Teleport>
</template>

<!-- Column Formatting -->
Expand Down Expand Up @@ -252,6 +260,11 @@ const props = defineProps({
required: false,
default: async () => true,
},
/** default to false, setting to true will teleport the toolbar button to the destination in the consuming app */
useActionOutside: {
type: Boolean,
default: false,
},
})

const { i18nT, i18n: { t } } = composables.useI18n()
Expand Down Expand Up @@ -543,10 +556,17 @@ const exitGroups = async (): Promise<void> => {
}
}

const hasData = ref(true)

/**
* Watchers
*/
watch(fetcherState, (state) => {
// if table is empty, hide the teleported Create button
if (state?.response?.data?.length === 0) {
hasData.value = false
}

if (state.status === FetcherStatus.Error) {
errorMessage.value = {
title: t('consumer_groups.errors.general'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:query="filterQuery"
:row-attributes="rowAttributes"
:table-headers="tableHeaders"
:use-action-outside="useActionOutside"
@clear-search-input="clearFilter"
@click:row="(row: any) => rowClick(row as EntityRow)"
@empty-state-cta-clicked="handleEmptyStateCtaClicked"
Expand All @@ -30,17 +31,24 @@
</template>
<!-- Create action -->
<template #toolbar-button>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
appearance="primary"
data-testid="toolbar-add-consumer"
icon="plus"
:to="config.consumerGroupId ? undefined : config.createRoute"
@click="() => config.consumerGroupId ? handleAddConsumerClick() : undefined"
>
{{ config.consumerGroupId ? t('consumers.actions.add_consumer') : t('consumers.list.toolbar_actions.new_consumer') }}
</KButton>
</PermissionsWrapper>
<!-- Hide Create button if table is empty -->
<Teleport
:disabled="!useActionOutside"
to="#kong-ui-app-page-header-action-button"
>
<PermissionsWrapper :auth-function="() => canCreate()">
<KButton
v-show="hasData"
appearance="primary"
data-testid="toolbar-add-consumer"
icon="plus"
:to="config.consumerGroupId ? undefined : config.createRoute"
@click="() => config.consumerGroupId ? handleAddConsumerClick() : undefined"
>
{{ config.consumerGroupId ? t('consumers.actions.add_consumer') : t('consumers.list.toolbar_actions.new_consumer') }}
</KButton>
</PermissionsWrapper>
</Teleport>
</template>

<!-- Column Formatting -->
Expand Down Expand Up @@ -252,6 +260,11 @@ const props = defineProps({
required: false,
default: async () => true,
},
/** default to false, setting to true will teleport the toolbar button to the destination in the consuming app */
useActionOutside: {
type: Boolean,
default: false,
},
})

const { i18nT, i18n: { t } } = composables.useI18n()
Expand Down Expand Up @@ -553,10 +566,17 @@ const removeConsumers = async (): Promise<void> => {
}
}

const hasData = ref(true)

/**
* Watchers
*/
watch(fetcherState, (state) => {
// if table is empty, hide the teleported Create button
if (state?.response?.data?.length === 0) {
hasData.value = false
}

if (state.status === FetcherStatus.Error) {
errorMessage.value = {
title: t('consumers.errors.general'),
Expand Down
Loading
Loading