Chore: Simplify selector access across the page

This commit is contained in:
Gustav Hansen 2023-01-30 17:29:52 +01:00
parent 9cf1567604
commit d7b18b9ece

View File

@ -15,7 +15,7 @@ import { setWorkflow } from './actions';
export function ReviewWorkflowsPage() { export function ReviewWorkflowsPage() {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const { workflows: workflowsData } = useReviewWorkflows(); const { workflows: workflowsData } = useReviewWorkflows();
const workflow = useSelector((state) => state?.[REDUX_NAMESPACE]); const state = useSelector((state) => state?.[REDUX_NAMESPACE]);
const dispatch = useDispatch(); const dispatch = useDispatch();
useInjectReducer(REDUX_NAMESPACE, reducer); useInjectReducer(REDUX_NAMESPACE, reducer);
@ -27,10 +27,12 @@ export function ReviewWorkflowsPage() {
// useInjectReducer() runs on the first rendering after useSelector // useInjectReducer() runs on the first rendering after useSelector
// which will return undefined. This helps to avoid too many optional // which will return undefined. This helps to avoid too many optional
// chaining operators down the component. // chaining operators down the component.
if (!workflow) { if (!state) {
return null; return null;
} }
const { workflows } = state;
return ( return (
<Layout> <Layout>
<SettingsPageTitle <SettingsPageTitle
@ -58,11 +60,11 @@ export function ReviewWorkflowsPage() {
id: 'Settings.review-workflows.page.subtitle', id: 'Settings.review-workflows.page.subtitle',
defaultMessage: '{count, plural, one {# stage} other {# stages}}', defaultMessage: '{count, plural, one {# stage} other {# stages}}',
}, },
{ count: workflow.workflows.stages.length } { count: workflows.stages.length }
)} )}
/> />
<ContentLayout> <ContentLayout>
{workflow.workflows.state === 'loading' ? ( {workflows.state === 'loading' ? (
<Loader> <Loader>
{formatMessage({ {formatMessage({
id: 'Settings.review-workflows.page.isLoading', id: 'Settings.review-workflows.page.isLoading',
@ -70,7 +72,7 @@ export function ReviewWorkflowsPage() {
})} })}
</Loader> </Loader>
) : ( ) : (
<Stages stages={workflow.workflows.stages} /> <Stages stages={workflows.stages} />
)} )}
</ContentLayout> </ContentLayout>
</Main> </Main>