Twnty-#6797 view/edit inactive feature (#6953)

This PR resolves the issue raised under #6797. Earlier no view/edit
option were present for inActive objects in data-model inside settings.
To resolve that following changes were done:

1. `SettingsObjectFieldItemTableRow` was not passing the onEdit with url
to `SettingsObjectFieldActiveActionDropdown` to redirect on clicking it.
So passed onEdit there.
2. `SettingsObjectFieldActiveActionDropdown` was not implementing the
onEdit functionality, so implemented that by creating `handleEdit()`
function.
3. `SettingsObjectFieldEdit` was assuming only `activeObjectMetadata
`will be coming to render on page. So, when inactive object was accessed
the path not found error message was thrown. Thus did changes to manage
both active and inactive objects by generalizing the
              `activeObjectMetadata ` ->  `objectMetadata` 
               `activeMetadataField `-> `metadataField`.
4. `findObjectMetadataItemBySlug `function was written inside
`useFilteredObjectMetadataItems` for fetching active/inactive object.
5. Updated `SettingsObjectFieldEdit` button to show and change the
active to inactive state and vice versa.
6. Test was written for `findObjectMetadataItemBySlug`.

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
HKS07
2024-09-18 15:31:21 +05:30
committed by GitHub
parent df8bb84b35
commit cfc00c7924
5 changed files with 99 additions and 37 deletions

View File

@ -1,4 +1,10 @@
import { IconArchiveOff, IconDotsVertical, IconTrash } from 'twenty-ui';
import {
IconArchiveOff,
IconDotsVertical,
IconEye,
IconPencil,
IconTrash,
} from 'twenty-ui';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
@ -12,6 +18,7 @@ type SettingsObjectFieldInactiveActionDropdownProps = {
isCustomField?: boolean;
fieldType?: FieldMetadataType;
onActivate: () => void;
onEdit: () => void;
onDelete: () => void;
scopeKey: string;
};
@ -20,6 +27,7 @@ export const SettingsObjectFieldInactiveActionDropdown = ({
onActivate,
scopeKey,
onDelete,
onEdit,
isCustomField,
}: SettingsObjectFieldInactiveActionDropdownProps) => {
const dropdownId = `${scopeKey}-settings-field-disabled-action-dropdown`;
@ -36,6 +44,11 @@ export const SettingsObjectFieldInactiveActionDropdown = ({
closeDropdown();
};
const handleEdit = () => {
onEdit();
closeDropdown();
};
const isDeletable = isCustomField;
return (
@ -47,6 +60,11 @@ export const SettingsObjectFieldInactiveActionDropdown = ({
dropdownComponents={
<DropdownMenu width="160px">
<DropdownMenuItemsContainer>
<MenuItem
text={isCustomField ? 'Edit' : 'View'}
LeftIcon={isCustomField ? IconPencil : IconEye}
onClick={handleEdit}
/>
<MenuItem
text="Activate"
LeftIcon={IconArchiveOff}

View File

@ -269,6 +269,7 @@ export const SettingsObjectFieldItemTableRow = ({
<SettingsObjectFieldInactiveActionDropdown
isCustomField={fieldMetadataItem.isCustom === true}
scopeKey={fieldMetadataItem.id}
onEdit={() => navigate(linkToNavigate)}
onActivate={() => activateMetadataField(fieldMetadataItem)}
onDelete={() => deleteMetadataField(fieldMetadataItem)}
/>