#124 - Add support to specify preview image

This commit is contained in:
Elio Struyf
2021-09-30 16:26:21 +02:00
parent 8199ab964e
commit 5f28e145c4
7 changed files with 47 additions and 17 deletions
+2 -12
View File
@@ -13,10 +13,10 @@ import { DateTimeField } from './Fields/DateTimeField';
import { TextField } from './Fields/TextField';
import "react-datepicker/dist/react-datepicker.css";
import { PreviewImageField } from './Fields/PreviewImageField';
import { DEFAULT_CONTENT_TYPE, DEFAULT_CONTENT_TYPE_NAME } from '../../constants/ContentType';
import { ListUnorderedIcon } from './Icons/ListUnorderedIcon';
import { NumberField } from './Fields/NumberField';
import { ChoiceField } from './Fields/ChoiceField';
import useContentType from '../../hooks/useContentType';
export interface IMetadataProps {
settings: PanelSettings | undefined;
@@ -26,6 +26,7 @@ export interface IMetadataProps {
}
export const Metadata: React.FunctionComponent<IMetadataProps> = ({settings, metadata, focusElm, unsetFocus}: React.PropsWithChildren<IMetadataProps>) => {
const contentType = useContentType(settings, metadata);
const sendUpdate = (field: string | undefined, value: any) => {
if (!field) {
@@ -49,17 +50,6 @@ export const Metadata: React.FunctionComponent<IMetadataProps> = ({settings, met
return null;
}
const contentTypeName = metadata.type as string || DEFAULT_CONTENT_TYPE_NAME;
let contentType = settings.contentTypes.find(ct => ct.name === contentTypeName);
if (!contentType) {
contentType = settings.contentTypes.find(ct => ct.name === DEFAULT_CONTENT_TYPE_NAME);
}
if (!contentType || !contentType.fields) {
contentType = DEFAULT_CONTENT_TYPE;
}
const renderFields = (ctFields: Field[]) => {
if (!ctFields) {
return;