mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +00:00
fix token type state
This commit is contained in:
parent
061be9d747
commit
2e53c78e8f
@ -139,51 +139,47 @@ const ApiTokenCreateView = () => {
|
|||||||
unlockApp();
|
unlockApp();
|
||||||
};
|
};
|
||||||
|
|
||||||
// const hasAllActionsSelected = useMemo(() => {
|
const hasAllActionsSelected = useMemo(() => {
|
||||||
// const {
|
const { data, selectedActions } = state;
|
||||||
// modifiedData: { collectionTypes, singleTypes, custom },
|
|
||||||
// } = state;
|
|
||||||
|
|
||||||
// const dataToCheck = { ...collectionTypes, ...singleTypes, ...custom };
|
const areAllActionsSelected = data.allActionsIds.every((actionId) =>
|
||||||
|
selectedActions.includes(actionId)
|
||||||
|
);
|
||||||
|
|
||||||
// const areAllActionsSelected = getActionsState(dataToCheck, true);
|
return areAllActionsSelected;
|
||||||
|
}, [state]);
|
||||||
|
|
||||||
// return areAllActionsSelected;
|
const hasAllActionsNotSelected = useMemo(() => {
|
||||||
// }, [state]);
|
const { selectedActions } = state;
|
||||||
|
|
||||||
// const hasAllActionsNotSelected = useMemo(() => {
|
const areAllActionsNotSelected = selectedActions.length === 0;
|
||||||
// const {
|
|
||||||
// modifiedData: { collectionTypes, singleTypes, custom },
|
|
||||||
// } = state;
|
|
||||||
|
|
||||||
// const dataToCheck = { ...collectionTypes, ...singleTypes, ...custom };
|
return areAllActionsNotSelected;
|
||||||
|
}, [state]);
|
||||||
|
|
||||||
// const areAllActionsNotSelected = getActionsState(dataToCheck, false);
|
const hasReadOnlyActionsSelected = useMemo(() => {
|
||||||
|
const { data, selectedActions } = state;
|
||||||
|
|
||||||
// return areAllActionsNotSelected;
|
const areAllActionsReadOnly = data.allActionsIds.every((actionId) => {
|
||||||
// }, [state]);
|
if (actionId.includes('find') || actionId.includes('findOne')) {
|
||||||
|
return selectedActions.includes(actionId);
|
||||||
|
}
|
||||||
|
|
||||||
// const hasReadOnlyActionsSelected = useMemo(() => {
|
return !selectedActions.includes(actionId);
|
||||||
// const {
|
});
|
||||||
// modifiedData: { collectionTypes, singleTypes, custom },
|
|
||||||
// } = state;
|
|
||||||
|
|
||||||
// const dataToCheck = { ...collectionTypes, ...singleTypes, ...custom };
|
return areAllActionsReadOnly;
|
||||||
|
}, [state]);
|
||||||
// const areAllActionsReadOnly = getActionsState(dataToCheck, false, ['find', 'findOne']);
|
|
||||||
|
|
||||||
// return areAllActionsReadOnly;
|
|
||||||
// }, [state]);
|
|
||||||
|
|
||||||
const tokenTypeValue = useMemo(() => {
|
const tokenTypeValue = useMemo(() => {
|
||||||
// if (hasAllActionsSelected && !hasReadOnlyActionsSelected) return 'full-access';
|
if (hasAllActionsSelected && !hasReadOnlyActionsSelected) return 'full-access';
|
||||||
|
|
||||||
// if (hasReadOnlyActionsSelected) return 'read-only';
|
if (hasReadOnlyActionsSelected) return 'read-only';
|
||||||
|
|
||||||
// if (hasAllActionsNotSelected) return null;
|
if (hasAllActionsNotSelected) return null;
|
||||||
|
|
||||||
return 'custom';
|
return 'custom';
|
||||||
}, []);
|
}, [hasAllActionsSelected, hasReadOnlyActionsSelected, hasAllActionsNotSelected]);
|
||||||
|
|
||||||
const handleChangeCheckbox = ({ target: { value } }) => {
|
const handleChangeCheckbox = ({ target: { value } }) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
@ -202,28 +198,14 @@ const ApiTokenCreateView = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeSelectApiTokenType = ({ target: { value } }) => {
|
const handleChangeSelectApiTokenType = ({ target: { value } }) => {
|
||||||
const { modifiedData } = state;
|
|
||||||
|
|
||||||
if (value === 'full-access') {
|
if (value === 'full-access') {
|
||||||
Object.keys(modifiedData).forEach((contentTypes) => {
|
dispatch({
|
||||||
Object.keys(modifiedData[contentTypes]).forEach((contentType) => {
|
type: 'SELECT_ALL_ACTIONS',
|
||||||
dispatch({
|
|
||||||
type: 'ON_CHANGE_SELECT_ALL',
|
|
||||||
keys: [contentTypes, contentType],
|
|
||||||
value: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (value === 'read-only') {
|
if (value === 'read-only') {
|
||||||
Object.keys(modifiedData).forEach((contentTypes) => {
|
dispatch({
|
||||||
Object.keys(modifiedData[contentTypes]).forEach((contentType) => {
|
type: 'ON_CHANGE_READ_ONLY',
|
||||||
dispatch({
|
|
||||||
type: 'ON_CHANGE_READ_ONLY',
|
|
||||||
keys: [contentTypes, contentType],
|
|
||||||
value: false,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { set, pull } from 'lodash';
|
import { pull } from 'lodash';
|
||||||
import togglePermissions from './utils/togglePermissions';
|
|
||||||
|
|
||||||
export const initialState = {
|
export const initialState = {
|
||||||
data: {},
|
data: {},
|
||||||
@ -15,26 +14,20 @@ const reducer = (state, action) =>
|
|||||||
if (draftState.selectedActions.includes(action.value)) {
|
if (draftState.selectedActions.includes(action.value)) {
|
||||||
pull(draftState.selectedActions, action.value);
|
pull(draftState.selectedActions, action.value);
|
||||||
} else {
|
} else {
|
||||||
// fill(draftState.selectedActions, action.value);
|
|
||||||
draftState.selectedActions.push(action.value);
|
draftState.selectedActions.push(action.value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'ON_CHANGE_SELECT_ALL': {
|
case 'SELECT_ALL_ACTIONS': {
|
||||||
const { pathToValue, updatedValues } = togglePermissions(action, state);
|
draftState.selectedActions = [...draftState.data.allActionsIds];
|
||||||
|
|
||||||
set(draftState, pathToValue, { ...updatedValues });
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'ON_CHANGE_READ_ONLY': {
|
case 'ON_CHANGE_READ_ONLY': {
|
||||||
const { pathToValue, updatedValues } = togglePermissions(action, state, [
|
const onlyReadOnlyActions = draftState.data.allActionsIds.filter(
|
||||||
'find',
|
(actionId) => actionId.includes('find') || actionId.includes('findOne')
|
||||||
'findOne',
|
);
|
||||||
]);
|
draftState.selectedActions = [...onlyReadOnlyActions];
|
||||||
|
|
||||||
set(draftState, pathToValue, { ...updatedValues });
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user