🎥 Make videos programmatically with React
JSON Date warning added
Patric Salvisbergdd2b0c62d320
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsxindex 222159189d..c186602e61 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx@@ -92,6 +92,7 @@ export const RenderModalData: React.FC<{}> = ({composition, inputProps, setInputProps, compact, mayShowSaveButton}) => {const [mode, setMode] = useState<Mode>('schema');const [valBeforeSafe, setValBeforeSafe] = useState<unknown>(inputProps);+ const [isCustomDateUsed, setIsCustomDateUsed] = useState<boolean>();const zodValidationResult = useMemo(() => {return composition.schema.safeParse(inputProps);}, [composition.schema, inputProps]);@@ -185,8 +186,13 @@ export const RenderModalData: React.FC<{const connectionStatus = useContext(PreviewServerConnectionCtx).type;const warnings = useMemo(() => {- return getRenderModalWarnings({canSaveDefaultProps, cliProps});- }, [canSaveDefaultProps, cliProps]);+ return getRenderModalWarnings({+ canSaveDefaultProps,+ cliProps,+ isCustomDateUsed,+ inJSONEditor: mode === 'json',+ });+ }, [canSaveDefaultProps, cliProps, isCustomDateUsed, mode]);if (connectionStatus === 'disconnected') {return (@@ -260,6 +266,7 @@ export const RenderModalData: React.FC<{onSave={onUpdate}valBeforeSafe={valBeforeSafe}showSaveButton={showSaveButton}+ setIsCustomDateUsed={setIsCustomDateUsed}/>)}</div>diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsxindex a7f5c44cdd..aa091c7e2d 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModalJSONInputPropsEditor.tsx@@ -5,6 +5,7 @@ import {useKeybinding} from '../../helpers/use-keybinding';import {Row, Spacing} from '../layout';import {RemTextarea} from '../NewComposition/RemTextarea';import {ValidationMessage} from '../NewComposition/ValidationMessage';+import type {SerializedJSONWithDate} from './SchemaEditor/date-serialization';import {deserializeJSONWithDate,serializeJSONWithDate,@@ -60,6 +61,9 @@ export const RenderModalJSONInputPropsEditor: React.FC<{onSave: () => void;valBeforeSafe: unknown;showSaveButton: boolean;+ setIsCustomDateUsed: React.Dispatch<+ React.SetStateAction<boolean | undefined>+ >;}> = ({setValue,value,@@ -68,11 +72,17 @@ export const RenderModalJSONInputPropsEditor: React.FC<{onSave,valBeforeSafe,showSaveButton,+ setIsCustomDateUsed,}) => {const keybindings = useKeybinding();const [localValue, setLocalValue] = React.useState<State>(() => {- return parseJSON(serializeJSONWithDate(value, 2));+ const serializedJSON: SerializedJSONWithDate = serializeJSONWithDate(+ value,+ 2+ );+ setIsCustomDateUsed(serializedJSON.customDateUsed);+ return parseJSON(serializedJSON.serializedString);});const onPretty = useCallback(() => {diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/date-serialization.ts b/packages/cli/src/editor/components/RenderModal/SchemaEditor/date-serialization.tsindex 22a24266c8..8dd9623b54 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/date-serialization.ts+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/date-serialization.ts@@ -1,11 +1,18 @@+export type SerializedJSONWithDate = {+ serializedString: string;+ customDateUsed: boolean;+};+export const serializeJSONWithDate = (data: unknown,indent: number | undefined-) => {- return JSON.stringify(+): SerializedJSONWithDate => {+ let customDateUsed = false;+ const serializedString = JSON.stringify(data,function (key, value) {if (this[key] instanceof Date) {+ customDateUsed = true;return `remotion-date:${this[key].toISOString()}`;}@@ -13,6 +20,7 @@ export const serializeJSONWithDate = (},indent);+ return {serializedString, customDateUsed};};export const deserializeJSONWithDate = (data: string) => {diff --git a/packages/cli/src/editor/components/RenderModal/get-render-modal-warnings.ts b/packages/cli/src/editor/components/RenderModal/get-render-modal-warnings.tsindex ec6f6b1a34..5142b81c51 100644--- a/packages/cli/src/editor/components/RenderModal/get-render-modal-warnings.ts+++ b/packages/cli/src/editor/components/RenderModal/get-render-modal-warnings.ts@@ -10,7 +10,7 @@ export type TypeCanSaveState =determined: boolean;};-const getInputPropsWarning = ({cliProps}: {cliProps: unknown}) => {+const getInputPropsWarning = (cliProps: unknown) => {if (Object.keys(cliProps as object).length > 0) {return 'The data that was passed using --props takes priority over the data you enter here.';}@@ -18,11 +18,7 @@ const getInputPropsWarning = ({cliProps}: {cliProps: unknown}) => {return null;};-const getCannotSaveDefaultProps = ({- canSaveDefaultProps,-}: {- canSaveDefaultProps: TypeCanSaveState;-}) => {+const getCannotSaveDefaultProps = (canSaveDefaultProps: TypeCanSaveState) => {if (canSaveDefaultProps.canUpdate) {return null;}@@ -31,18 +27,31 @@ const getCannotSaveDefaultProps = ({return null;}- return `Can't save default props: ${canSaveDefaultProps.reason}`;+ return `Can't save default props: ${canSaveDefaultProps.reason}.`;+};++const customDateUsed = (used: boolean | undefined, inJSONEditor: boolean) => {+ if (used && inJSONEditor) {+ return "There is a Date in the schema that can't be serialized into a JSON. It has been converted into a string.";+ }++ return null;};export const getRenderModalWarnings = ({cliProps,canSaveDefaultProps,+ isCustomDateUsed,+ inJSONEditor,}: {cliProps: unknown;canSaveDefaultProps: TypeCanSaveState;+ isCustomDateUsed: boolean | undefined;+ inJSONEditor: boolean;}) => {return [- getInputPropsWarning({cliProps}),- getCannotSaveDefaultProps({canSaveDefaultProps}),+ getInputPropsWarning(cliProps),+ getCannotSaveDefaultProps(canSaveDefaultProps),+ customDateUsed(isCustomDateUsed, inJSONEditor),].filter(truthy);};diff --git a/packages/cli/src/editor/components/RenderQueue/actions.ts b/packages/cli/src/editor/components/RenderQueue/actions.tsindex c9a9eccbf0..48890b854a 100644--- a/packages/cli/src/editor/components/RenderQueue/actions.ts+++ b/packages/cli/src/editor/components/RenderQueue/actions.ts@@ -219,7 +219,8 @@ export const updateDefaultProps = () => {return callApi('/api/update-default-props', {compositionId,- defaultProps: serializeJSONWithDate(defaultProps, undefined),+ defaultProps: serializeJSONWithDate(defaultProps, undefined)+ .serializedString,});};diff --git a/packages/cli/src/test/date-serialization.test.ts b/packages/cli/src/test/date-serialization.test.tsindex 84d19d4c96..ea9e2a109d 100644--- a/packages/cli/src/test/date-serialization.test.ts+++ b/packages/cli/src/test/date-serialization.test.ts@@ -7,7 +7,7 @@ import {test('date serialization', () => {const date = {data: new Date(), hi: 'there'};- const chat = serializeJSONWithDate(date, 2);+ const chat = serializeJSONWithDate(date, 2).serializedString;const deserialized = deserializeJSONWithDate(chat);expect(deserialized.data).toBeInstanceOf(Date);