fix: delete option mutation

This commit is contained in:
Aaryan Khandelwal 2023-09-21 02:23:27 +05:30
parent d57e99ed30
commit 998dc1bbae
3 changed files with 15 additions and 15 deletions

View File

@ -92,7 +92,7 @@ export const OptionForm: React.FC<Props> = observer((props) => {
<div className="bg-custom-background-100 rounded border border-custom-border-200 flex items-center gap-2 px-3 py-2 flex-grow"> <div className="bg-custom-background-100 rounded border border-custom-border-200 flex items-center gap-2 px-3 py-2 flex-grow">
<input <input
type="text" type="text"
className="flex-grow border-none outline-none placeholder:text-custom-text-400 text-xs" className="flex-grow border-none outline-none placeholder:text-custom-text-400 text-xs bg-transparent"
value={option.display_name} value={option.display_name}
onChange={(e) => setOption((prev) => ({ ...prev, display_name: e.target.value }))} onChange={(e) => setOption((prev) => ({ ...prev, display_name: e.target.value }))}
placeholder="Enter new option" placeholder="Enter new option"

View File

@ -57,7 +57,7 @@ export const SelectOption: React.FC<Props> = observer((props) => {
</button> */} </button> */}
<Tooltip tooltipContent={option.display_name}> <Tooltip tooltipContent={option.display_name}>
<p <p
className="text-custom-text-300 text-xs p-1 rounded inline truncate" className="text-custom-text-200 text-xs p-1 rounded inline truncate"
style={{ style={{
backgroundColor: `${option.color}40`, backgroundColor: `${option.color}40`,
}} }}

View File

@ -64,13 +64,13 @@ class CustomAttributesStore {
} }
}; };
fetchObjectDetails = async (workspaceSlug: string, propertyId: string) => { fetchObjectDetails = async (workspaceSlug: string, objectId: string) => {
try { try {
runInAction(() => { runInAction(() => {
this.fetchObjectDetailsLoader = true; this.fetchObjectDetailsLoader = true;
}); });
const response = await customAttributesService.getPropertyDetails(workspaceSlug, propertyId); const response = await customAttributesService.getPropertyDetails(workspaceSlug, objectId);
const objectChildren: { [key: string]: ICustomAttribute } = response.children.reduce( const objectChildren: { [key: string]: ICustomAttribute } = response.children.reduce(
(acc, child) => ({ (acc, child) => ({
@ -83,7 +83,7 @@ class CustomAttributesStore {
runInAction(() => { runInAction(() => {
this.objectAttributes = { this.objectAttributes = {
...this.objectAttributes, ...this.objectAttributes,
[propertyId]: objectChildren, [objectId]: objectChildren,
}; };
this.fetchObjectDetailsLoader = false; this.fetchObjectDetailsLoader = false;
}); });
@ -137,11 +137,11 @@ class CustomAttributesStore {
} }
}; };
deleteObject = async (workspaceSlug: string, propertyId: string) => { deleteObject = async (workspaceSlug: string, objectId: string) => {
try { try {
await customAttributesService.deleteProperty(workspaceSlug, propertyId); await customAttributesService.deleteProperty(workspaceSlug, objectId);
const newObjects = this.objects?.filter((object) => object.id !== propertyId); const newObjects = this.objects?.filter((object) => object.id !== objectId);
runInAction(() => { runInAction(() => {
this.objects = [...(newObjects ?? [])]; this.objects = [...(newObjects ?? [])];
@ -309,13 +309,11 @@ class CustomAttributesStore {
parentId: string, parentId: string,
propertyId: string propertyId: string
) => { ) => {
try {
const response = await customAttributesService.deleteProperty(workspaceSlug, propertyId);
const newOptions = this.objectAttributes[objectId][parentId].children.filter( const newOptions = this.objectAttributes[objectId][parentId].children.filter(
(option) => option.id !== propertyId (option) => option.id !== propertyId
); );
try {
runInAction(() => { runInAction(() => {
this.objectAttributes = { this.objectAttributes = {
...this.objectAttributes, ...this.objectAttributes,
@ -329,11 +327,13 @@ class CustomAttributesStore {
}; };
}); });
return response; await customAttributesService.deleteProperty(workspaceSlug, propertyId);
} catch (error) { } catch (error) {
runInAction(() => { runInAction(() => {
this.error = error; this.error = error;
}); });
this.fetchObjectDetails(workspaceSlug, objectId);
} }
}; };
} }