From 78ffafca02bb59ea641cb430dba76f7e1a334ab3 Mon Sep 17 00:00:00 2001 From: EiffelFly <57251712+EiffelFly@users.noreply.github.com> Date: Wed, 7 Feb 2024 19:42:52 +0800 Subject: [PATCH] feat: support video format at the end operator --- .../VideoPreview.tsx | 75 ++++++++++++------- .../components/common/index.ts | 1 + .../component-output/ImagesField.tsx | 4 +- .../component-output/VideoField.tsx | 20 +++++ .../component-output/VideosField.tsx | 32 ++++++++ .../components/component-output/index.ts | 4 + .../VideoField.tsx | 5 +- .../VideosField.tsx | 5 +- ...mponentOutputFieldsFromInstillFormTree.tsx | 20 +++++ .../transformStartOperatorMetadataToZod.ts | 9 +++ 10 files changed, 141 insertions(+), 34 deletions(-) rename packages/toolkit/src/lib/use-instill-form/components/{start-operator-free-form-fields => common}/VideoPreview.tsx (52%) create mode 100644 packages/toolkit/src/lib/use-instill-form/components/component-output/VideoField.tsx create mode 100644 packages/toolkit/src/lib/use-instill-form/components/component-output/VideosField.tsx diff --git a/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideoPreview.tsx b/packages/toolkit/src/lib/use-instill-form/components/common/VideoPreview.tsx similarity index 52% rename from packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideoPreview.tsx rename to packages/toolkit/src/lib/use-instill-form/components/common/VideoPreview.tsx index 8feda6c630..d716fc4ec7 100644 --- a/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideoPreview.tsx +++ b/packages/toolkit/src/lib/use-instill-form/components/common/VideoPreview.tsx @@ -1,14 +1,13 @@ import cn from "clsx"; import * as React from "react"; -import { FieldMode } from "../../type"; +import { FieldMode } from "../../types"; +import { Icons } from "@instill-ai/design-system"; export const VideoPreview = ({ src, - mode, className, }: { src: string; - mode: FieldMode; className?: string; }) => { const [isPlaying, setIsPlaying] = React.useState(false); @@ -34,40 +33,20 @@ export const VideoPreview = ({ /> {isPlaying ? (
- +
) : (
- +
)} ); }; -const PauseIcon = ({ className }: { className?: string }) => { +const CustomizePlayIcon = ({ className }: { className?: string }) => { return ( - - - ); -}; - -const PlayIcon = ({ className }: { className?: string }) => { - return ( - { ); }; + +const CustomizePauseIcon = ({ className }: { className?: string }) => { + return ( + + + + + + + + + + + + + + ); +}; diff --git a/packages/toolkit/src/lib/use-instill-form/components/common/index.ts b/packages/toolkit/src/lib/use-instill-form/components/common/index.ts index 676ecac81b..610f53f90a 100644 --- a/packages/toolkit/src/lib/use-instill-form/components/common/index.ts +++ b/packages/toolkit/src/lib/use-instill-form/components/common/index.ts @@ -1 +1,2 @@ export * from "./FieldDescriptionTooltip"; +export * from "./VideoPreview"; diff --git a/packages/toolkit/src/lib/use-instill-form/components/component-output/ImagesField.tsx b/packages/toolkit/src/lib/use-instill-form/components/component-output/ImagesField.tsx index dc84d2a4c7..5917663931 100644 --- a/packages/toolkit/src/lib/use-instill-form/components/component-output/ImagesField.tsx +++ b/packages/toolkit/src/lib/use-instill-form/components/component-output/ImagesField.tsx @@ -12,8 +12,8 @@ export const ImagesField = (props: ImagesFieldProps) => { return ( {images && !hideField ? ( -
- {images?.slice(0, 5)?.map((image) => { +
+ {images?.map((image) => { if (!image) return null; return ( diff --git a/packages/toolkit/src/lib/use-instill-form/components/component-output/VideoField.tsx b/packages/toolkit/src/lib/use-instill-form/components/component-output/VideoField.tsx new file mode 100644 index 0000000000..a7e92889b7 --- /dev/null +++ b/packages/toolkit/src/lib/use-instill-form/components/component-output/VideoField.tsx @@ -0,0 +1,20 @@ +import { Nullable } from "../../../type"; +import { ComponentOutputFieldBaseProps } from "../../types"; +import { VideoPreview } from "../common"; +import { FieldRoot } from "./FieldRoot"; + +export type VideoFieldProps = { + video: Nullable; +} & ComponentOutputFieldBaseProps; + +export const VideoField = (props: VideoFieldProps) => { + const { title, video, hideField } = props; + + return ( + + {!hideField && video ? ( + + ) : null} + + ); +}; diff --git a/packages/toolkit/src/lib/use-instill-form/components/component-output/VideosField.tsx b/packages/toolkit/src/lib/use-instill-form/components/component-output/VideosField.tsx new file mode 100644 index 0000000000..a7f44b5d7b --- /dev/null +++ b/packages/toolkit/src/lib/use-instill-form/components/component-output/VideosField.tsx @@ -0,0 +1,32 @@ +import { Nullable } from "../../../type"; +import { ComponentOutputFieldBaseProps } from "../../types"; +import { VideoPreview } from "../common"; +import { FieldRoot } from "./FieldRoot"; + +export type VideosFieldProps = { + videos: Nullable[]; +} & ComponentOutputFieldBaseProps; + +export const VideosField = (props: VideosFieldProps) => { + const { title, videos, hideField } = props; + + return ( + + {videos && !hideField ? ( +
+ {videos.map((video) => { + if (!video) return null; + + return ( + + ); + })} +
+ ) : null} +
+ ); +}; diff --git a/packages/toolkit/src/lib/use-instill-form/components/component-output/index.ts b/packages/toolkit/src/lib/use-instill-form/components/component-output/index.ts index 237cd31fa4..dcee27d412 100644 --- a/packages/toolkit/src/lib/use-instill-form/components/component-output/index.ts +++ b/packages/toolkit/src/lib/use-instill-form/components/component-output/index.ts @@ -8,6 +8,8 @@ import { ObjectField } from "./ObjectField"; import { ObjectsField } from "./ObjectsField"; import { TextField } from "./TextField"; import { TextsField } from "./TextsField"; +import { VideoField } from "./VideoField"; +import { VideosField } from "./VideosField"; export const ComponentOutputFields = { AudioField, @@ -20,4 +22,6 @@ export const ComponentOutputFields = { ObjectsField, TextField, TextsField, + VideoField, + VideosField, }; diff --git a/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideoField.tsx b/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideoField.tsx index 572690a365..2229cbbb28 100644 --- a/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideoField.tsx +++ b/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideoField.tsx @@ -6,8 +6,8 @@ import { readFileToBinary } from "../../../../view"; import { FieldHead } from "./FieldHead"; import { FileListItem } from "./FileListItem"; import { UploadFileInput } from "./UploadFileInput"; -import { StartOperatorFreeFormFieldBaseProps } from "../../type"; -import { VideoPreview } from "./VideoPreview"; +import { StartOperatorFreeFormFieldBaseProps } from "../../types"; +import { VideoPreview } from "../common"; export const VideoField = ({ mode, @@ -51,7 +51,6 @@ export const VideoField = ({ {videoFile ? ( ) : ( diff --git a/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideosField.tsx b/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideosField.tsx index 7870ed9c32..781df2b1a4 100644 --- a/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideosField.tsx +++ b/packages/toolkit/src/lib/use-instill-form/components/start-operator-free-form-fields/VideosField.tsx @@ -6,8 +6,8 @@ import { readFileToBinary } from "../../../../view"; import { FieldHead } from "./FieldHead"; import { FileListItem } from "./FileListItem"; import { UploadFileInput } from "./UploadFileInput"; -import { StartOperatorFreeFormFieldBaseProps } from "../../type"; -import { VideoPreview } from "./VideoPreview"; +import { StartOperatorFreeFormFieldBaseProps } from "../../types"; +import { VideoPreview } from "../common"; export const VideosField = ({ mode, @@ -63,7 +63,6 @@ export const VideosField = ({ ); } + case "video": { + return ( + + ); + } case "text": { return ( ); } + case "video": { + return ( + + ); + } case "image": { return (