Skip to content

Commit 0d9287f

Browse files
committed
feat(dashboard): use preview schema in preview sections
1 parent ffad83f commit 0d9287f

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

apps/dashboard/src/components/preview-context-section.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ContextSectionProps } from './workflow-editor/steps/types/preview-conte
1414
export function PreviewContextSection({
1515
error,
1616
context,
17+
schema,
1718
onUpdate,
1819
onContextSelect,
1920
onClearPersisted,
@@ -125,6 +126,7 @@ export function PreviewContextSection({
125126
value={displayValue}
126127
onChange={handleContextChange}
127128
className={ACCORDION_STYLES.jsonViewer}
129+
schema={schema}
128130
/>
129131
{error && <p className="text-destructive text-xs">{error}</p>}
130132
</div>

apps/dashboard/src/components/preview-subscriber-section.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SubscriberSectionProps } from './workflow-editor/steps/types/preview-co
1212
export function PreviewSubscriberSection({
1313
error,
1414
subscriber,
15+
schema,
1516
onUpdate,
1617
onSubscriberSelect,
1718
onClearPersisted,
@@ -75,6 +76,7 @@ export function PreviewSubscriberSection({
7576
<EditableJsonViewer
7677
value={subscriber}
7778
onChange={(updatedData) => onUpdate('subscriber', updatedData)}
79+
schema={schema}
7880
className={ACCORDION_STYLES.jsonViewer}
7981
/>
8082
{error && <p className="text-destructive text-xs">{error}</p>}

apps/dashboard/src/components/workflow-editor/steps/components/preview-payload-section.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function PreviewPayloadSection({
1212
errors,
1313
localParsedData,
1414
workflow,
15+
schema,
1516
onUpdate,
1617
onClearPersisted,
1718
hasDigestStep,
@@ -64,7 +65,7 @@ export function PreviewPayloadSection({
6465
<EditableJsonViewer
6566
value={localParsedData.payload}
6667
onChange={(updatedData) => onUpdate('payload', updatedData)}
67-
schema={workflow?.payloadSchema}
68+
schema={schema}
6869
className={ACCORDION_STYLES.jsonViewer}
6970
/>
7071
{errors.payload && <p className="text-destructive text-xs">{errors.payload}</p>}

apps/dashboard/src/components/workflow-editor/steps/preview-context-panel.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { FeatureFlagsKeysEnum, ISubscriberResponseDto } from '@novu/shared';
2+
import { JSONSchema7 } from 'json-schema';
23
import { useCallback, useEffect, useMemo, useRef } from 'react';
34
import { type ContextResponseDto } from '@/api/contexts';
45
import { Accordion } from '@/components/primitives/accordion';
56
import { useCreateVariable } from '@/components/variable/hooks/use-create-variable';
67
import { useEnvironment } from '@/context/environment/hooks';
78
import { useDefaultSubscriberData } from '@/hooks/use-default-subscriber-data';
9+
import { useDynamicPreviewSchema } from '@/hooks/use-dynamic-preview-schema';
810
import { useFeatureFlag } from '@/hooks/use-feature-flag';
911
import { useFetchOrganizationSettings } from '@/hooks/use-fetch-organization-settings';
1012
import { useIsPayloadSchemaEnabled } from '@/hooks/use-is-payload-schema-enabled';
@@ -101,6 +103,17 @@ export function PreviewContextPanel({
101103
const { isPayloadSchemaDrawerOpen, highlightedVariableKey, openSchemaDrawer, closeSchemaDrawer } =
102104
useCreateVariable();
103105

106+
const previewSchema = useDynamicPreviewSchema();
107+
const schemas = useMemo(
108+
() => ({
109+
payload: workflow?.payloadSchema,
110+
subscriber: previewSchema?.properties?.subscriber as JSONSchema7 | undefined,
111+
context: previewSchema?.properties?.context as JSONSchema7 | undefined,
112+
steps: previewSchema?.properties?.steps as JSONSchema7 | undefined,
113+
}),
114+
[previewSchema, workflow?.payloadSchema]
115+
);
116+
104117
const hasDigestStep = useMemo(() => {
105118
return workflow?.steps?.some((step) => step.type === StepTypeEnum.DIGEST) ?? false;
106119
}, [workflow?.steps]);
@@ -249,6 +262,7 @@ export function PreviewContextPanel({
249262
errors={errors}
250263
localParsedData={localParsedData}
251264
workflow={workflow}
265+
schema={schemas.payload}
252266
onUpdate={updateJsonSection}
253267
onClearPersisted={canClearPersisted ? handleClearPersistedPayload : undefined}
254268
hasDigestStep={hasDigestStep}
@@ -258,7 +272,7 @@ export function PreviewContextPanel({
258272
<PreviewSubscriberSection
259273
error={errors.subscriber}
260274
subscriber={localParsedData.subscriber}
261-
workflow={workflow}
275+
schema={schemas.subscriber}
262276
onUpdate={updateJsonSection}
263277
onSubscriberSelect={handleSubscriberSelection}
264278
onClearPersisted={canClearPersisted ? handleClearPersistedSubscriber : undefined}
@@ -276,7 +290,7 @@ export function PreviewContextPanel({
276290
<PreviewContextSection
277291
error={errors.context}
278292
context={localParsedData.context}
279-
workflow={workflow}
293+
schema={schemas.context}
280294
onUpdate={updateJsonSection}
281295
onContextSelect={handleContextSelection}
282296
onClearPersisted={canClearPersisted ? handleClearPersistedContext : undefined}

apps/dashboard/src/components/workflow-editor/steps/types/preview-context.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ContextPayload, ISubscriberResponseDto, SubscriberDto, WorkflowResponseDto } from '@novu/shared';
2+
import { JSONSchema7 } from 'json-schema';
23
import { type ContextResponseDto } from '@/api/contexts';
34

45
export type PayloadData = Record<string, unknown>;
@@ -37,6 +38,7 @@ export type AccordionSectionProps = {
3738
};
3839

3940
export type PayloadSectionProps = AccordionSectionProps & {
41+
schema?: JSONSchema7;
4042
onClearPersisted?: () => void;
4143
hasDigestStep?: boolean;
4244
};
@@ -48,6 +50,7 @@ export type StepResultsSectionProps = AccordionSectionProps & {
4850
export type SubscriberSectionProps = Omit<AccordionSectionProps, 'errors' | 'localParsedData' | 'onUpdate'> & {
4951
error: string | null;
5052
subscriber: Partial<SubscriberDto>;
53+
schema?: JSONSchema7;
5154
onUpdate: (section: 'subscriber', data: PreviewSubscriberData) => void;
5255
onSubscriberSelect: (subscriber: ISubscriberResponseDto) => void;
5356
onClearPersisted?: () => void;
@@ -56,6 +59,7 @@ export type SubscriberSectionProps = Omit<AccordionSectionProps, 'errors' | 'loc
5659
export type ContextSectionProps = Omit<AccordionSectionProps, 'errors' | 'localParsedData' | 'onUpdate'> & {
5760
error: string | null;
5861
context: ContextPayload;
62+
schema?: JSONSchema7;
5963
onUpdate: (section: 'context', data: ContextPayload) => void;
6064
onContextSelect: (context: ContextResponseDto) => void;
6165
onClearPersisted?: () => void;

0 commit comments

Comments
 (0)