From 783d7ff7c731712844b48b83743cf08ef126fa66 Mon Sep 17 00:00:00 2001 From: Jan-Gerke Salomon Date: Wed, 11 Oct 2023 12:27:44 +0200 Subject: [PATCH] uncommit me --- package.json | 1 + src/pages/dataElements/Edit.tsx | 2 +- src/pages/dataElements/New.tsx | 2 +- .../edit/createJsonPatchOperations.ts | 2 +- .../dataElements/edit/dataElementSchema.ts | 87 +++++++++++++++++++ src/pages/dataElements/form/index.ts | 1 + yarn.lock | 5 ++ 7 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 src/pages/dataElements/edit/dataElementSchema.ts diff --git a/package.json b/package.json index e0ab18ae..aa8b421e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "react-router-dom": "^6.11.2", "use-debounce": "^9.0.4", "use-query-params": "^2.2.1", + "zod": "^3.22.2", "zustand": "^4.4.0" } } diff --git a/src/pages/dataElements/Edit.tsx b/src/pages/dataElements/Edit.tsx index ed7e61fd..78690f85 100644 --- a/src/pages/dataElements/Edit.tsx +++ b/src/pages/dataElements/Edit.tsx @@ -13,7 +13,7 @@ import { Attribute, DataElement } from '../../types/generated' import { createJsonPatchOperations } from './edit' import classes from './Edit.module.css' import { DataElementFormFields, useCustomAttributesQuery } from './form' -import { FormValues } from './form/types' +import type { FormValues } from './form' type FinalFormFormApi = FormApi diff --git a/src/pages/dataElements/New.tsx b/src/pages/dataElements/New.tsx index a6ddf2ea..7ecbf49e 100644 --- a/src/pages/dataElements/New.tsx +++ b/src/pages/dataElements/New.tsx @@ -10,7 +10,7 @@ import { SCHEMA_SECTIONS } from '../../constants' import { getSectionPath } from '../../lib' import { Attribute } from '../../types/generated' import { DataElementFormFields, useCustomAttributesQuery } from './form' -import { FormValues } from './form/types' +import type { FormValues } from './form' import classes from './New.module.css' const listPath = `/${getSectionPath(SCHEMA_SECTIONS.dataElement)}` diff --git a/src/pages/dataElements/edit/createJsonPatchOperations.ts b/src/pages/dataElements/edit/createJsonPatchOperations.ts index 11feec85..5c7e889b 100644 --- a/src/pages/dataElements/edit/createJsonPatchOperations.ts +++ b/src/pages/dataElements/edit/createJsonPatchOperations.ts @@ -1,7 +1,7 @@ import get from 'lodash/fp/get' import { JsonPatchOperation } from '../../../types' import { DataElement } from '../../../types/generated' -import { FormValues } from '../form/types' +import type { FormValues } from '../form' type DataElementKey = keyof DataElement diff --git a/src/pages/dataElements/edit/dataElementSchema.ts b/src/pages/dataElements/edit/dataElementSchema.ts new file mode 100644 index 00000000..8bcb2d64 --- /dev/null +++ b/src/pages/dataElements/edit/dataElementSchema.ts @@ -0,0 +1,87 @@ +import { z } from 'zod' + +export const dataElementSchema = z.object({ + name: z.string(), + shortName: z.string(), + code: z.string().optional(), + description: z.string().optional(), + url: z.string().optional(), + color: z.string().optional(), + icon: z.string().optional(), + fieldMask: z.string().optional(), + domainType: z.union([ + z.literal('AGGREGATE'), + z.literal('TRACKER'), + ]), + formName: z.string().optional(), + valueType: z.union([ + z.literal('TEXT'), + z.literal('LONG_TEXT'), + z.literal('MULTI_TEXT'), + z.literal('LETTER'), + z.literal('PHONE_NUMBER'), + z.literal('EMAIL'), + z.literal('BOOLEAN'), + z.literal('TRUE_ONLY'), + z.literal('DATE'), + z.literal('DATETIME'), + z.literal('TIME'), + z.literal('NUMBER'), + z.literal('UNIT_INTERVAL'), + z.literal('PERCENTAGE'), + z.literal('INTEGER'), + z.literal('INTEGER_POSITIVE'), + z.literal('INTEGER_NEGATIVE'), + z.literal('INTEGER_ZERO_OR_POSITIVE'), + z.literal('TRACKER_ASSOCIATE'), + z.literal('USERNAME'), + z.literal('COORDINATE'), + z.literal('ORGANISATION_UNIT'), + z.literal('REFERENCE'), + z.literal('AGE'), + z.literal('URL'), + z.literal('FILE_RESOURCE'), + z.literal('IMAGE'), + z.literal('GEOJSON'), + ]).optional(), + aggregationType: z.union([ + z.literal('SUM'), + z.literal('AVERAGE'), + z.literal('AVERAGE_SUM_ORG_UNIT'), + z.literal('LAST'), + z.literal('LAST_AVERAGE_ORG_UNIT'), + z.literal('LAST_LAST_ORG_UNIT'), + z.literal('LAST_IN_PERIOD'), + z.literal('LAST_IN_PERIOD_AVERAGE_ORG_UNIT'), + z.literal('FIRST'), + z.literal('FIRST_AVERAGE_ORG_UNIT'), + z.literal('FIRST_FIRST_ORG_UNIT'), + z.literal('COUNT'), + z.literal('STDDEV'), + z.literal('VARIANCE'), + z.literal('MIN'), + z.literal('MAX'), + z.literal('MIN_SUM_ORG_UNIT'), + z.literal('MAX_SUM_ORG_UNIT'), + z.literal('NONE'), + z.literal('CUSTOM'), + z.literal('DEFAULT'), + ]).optional(), + categoryCombo: z.object({ + id: z.string(), + }), + optionSet: z.object({ + id: z.string().optional(), + }), + commentOptionSet: z.object({ + id: z.string().optional(), + }), + legendSets: z.array(z.string()), + aggregationLevels: z.array(z.number()), + attributeValues: z.array(z.object({ + value: z.string(), + attribute: z.object({ + id: z.string(), + }), + })), +}) diff --git a/src/pages/dataElements/form/index.ts b/src/pages/dataElements/form/index.ts index 5cd40f47..9a489b80 100644 --- a/src/pages/dataElements/form/index.ts +++ b/src/pages/dataElements/form/index.ts @@ -1,3 +1,4 @@ export { DataElementFormFields } from './DataElementFormFields' export { computeInitialValues } from './computeInitialValues' export { useCustomAttributesQuery } from './useCustomAttributesQuery' +export { FormValues } from './types' diff --git a/yarn.lock b/yarn.lock index 661e9b80..34a2574d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14181,6 +14181,11 @@ zip-stream@^2.1.2: compress-commons "^2.1.1" readable-stream "^3.4.0" +zod@^3.22.2: + version "3.22.4" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" + integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg== + zustand@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.4.0.tgz#13b3e8ca959dd53d536034440aec382ff91b65c3"