From cd3e09253c785b51da2a94bfa6dc9da2cf13ca46 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 22 Nov 2021 15:11:14 +0100 Subject: [PATCH] Typescript 4.5 --- example/src/SampleApp/SampleApp.tsx | 1 + package.json | 2 +- .../CollectionTable/column_builder.tsx | 2 + src/form/EntityForm.tsx | 2 +- src/models/properties.ts | 4 +- src/test/test_site_config.ts | 62 +++++++++++++++++++ 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/example/src/SampleApp/SampleApp.tsx b/example/src/SampleApp/SampleApp.tsx index a2eabbb..c17cd67 100644 --- a/example/src/SampleApp/SampleApp.tsx +++ b/example/src/SampleApp/SampleApp.tsx @@ -115,6 +115,7 @@ function SampleApp() { schema: testEntitySchema, callbacks: testCallbacks, name: "Test entity", + properties: ["subcollection_test_subcollection", "gallery"], subcollections: [{ path: "test_subcollection", schema: testEntitySchema, diff --git a/package.json b/package.json index e2b6d68..0439ef1 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "react-router-dom": "^6.0.0", "react-scripts": "^4.0.3", "tsd": "0.17.0", - "typescript": "^4.4.3" + "typescript": "^4.5.2" }, "files": [ "dist" diff --git a/src/core/components/CollectionTable/column_builder.tsx b/src/core/components/CollectionTable/column_builder.tsx index 0f621e8..84b2441 100644 --- a/src/core/components/CollectionTable/column_builder.tsx +++ b/src/core/components/CollectionTable/column_builder.tsx @@ -161,6 +161,8 @@ export function buildColumnsFromSchema { const escFunction = (event: any) => { diff --git a/src/form/EntityForm.tsx b/src/form/EntityForm.tsx index ec73285..c76333c 100644 --- a/src/form/EntityForm.tsx +++ b/src/form/EntityForm.tsx @@ -329,7 +329,7 @@ export function EntityForm({ const formFields = ( - {Object.entries(schemaProperties) + {Object.entries(schemaProperties as Record>) .filter(([key, property]) => !isHidden(property)) .map(([key, property]) => { diff --git a/src/models/properties.ts b/src/models/properties.ts index 50a6432..805a629 100644 --- a/src/models/properties.ts +++ b/src/models/properties.ts @@ -176,7 +176,7 @@ export interface EnumValueConfig { * Record of properties of an entity or a map property * @category Entity properties */ -export type Properties = { +export type Properties = { [k in keyof M]: Property; }; @@ -337,7 +337,7 @@ export interface MapProperty extends Bas /** * Record of properties included in this map. */ - properties?: Properties; // TODO: this should be Properties but it breaks if building properties without `buildProperties` + properties?: Properties>; // TODO: this should be Properties but it breaks if building properties without `buildProperties` /** * Rules for validating this property diff --git a/src/test/test_site_config.ts b/src/test/test_site_config.ts index 2774dc4..2560d2a 100644 --- a/src/test/test_site_config.ts +++ b/src/test/test_site_config.ts @@ -278,5 +278,67 @@ export const siteConfig: FirebaseCMSAppProps = { ] }; +export const usersSchema = buildSchema({ + name: "User", + properties: { + first_name: { + title: "First name", + dataType: "string" + }, + last_name: { + title: "Last name", + dataType: "string" + }, + email: { + title: "Email", + dataType: "string", + validation: { + email: true + } + }, + phone: { + title: "Phone", + dataType: "string" + }, + liked_products: { + dataType: "array", + title: "Liked products", + description: "Products this user has liked", + of: { + dataType: "reference", + path: "products" + } + }, + picture: { + title: "Picture", + dataType: "map", + properties: { + large: { + title: "Large", + dataType: "string", + config: { + url: "image" + }, + validation: { + url: true + } + }, + thumbnail: { + title: "Thumbnail", + dataType: "string", + config: { + url: "image" + }, + validation: { + url: true + } + } + }, + previewProperties: ["large"] + } + } +}); + +