mirror of
https://github.com/strapi/strapi.git
synced 2025-08-03 14:28:40 +00:00
Chore: Update license limits in create, edit and list-views
This commit is contained in:
parent
2a92cba09d
commit
9aef0d0f08
@ -24,6 +24,10 @@ jest.mock('../../../../../../hooks', () => ({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
meta: {
|
||||||
|
workflowCount: 2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
@ -40,5 +44,9 @@ describe('useReviewWorkflowLicenseLimits', () => {
|
|||||||
workflows: 10,
|
workflows: 10,
|
||||||
stagesPerWorkflow: 10,
|
stagesPerWorkflow: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(result.current.meta).toStrictEqual({
|
||||||
|
workflowCount: 2,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -36,7 +36,9 @@ export function useReviewWorkflows(params = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pagination: data?.pagination ?? {},
|
// meta contains e.g. the total of all workflows. we can not use
|
||||||
|
// the pagination object here, because the list is not paginated.
|
||||||
|
meta: data?.meta ?? {},
|
||||||
workflows,
|
workflows,
|
||||||
isLoading,
|
isLoading,
|
||||||
status,
|
status,
|
||||||
|
@ -37,7 +37,7 @@ export function ReviewWorkflowsCreateView() {
|
|||||||
} = useSelector((state) => state?.[REDUX_NAMESPACE] ?? initialState);
|
} = useSelector((state) => state?.[REDUX_NAMESPACE] ?? initialState);
|
||||||
const [showLimitModal, setShowLimitModal] = React.useState(false);
|
const [showLimitModal, setShowLimitModal] = React.useState(false);
|
||||||
const { limits, isLoading: isLicenseLoading } = useReviewWorkflowLicenseLimits();
|
const { limits, isLoading: isLicenseLoading } = useReviewWorkflowLicenseLimits();
|
||||||
const { pagination, isLoading: isWorkflowLoading } = useReviewWorkflows();
|
const { meta, isLoading: isWorkflowLoading } = useReviewWorkflows();
|
||||||
|
|
||||||
const { mutateAsync, isLoading } = useMutation(
|
const { mutateAsync, isLoading } = useMutation(
|
||||||
async ({ workflow }) => {
|
async ({ workflow }) => {
|
||||||
@ -94,21 +94,34 @@ export function ReviewWorkflowsCreateView() {
|
|||||||
dispatch(resetWorkflow());
|
dispatch(resetWorkflow());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the current license has a limit:
|
||||||
|
* check if the total count of workflows or stages exceeds that limit and display
|
||||||
|
* the limits modal on page load. It can be closed by the user, but the
|
||||||
|
* API will throw an error in case they try to create a new workflow or update the
|
||||||
|
* stages.
|
||||||
|
*
|
||||||
|
* If the current license does not have a limit (e.g. offline license):
|
||||||
|
* do nothing (for now). In case they are trying to create the 201st workflow/ stage
|
||||||
|
* the API will throw an error.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!isWorkflowLoading && !isLicenseLoading) {
|
if (!isWorkflowLoading && !isLicenseLoading) {
|
||||||
if (pagination?.total >= limits?.workflows) {
|
if (meta?.workflowsTotal >= limits?.workflows) {
|
||||||
setShowLimitModal('workflow');
|
setShowLimitModal('workflow');
|
||||||
} else if (currentWorkflow.stages.length >= limits.stagesPerWorkflow) {
|
} else if (currentWorkflow.stages.length >= limits.stagesPerWorkflow) {
|
||||||
setShowLimitModal('stage');
|
setShowLimitModal('stage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
currentWorkflow.stages.length,
|
|
||||||
isLicenseLoading,
|
isLicenseLoading,
|
||||||
isWorkflowLoading,
|
isWorkflowLoading,
|
||||||
limits.stagesPerWorkflow,
|
limits.stagesPerWorkflow,
|
||||||
limits?.workflows,
|
limits?.workflows,
|
||||||
pagination?.total,
|
meta?.workflowsTotal,
|
||||||
|
currentWorkflow.stages.length,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -38,7 +38,7 @@ export function ReviewWorkflowsEditView() {
|
|||||||
const toggleNotification = useNotification();
|
const toggleNotification = useNotification();
|
||||||
const {
|
const {
|
||||||
isLoading: isWorkflowLoading,
|
isLoading: isWorkflowLoading,
|
||||||
pagination,
|
meta,
|
||||||
workflows: [workflow],
|
workflows: [workflow],
|
||||||
status: workflowStatus,
|
status: workflowStatus,
|
||||||
refetch,
|
refetch,
|
||||||
@ -132,11 +132,27 @@ export function ReviewWorkflowsEditView() {
|
|||||||
dispatch(setWorkflow({ status: workflowStatus, data: workflow }));
|
dispatch(setWorkflow({ status: workflowStatus, data: workflow }));
|
||||||
}, [workflowStatus, workflow, dispatch]);
|
}, [workflowStatus, workflow, dispatch]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the current license has a limit:
|
||||||
|
* check if the total count of workflows or stages exceeds that limit and display
|
||||||
|
* the limits modal on page load. It can be closed by the user, but the
|
||||||
|
* API will throw an error in case they try to create a new workflow or update the
|
||||||
|
* stages.
|
||||||
|
*
|
||||||
|
* If the current license does not have a limit (e.g. offline license):
|
||||||
|
* do nothing (for now). In case they are trying to create the 201st workflow/ stage
|
||||||
|
* the API will throw an error.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!isWorkflowLoading && !isLicenseLoading) {
|
if (!isWorkflowLoading && !isLicenseLoading) {
|
||||||
if (pagination?.total >= limits?.workflows) {
|
if (limits?.workflows && meta?.workflowCount >= limits.workflows) {
|
||||||
setShowLimitModal('workflow');
|
setShowLimitModal('workflow');
|
||||||
} else if (currentWorkflow.stages.length >= limits?.stagesPerWorkflow) {
|
} else if (
|
||||||
|
limits?.stagesPerWorkflow &&
|
||||||
|
currentWorkflow.stages.length >= limits.stagesPerWorkflow
|
||||||
|
) {
|
||||||
setShowLimitModal('stage');
|
setShowLimitModal('stage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,12 +160,13 @@ export function ReviewWorkflowsEditView() {
|
|||||||
currentWorkflow.stages.length,
|
currentWorkflow.stages.length,
|
||||||
isLicenseLoading,
|
isLicenseLoading,
|
||||||
isWorkflowLoading,
|
isWorkflowLoading,
|
||||||
limits?.stagesPerWorkflow,
|
limits.stagesPerWorkflow,
|
||||||
limits?.workflows,
|
limits.workflows,
|
||||||
pagination?.total,
|
meta?.workflowCount,
|
||||||
|
meta.workflowsTotal,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// TODO redirect back to list-view if workflow is not found?
|
// TODO: redirect back to list-view if workflow is not found?
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -67,7 +67,7 @@ export function ReviewWorkflowsListView() {
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { push } = useHistory();
|
const { push } = useHistory();
|
||||||
const { collectionTypes, singleTypes, isLoading: isLoadingModels } = useContentTypes();
|
const { collectionTypes, singleTypes, isLoading: isLoadingModels } = useContentTypes();
|
||||||
const { pagination, workflows, isLoading, refetch } = useReviewWorkflows();
|
const { meta, workflows, isLoading, refetch } = useReviewWorkflows();
|
||||||
const [workflowToDelete, setWorkflowToDelete] = React.useState(null);
|
const [workflowToDelete, setWorkflowToDelete] = React.useState(null);
|
||||||
const [showLimitModal, setShowLimitModal] = React.useState(false);
|
const [showLimitModal, setShowLimitModal] = React.useState(false);
|
||||||
const { del } = useFetchClient();
|
const { del } = useFetchClient();
|
||||||
@ -138,7 +138,17 @@ export function ReviewWorkflowsListView() {
|
|||||||
size="S"
|
size="S"
|
||||||
to="/settings/review-workflows/create"
|
to="/settings/review-workflows/create"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
if (pagination?.total >= limits.workflows) {
|
/**
|
||||||
|
* If the current license has a workflow limit:
|
||||||
|
* check if the total count of workflows exceeds that limit. If so,
|
||||||
|
* prevent the navigation and show the limits overlay.
|
||||||
|
*
|
||||||
|
* If the current license does not have a limit (e.g. offline license):
|
||||||
|
* allow the user to navigate to the create-view. In case they exceed the
|
||||||
|
* current hard-limit of 200 they will see an error thrown by the API.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (limits?.workflows && meta?.workflowCount >= limits.workflows) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setShowLimitModal(true);
|
setShowLimitModal(true);
|
||||||
}
|
}
|
||||||
@ -177,7 +187,16 @@ export function ReviewWorkflowsListView() {
|
|||||||
<TFooter
|
<TFooter
|
||||||
icon={<Plus />}
|
icon={<Plus />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (pagination?.total >= limits?.workflows) {
|
/**
|
||||||
|
* If the current license has a workflow limit:
|
||||||
|
* check if the total count of workflows exceeds that limit
|
||||||
|
*
|
||||||
|
* If the current license does not have a limit (e.g. offline license):
|
||||||
|
* allow the user to navigate to the create-view. In case they exceed the
|
||||||
|
* current hard-limit of 200 they will see an error thrown by the API.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (limits?.workflows && meta?.workflowCount >= limits.workflows) {
|
||||||
setShowLimitModal(true);
|
setShowLimitModal(true);
|
||||||
} else {
|
} else {
|
||||||
push('/settings/review-workflows/create');
|
push('/settings/review-workflows/create');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user