Skip to content

Commit

Permalink
fix: don't let users submit an empty field for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Feb 8, 2024
1 parent 1d47602 commit 96b5260
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ const reducer = <TFormValues extends FormValues = FormValues>(
}
case 'SET_ERRORS':
if (!isEqual(state.errors, action.payload)) {
state.errors = action.payload;
// @ts-expect-error – TODO: figure out why this fails a TS check.
draft.errors = action.payload;
}
break;
case 'SET_ISSUBMITTING':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const StringInput = forwardRef<any, InputProps>(
hint={hint}
label={label}
name={name}
error={field.error}
defaultValue={field.initialValue}
onChange={field.onChange}
placeholder={placeholder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Navigate } from 'react-router-dom';

import { useTypedSelector } from '../../../core/store/hooks';
import { Form, FormProps } from '../../components/Form';
import { SINGLE_TYPES } from '../../constants/collections';
import { useDoc } from '../../hooks/useDocument';
import { ListFieldLayout, ListLayout, useDocLayout } from '../../hooks/useDocumentLayout';
import { useUpdateContentTypeConfigurationMutation } from '../../services/contentTypes';
Expand Down Expand Up @@ -113,7 +114,7 @@ const ListConfiguration = () => {
} satisfies FormData;
}, [formatMessage, list.layout, list.settings]);

if (collectionType === 'single-types') {
if (collectionType === SINGLE_TYPES) {
return <Navigate to={`/single-types/${model}`} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@strapi/design-system';
import { useIntl } from 'react-intl';
import styled from 'styled-components';
import * as yup from 'yup';

import { capitalise } from '../../../../utils/strings';
import { FieldTypeIcon } from '../../../components/FieldTypeIcon';
Expand All @@ -28,6 +29,11 @@ interface EditFieldFormProps extends Pick<ListFieldLayout, 'attribute'> {
onClose: () => void;
}

const FIELD_SCHEMA = yup.object().shape({
label: yup.string().required(),
sortable: yup.boolean(),
});

const EditFieldForm = ({ attribute, name, onClose }: EditFieldFormProps) => {
const { formatMessage } = useIntl();
const id = useId();
Expand All @@ -52,6 +58,7 @@ const EditFieldForm = ({ attribute, name, onClose }: EditFieldFormProps) => {
<Form
method="PUT"
initialValues={value}
validationSchema={FIELD_SCHEMA}
onSubmit={(data) => {
onChange(name, data);
onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const Settings = () => {
return [...ceOptions, { ...eeOption, label: formatMessage(eeOption.label) }];
},
defaultValue: sortOptionsCE,
enabled: schema?.options?.reviewWorkflows,
enabled: !!schema?.options?.reviewWorkflows,
}
) as SortOption[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const ListViewPage = () => {
(await import('../../../../../ee/admin/src/content-manager/pages/ListView/constants'))
.REVIEW_WORKFLOW_COLUMNS_EE,
{
enabled: schema?.options?.reviewWorkflows,
enabled: !!schema?.options?.reviewWorkflows,
}
);
const ReviewWorkflowsColumns = useEnterprise(
Expand All @@ -165,7 +165,7 @@ const ListViewPage = () => {
return { ReviewWorkflowsStageEE, ReviewWorkflowsAssigneeEE };
},
{
enabled: schema?.options?.reviewWorkflows,
enabled: !!schema?.options?.reviewWorkflows,
}
);

Expand Down

0 comments on commit 96b5260

Please sign in to comment.