remove retenion period and displayName edit button if table is deleted (#15653)

This commit is contained in:
Ashish Gupta 2024-03-21 19:22:58 +05:30 committed by GitHub
parent 834720c445
commit c56a1533d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 49 additions and 35 deletions

View File

@ -410,7 +410,7 @@ export const DataAssetsHeader = ({
{entityType === EntityType.TABLE && onUpdateRetentionPeriod && ( {entityType === EntityType.TABLE && onUpdateRetentionPeriod && (
<RetentionPeriod <RetentionPeriod
permissions={permissions} hasPermission={permissions.EditAll && !dataAsset.deleted}
retentionPeriod={(dataAsset as Table).retentionPeriod} retentionPeriod={(dataAsset as Table).retentionPeriod}
onUpdate={onUpdateRetentionPeriod} onUpdate={onUpdateRetentionPeriod}
/> />

View File

@ -14,7 +14,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'; import { act, fireEvent, render, screen } from '@testing-library/react';
import React from 'react'; import React from 'react';
import { NO_DATA_PLACEHOLDER } from '../../../constants/constants'; import { NO_DATA_PLACEHOLDER } from '../../../constants/constants';
import { OperationPermission } from '../../../context/PermissionProvider/PermissionProvider.interface';
import RetentionPeriod from './RetentionPeriod.component'; import RetentionPeriod from './RetentionPeriod.component';
import { RetentionPeriodProps } from './RetentionPeriod.interface'; import { RetentionPeriodProps } from './RetentionPeriod.interface';
@ -34,7 +33,7 @@ const mockOnUpdate = jest.fn();
const mockRetentionPeriodProps: RetentionPeriodProps = { const mockRetentionPeriodProps: RetentionPeriodProps = {
retentionPeriod: undefined, retentionPeriod: undefined,
onUpdate: mockOnUpdate, onUpdate: mockOnUpdate,
permissions: { EditAll: true } as OperationPermission, hasPermission: true,
}; };
describe('Test Retention Period Component', () => { describe('Test Retention Period Component', () => {
@ -145,12 +144,8 @@ describe('Test Retention Period Component', () => {
}); });
it('Should not render Retention Period Component if has no permission', () => { it('Should not render Retention Period Component if has no permission', () => {
const permissions = { EditAll: false } as OperationPermission;
render( render(
<RetentionPeriod <RetentionPeriod {...mockRetentionPeriodProps} hasPermission={false} />
{...mockRetentionPeriodProps}
permissions={permissions}
/>
); );
expect( expect(
@ -158,5 +153,8 @@ describe('Test Retention Period Component', () => {
).toBeInTheDocument(); ).toBeInTheDocument();
expect(screen.getByText(NO_DATA_PLACEHOLDER)).toBeInTheDocument(); expect(screen.getByText(NO_DATA_PLACEHOLDER)).toBeInTheDocument();
expect(
screen.queryByTestId('edit-retention-period-button')
).not.toBeInTheDocument();
}); });
}); });

View File

@ -37,7 +37,7 @@ import { RetentionPeriodProps } from './RetentionPeriod.interface';
const RetentionPeriod = ({ const RetentionPeriod = ({
retentionPeriod, retentionPeriod,
onUpdate, onUpdate,
permissions, hasPermission,
}: RetentionPeriodProps) => { }: RetentionPeriodProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [form] = useForm(); const [form] = useForm();
@ -70,7 +70,7 @@ const RetentionPeriod = ({
value={retentionPeriod ?? NO_DATA_PLACEHOLDER} value={retentionPeriod ?? NO_DATA_PLACEHOLDER}
/> />
{permissions?.EditAll && ( {hasPermission && (
<Tooltip <Tooltip
title={t('label.edit-entity', { title={t('label.edit-entity', {
entity: t('label.retention-period'), entity: t('label.retention-period'),

View File

@ -11,10 +11,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { OperationPermission } from '../../../context/PermissionProvider/PermissionProvider.interface';
export interface RetentionPeriodProps { export interface RetentionPeriodProps {
retentionPeriod?: string; retentionPeriod?: string;
onUpdate: (retentionPeriod: string) => Promise<void>; onUpdate: (retentionPeriod: string) => Promise<void>;
permissions: OperationPermission; hasPermission: boolean;
} }

View File

@ -348,7 +348,8 @@ const SchemaTable = ({
</Typography.Text> </Typography.Text>
) : null} ) : null}
{(tablePermissions?.EditAll || {(tablePermissions?.EditAll ||
tablePermissions?.EditDisplayName) && ( tablePermissions?.EditDisplayName) &&
!isReadOnly && (
<Tooltip <Tooltip
placement="right" placement="right"
title={t('label.edit-entity', { title={t('label.edit-entity', {

View File

@ -250,4 +250,21 @@ describe('Test EntityTable Component', () => {
expect(columnDisplayName[0].textContent).toBe('Comments'); expect(columnDisplayName[0].textContent).toBe('Comments');
expect(columnName[0].textContent).toBe('comments'); expect(columnName[0].textContent).toBe('comments');
}); });
it('should not render edit displayName button is table is deleted', async () => {
render(
<EntityTableV1
{...mockEntityTableProp}
isReadOnly
tableColumns={[...columnsWithDisplayName]}
/>,
{
wrapper: MemoryRouter,
}
);
expect(
screen.queryByTestId('edit-displayName-button')
).not.toBeInTheDocument();
});
}); });