Skip to content

Commit cd77e5d

Browse files
authored
fix(plugin-multi-tenant): cannot clear selected tenant from dashboard view (#15141)
This PR allows clearing the currently selected tenant from the admin panel dashboard.
1 parent 529726e commit cd77e5d

3 files changed

Lines changed: 85 additions & 4 deletions

File tree

packages/plugin-multi-tenant/src/components/TenantSelector/index.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const TenantSelectorClient = ({
7373
return (
7474
<div className="tenant-selector">
7575
<SelectInput
76-
isClearable={viewType === 'list'}
76+
isClearable={['dashboard', 'list'].includes(viewType ?? '')}
7777
label={
7878
label ? getTranslation(label, i18n) : t('plugin-multi-tenant:nav-tenantSelector-label')
7979
}

test/helpers/e2e/selectInput.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Locator } from '@playwright/test'
1+
import { expect, type Locator } from '@playwright/test'
22

33
import { exactText } from '../../helpers.js'
44

@@ -124,7 +124,7 @@ type GetSelectInputValueFunction = <TMultiSelect = true>(args: {
124124
selectLocator: Locator
125125
selectType?: 'relationship' | 'select'
126126
valueLabelClass?: string
127-
}) => Promise<TMultiSelect extends true ? string[] : string | undefined>
127+
}) => Promise<TMultiSelect extends true ? string[] : false | string | undefined>
128128

129129
export const getSelectInputValue: GetSelectInputValueFunction = async ({
130130
selectLocator,
@@ -139,8 +139,15 @@ export const getSelectInputValue: GetSelectInputValueFunction = async ({
139139
return selectedOptions || []
140140
}
141141

142+
await expect(selectLocator).toBeVisible()
143+
142144
// For single-select, get the selected value
143-
const singleValue = await selectLocator.locator(selectors.hasOne[selectType]).textContent()
145+
const valueLocator = selectLocator.locator(selectors.hasOne[selectType])
146+
const count = await valueLocator.count()
147+
if (count === 0) {
148+
return false
149+
}
150+
const singleValue = await valueLocator.textContent()
144151
return (singleValue ?? undefined) as any
145152
}
146153

test/plugin-multi-tenant/e2e.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,80 @@ test.describe('Multi Tenant', () => {
802802
})
803803
.toEqual(['Blue Dog', 'Steel Cat', 'Anchor Bar', 'Public Tenant', 'House Rules'].sort())
804804
})
805+
806+
test('should allow clearing tenant filter from dashboard view', async () => {
807+
await loginClientSide({
808+
data: credentials.admin,
809+
page,
810+
serverURL,
811+
})
812+
813+
// First set a tenant filter
814+
await setTenantFilter({
815+
page,
816+
tenant: 'Blue Dog',
817+
urlUtil: tenantsURL,
818+
})
819+
820+
// Navigate to dashboard view
821+
await page.goto(`${serverURL}/admin`)
822+
823+
// Clear the tenant filter from the dashboard
824+
await clearTenantFilter({ page })
825+
826+
// Verify the tenant selector is cleared
827+
await openNav(page)
828+
await expect
829+
.poll(async () => {
830+
return await getSelectInputValue<false>({
831+
multiSelect: false,
832+
selectLocator: page.locator('.tenant-selector'),
833+
})
834+
})
835+
.toBeFalsy()
836+
})
837+
838+
test('should allow clearing tenant filter from list view', async () => {
839+
await loginClientSide({
840+
data: credentials.admin,
841+
page,
842+
serverURL,
843+
})
844+
845+
// First set a tenant filter
846+
await setTenantFilter({
847+
page,
848+
tenant: 'Steel Cat',
849+
urlUtil: menuItemsURL,
850+
})
851+
852+
// Verify tenant is set
853+
await openNav(page)
854+
855+
await expect
856+
.poll(async () => {
857+
return await getSelectInputValue<false>({
858+
multiSelect: false,
859+
selectLocator: page.locator('.tenant-selector'),
860+
})
861+
})
862+
.toBe('Steel Cat')
863+
864+
// Clear the tenant filter from the list view
865+
await clearTenantFilter({ page })
866+
867+
// Verify the tenant selector is cleared
868+
await openNav(page)
869+
870+
await expect
871+
.poll(async () => {
872+
return await getSelectInputValue<false>({
873+
multiSelect: false,
874+
selectLocator: page.locator('.tenant-selector'),
875+
})
876+
})
877+
.toBeFalsy()
878+
})
805879
})
806880
})
807881

0 commit comments

Comments
 (0)