From 53818549b7737236e0d50f83ed9b6aaffa6e5e67 Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 7 Jan 2025 15:12:05 +0200 Subject: [PATCH 1/5] feat(empty-value-message): allow passing empty value message for summary --- .../EventOverview/components/EventSummary.tsx | 7 +++++-- .../features/workqueues/Workqueue.tsx | 2 +- packages/commons/src/events/EventConfig.ts | 8 +++++-- packages/commons/src/events/SummaryConfig.ts | 21 +++++++++++++++---- packages/commons/src/events/defineConfig.ts | 10 ++++----- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx b/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx index 7a088c5cf2..02caa13d91 100644 --- a/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx +++ b/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx @@ -10,6 +10,7 @@ */ import React from 'react' +import { useIntl } from 'react-intl' import { Summary } from '@opencrvs/components/lib/Summary' import { SummaryConfig } from '@opencrvs/commons/events' import { EventIndex } from '@opencrvs/commons/client' @@ -26,6 +27,7 @@ export function EventSummary({ event: EventIndex summary: SummaryConfig }) { + const intl = useIntl() const { toString } = useTransformer(event.type) const data = toString(event.data) return ( @@ -36,9 +38,10 @@ export function EventSummary({ diff --git a/packages/client/src/v2-events/features/workqueues/Workqueue.tsx b/packages/client/src/v2-events/features/workqueues/Workqueue.tsx index 91d7eaba83..e325effca8 100644 --- a/packages/client/src/v2-events/features/workqueues/Workqueue.tsx +++ b/packages/client/src/v2-events/features/workqueues/Workqueue.tsx @@ -18,7 +18,7 @@ import { orderBy, mapKeys, get } from 'lodash' import { useTypedSearchParams } from 'react-router-typesafe-routes/dom' import { Link } from 'react-router-dom' -import { EventIndex, getCurrentEventState } from '@opencrvs/commons/client' +import { EventIndex } from '@opencrvs/commons/client' import { useWindowSize } from '@opencrvs/components/lib/hooks' import { WorkqueueConfig } from '@opencrvs/commons' import { diff --git a/packages/commons/src/events/EventConfig.ts b/packages/commons/src/events/EventConfig.ts index 0fc8267520..75f3cbfd25 100644 --- a/packages/commons/src/events/EventConfig.ts +++ b/packages/commons/src/events/EventConfig.ts @@ -11,7 +11,7 @@ import { z } from 'zod' import { ActionConfig } from './ActionConfig' import { TranslationConfig } from './TranslationConfig' -import { SummaryConfig } from './SummaryConfig' +import { SummaryConfig, SummaryConfigInput } from './SummaryConfig' import { WorkqueueConfig } from './WorkqueueConfig' import { FormConfig, FormConfigInput } from './FormConfig' @@ -32,8 +32,12 @@ export const EventConfig = z.object({ workqueues: z.array(WorkqueueConfig) }) +export const EventConfigInput = EventConfig.extend({ + summary: SummaryConfigInput +}) + export type EventConfig = z.infer -export type EventConfigInput = z.input +export type EventConfigInput = z.input export const defineForm = (form: FormConfigInput): FormConfig => FormConfig.parse(form) diff --git a/packages/commons/src/events/SummaryConfig.ts b/packages/commons/src/events/SummaryConfig.ts index 2e209cd372..c533da78f3 100644 --- a/packages/commons/src/events/SummaryConfig.ts +++ b/packages/commons/src/events/SummaryConfig.ts @@ -11,19 +11,32 @@ import { z } from 'zod' import { TranslationConfig } from './TranslationConfig' -export const SummaryConfig = z +export const SummaryConfigInput = z .object({ title: TranslationConfig.describe('Header title of summary'), fields: z .array( z.object({ id: z.string().describe('Id of a field defined under form.'), - label: TranslationConfig.optional() + // label is enforced during runtime. + label: TranslationConfig.optional(), + emptyValueMessage: TranslationConfig.optional() }) ) - .describe('Fields to be rendered under in summary.') + .describe('Fields rendered in summary view.') }) .describe('Configuration for summary in event.') +export const SummaryConfig = SummaryConfigInput.extend({ + fields: z.array( + z.object({ + id: z.string().describe('Id of a field defined under form.'), + // label is enforced during runtime. + label: TranslationConfig, + emptyValueMessage: TranslationConfig.optional() + }) + ) +}) + export type SummaryConfig = z.infer -export type SummaryConfigInput = z.input +export type SummaryConfigInput = z.input diff --git a/packages/commons/src/events/defineConfig.ts b/packages/commons/src/events/defineConfig.ts index d5e6908901..c9dfb77b82 100644 --- a/packages/commons/src/events/defineConfig.ts +++ b/packages/commons/src/events/defineConfig.ts @@ -17,20 +17,20 @@ import { findPageFields, resolveFieldLabels } from './utils' * @param config - Event specific configuration */ export const defineConfig = (config: EventConfigInput) => { - const parsed = EventConfig.parse(config) + const input = EventConfigInput.parse(config) - const pageFields = findPageFields(parsed).map(({ id, label }) => ({ + const pageFields = findPageFields(input).map(({ id, label }) => ({ id, label })) return EventConfig.parse({ - ...parsed, + ...input, summary: resolveFieldLabels({ - config: parsed.summary, + config: input.summary, pageFields }), - workqueues: parsed.workqueues.map((workqueue) => + workqueues: input.workqueues.map((workqueue) => resolveFieldLabels({ config: workqueue, pageFields From 135b39f123039a6a584bae406cf8a20a1ee71bd9 Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 7 Jan 2025 15:17:01 +0200 Subject: [PATCH 2/5] chore: clean up summary definition --- packages/commons/src/events/SummaryConfig.ts | 36 +++++++++---------- .../fixtures/tennis-club-membership-event.ts | 7 +++- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/commons/src/events/SummaryConfig.ts b/packages/commons/src/events/SummaryConfig.ts index c533da78f3..b2bbca64be 100644 --- a/packages/commons/src/events/SummaryConfig.ts +++ b/packages/commons/src/events/SummaryConfig.ts @@ -11,31 +11,27 @@ import { z } from 'zod' import { TranslationConfig } from './TranslationConfig' -export const SummaryConfigInput = z +const Field = z.object({ + id: z.string().describe('Id of a field defined under form.'), + // label is enforced during runtime. + label: TranslationConfig, + emptyValueMessage: TranslationConfig.optional() +}) + +const FieldInput = Field.extend({ + // label is enforced during runtime. + label: TranslationConfig.optional() +}) + +export const SummaryConfig = z .object({ title: TranslationConfig.describe('Header title of summary'), - fields: z - .array( - z.object({ - id: z.string().describe('Id of a field defined under form.'), - // label is enforced during runtime. - label: TranslationConfig.optional(), - emptyValueMessage: TranslationConfig.optional() - }) - ) - .describe('Fields rendered in summary view.') + fields: z.array(Field).describe('Fields rendered in summary view.') }) .describe('Configuration for summary in event.') -export const SummaryConfig = SummaryConfigInput.extend({ - fields: z.array( - z.object({ - id: z.string().describe('Id of a field defined under form.'), - // label is enforced during runtime. - label: TranslationConfig, - emptyValueMessage: TranslationConfig.optional() - }) - ) +export const SummaryConfigInput = SummaryConfig.extend({ + fields: z.array(FieldInput) }) export type SummaryConfig = z.infer diff --git a/packages/commons/src/fixtures/tennis-club-membership-event.ts b/packages/commons/src/fixtures/tennis-club-membership-event.ts index 4003d51ed5..2c2041257c 100644 --- a/packages/commons/src/fixtures/tennis-club-membership-event.ts +++ b/packages/commons/src/fixtures/tennis-club-membership-event.ts @@ -25,7 +25,12 @@ export const tennisClubMembershipEvent = defineConfig({ }, fields: [ { - id: 'applicant.firstname' + id: 'applicant.firstname', + emptyValueMessage: { + defaultMessage: 'First name is not provided', + description: 'This is the message to show when the field is empty', + id: 'event.tennis-club-membership.summary.field.firstname.empty' + } } ] }, From b2da3a7cf4a0e387d6eef8ec86e9119698640e5f Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 7 Jan 2025 15:17:37 +0200 Subject: [PATCH 3/5] chore: bump toolkit version --- packages/toolkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 8e13ed80ed..6b75847f3f 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@opencrvs/toolkit", - "version": "0.0.7-events", + "version": "0.0.8-events", "description": "OpenCRVS toolkit for building country configurations", "license": "MPL-2.0", "exports": { From 6e55f2005b9e235f8a11f4133482b5552124da47 Mon Sep 17 00:00:00 2001 From: Markus Date: Tue, 7 Jan 2025 15:34:59 +0200 Subject: [PATCH 4/5] fix: remove unneeded comment --- packages/commons/src/events/SummaryConfig.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/commons/src/events/SummaryConfig.ts b/packages/commons/src/events/SummaryConfig.ts index b2bbca64be..d9190b6653 100644 --- a/packages/commons/src/events/SummaryConfig.ts +++ b/packages/commons/src/events/SummaryConfig.ts @@ -13,7 +13,6 @@ import { TranslationConfig } from './TranslationConfig' const Field = z.object({ id: z.string().describe('Id of a field defined under form.'), - // label is enforced during runtime. label: TranslationConfig, emptyValueMessage: TranslationConfig.optional() }) From 36d2faa75b8834c112a7a8bc2adaf735adb1737a Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Wed, 8 Jan 2025 13:25:31 +0900 Subject: [PATCH 5/5] bump version once again to include new DELETE action types to build toolkit --- packages/toolkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 6b75847f3f..05ac70d02f 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@opencrvs/toolkit", - "version": "0.0.8-events", + "version": "0.0.9-events", "description": "OpenCRVS toolkit for building country configurations", "license": "MPL-2.0", "exports": {