🎥 Make videos programmatically with React
remove redundancy
Patric Salvisberg189413c70a8a
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ClickableSchemaLabel.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ClickableSchemaLabel.tsxdeleted file mode 100644index 502da360a7..0000000000--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ClickableSchemaLabel.tsx+++ /dev/null@@ -1,72 +0,0 @@-import React, {useMemo} from 'react';-import {FAIL_COLOR, LIGHT_TEXT} from '../../../helpers/colors';-import {Flex} from '../../layout';-import {InlineRemoveButton} from '../InlineRemoveButton';-import {getSchemaLabel} from './get-schema-label';-import {SchemaResetButton} from './SchemaResetButton';-import {SchemaSaveButton} from './SchemaSaveButton';-import type {JSONPath} from './zod-types';--const compactStyles: React.CSSProperties = {- fontSize: 15,- color: LIGHT_TEXT,- fontFamily: 'sans-serif',- display: 'flex',- flexDirection: 'row',- alignItems: 'center',- flex: 1,-};--export const ClickableSchemaLabel: React.FC<{- jsonPath: JSONPath;- isDefaultValue: boolean;- onReset: () => void;- onSave: () => void;- onRemove: null | (() => void);- showSaveButton: boolean;- saving: boolean;- valid: boolean;- saveDisabledByParent: boolean;- suffix: string | null;- handleClick: () => void;-}> = ({- jsonPath,- isDefaultValue,- onReset,- onSave,- showSaveButton,- onRemove,- saving,- valid,- saveDisabledByParent,- suffix,- handleClick,-}) => {- const disableSave = saving || !valid || saveDisabledByParent;- const labelStyle: React.CSSProperties = useMemo(() => {- return {- cursor: 'pointer',- fontFamily: 'monospace',- fontSize: 14,- color: valid ? LIGHT_TEXT : FAIL_COLOR,- lineHeight: '24px',- };- }, [valid]);-- return (- <div style={compactStyles}>- <button type="button" onClick={handleClick} style={{border: 'none'}}>- <span style={labelStyle}>- {getSchemaLabel(jsonPath)} {suffix ? suffix : null}- </span>- </button>-- <Flex />- {isDefaultValue ? null : <SchemaResetButton onClick={onReset} />}- {isDefaultValue ? null : showSaveButton ? (- <SchemaSaveButton onClick={onSave} disabled={disableSave} />- ) : null}- {onRemove ? <InlineRemoveButton onClick={onRemove} /> : null}- </div>- );-};diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsxindex 2790acad07..40605cebbf 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaLabel.tsx@@ -27,6 +27,7 @@ export const SchemaLabel: React.FC<{valid: boolean;saveDisabledByParent: boolean;suffix: string | null;+ handleClick?: () => void;}> = ({jsonPath,isDefaultValue,@@ -38,6 +39,7 @@ export const SchemaLabel: React.FC<{valid,saveDisabledByParent,suffix,+ handleClick,}) => {const disableSave = saving || !valid || saveDisabledByParent;const labelStyle: React.CSSProperties = useMemo(() => {@@ -49,11 +51,21 @@ export const SchemaLabel: React.FC<{};}, [valid]);+ const labelContent = (+ <span style={labelStyle}>+ {getSchemaLabel(jsonPath)} {suffix ? suffix : null}+ </span>+ );+return (<div style={compactStyles}>- <span style={labelStyle}>- {getSchemaLabel(jsonPath)} {suffix ? suffix : null}- </span>+ {handleClick ? (+ <button type="button" onClick={handleClick} style={{border: 'none'}}>+ {labelContent}+ </button>+ ) : (+ labelContent+ )}<Flex />{isDefaultValue ? null : <SchemaResetButton onClick={onReset} />}{isDefaultValue ? null : showSaveButton ? (diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsxindex 6b3e7ceb4f..a33cc013dd 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx@@ -8,11 +8,11 @@ import {import type {RenderInlineAction} from '../../InlineAction';import {InlineAction} from '../../InlineAction';import {fieldsetLabel} from '../layout';-import {ClickableSchemaLabel} from './ClickableSchemaLabel';import {createZodValues} from './create-zod-values';import {deepEqual} from './deep-equal';import {Fieldset} from './Fieldset';import {useLocalState} from './local-state';+import {SchemaLabel} from './SchemaLabel';import {SchemaSeparationLine} from './SchemaSeparationLine';import {SchemaVerticalGuide} from './SchemaVerticalGuide';import type {JSONPath} from './zod-types';@@ -97,7 +97,7 @@ export const ZodArrayEditor: React.FC<{flexDirection: 'row',}}>- <ClickableSchemaLabel+ <SchemaLabelonReset={reset}isDefaultValue={isDefaultValue}jsonPath={jsonPath}diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsxindex d4036cf5a1..7e697e9fa2 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx@@ -2,10 +2,10 @@ import React, {useMemo, useState} from 'react';import type {z} from 'zod';import {useZodIfPossible} from '../../get-zod-if-possible';import {fieldsetLabel} from '../layout';-import {ClickableSchemaLabel} from './ClickableSchemaLabel';import {deepEqual} from './deep-equal';import {Fieldset} from './Fieldset';import {useLocalState} from './local-state';+import {SchemaLabel} from './SchemaLabel';import {SchemaSeparationLine} from './SchemaSeparationLine';import {SchemaVerticalGuide} from './SchemaVerticalGuide';import type {JSONPath} from './zod-types';@@ -78,98 +78,100 @@ export const ZodObjectEditor: React.FC<{}, [expanded]);return (- <Fieldset- shouldPad={!isRoot && mayPad}- success={localValue.zodValidation.success}- >- {isRoot ? null : (- <ClickableSchemaLabel- isDefaultValue={isDefaultValue}- onReset={reset}- jsonPath={jsonPath}- onRemove={onRemove}- suffix={suffix}- onSave={() => {- onSave(- () => {- return localValue.value;- },- false,- false,- );- }}- saveDisabledByParent={saveDisabledByParent}- saving={saving}- showSaveButton={showSaveButton}- valid={localValue.zodValidation.success}- handleClick={() => setExpanded(!expanded)}- />- )}+ <div style={{display: 'flex', flexDirection: 'row'}}>+ <Fieldset+ shouldPad={!isRoot && mayPad}+ success={localValue.zodValidation.success}+ >+ {isRoot ? null : (+ <SchemaLabel+ isDefaultValue={isDefaultValue}+ onReset={reset}+ jsonPath={jsonPath}+ onRemove={onRemove}+ suffix={suffix}+ onSave={() => {+ onSave(+ () => {+ return localValue.value;+ },+ false,+ false,+ );+ }}+ saveDisabledByParent={saveDisabledByParent}+ saving={saving}+ showSaveButton={showSaveButton}+ valid={localValue.zodValidation.success}+ handleClick={() => setExpanded(!expanded)}+ />+ )}- {expanded ? (- <RevisionContextProvider>- <SchemaVerticalGuide isRoot={isRoot}>- {keys.map((key, i) => {- if (- discriminatedUnionReplacement &&- key === discriminatedUnionReplacement.discriminator- ) {- return discriminatedUnionReplacement.markup;- }+ {expanded ? (+ <RevisionContextProvider>+ <SchemaVerticalGuide isRoot={isRoot}>+ {keys.map((key, i) => {+ if (+ discriminatedUnionReplacement &&+ key === discriminatedUnionReplacement.discriminator+ ) {+ return discriminatedUnionReplacement.markup;+ }- return (- <React.Fragment key={key}>- <ZodSwitch- mayPad- jsonPath={[...jsonPath, key]}- schema={shape[key]}- value={localValue.value[key]}- // In case of null | {a: string, b: string} type, we need to fallback to the default value- defaultValue={(defaultValue ?? value)[key]}- setValue={(val, forceApply) => {- onChange(- (oldVal) => {- return {- ...oldVal,- [key]:- typeof val === 'function'- ? val(oldVal[key])- : val,- };- },- forceApply,- false,- );- }}- onSave={(val, forceApply) => {- onSave(- (oldVal) => {- return {- ...oldVal,- [key]:- typeof val === 'function'- ? val(oldVal[key])- : val,- };- },- forceApply,- false,- );- }}- onRemove={null}- showSaveButton={showSaveButton}- saving={saving}- saveDisabledByParent={saveDisabledByParent}- />- {i === keys.length - 1 ? null : <SchemaSeparationLine />}- </React.Fragment>- );- })}- </SchemaVerticalGuide>- </RevisionContextProvider>- ) : null}+ return (+ <React.Fragment key={key}>+ <ZodSwitch+ mayPad+ jsonPath={[...jsonPath, key]}+ schema={shape[key]}+ value={localValue.value[key]}+ // In case of null | {a: string, b: string} type, we need to fallback to the default value+ defaultValue={(defaultValue ?? value)[key]}+ setValue={(val, forceApply) => {+ onChange(+ (oldVal) => {+ return {+ ...oldVal,+ [key]:+ typeof val === 'function'+ ? val(oldVal[key])+ : val,+ };+ },+ forceApply,+ false,+ );+ }}+ onSave={(val, forceApply) => {+ onSave(+ (oldVal) => {+ return {+ ...oldVal,+ [key]:+ typeof val === 'function'+ ? val(oldVal[key])+ : val,+ };+ },+ forceApply,+ false,+ );+ }}+ onRemove={null}+ showSaveButton={showSaveButton}+ saving={saving}+ saveDisabledByParent={saveDisabledByParent}+ />+ {i === keys.length - 1 ? null : <SchemaSeparationLine />}+ </React.Fragment>+ );+ })}+ </SchemaVerticalGuide>+ </RevisionContextProvider>+ ) : null}- {isRoot || !expanded ? null : <div style={fieldsetLabel}>{'}'}</div>}- </Fieldset>+ {isRoot || !expanded ? null : <div style={fieldsetLabel}>{'}'}</div>}+ </Fieldset>+ </div>);};