chore: rename entities to objects throughout

This commit is contained in:
Aaryan Khandelwal 2023-09-20 21:47:29 +05:30
parent 95ae0f065a
commit 1428e6b555
17 changed files with 143 additions and 145 deletions

View File

@ -99,7 +99,7 @@ export const AttributeForm: React.FC<Props> = observer(({ attributeDetails, obje
const handleUpdateAttribute = async (data: Partial<ICustomAttribute>) => {
if (!workspaceSlug || !attributeDetails.id || !objectId) return;
await customAttributes.updateEntityAttribute(
await customAttributes.updateObjectAttribute(
workspaceSlug.toString(),
objectId,
attributeDetails.id,
@ -113,7 +113,7 @@ export const AttributeForm: React.FC<Props> = observer(({ attributeDetails, obje
setIsRemoving(true);
await customAttributes
.deleteEntityAttribute(workspaceSlug.toString(), objectId, attributeDetails.id)
.deleteObjectAttribute(workspaceSlug.toString(), objectId, attributeDetails.id)
.finally(() => setIsRemoving(false));
};

View File

@ -16,7 +16,7 @@ export const SelectAttributeForm: React.FC<FormComponentProps & { multiple?: boo
const { customAttributes } = useMobxStore();
const options = customAttributes.entityAttributes?.[objectId]?.[watch("id") ?? ""]?.children;
const options = customAttributes.objectAttributes?.[objectId]?.[watch("id") ?? ""]?.children;
return (
<div className="space-y-3">

View File

@ -7,7 +7,7 @@ import { CustomCheckboxAttribute } from "components/custom-attributes";
import { Tooltip } from "components/ui";
type Props = {
entityId: string;
objectId: string;
issueId: string;
onChange: (attributeId: string, val: string | string[] | undefined) => void;
projectId: string;
@ -15,11 +15,11 @@ type Props = {
};
export const CustomAttributesCheckboxes: React.FC<Props> = observer((props) => {
const { entityId, issueId, onChange, projectId, values } = props;
const { objectId, issueId, onChange, projectId, values } = props;
const { customAttributes } = useMobxStore();
const attributes = customAttributes.entityAttributes[entityId] ?? {};
const attributes = customAttributes.objectAttributes[objectId] ?? {};
const checkboxFields = Object.values(attributes).filter((a) => a.type === "checkbox");

View File

@ -13,7 +13,7 @@ import { ChevronDown } from "lucide-react";
import { TCustomAttributeTypes } from "types";
type Props = {
entityId: string;
objectId: string;
issueId: string;
onChange: (attributeId: string, val: string | string[] | undefined) => void;
projectId: string;
@ -23,13 +23,13 @@ type Props = {
const DESCRIPTION_FIELDS: TCustomAttributeTypes[] = ["email", "number", "text", "url"];
export const CustomAttributesDescriptionFields: React.FC<Props> = observer((props) => {
const { entityId, onChange, values } = props;
const { objectId, onChange, values } = props;
const [hideOptionalFields, setHideOptionalFields] = useState(false);
const { customAttributes } = useMobxStore();
const attributes = customAttributes.entityAttributes[entityId] ?? {};
const attributes = customAttributes.objectAttributes[objectId] ?? {};
const descriptionFields = Object.values(attributes).filter((a) =>
DESCRIPTION_FIELDS.includes(a.type)

View File

@ -28,7 +28,7 @@ import { ICustomAttribute } from "types";
import { MAX_FILE_SIZE } from "constants/workspace";
type Props = {
entityId: string;
objectId: string;
issueId: string;
onChange: (attributeId: string, val: string | string[] | undefined) => void;
projectId: string;
@ -183,17 +183,17 @@ const UploadFile: React.FC<FileUploadProps> = (props) => {
};
export const CustomAttributesFileUploads: React.FC<Props> = observer((props) => {
const { entityId, onChange, issueId, projectId, values } = props;
const { objectId, onChange, issueId, projectId, values } = props;
const { customAttributes } = useMobxStore();
const attributes = customAttributes.entityAttributes[entityId] ?? {};
const attributes = customAttributes.objectAttributes[objectId] ?? {};
const fileUploadFields = Object.values(attributes).filter((a) => a.type === "file");
return (
<>
{customAttributes.fetchEntityDetailsLoader ? (
{customAttributes.fetchObjectDetailsLoader ? (
<Loader className="space-y-3.5">
<Loader.Item height="35px" />
<Loader.Item height="35px" />

View File

@ -14,7 +14,7 @@ import { Loader } from "components/ui";
import { TCustomAttributeTypes } from "types";
type Props = {
entityId: string;
objectId: string;
issueId: string;
onChange: (attributeId: string, val: string | string[] | undefined) => void;
projectId: string;
@ -24,17 +24,17 @@ type Props = {
const SELECT_FIELDS: TCustomAttributeTypes[] = ["datetime", "multi_select", "relation", "select"];
export const CustomAttributesSelectFields: React.FC<Props> = observer((props) => {
const { entityId, issueId, onChange, projectId, values } = props;
const { objectId, issueId, onChange, projectId, values } = props;
const { customAttributes } = useMobxStore();
const attributes = customAttributes.entityAttributes[entityId] ?? {};
const attributes = customAttributes.objectAttributes[objectId] ?? {};
const selectFields = Object.values(attributes).filter((a) => SELECT_FIELDS.includes(a.type));
return (
<>
{customAttributes.fetchEntityDetailsLoader ? (
{customAttributes.fetchObjectDetailsLoader ? (
<Loader className="flex items-center gap-2">
<Loader.Item height="27px" width="90px" />
<Loader.Item height="27px" width="90px" />

View File

@ -67,10 +67,10 @@ export const PeekOverviewCustomAttributesList: React.FC<Props> = observer(
useEffect(() => {
if (!issue?.entity) return;
if (!customAttributes.entityAttributes[issue.entity]) {
if (!customAttributes.objectAttributes[issue.entity]) {
if (!workspaceSlug) return;
customAttributes.fetchEntityDetails(workspaceSlug.toString(), issue.entity);
customAttributes.fetchObjectDetails(workspaceSlug.toString(), issue.entity);
}
}, [customAttributes, issue?.entity, workspaceSlug]);
@ -95,7 +95,7 @@ export const PeekOverviewCustomAttributesList: React.FC<Props> = observer(
if (!issue || !issue?.entity) return null;
if (
!customAttributes.entityAttributes[issue.entity] ||
!customAttributes.objectAttributes[issue.entity] ||
!customAttributeValues.issueAttributeValues?.[issue.id]
)
return (
@ -109,7 +109,7 @@ export const PeekOverviewCustomAttributesList: React.FC<Props> = observer(
return (
<>
{Object.values(customAttributes.entityAttributes?.[issue.entity] ?? {}).map((attribute) => {
{Object.values(customAttributes.objectAttributes?.[issue.entity] ?? {}).map((attribute) => {
const typeMetaData = CUSTOM_ATTRIBUTES_LIST[attribute.type];
const attributeValue = customAttributeValues.issueAttributeValues?.[issue.id].find(
(a) => a.id === attribute.id

View File

@ -66,10 +66,10 @@ export const SidebarCustomAttributesList: React.FC<Props> = observer(({ issue, p
useEffect(() => {
if (!issue?.entity) return;
if (!customAttributes.entityAttributes[issue.entity]) {
if (!customAttributes.objectAttributes[issue.entity]) {
if (!workspaceSlug) return;
customAttributes.fetchEntityDetails(workspaceSlug.toString(), issue.entity);
customAttributes.fetchObjectDetails(workspaceSlug.toString(), issue.entity);
}
}, [customAttributes, issue?.entity, workspaceSlug]);
@ -94,7 +94,7 @@ export const SidebarCustomAttributesList: React.FC<Props> = observer(({ issue, p
if (!issue || !issue?.entity) return null;
if (
!customAttributes.entityAttributes[issue.entity] ||
!customAttributes.objectAttributes[issue.entity] ||
!customAttributeValues.issueAttributeValues?.[issue.id]
)
return (
@ -108,7 +108,7 @@ export const SidebarCustomAttributesList: React.FC<Props> = observer(({ issue, p
return (
<div>
{Object.values(customAttributes.entityAttributes?.[issue.entity] ?? {}).map((attribute) => {
{Object.values(customAttributes.objectAttributes?.[issue.entity] ?? {}).map((attribute) => {
const typeMetaData = CUSTOM_ATTRIBUTES_LIST[attribute.type];
const attributeValue = customAttributeValues.issueAttributeValues?.[issue.id].find(
(a) => a.id === attribute.id

View File

@ -40,7 +40,7 @@ export const DeleteObjectModal: React.FC<Props> = observer(
setIsDeleting(true);
await customAttributes
.deleteEntity(workspaceSlug.toString(), objectToDelete.id)
.deleteObject(workspaceSlug.toString(), objectToDelete.id)
.then(async () => {
if (onSubmit) await onSubmit();
handleClose();

View File

@ -61,7 +61,7 @@ export const ObjectModal: React.FC<Props> = observer(
};
await customAttributes
.createEntity(workspaceSlug.toString(), payload)
.createObject(workspaceSlug.toString(), payload)
.then((res) => {
setObject((prevData) => ({ ...prevData, ...res }));
if (onSubmit) onSubmit();
@ -81,11 +81,11 @@ export const ObjectModal: React.FC<Props> = observer(
};
await customAttributes
.updateEntity(workspaceSlug.toString(), object.id, payload)
.updateObject(workspaceSlug.toString(), object.id, payload)
.finally(() => setIsUpdatingObject(false));
};
const handleCreateEntityAttribute = async (type: TCustomAttributeTypes) => {
const handleCreateObjectAttribute = async (type: TCustomAttributeTypes) => {
if (!workspaceSlug || !object || !object.id) return;
const typeMetaData = CUSTOM_ATTRIBUTES_LIST[type];
@ -96,7 +96,7 @@ export const ObjectModal: React.FC<Props> = observer(
...typeMetaData.initialPayload,
};
await customAttributes.createEntityAttribute(workspaceSlug.toString(), {
await customAttributes.createObjectAttribute(workspaceSlug.toString(), {
...payload,
parent: object.id,
});
@ -106,16 +106,16 @@ export const ObjectModal: React.FC<Props> = observer(
useEffect(() => {
if (!object.id || object.id === "") return;
if (!customAttributes.entityAttributes[object.id]) {
if (!customAttributes.objectAttributes[object.id]) {
if (!workspaceSlug) return;
customAttributes.fetchEntityDetails(workspaceSlug.toString(), object.id).then((res) => {
customAttributes.fetchObjectDetails(workspaceSlug.toString(), object.id).then((res) => {
setObject((prev) => ({ ...prev, ...res }));
});
} else {
setObject((prev) => ({
...prev,
...customAttributes.entities?.find((e) => e.id === object.id),
...customAttributes.objects?.find((e) => e.id === object.id),
}));
}
}, [customAttributes, object.id, workspaceSlug]);
@ -204,15 +204,15 @@ export const ObjectModal: React.FC<Props> = observer(
<div className="px-6 pb-5">
<h4 className="font-medium">Attributes</h4>
<div className="mt-2 space-y-2">
{customAttributes.fetchEntityDetailsLoader ? (
{customAttributes.fetchObjectDetailsLoader ? (
<Loader>
<Loader.Item height="40px" />
</Loader>
) : (
Object.keys(customAttributes.entityAttributes[object.id] ?? {})?.map(
Object.keys(customAttributes.objectAttributes[object.id] ?? {})?.map(
(attributeId) => {
const attribute =
customAttributes.entityAttributes[object.id ?? ""][attributeId];
customAttributes.objectAttributes[object.id ?? ""][attributeId];
return (
<AttributeForm
@ -225,7 +225,7 @@ export const ObjectModal: React.FC<Props> = observer(
}
)
)}
{customAttributes.createEntityAttributeLoader && (
{customAttributes.createObjectAttributeLoader && (
<Loader>
<Loader.Item height="40px" />
</Loader>
@ -241,7 +241,7 @@ export const ObjectModal: React.FC<Props> = observer(
>
{object.id && (
<div className="flex-shrink-0">
<TypesDropdown onClick={handleCreateEntityAttribute} />
<TypesDropdown onClick={handleCreateObjectAttribute} />
</div>
)}
<div className="flex items-center gap-3">

View File

@ -36,8 +36,8 @@ export const ObjectsList: React.FC<Props> = observer(({ handleEditObject, projec
useEffect(() => {
if (!workspaceSlug) return;
if (!customAttributes.entities)
customAttributes.fetchEntities(workspaceSlug.toString(), projectId);
if (!customAttributes.objects)
customAttributes.fetchObjects(workspaceSlug.toString(), projectId);
}, [customAttributes, projectId, workspaceSlug]);
return (
@ -54,14 +54,14 @@ export const ObjectsList: React.FC<Props> = observer(({ handleEditObject, projec
}}
/>
<div className="divide-y divide-custom-border-100">
{customAttributes.entities ? (
customAttributes.entities.length > 0 ? (
customAttributes.entities.map((entity) => (
{customAttributes.objects ? (
customAttributes.objects.length > 0 ? (
customAttributes.objects.map((object) => (
<SingleObject
key={entity.id}
object={entity}
handleDeleteObject={() => handleDeleteObject(entity)}
handleEditObject={() => handleEditObject(entity)}
key={object.id}
object={object}
handleDeleteObject={() => handleDeleteObject(object)}
handleEditObject={() => handleEditObject(object)}
/>
))
) : (

View File

@ -28,13 +28,13 @@ export const ObjectsSelect: React.FC<Props> = observer(({ onChange, projectId, v
query: string;
content: JSX.Element;
}[]
| undefined = customAttributes.entities?.map((entity) => ({
value: entity.id,
query: entity.display_name,
| undefined = customAttributes.objects?.map((object) => ({
value: object.id,
query: object.display_name,
content: (
<div className="flex items-center gap-2 text-xs">
{entity.icon ? renderEmoji(entity.icon) : <TableProperties size={14} strokeWidth={1.5} />}
<span>{entity.display_name}</span>
{object.icon ? renderEmoji(object.icon) : <TableProperties size={14} strokeWidth={1.5} />}
<span>{object.display_name}</span>
</div>
),
}));
@ -52,23 +52,23 @@ export const ObjectsSelect: React.FC<Props> = observer(({ onChange, projectId, v
useEffect(() => {
if (!workspaceSlug) return;
if (!customAttributes.entities)
customAttributes.fetchEntities(workspaceSlug.toString(), projectId);
if (!customAttributes.objects)
customAttributes.fetchObjects(workspaceSlug.toString(), projectId);
}, [customAttributes, projectId, workspaceSlug]);
const selectedEntity = customAttributes.entities?.find((e) => e.id === value);
const selectedObject = customAttributes.objects?.find((o) => o.id === value);
return (
<CustomSearchSelect
label={
<span className="flex items-center gap-2">
<div className="flex items-center gap-2 text-xs">
{selectedEntity?.icon ? (
renderEmoji(selectedEntity.icon)
{selectedObject?.icon ? (
renderEmoji(selectedObject.icon)
) : (
<TableProperties size={14} strokeWidth={1.5} />
)}
<span>{selectedEntity?.display_name ?? "Default"}</span>
<span>{selectedObject?.display_name ?? "Default"}</span>
</div>
</span>
}

View File

@ -253,10 +253,10 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
useEffect(() => {
if (!entityId) return;
if (!customAttributes.entityAttributes[entityId]) {
if (!customAttributes.objectAttributes[entityId]) {
if (!workspaceSlug) return;
customAttributes.fetchEntityDetails(workspaceSlug.toString(), entityId);
customAttributes.fetchObjectDetails(workspaceSlug.toString(), entityId);
}
}, [customAttributes, entityId, workspaceSlug]);
@ -264,12 +264,12 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
useEffect(() => {
if (
!entityId ||
!customAttributes.entityAttributes[entityId] ||
!customAttributes.objectAttributes[entityId] ||
Object.keys(customAttributesList).length > 0
)
return;
Object.values(customAttributes.entityAttributes[entityId]).forEach((attribute) => {
Object.values(customAttributes.objectAttributes[entityId]).forEach((attribute) => {
handleCustomAttributesChange(attribute.id, attribute.default_value);
});
}, [customAttributes, customAttributesList, entityId, handleCustomAttributesChange]);
@ -498,7 +498,7 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
)}
{entityId !== null && (
<>
{customAttributes.fetchEntityDetailsLoader ? (
{customAttributes.fetchObjectDetailsLoader ? (
<Loader className="space-y-3.5">
<Loader.Item height="35px" />
<Loader.Item height="35px" />
@ -507,21 +507,21 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
) : (
<div className="space-y-5">
<CustomAttributesDescriptionFields
entityId={entityId ?? ""}
objectId={entityId ?? ""}
issueId={watch("id") ?? ""}
onChange={handleCustomAttributesChange}
projectId={projectId}
values={customAttributesList}
/>
<CustomAttributesCheckboxes
entityId={entityId ?? ""}
objectId={entityId ?? ""}
issueId={watch("id") ?? ""}
onChange={handleCustomAttributesChange}
projectId={projectId}
values={customAttributesList}
/>
<CustomAttributesFileUploads
entityId={entityId ?? ""}
objectId={entityId ?? ""}
issueId={watch("id") ?? ""}
onChange={handleCustomAttributesChange}
projectId={projectId}
@ -679,7 +679,7 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
</>
) : (
<CustomAttributesSelectFields
entityId={entityId ?? ""}
objectId={entityId ?? ""}
issueId={watch("id") ?? ""}
onChange={handleCustomAttributesChange}
projectId={projectId}

View File

@ -454,7 +454,7 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer(
state: formData.state,
};
// if entity is null, set the default object entity properties for the payload
// if entity is null, set the default object properties for the payload
if (formData.entity === null)
payload = {
...payload,

View File

@ -3,11 +3,9 @@ import { Disclosure } from "@headlessui/react";
import { StateGroupIcon } from "components/icons";
// hooks
import useToast from "hooks/use-toast";
import useUser from "hooks/use-user";
// components
import {
SidebarAssigneeSelect,
SidebarEstimateSelect,
SidebarPrioritySelect,
SidebarStateSelect,
TPeekOverviewModes,

View File

@ -10,7 +10,7 @@ class CustomAttributesService extends APIService {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
}
async getEntitiesList(
async getObjectsList(
workspaceSlug: string,
params: { project: string }
): Promise<ICustomAttribute[]> {

View File

@ -6,14 +6,14 @@ import customAttributesService from "services/custom-attributes.service";
import type { ICustomAttribute } from "types";
class CustomAttributesStore {
entities: ICustomAttribute[] | null = null;
entityAttributes: {
[entityId: string]: { [entityAttributeId: string]: ICustomAttribute };
objects: ICustomAttribute[] | null = null;
objectAttributes: {
[objectId: string]: { [objectAttributeId: string]: ICustomAttribute };
} = {};
// loaders
fetchEntitiesLoader = false;
fetchEntityDetailsLoader = false;
createEntityAttributeLoader = false;
fetchObjectsLoader = false;
fetchObjectDetailsLoader = false;
createObjectAttributeLoader = false;
createAttributeOptionLoader = false;
// errors
attributesFetchError: any | null = null;
@ -22,16 +22,16 @@ class CustomAttributesStore {
constructor(_rootStore: any | null = null) {
makeAutoObservable(this, {
entities: observable.ref,
entityAttributes: observable.ref,
fetchEntities: action,
fetchEntityDetails: action,
createEntity: action,
updateEntity: action,
deleteEntity: action,
createEntityAttribute: action,
updateEntityAttribute: action,
deleteEntityAttribute: action,
objects: observable.ref,
objectAttributes: observable.ref,
fetchObjects: action,
fetchObjectDetails: action,
createObject: action,
updateObject: action,
deleteObject: action,
createObjectAttribute: action,
updateObjectAttribute: action,
deleteObjectAttribute: action,
createAttributeOption: action,
updateAttributeOption: action,
deleteAttributeOption: action,
@ -40,39 +40,39 @@ class CustomAttributesStore {
this.rootStore = _rootStore;
}
fetchEntities = async (workspaceSlug: string, projectId: string) => {
fetchObjects = async (workspaceSlug: string, projectId: string) => {
try {
runInAction(() => {
this.fetchEntitiesLoader = true;
this.fetchObjectsLoader = true;
});
const response = await customAttributesService.getEntitiesList(workspaceSlug, {
const response = await customAttributesService.getObjectsList(workspaceSlug, {
project: projectId,
});
if (response) {
runInAction(() => {
this.entities = response;
this.fetchEntitiesLoader = false;
this.objects = response;
this.fetchObjectsLoader = false;
});
}
} catch (error) {
runInAction(() => {
this.fetchEntitiesLoader = false;
this.fetchObjectsLoader = false;
this.attributesFetchError = error;
});
}
};
fetchEntityDetails = async (workspaceSlug: string, propertyId: string) => {
fetchObjectDetails = async (workspaceSlug: string, propertyId: string) => {
try {
runInAction(() => {
this.fetchEntityDetailsLoader = true;
this.fetchObjectDetailsLoader = true;
});
const response = await customAttributesService.getPropertyDetails(workspaceSlug, propertyId);
const entityChildren: { [key: string]: ICustomAttribute } = response.children.reduce(
const objectChildren: { [key: string]: ICustomAttribute } = response.children.reduce(
(acc, child) => ({
...acc,
[child.id]: child,
@ -81,28 +81,28 @@ class CustomAttributesStore {
);
runInAction(() => {
this.entityAttributes = {
...this.entityAttributes,
[propertyId]: entityChildren,
this.objectAttributes = {
...this.objectAttributes,
[propertyId]: objectChildren,
};
this.fetchEntityDetailsLoader = false;
this.fetchObjectDetailsLoader = false;
});
return response;
} catch (error) {
runInAction(() => {
this.fetchEntityDetailsLoader = false;
this.fetchObjectDetailsLoader = false;
this.error = error;
});
}
};
createEntity = async (workspaceSlug: string, data: Partial<ICustomAttribute>) => {
createObject = async (workspaceSlug: string, data: Partial<ICustomAttribute>) => {
try {
const response = await customAttributesService.createProperty(workspaceSlug, data);
runInAction(() => {
this.entities = [...(this.entities ?? []), response];
this.objects = [...(this.objects ?? []), response];
});
return response;
@ -113,7 +113,7 @@ class CustomAttributesStore {
}
};
updateEntity = async (
updateObject = async (
workspaceSlug: string,
objectId: string,
data: Partial<ICustomAttribute>
@ -121,12 +121,12 @@ class CustomAttributesStore {
try {
const response = await customAttributesService.patchProperty(workspaceSlug, objectId, data);
const newEntities = [...(this.entities ?? [])].map((entity) =>
entity.id === objectId ? { ...entity, ...response } : entity
const newObjects = [...(this.objects ?? [])].map((object) =>
object.id === objectId ? { ...object, ...response } : object
);
runInAction(() => {
this.entities = newEntities;
this.objects = newObjects;
});
return response;
@ -137,14 +137,14 @@ class CustomAttributesStore {
}
};
deleteEntity = async (workspaceSlug: string, propertyId: string) => {
deleteObject = async (workspaceSlug: string, propertyId: string) => {
try {
await customAttributesService.deleteProperty(workspaceSlug, propertyId);
const newEntities = this.entities?.filter((entity) => entity.id !== propertyId);
const newObjects = this.objects?.filter((object) => object.id !== propertyId);
runInAction(() => {
this.entities = [...(newEntities ?? [])];
this.objects = [...(newObjects ?? [])];
});
} catch (error) {
runInAction(() => {
@ -153,38 +153,38 @@ class CustomAttributesStore {
}
};
createEntityAttribute = async (
createObjectAttribute = async (
workspaceSlug: string,
data: Partial<ICustomAttribute> & { parent: string }
) => {
try {
runInAction(() => {
this.createEntityAttributeLoader = true;
this.createObjectAttributeLoader = true;
});
const response = await customAttributesService.createProperty(workspaceSlug, data);
runInAction(() => {
this.entityAttributes = {
...this.entityAttributes,
this.objectAttributes = {
...this.objectAttributes,
[data.parent]: {
...this.entityAttributes[data.parent],
...this.objectAttributes[data.parent],
[response.id]: response,
},
};
this.createEntityAttributeLoader = false;
this.createObjectAttributeLoader = false;
});
return response;
} catch (error) {
runInAction(() => {
this.error = error;
this.createEntityAttributeLoader = false;
this.createObjectAttributeLoader = false;
});
}
};
updateEntityAttribute = async (
updateObjectAttribute = async (
workspaceSlug: string,
parentId: string,
propertyId: string,
@ -193,16 +193,16 @@ class CustomAttributesStore {
try {
await customAttributesService.patchProperty(workspaceSlug, propertyId, data);
const newEntities = this.entityAttributes[parentId];
newEntities[propertyId] = {
...newEntities[propertyId],
const newObjects = this.objectAttributes[parentId];
newObjects[propertyId] = {
...newObjects[propertyId],
...data,
};
runInAction(() => {
this.entityAttributes = {
...this.entityAttributes,
[parentId]: newEntities,
this.objectAttributes = {
...this.objectAttributes,
[parentId]: newObjects,
};
});
} catch (error) {
@ -212,17 +212,17 @@ class CustomAttributesStore {
}
};
deleteEntityAttribute = async (workspaceSlug: string, parentId: string, propertyId: string) => {
deleteObjectAttribute = async (workspaceSlug: string, parentId: string, propertyId: string) => {
try {
await customAttributesService.deleteProperty(workspaceSlug, propertyId);
const newEntities = this.entityAttributes[parentId];
delete newEntities[propertyId];
const newObjects = this.objectAttributes[parentId];
delete newObjects[propertyId];
runInAction(() => {
this.entityAttributes = {
...this.entityAttributes,
[parentId]: newEntities,
this.objectAttributes = {
...this.objectAttributes,
[parentId]: newObjects,
};
});
} catch (error) {
@ -245,13 +245,13 @@ class CustomAttributesStore {
const response = await customAttributesService.createProperty(workspaceSlug, data);
runInAction(() => {
this.entityAttributes = {
...this.entityAttributes,
this.objectAttributes = {
...this.objectAttributes,
[objectId]: {
...this.entityAttributes[objectId],
...this.objectAttributes[objectId],
[data.parent]: {
...this.entityAttributes[objectId][data.parent],
children: [...this.entityAttributes[objectId][data.parent].children, response],
...this.objectAttributes[objectId][data.parent],
children: [...this.objectAttributes[objectId][data.parent].children, response],
},
},
};
@ -277,18 +277,18 @@ class CustomAttributesStore {
try {
const response = await customAttributesService.patchProperty(workspaceSlug, propertyId, data);
const newOptions = this.entityAttributes[objectId][parentId].children.map((option) => ({
const newOptions = this.objectAttributes[objectId][parentId].children.map((option) => ({
...option,
...(option.id === propertyId ? response : {}),
}));
runInAction(() => {
this.entityAttributes = {
...this.entityAttributes,
this.objectAttributes = {
...this.objectAttributes,
[objectId]: {
...this.entityAttributes[objectId],
...this.objectAttributes[objectId],
[parentId]: {
...this.entityAttributes[objectId][parentId],
...this.objectAttributes[objectId][parentId],
children: newOptions,
},
},
@ -312,17 +312,17 @@ class CustomAttributesStore {
try {
const response = await customAttributesService.deleteProperty(workspaceSlug, propertyId);
const newOptions = this.entityAttributes[objectId][parentId].children.filter(
const newOptions = this.objectAttributes[objectId][parentId].children.filter(
(option) => option.id !== propertyId
);
runInAction(() => {
this.entityAttributes = {
...this.entityAttributes,
this.objectAttributes = {
...this.objectAttributes,
[objectId]: {
...this.entityAttributes[objectId],
...this.objectAttributes[objectId],
[parentId]: {
...this.entityAttributes[objectId][parentId],
...this.objectAttributes[objectId][parentId],
children: newOptions,
},
},