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

View File

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

View File

@ -7,7 +7,7 @@ import { CustomCheckboxAttribute } from "components/custom-attributes";
import { Tooltip } from "components/ui"; import { Tooltip } from "components/ui";
type Props = { type Props = {
entityId: string; objectId: string;
issueId: string; issueId: string;
onChange: (attributeId: string, val: string | string[] | undefined) => void; onChange: (attributeId: string, val: string | string[] | undefined) => void;
projectId: string; projectId: string;
@ -15,11 +15,11 @@ type Props = {
}; };
export const CustomAttributesCheckboxes: React.FC<Props> = observer((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 { customAttributes } = useMobxStore();
const attributes = customAttributes.entityAttributes[entityId] ?? {}; const attributes = customAttributes.objectAttributes[objectId] ?? {};
const checkboxFields = Object.values(attributes).filter((a) => a.type === "checkbox"); 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"; import { TCustomAttributeTypes } from "types";
type Props = { type Props = {
entityId: string; objectId: string;
issueId: string; issueId: string;
onChange: (attributeId: string, val: string | string[] | undefined) => void; onChange: (attributeId: string, val: string | string[] | undefined) => void;
projectId: string; projectId: string;
@ -23,13 +23,13 @@ type Props = {
const DESCRIPTION_FIELDS: TCustomAttributeTypes[] = ["email", "number", "text", "url"]; const DESCRIPTION_FIELDS: TCustomAttributeTypes[] = ["email", "number", "text", "url"];
export const CustomAttributesDescriptionFields: React.FC<Props> = observer((props) => { export const CustomAttributesDescriptionFields: React.FC<Props> = observer((props) => {
const { entityId, onChange, values } = props; const { objectId, onChange, values } = props;
const [hideOptionalFields, setHideOptionalFields] = useState(false); const [hideOptionalFields, setHideOptionalFields] = useState(false);
const { customAttributes } = useMobxStore(); const { customAttributes } = useMobxStore();
const attributes = customAttributes.entityAttributes[entityId] ?? {}; const attributes = customAttributes.objectAttributes[objectId] ?? {};
const descriptionFields = Object.values(attributes).filter((a) => const descriptionFields = Object.values(attributes).filter((a) =>
DESCRIPTION_FIELDS.includes(a.type) DESCRIPTION_FIELDS.includes(a.type)

View File

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

View File

@ -14,7 +14,7 @@ import { Loader } from "components/ui";
import { TCustomAttributeTypes } from "types"; import { TCustomAttributeTypes } from "types";
type Props = { type Props = {
entityId: string; objectId: string;
issueId: string; issueId: string;
onChange: (attributeId: string, val: string | string[] | undefined) => void; onChange: (attributeId: string, val: string | string[] | undefined) => void;
projectId: string; projectId: string;
@ -24,17 +24,17 @@ type Props = {
const SELECT_FIELDS: TCustomAttributeTypes[] = ["datetime", "multi_select", "relation", "select"]; const SELECT_FIELDS: TCustomAttributeTypes[] = ["datetime", "multi_select", "relation", "select"];
export const CustomAttributesSelectFields: React.FC<Props> = observer((props) => { 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 { customAttributes } = useMobxStore();
const attributes = customAttributes.entityAttributes[entityId] ?? {}; const attributes = customAttributes.objectAttributes[objectId] ?? {};
const selectFields = Object.values(attributes).filter((a) => SELECT_FIELDS.includes(a.type)); const selectFields = Object.values(attributes).filter((a) => SELECT_FIELDS.includes(a.type));
return ( return (
<> <>
{customAttributes.fetchEntityDetailsLoader ? ( {customAttributes.fetchObjectDetailsLoader ? (
<Loader className="flex items-center gap-2"> <Loader className="flex items-center gap-2">
<Loader.Item height="27px" width="90px" /> <Loader.Item height="27px" width="90px" />
<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(() => { useEffect(() => {
if (!issue?.entity) return; if (!issue?.entity) return;
if (!customAttributes.entityAttributes[issue.entity]) { if (!customAttributes.objectAttributes[issue.entity]) {
if (!workspaceSlug) return; if (!workspaceSlug) return;
customAttributes.fetchEntityDetails(workspaceSlug.toString(), issue.entity); customAttributes.fetchObjectDetails(workspaceSlug.toString(), issue.entity);
} }
}, [customAttributes, issue?.entity, workspaceSlug]); }, [customAttributes, issue?.entity, workspaceSlug]);
@ -95,7 +95,7 @@ export const PeekOverviewCustomAttributesList: React.FC<Props> = observer(
if (!issue || !issue?.entity) return null; if (!issue || !issue?.entity) return null;
if ( if (
!customAttributes.entityAttributes[issue.entity] || !customAttributes.objectAttributes[issue.entity] ||
!customAttributeValues.issueAttributeValues?.[issue.id] !customAttributeValues.issueAttributeValues?.[issue.id]
) )
return ( return (
@ -109,7 +109,7 @@ export const PeekOverviewCustomAttributesList: React.FC<Props> = observer(
return ( 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 typeMetaData = CUSTOM_ATTRIBUTES_LIST[attribute.type];
const attributeValue = customAttributeValues.issueAttributeValues?.[issue.id].find( const attributeValue = customAttributeValues.issueAttributeValues?.[issue.id].find(
(a) => a.id === attribute.id (a) => a.id === attribute.id

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -454,7 +454,7 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer(
state: formData.state, 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) if (formData.entity === null)
payload = { payload = {
...payload, ...payload,

View File

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

View File

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

View File

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