Skip to content

Commit

Permalink
chore: fix error state on users
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Mar 13, 2024
1 parent bbb5e8b commit e9623e7
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/core/admin/admin/src/components/Filters.tsx
Expand Up @@ -338,10 +338,10 @@ const List = () => {
return true;
}

const type = options.find(({ name }) => name === attributeName)?.type;
const { type, mainField } = options.find(({ name }) => name === attributeName)!;

if (type === 'relation') {
const filterObj = filter[attributeName].id;
const filterObj = filter[attributeName][mainField?.name ?? 'id'];

if (typeof filterObj === 'object') {
const [operator] = Object.keys(filterObj);
Expand Down Expand Up @@ -379,7 +379,7 @@ const List = () => {
}

if (filter.type === 'relation') {
const modelFilter = filterObj.id;
const modelFilter = filterObj[filter.mainField?.name ?? 'id'];

if (typeof modelFilter === 'object') {
const [operator] = Object.keys(modelFilter);
Expand Down
Expand Up @@ -8,7 +8,7 @@ import { useField } from '../Form';

import { InputProps } from './types';

const DateInput = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
const DateInput = forwardRef<HTMLInputElement, InputProps>(({ type: _type, ...props }, ref) => {
const { formatMessage } = useIntl();
const field = useField<Date>(props.name);
const fieldRef = useFocusInputField(props.name);
Expand Down
Expand Up @@ -79,6 +79,7 @@ const ConfigurationForm = ({
const initialValues: ConfigurationFormData = React.useMemo(() => {
const transformations = pipe(
flattenPanels,
replaceMainFieldWithNameOnly,
extractMetadata,
addTmpSpaceToLayout,
addTmpKeysToLayout
Expand Down Expand Up @@ -187,6 +188,18 @@ const ConfigurationForm = ({
const flattenPanels = (layout: EditLayout['layout']): EditLayout['layout'][number] =>
layout.flat(1);

/**
* @internal
* @description We don't need the mainField object in the layout, we only need the name.
*/
const replaceMainFieldWithNameOnly = (layout: EditLayout['layout'][number]) =>
layout.map((row) =>
row.map((field) => ({
...field,
mainField: field.mainField?.name,
}))
);

/**
* @internal
* @description We extract the metadata values from the field layout, because these are editable by the user.
Expand Down
Expand Up @@ -43,6 +43,7 @@ const useContentTypeSchema = (model?: string) => {

return {
isLoading: res.isLoading,
isFetching: res.isFetching,
error: res.error,
components: Object.keys(components).length === 0 ? undefined : components,
contentType,
Expand Down
Expand Up @@ -141,7 +141,7 @@ const useDocument: UseDocument = (args, opts) => {
[validationSchema]
);

const isLoading = isLoadingDocument || isFetchingDocument || isFetchingSchema || isLoadingSchema;
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;

return {
components,
Expand Down
Expand Up @@ -135,7 +135,7 @@ const EditViewPage = () => {
return transformDocument(schema, components)(form);
}, [document, isCreatingDocument, isSingleType, schema, components]);

if (isLoading) {
if (isLoading && !document?.documentId) {
return <Page.Loading />;
}

Expand Down
Expand Up @@ -59,9 +59,7 @@ interface Relation extends Contracts.Relations.RelationResult {

interface RelationsFieldProps
extends Omit<Extract<EditFieldLayout, { type: 'relation' }>, 'size' | 'hint'>,
Pick<InputProps, 'hint'> {
mainField?: string;
}
Pick<InputProps, 'hint'> {}

interface RelationsFormValue {
connect?: Contracts.Relations.RelationResult[];
Expand Down
Expand Up @@ -20,7 +20,7 @@ const render = ({
relationType: 'manyToMany',
}}
label="relations"
mainField="name"
mainField={{ name: 'name', type: 'string' }}
name="relations"
type="relation"
{...props}
Expand Down
@@ -1,4 +1,5 @@
import { Contracts } from '@strapi/plugin-content-manager/_internal/shared';
import type { MainField } from './attributes';
import type { Contracts } from '@strapi/plugin-content-manager/_internal/shared';

/**
* @internal
Expand All @@ -10,9 +11,9 @@ import { Contracts } from '@strapi/plugin-content-manager/_internal/shared';
*/
const getRelationLabel = (
relation: Contracts.Relations.RelationResult,
mainField?: string
mainField?: MainField
): string => {
const label = mainField && relation[mainField] ? relation[mainField] : null;
const label = mainField && relation[mainField.name] ? relation[mainField.name] : null;

if (typeof label === 'string') {
return label;
Expand Down
Expand Up @@ -88,6 +88,10 @@ const ListPageCE = () => {
return null;
}

if (isError) {
return <Page.Error />;
}

return (
<Main aria-busy={isLoading}>
<Helmet
Expand Down Expand Up @@ -124,8 +128,6 @@ const ListPageCE = () => {
}
/>
<ContentLayout>
{/* TODO: Replace error message with something better */}
{isError && <div>TODO: An error occurred</div>}
{!isError && (
<>
<DynamicTable
Expand Down

0 comments on commit e9623e7

Please sign in to comment.