fix: clean up dependencies and config schema (#704)

This commit is contained in:
Daniel Lautzenheiser
2023-04-17 10:35:35 -04:00
committed by GitHub
parent 778e6bac75
commit ecb1218646
28 changed files with 304 additions and 179 deletions

View File

@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { Navigate, useParams } from 'react-router-dom';
import { Navigate, useParams, useSearchParams } from 'react-router-dom';
import {
selectCollection,
@ -16,6 +16,8 @@ interface CollectionRouteProps {
const CollectionRoute = ({ isSearchResults, isSingleSearchResult }: CollectionRouteProps) => {
const { name, searchTerm } = useParams();
const [searchParams] = useSearchParams();
const noRedirect = searchParams.has('noredirect');
const collectionSelector = useMemo(() => selectCollection(name), [name]);
const collection = useAppSelector(collectionSelector);
@ -27,7 +29,12 @@ const CollectionRoute = ({ isSearchResults, isSingleSearchResult }: CollectionRo
return <Navigate to={defaultPath} />;
}
if (collection && 'files' in collection && collection.files?.length === 1) {
if (collection && 'files' in collection && collection.files?.length === 1 && !noRedirect) {
const href = window.location.href;
if (!href.includes('noredirect')) {
window.history.replaceState(null, document.title, `${href}?noredirect`);
console.log('REPLACE STATE', document.title, `${href}?noredirect`);
}
return <Navigate to={`/collections/${collection.name}/entries/${collection.files[0].name}`} />;
}

View File

@ -1,23 +1,31 @@
import React from 'react';
import type { FC } from 'react';
import classNames from '@staticcms/core/lib/util/classNames.util';
import type { FieldError } from '@staticcms/core/interface';
import type { FC } from 'react';
export interface ErrorMessageProps {
errors: FieldError[];
className?: string;
}
const ErrorMessage: FC<ErrorMessageProps> = ({ errors }) => {
const ErrorMessage: FC<ErrorMessageProps> = ({ errors, className }) => {
return errors.length ? (
<div
key="error"
data-testid="error"
className="flex
w-full
text-xs
text-red-500
px-3
pt-1"
className={classNames(
`
flex
w-full
text-xs
text-red-500
px-3
pt-1
`,
className,
)}
>
{errors[0].message}
</div>

View File

@ -58,7 +58,6 @@ const Pill: FC<PillProps> = ({
`
text-xs
font-medium
mr-2
px-3
py-1
rounded-lg

View File

@ -80,7 +80,7 @@ const EditorControl = ({
[field.name, fieldName, parentPath],
);
const [dirty, setDirty] = useState(!isEmpty(value));
const [dirty, setDirty] = useState(!isEmpty(widget.getValidValue(value, field as UnknownField)));
const fieldErrorsSelector = useMemo(
() => selectFieldErrors(path, i18n, isMeta),
@ -114,10 +114,12 @@ const EditorControl = ({
const handleChangeDraftField = useCallback(
(value: ValueOrNestedValue) => {
setDirty(true);
setDirty(
oldDirty => oldDirty || !isEmpty(widget.getValidValue(value, field as UnknownField)),
);
changeDraftField({ path, field, value, i18n, isMeta });
},
[changeDraftField, field, i18n, isMeta, path],
[changeDraftField, field, i18n, isMeta, path, widget],
);
const config = useMemo(() => configState.config, [configState.config]);