mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
[WEB-1501] chore: update selected entity details on entities list change (#4702)
* chore: update selected entity detials on entities list change * chore: addd selectionHelpers as a prop
This commit is contained in:
parent
453459d271
commit
93a22034bd
@ -162,7 +162,7 @@ export const GanttChartMainContent: React.FC<Props> = observer((props) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<IssueBulkOperationsRoot />
|
<IssueBulkOperationsRoot selectionHelpers={helpers} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</MultipleSelectGroup>
|
</MultipleSelectGroup>
|
||||||
|
@ -3,9 +3,11 @@ import { observer } from "mobx-react";
|
|||||||
import { BulkOperationsUpgradeBanner } from "@/components/issues";
|
import { BulkOperationsUpgradeBanner } from "@/components/issues";
|
||||||
// hooks
|
// hooks
|
||||||
import { useMultipleSelectStore } from "@/hooks/store";
|
import { useMultipleSelectStore } from "@/hooks/store";
|
||||||
|
import { TSelectionHelper } from "@/hooks/use-multiple-select";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
className?: string;
|
className?: string;
|
||||||
|
selectionHelpers: TSelectionHelper;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const IssueBulkOperationsRoot: React.FC<Props> = observer((props) => {
|
export const IssueBulkOperationsRoot: React.FC<Props> = observer((props) => {
|
||||||
|
@ -170,7 +170,7 @@ const GroupByList: React.FC<IGroupByList> = observer((props) => {
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<IssueBulkOperationsRoot />
|
<IssueBulkOperationsRoot selectionHelpers={helpers} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</MultipleSelectGroup>
|
</MultipleSelectGroup>
|
||||||
|
@ -107,7 +107,7 @@ export const SpreadsheetView: React.FC<Props> = observer((props) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<IssueBulkOperationsRoot />
|
<IssueBulkOperationsRoot selectionHelpers={helpers} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</MultipleSelectGroup>
|
</MultipleSelectGroup>
|
||||||
|
@ -33,6 +33,7 @@ export const useMultipleSelect = (props: Props) => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
// store hooks
|
// store hooks
|
||||||
const {
|
const {
|
||||||
|
selectedEntityIds,
|
||||||
updateSelectedEntityDetails,
|
updateSelectedEntityDetails,
|
||||||
bulkUpdateSelectedEntityDetails,
|
bulkUpdateSelectedEntityDetails,
|
||||||
getActiveEntityDetails,
|
getActiveEntityDetails,
|
||||||
@ -45,6 +46,7 @@ export const useMultipleSelect = (props: Props) => {
|
|||||||
clearSelection,
|
clearSelection,
|
||||||
getIsEntitySelected,
|
getIsEntitySelected,
|
||||||
getIsEntityActive,
|
getIsEntityActive,
|
||||||
|
getEntityDetailsFromEntityID,
|
||||||
} = useMultipleSelectStore();
|
} = useMultipleSelectStore();
|
||||||
|
|
||||||
const groups = useMemo(() => Object.keys(entities), [entities]);
|
const groups = useMemo(() => Object.keys(entities), [entities]);
|
||||||
@ -248,10 +250,6 @@ export const useMultipleSelect = (props: Props) => {
|
|||||||
(groupID: string) => {
|
(groupID: string) => {
|
||||||
const groupEntities = entitiesList.filter((entity) => entity.groupID === groupID);
|
const groupEntities = entitiesList.filter((entity) => entity.groupID === groupID);
|
||||||
const groupSelectionStatus = isGroupSelected(groupID);
|
const groupSelectionStatus = isGroupSelected(groupID);
|
||||||
// groupEntities.map((entity) => {
|
|
||||||
// console.log("group click");
|
|
||||||
// handleEntitySelection(entity, false, groupSelectionStatus === "empty" ? "force-add" : "force-remove");
|
|
||||||
// });
|
|
||||||
handleEntitySelection(groupEntities, false, groupSelectionStatus === "empty" ? "force-add" : "force-remove");
|
handleEntitySelection(groupEntities, false, groupSelectionStatus === "empty" ? "force-add" : "force-remove");
|
||||||
},
|
},
|
||||||
[entitiesList, handleEntitySelection, isGroupSelected]
|
[entitiesList, handleEntitySelection, isGroupSelected]
|
||||||
@ -346,6 +344,19 @@ export const useMultipleSelect = (props: Props) => {
|
|||||||
};
|
};
|
||||||
}, [clearSelection, router.events]);
|
}, [clearSelection, router.events]);
|
||||||
|
|
||||||
|
// when entities list change, remove entityIds from the selected entities array, which are not present in the new list
|
||||||
|
useEffect(() => {
|
||||||
|
selectedEntityIds.map((entityID) => {
|
||||||
|
const isEntityPresent = entitiesList.find((en) => en.entityID === entityID);
|
||||||
|
if (!isEntityPresent) {
|
||||||
|
const entityDetails = getEntityDetailsFromEntityID(entityID);
|
||||||
|
if (entityDetails) {
|
||||||
|
handleEntitySelection(entityDetails);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [entitiesList, getEntityDetailsFromEntityID, handleEntitySelection, selectedEntityIds]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description helper functions for selection
|
* @description helper functions for selection
|
||||||
*/
|
*/
|
||||||
|
@ -19,6 +19,7 @@ export type IMultipleSelectStore = {
|
|||||||
getPreviousActiveEntity: () => TEntityDetails | null;
|
getPreviousActiveEntity: () => TEntityDetails | null;
|
||||||
getNextActiveEntity: () => TEntityDetails | null;
|
getNextActiveEntity: () => TEntityDetails | null;
|
||||||
getActiveEntityDetails: () => TEntityDetails | null;
|
getActiveEntityDetails: () => TEntityDetails | null;
|
||||||
|
getEntityDetailsFromEntityID: (entityID: string) => TEntityDetails | null;
|
||||||
// entity actions
|
// entity actions
|
||||||
updateSelectedEntityDetails: (entityDetails: TEntityDetails, action: "add" | "remove") => void;
|
updateSelectedEntityDetails: (entityDetails: TEntityDetails, action: "add" | "remove") => void;
|
||||||
bulkUpdateSelectedEntityDetails: (entitiesList: TEntityDetails[], action: "add" | "remove") => void;
|
bulkUpdateSelectedEntityDetails: (entitiesList: TEntityDetails[], action: "add" | "remove") => void;
|
||||||
@ -119,6 +120,16 @@ export class MultipleSelectStore implements IMultipleSelectStore {
|
|||||||
*/
|
*/
|
||||||
getActiveEntityDetails = computedFn(() => this.activeEntityDetails);
|
getActiveEntityDetails = computedFn(() => this.activeEntityDetails);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get the entity details from entityID
|
||||||
|
* @param {string} entityID
|
||||||
|
* @returns {TEntityDetails | null}
|
||||||
|
*/
|
||||||
|
getEntityDetailsFromEntityID = computedFn(
|
||||||
|
(entityID: string): TEntityDetails | null =>
|
||||||
|
this.selectedEntityDetails.find((en) => en.entityID === entityID) ?? null
|
||||||
|
);
|
||||||
|
|
||||||
// entity actions
|
// entity actions
|
||||||
/**
|
/**
|
||||||
* @description add or remove entities
|
* @description add or remove entities
|
||||||
@ -159,8 +170,11 @@ export class MultipleSelectStore implements IMultipleSelectStore {
|
|||||||
if (entitiesList.length > 0) this.updateLastSelectedEntityDetails(entitiesList[entitiesList.length - 1]);
|
if (entitiesList.length > 0) this.updateLastSelectedEntityDetails(entitiesList[entitiesList.length - 1]);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
const newEntities = differenceWith(this.selectedEntityDetails, entitiesList, (obj1, obj2) =>
|
||||||
|
isEqual(obj1.entityID, obj2.entityID)
|
||||||
|
);
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.selectedEntityDetails = differenceWith(this.selectedEntityDetails, entitiesList, isEqual);
|
this.selectedEntityDetails = newEntities;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user