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

fix(ui) Fix bug with editing entity names #11186

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 @@ -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
Loading