Enable deletion of relation fields (#5338)
In this PR 1. Enable deletion of relation fields in the product and via the api (migration part was missing in the api) 3. Change wording, only use "deactivate" and "delete" everywhere (and not a mix of the two + "disable", "erase")
This commit is contained in:
@ -12,14 +12,14 @@ type SettingsObjectFieldInactiveActionDropdownProps = {
|
||||
isCustomField?: boolean;
|
||||
fieldType?: FieldMetadataType;
|
||||
onActivate: () => void;
|
||||
onErase: () => void;
|
||||
onDelete: () => void;
|
||||
scopeKey: string;
|
||||
};
|
||||
|
||||
export const SettingsObjectFieldInactiveActionDropdown = ({
|
||||
onActivate,
|
||||
scopeKey,
|
||||
onErase,
|
||||
onDelete,
|
||||
isCustomField,
|
||||
fieldType,
|
||||
}: SettingsObjectFieldInactiveActionDropdownProps) => {
|
||||
@ -32,15 +32,12 @@ export const SettingsObjectFieldInactiveActionDropdown = ({
|
||||
closeDropdown();
|
||||
};
|
||||
|
||||
const handleErase = () => {
|
||||
onErase();
|
||||
const handleDelete = () => {
|
||||
onDelete();
|
||||
closeDropdown();
|
||||
};
|
||||
|
||||
const isErasable =
|
||||
isCustomField &&
|
||||
fieldType !== FieldMetadataType.Relation &&
|
||||
fieldType !== FieldMetadataType.Address;
|
||||
const isDeletable = isCustomField && fieldType !== FieldMetadataType.Address;
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
@ -56,12 +53,12 @@ export const SettingsObjectFieldInactiveActionDropdown = ({
|
||||
LeftIcon={IconArchiveOff}
|
||||
onClick={handleActivate}
|
||||
/>
|
||||
{isErasable && (
|
||||
{isDeletable && (
|
||||
<MenuItem
|
||||
text="Erase"
|
||||
text="Delete"
|
||||
accent="danger"
|
||||
LeftIcon={IconTrash}
|
||||
onClick={handleErase}
|
||||
onClick={handleDelete}
|
||||
/>
|
||||
)}
|
||||
</DropdownMenuItemsContainer>
|
||||
|
||||
@ -10,14 +10,14 @@ import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
|
||||
type SettingsObjectInactiveMenuDropDownProps = {
|
||||
isCustomObject: boolean;
|
||||
onActivate: () => void;
|
||||
onErase: () => void;
|
||||
onDelete: () => void;
|
||||
scopeKey: string;
|
||||
};
|
||||
|
||||
export const SettingsObjectInactiveMenuDropDown = ({
|
||||
onActivate,
|
||||
scopeKey,
|
||||
onErase,
|
||||
onDelete,
|
||||
isCustomObject,
|
||||
}: SettingsObjectInactiveMenuDropDownProps) => {
|
||||
const dropdownId = `${scopeKey}-settings-object-inactive-menu-dropdown`;
|
||||
@ -29,8 +29,8 @@ export const SettingsObjectInactiveMenuDropDown = ({
|
||||
closeDropdown();
|
||||
};
|
||||
|
||||
const handleErase = () => {
|
||||
onErase();
|
||||
const handleDelete = () => {
|
||||
onDelete();
|
||||
closeDropdown();
|
||||
};
|
||||
|
||||
@ -50,10 +50,10 @@ export const SettingsObjectInactiveMenuDropDown = ({
|
||||
/>
|
||||
{isCustomObject && (
|
||||
<MenuItem
|
||||
text="Erase"
|
||||
text="Delete"
|
||||
LeftIcon={IconTrash}
|
||||
accent="danger"
|
||||
onClick={handleErase}
|
||||
onClick={handleDelete}
|
||||
/>
|
||||
)}
|
||||
</DropdownMenuItemsContainer>
|
||||
|
||||
@ -5,12 +5,12 @@ import { ComponentDecorator } from 'twenty-ui';
|
||||
import { SettingsObjectInactiveMenuDropDown } from '../SettingsObjectInactiveMenuDropDown';
|
||||
|
||||
const handleActivateMockFunction = fn();
|
||||
const handleEraseMockFunction = fn();
|
||||
const handleDeleteMockFunction = fn();
|
||||
|
||||
const ClearMocksDecorator: Decorator = (Story, context) => {
|
||||
if (context.parameters.clearMocks === true) {
|
||||
handleActivateMockFunction.mockClear();
|
||||
handleEraseMockFunction.mockClear();
|
||||
handleDeleteMockFunction.mockClear();
|
||||
}
|
||||
return <Story />;
|
||||
};
|
||||
@ -21,7 +21,7 @@ const meta: Meta<typeof SettingsObjectInactiveMenuDropDown> = {
|
||||
args: {
|
||||
scopeKey: 'settings-object-inactive-menu-dropdown',
|
||||
onActivate: handleActivateMockFunction,
|
||||
onErase: handleEraseMockFunction,
|
||||
onDelete: handleDeleteMockFunction,
|
||||
},
|
||||
decorators: [ComponentDecorator, ClearMocksDecorator],
|
||||
parameters: {
|
||||
@ -64,7 +64,7 @@ export const WithActivate: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const WithErase: Story = {
|
||||
export const WithDelete: Story = {
|
||||
args: { isCustomObject: true },
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
@ -73,13 +73,13 @@ export const WithErase: Story = {
|
||||
|
||||
await userEvent.click(dropdownButton);
|
||||
|
||||
await expect(handleEraseMockFunction).toHaveBeenCalledTimes(0);
|
||||
await expect(handleDeleteMockFunction).toHaveBeenCalledTimes(0);
|
||||
|
||||
const eraseMenuItem = await canvas.getByText('Erase');
|
||||
const deleteMenuItem = await canvas.getByText('Delete');
|
||||
|
||||
await userEvent.click(eraseMenuItem);
|
||||
await userEvent.click(deleteMenuItem);
|
||||
|
||||
await expect(handleEraseMockFunction).toHaveBeenCalledTimes(1);
|
||||
await expect(handleDeleteMockFunction).toHaveBeenCalledTimes(1);
|
||||
|
||||
await userEvent.click(dropdownButton);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user