Fix the deleted assets showing even when deleted switch is not checked (#22217)

This commit is contained in:
Aniket Katkar 2025-07-08 18:48:58 +05:30 committed by GitHub
parent 573e3bfc21
commit 7a6bace101
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 307 additions and 6 deletions

View File

@ -0,0 +1,186 @@
/*
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import test, { expect } from '@playwright/test';
import { TableClass } from '../../support/entity/TableClass';
import { createNewPage, redirectToHomePage } from '../../utils/common';
import { getJsonTreeObject } from '../../utils/exploreDiscovery';
// use the admin user to login
test.use({ storageState: 'playwright/.auth/admin.json' });
const table = new TableClass();
test.describe('Explore Assets Discovery', () => {
test.beforeAll(async ({ browser }) => {
const { apiContext, afterAction } = await createNewPage(browser);
await table.create(apiContext);
await table.delete(apiContext, false);
await afterAction();
});
test.afterAll(async ({ browser }) => {
const { apiContext, afterAction } = await createNewPage(browser);
await table.delete(apiContext);
await afterAction();
});
test.beforeEach(async ({ page }) => {
await redirectToHomePage(page);
});
test('Should not display deleted assets when showDeleted is not checked and deleted is not present in queryFilter', async ({
page,
}) => {
const queryFilter = getJsonTreeObject(
table.entityResponseData.name,
table.schemaResponseData.name,
false
);
await page.goto(
`/explore?page=1&size=10&queryFilter=${JSON.stringify(queryFilter)}`
);
await page.waitForLoadState('networkidle');
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
await expect(
page.locator(
`[data-testid="table-data-card_${table.entityResponseData.fullyQualifiedName}"]`
)
).not.toBeAttached();
});
test('Should display deleted assets when showDeleted is not checked but deleted is true in queryFilter', async ({
page,
}) => {
const queryFilter = getJsonTreeObject(
table.entityResponseData.name,
table.schemaResponseData.name,
true,
true
);
await page.goto(
`/explore?page=1&size=10&queryFilter=${JSON.stringify(queryFilter)}`
);
await page.waitForLoadState('networkidle');
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
await expect(
page.locator(
`[data-testid="table-data-card_${table.entityResponseData.fullyQualifiedName}"]`
)
).toBeAttached();
});
test('Should not display deleted assets when showDeleted is not checked but deleted is false in queryFilter', async ({
page,
}) => {
const queryFilter = getJsonTreeObject(
table.entityResponseData.name,
table.schemaResponseData.name,
true,
false
);
await page.goto(
`/explore?page=1&size=10&queryFilter=${JSON.stringify(queryFilter)}`
);
await page.waitForLoadState('networkidle');
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
await expect(
page.locator(
`[data-testid="table-data-card_${table.entityResponseData.fullyQualifiedName}"]`
)
).not.toBeAttached();
});
test('Should display deleted assets when showDeleted is checked and deleted is not present in queryFilter', async ({
page,
}) => {
const queryFilter = getJsonTreeObject(
table.entityResponseData.name,
table.schemaResponseData.name,
false
);
await page.goto(
`/explore?page=1&size=10&showDeleted=true&queryFilter=${JSON.stringify(
queryFilter
)}`
);
await page.waitForLoadState('networkidle');
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
await expect(
page.locator(
`[data-testid="table-data-card_${table.entityResponseData.fullyQualifiedName}"]`
)
).toBeAttached();
});
test('Should display deleted assets when showDeleted is checked and deleted is true in queryFilter', async ({
page,
}) => {
const queryFilter = getJsonTreeObject(
table.entityResponseData.name,
table.schemaResponseData.name,
true,
true
);
await page.goto(
`/explore?page=1&size=10&showDeleted=true&queryFilter=${JSON.stringify(
queryFilter
)}`
);
await page.waitForLoadState('networkidle');
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
await expect(
page.locator(
`[data-testid="table-data-card_${table.entityResponseData.fullyQualifiedName}"]`
)
).toBeAttached();
});
test('Should not display deleted assets when showDeleted is checked but deleted is false in queryFilter', async ({
page,
}) => {
const queryFilter = getJsonTreeObject(
table.entityResponseData.name,
table.schemaResponseData.name,
true,
false
);
await page.goto(
`/explore?page=1&size=10&showDeleted=true&queryFilter=${JSON.stringify(
queryFilter
)}`
);
await page.waitForLoadState('networkidle');
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
await expect(
page.locator(
`[data-testid="table-data-card_${table.entityResponseData.fullyQualifiedName}"]`
)
).not.toBeAttached();
});
});

View File

@ -0,0 +1,103 @@
/*
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const getJsonTreeObjectDeletedTerm = (deleted: boolean) => {
return {
'9a89a899-cdef-4012-b456-7197e8b38b31': {
type: 'rule',
id: '9a89a899-cdef-4012-b456-7197e8b38b31',
properties: {
fieldSrc: 'field',
field: 'deleted',
operator: 'equal',
value: [deleted],
valueSrc: ['value'],
operatorOptions: null,
valueType: ['boolean'],
},
path: [
'8baba8ab-89ab-4cde-b012-3197e53630f9',
'99a9b98a-4567-489a-bcde-f197e53630f9',
'9a89a899-cdef-4012-b456-7197e8b38b31',
],
},
};
};
export const getJsonTreeObject = (
assetName: string,
schemaName: string,
includeDeleted: boolean,
deleted = false
) => {
return {
id: '8baba8ab-89ab-4cde-b012-3197e53630f9',
type: 'group',
properties: { conjunction: 'AND', not: false },
children1: {
'99a9b98a-4567-489a-bcde-f197e53630f9': {
type: 'group',
properties: { conjunction: 'AND', not: false },
children1: {
'898ba9bb-0123-4456-b89a-b197e53630f9': {
type: 'rule',
properties: {
field: 'name.keyword',
operator: 'select_equals',
fieldSrc: 'field',
value: [assetName],
valueSrc: ['value'],
operatorOptions: null,
valueType: ['select'],
valueError: [null],
asyncListValues: [{ value: assetName, title: assetName }],
},
path: [
'8baba8ab-89ab-4cde-b012-3197e53630f9',
'99a9b98a-4567-489a-bcde-f197e53630f9',
'898ba9bb-0123-4456-b89a-b197e53630f9',
],
id: '898ba9bb-0123-4456-b89a-b197e53630f9',
},
'9aaa99ba-89ab-4cde-b012-3197e5458b56': {
type: 'rule',
id: '9aaa99ba-89ab-4cde-b012-3197e5458b56',
properties: {
fieldSrc: 'field',
value: [schemaName],
asyncListValues: [{ value: schemaName, title: schemaName }],
valueSrc: ['value'],
valueError: [null],
valueType: ['select'],
operatorOptions: null,
operator: 'select_equals',
field: 'databaseSchema.displayName.keyword',
},
path: [
'8baba8ab-89ab-4cde-b012-3197e53630f9',
'99a9b98a-4567-489a-bcde-f197e53630f9',
'9aaa99ba-89ab-4cde-b012-3197e5458b56',
],
},
...(includeDeleted ? getJsonTreeObjectDeletedTerm(deleted) : {}),
},
path: [
'8baba8ab-89ab-4cde-b012-3197e53630f9',
'99a9b98a-4567-489a-bcde-f197e53630f9',
],
id: '99a9b98a-4567-489a-bcde-f197e53630f9',
},
},
path: ['8baba8ab-89ab-4cde-b012-3197e53630f9'],
};
};

View File

@ -102,8 +102,8 @@ const ExplorePageV1: FC<unknown> = () => {
size,
showDeleted,
} = useMemo(() => {
return parseSearchParams(location.search);
}, [location.search]);
return parseSearchParams(location.search, queryFilter);
}, [location.search, queryFilter]);
const handlePageChange: ExploreProps['onChangePage'] = (page, size) => {
navigate({

View File

@ -413,7 +413,10 @@ export const isElasticsearchError = (error: unknown): boolean => {
/**
* Parse search parameters from URL query
*/
export const parseSearchParams = (search: string) => {
export const parseSearchParams = (
search: string,
queryFilter?: Record<string, unknown>
) => {
const parsedSearch = Qs.parse(
search.startsWith('?') ? search.substring(1) : search
);
@ -440,9 +443,18 @@ export const parseSearchParams = (search: string) => {
? Number.parseInt(parsedSearch.size)
: PAGE_SIZE;
// We are not setting showDeleted as 'false' since we don't want it to conflict with
// the `Deleted` field value in the advanced search quick filters when the value there is true.
const showDeleted = parsedSearch.showDeleted === 'true' ? true : undefined;
const stringifiedQueryFilter = isEmpty(queryFilter)
? ''
: JSON.stringify(queryFilter);
const queryFilterContainsDeleted =
stringifiedQueryFilter.includes('"deleted":');
// Since the 'Deleted' field in the queryFilter conflicts with the 'showDeleted' parameter,
// We are giving priority to the 'Deleted' field in the queryFilter if it exists.
// If not there in the queryFilter, use the 'showDeleted' parameter from the URL.
const showDeleted = queryFilterContainsDeleted
? undefined
: parsedSearch.showDeleted === 'true';
return {
parsedSearch,