Skip to content

Commit

Permalink
fix(ui) Fix bug with editing entity names (datahub-project#11186)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscollins3456 authored Aug 16, 2024
1 parent 608c5cf commit ae30041
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { EntityType } from '../../../../../../types.generated';
import { getCanEditName } from '../header/EntityHeader';

describe('getCanEditName', () => {
const entityDataWithManagePrivileges = { privileges: { canManageEntity: true } };
const entityDataWithoutManagePrivileges = { privileges: { canManageEntity: false } };
const entityDataWithManagePrivileges = { privileges: { canManageEntity: true, canEditProperties: true } };
const entityDataWithoutManagePrivileges = { privileges: { canManageEntity: false, canEditProperties: false } };

it('should return true for Terms if manageGlossaries privilege is true', () => {
const canEditName = getCanEditName(
EntityType.GlossaryTerm,
entityDataWithoutManagePrivileges,
true,
platformPrivileges,
);

Expand All @@ -21,6 +22,7 @@ describe('getCanEditName', () => {
const canEditName = getCanEditName(
EntityType.GlossaryTerm,
entityDataWithoutManagePrivileges,
true,
privilegesWithoutGlossaries,
);

Expand All @@ -32,6 +34,7 @@ describe('getCanEditName', () => {
const canEditName = getCanEditName(
EntityType.GlossaryTerm,
entityDataWithManagePrivileges,
true,
privilegesWithoutGlossaries,
);

Expand All @@ -42,6 +45,7 @@ describe('getCanEditName', () => {
const canEditName = getCanEditName(
EntityType.GlossaryNode,
entityDataWithoutManagePrivileges,
true,
platformPrivileges,
);

Expand All @@ -53,6 +57,7 @@ describe('getCanEditName', () => {
const canEditName = getCanEditName(
EntityType.GlossaryNode,
entityDataWithoutManagePrivileges,
true,
privilegesWithoutGlossaries,
);

Expand All @@ -64,14 +69,20 @@ describe('getCanEditName', () => {
const canEditName = getCanEditName(
EntityType.GlossaryNode,
entityDataWithManagePrivileges,
true,
privilegesWithoutGlossaries,
);

expect(canEditName).toBe(true);
});

it('should return true for Domains if manageDomains privilege is true', () => {
const canEditName = getCanEditName(EntityType.Domain, entityDataWithoutManagePrivileges, platformPrivileges);
const canEditName = getCanEditName(
EntityType.Domain,
entityDataWithoutManagePrivileges,
true,
platformPrivileges,
);

expect(canEditName).toBe(true);
});
Expand All @@ -81,14 +92,38 @@ describe('getCanEditName', () => {
const canEditName = getCanEditName(
EntityType.Domain,
entityDataWithoutManagePrivileges,
true,
privilegesWithoutDomains,
);

expect(canEditName).toBe(false);
});

it('should return false for an unsupported entity', () => {
const canEditName = getCanEditName(EntityType.Chart, entityDataWithManagePrivileges, platformPrivileges);
const canEditName = getCanEditName(EntityType.Chart, entityDataWithManagePrivileges, true, platformPrivileges);

expect(canEditName).toBe(false);
});

it('should return true for a dataset if canEditProperties is true', () => {
const canEditName = getCanEditName(EntityType.Chart, entityDataWithManagePrivileges, true, platformPrivileges);

expect(canEditName).toBe(false);
});

it('should return false for a dataset if canEditProperties is false', () => {
const canEditName = getCanEditName(
EntityType.Chart,
entityDataWithoutManagePrivileges,
true,
platformPrivileges,
);

expect(canEditName).toBe(false);
});

it('should return false for a dataset if isEditableDatasetNameEnabled is false', () => {
const canEditName = getCanEditName(EntityType.Chart, entityDataWithManagePrivileges, false, platformPrivileges);

expect(canEditName).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const TopButtonsWrapper = styled.div`
export function getCanEditName(
entityType: EntityType,
entityData: GenericEntityProperties | null,
isEditableDatasetNameEnabled: boolean,
privileges?: PlatformPrivileges,
) {
switch (entityType) {
Expand All @@ -73,7 +74,7 @@ export function getCanEditName(
case EntityType.BusinessAttribute:
return privileges?.manageBusinessAttributes;
case EntityType.Dataset:
return entityData?.privileges?.canEditProperties;
return isEditableDatasetNameEnabled && entityData?.privileges?.canEditProperties;
default:
return false;
}
Expand All @@ -99,9 +100,13 @@ export const EntityHeader = ({ headerDropdownItems, headerActionItems, isNameEdi

const isEditableDatasetNameEnabled = useIsEditableDatasetNameEnabled();
const canEditName =
isEditableDatasetNameEnabled &&
isNameEditable &&
getCanEditName(entityType, entityData, me?.platformPrivileges as PlatformPrivileges);
getCanEditName(
entityType,
entityData,
isEditableDatasetNameEnabled,
me?.platformPrivileges as PlatformPrivileges,
);
const entityRegistry = useEntityRegistry();

return (
Expand Down

0 comments on commit ae30041

Please sign in to comment.