mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
added code comments
This commit is contained in:
parent
0e26a36dc4
commit
a757f0ffc7
@ -35,11 +35,13 @@ export const useSelectionState = (keys, initialValue) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const selectMultiple = (nextSelections) => {
|
const selectMultiple = (nextSelections) => {
|
||||||
setSelections([
|
setSelections((currSelections) => [
|
||||||
...selections,
|
// already selected items
|
||||||
|
...currSelections,
|
||||||
|
// filter out already selected items from nextSelections
|
||||||
...nextSelections.filter(
|
...nextSelections.filter(
|
||||||
(nextSelection) =>
|
(nextSelection) =>
|
||||||
selections.findIndex((currentSelection) =>
|
currSelections.findIndex((currentSelection) =>
|
||||||
keys.every((key) => currentSelection[key] === nextSelection[key])
|
keys.every((key) => currentSelection[key] === nextSelection[key])
|
||||||
) === -1
|
) === -1
|
||||||
),
|
),
|
||||||
@ -47,8 +49,9 @@ export const useSelectionState = (keys, initialValue) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const deselectMultiple = (nextSelections) => {
|
const deselectMultiple = (nextSelections) => {
|
||||||
setSelections([
|
setSelections((currSelections) => [
|
||||||
...selections.filter(
|
// filter out items in currSelections that are in nextSelections
|
||||||
|
...currSelections.filter(
|
||||||
(currentSelection) =>
|
(currentSelection) =>
|
||||||
nextSelections.findIndex((nextSelection) =>
|
nextSelections.findIndex((nextSelection) =>
|
||||||
keys.every((key) => currentSelection[key] === nextSelection[key])
|
keys.every((key) => currentSelection[key] === nextSelection[key])
|
||||||
|
@ -14,7 +14,7 @@ This hook is used in order to facilitate the select / partial selection of a glo
|
|||||||
import { useSelectionState } from '@strapi/helper-plugin';
|
import { useSelectionState } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
const Modal = ({ onToggle, isOpen }) => {
|
const Modal = ({ onToggle, isOpen }) => {
|
||||||
const [selectedAssets, { selectOne, selectAll, selectOnly, setSelections }] = useSelectionState(
|
const [selectedAssets, { selectOne, selectAll, selectOnly, selectMultiple, deselectMultiple, setSelections }] = useSelectionState(
|
||||||
['id'], // This are the comparaison attribute names
|
['id'], // This are the comparaison attribute names
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
@ -24,6 +24,8 @@ const Modal = ({ onToggle, isOpen }) => {
|
|||||||
// selectOne({ id: 1 name: 'Hello' }) add the object to the selection list
|
// selectOne({ id: 1 name: 'Hello' }) add the object to the selection list
|
||||||
// selectOnly({ id: 1 name: 'Hello' }) add the object to the selection list and remove every others in the list
|
// selectOnly({ id: 1 name: 'Hello' }) add the object to the selection list and remove every others in the list
|
||||||
// selectAll(assets) select all or remove all
|
// selectAll(assets) select all or remove all
|
||||||
|
// selectMultiple(assets) add the objects to the selection list - does not change already selected objects
|
||||||
|
// deselectMultiple(assets) remove the objects from the selection list - does not change already selected objects
|
||||||
// setSelections(): regular state used in react
|
// setSelections(): regular state used in react
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -108,6 +108,7 @@ export const AssetDialog = ({
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selected files in current folder
|
||||||
const alreadySelected = allowedAssets.filter(
|
const alreadySelected = allowedAssets.filter(
|
||||||
(asset) => selectedAssets.findIndex((selectedAsset) => selectedAsset.id === asset.id) !== -1
|
(asset) => selectedAssets.findIndex((selectedAsset) => selectedAsset.id === asset.id) !== -1
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user