diff --git a/package.json b/package.json index 3d7e2ce5..752057cb 100644 --- a/package.json +++ b/package.json @@ -358,6 +358,11 @@ "default": {}, "description": "The JSON schema for your data which will be used to render the data form.", "additionalProperties": true + }, + "type": { + "type": "string", + "default": "content", + "description": "If you are using data types, you can specify your type ID." } }, "additionalProperties": false, @@ -365,8 +370,45 @@ "id", "title", "file", - "schema", "labelField" + ], + "anyOf": [ + { + "required": [ + "schema" + ] + }, + { + "required": [ + "type" + ] + } + ] + }, + "scope": "Data" + }, + "frontMatter.data.types": { + "type": "array", + "default": [], + "markdownDescription": "Specify the data types. These types can be used in for your data files. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.data.types)", + "items": { + "type": "object", + "default": {}, + "properties": { + "id": { + "type": "string", + "description": "Your unique ID you want to use for your data type." + }, + "schema": { + "type": "object", + "default": {}, + "description": "The JSON schema for your data which will be used to render the data form.", + "additionalProperties": true + } + }, + "required": [ + "id", + "schema" ] }, "scope": "Data" diff --git a/src/constants/settings.ts b/src/constants/settings.ts index 166fa47e..45c612e4 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -56,6 +56,7 @@ export const SETTINGS_DASHBOARD_OPENONSTART = "dashboard.openOnStart"; export const SETTINGS_DASHBOARD_MEDIA_SNIPPET = "dashboard.mediaSnippet"; export const SETTINGS_DATA_FILES = "data.files"; +export const SETTINGS_DATA_TYPES = "data.types"; export const SETTINGS_FRAMEWORK_ID = "framework.id"; diff --git a/src/dashboardWebView/components/DataView/DataView.tsx b/src/dashboardWebView/components/DataView/DataView.tsx index bb619e70..4c107d34 100644 --- a/src/dashboardWebView/components/DataView/DataView.tsx +++ b/src/dashboardWebView/components/DataView/DataView.tsx @@ -18,6 +18,7 @@ import { SortableItem } from './SortableItem'; import { ChevronRightIcon } from '@heroicons/react/outline'; import { ToastContainer, toast, Slide } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; +import { DataType } from '../../../models/DataType'; export interface IDataViewProps {} @@ -75,7 +76,7 @@ export const DataView: React.FunctionComponent = (props: React.P }); // Show toast message - toast.success("Wow so easy!", { + toast.success("Your entry was submitted", { position: "top-right", autoClose: 2000, hideProgressBar: true, @@ -115,6 +116,25 @@ export const DataView: React.FunctionComponent = (props: React.P Messenger.unlisten(messageListener); } }, []); + + // Retrieve the data files, check if they have a schema or ID, if not, they shouldn't be shown + const dataFiles = (settings?.dataFiles || []).map((dataFile: DataFile) => { + if (!dataFile.schema && !dataFile.id) { + return null; + } + + const clonedFile = Object.assign({}, dataFile); + + if (clonedFile.type) { + const dataType = settings?.dataTypes?.find((dataType: DataType) => dataType.id === clonedFile.type); + if (!dataType) { + return null; + } + clonedFile.schema = Object.assign({}, dataType.schema); + } + + return clonedFile; + }).filter(d => d !== null) as DataFile[]; return (
@@ -130,8 +150,8 @@ export const DataView: React.FunctionComponent = (props: React.P