Skip to content

Commit

Permalink
feat(auto-gen-form): handle Airbyte form and instill data form separa…
Browse files Browse the repository at this point in the history
…tely (#956)

Because

- handle Airbyte form and instill data form separately

This commit

- handle Airbyte form and instill data form separately
  • Loading branch information
EiffelFly committed Feb 14, 2024
1 parent 4028d53 commit 23ce0eb
Show file tree
Hide file tree
Showing 38 changed files with 221 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from "react";
import { Button, Dialog, Form, Input } from "@instill-ai/design-system";
import { GeneralUseFormReturn } from "../lib";
import { FormLabel } from "../view/settings/FormLabel";
import AvatarEditor from "react-avatar-editor";
import { UseFormReturn } from "react-hook-form";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from "@tanstack/react-query";
import { getAuthenticatedUserQuery, type User } from "../../vdp-sdk";
import { getAuthenticatedUserQuery } from "../../vdp-sdk";
import type { Nullable } from "../../type";

export function useAuthenticatedUser({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from "@tanstack/react-query";
import { getUserQuery, type User } from "../../vdp-sdk";
import { getUserQuery } from "../../vdp-sdk";
import type { Nullable } from "../../type";

export function useUser({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import cn from "clsx";
import * as React from "react";
import { FieldMode } from "../../types";
import { Icons } from "@instill-ai/design-system";

export const VideoPreview = ({
src,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Nullable } from "../../../type";
import { Tag } from "@instill-ai/design-system";
import { SmartHintWarning } from "../../types";
import { SmartHint } from "../../../use-smart-hint";
import { transformInstillFormatToHumanReadableFormat } from "../../transform";

export const SmartHintInfoCard = ({
className,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import cn from "clsx";
import { ScrollArea, Tag } from "@instill-ai/design-system";
import { ScrollArea } from "@instill-ai/design-system";
import { SmartHint } from "../../../use-smart-hint";
import { onClickSmartHint } from "./onClickSmartHint";
import { ControllerRenderProps } from "react-hook-form";
Expand All @@ -19,7 +19,6 @@ export const SmartHintList = ({
setHighlightedHintIndex,
inputRef,
smartHintEnabledPos,
instillUpstreamTypes,
instillAcceptFormats,
}: {
field: ControllerRenderProps<
Expand All @@ -38,7 +37,6 @@ export const SmartHintList = ({
setHighlightedHintIndex: React.Dispatch<React.SetStateAction<number>>;
inputRef: React.RefObject<HTMLInputElement | HTMLTextAreaElement>;
smartHintEnabledPos: Nullable<number>;
instillUpstreamTypes: string[];
instillAcceptFormats: string[];
}) => {
const humanReadableAcceptFormatString = React.useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { FieldDescriptionTooltip } from "../common";

export const TextArea = ({
form,
fieldKey,
path,
title,
description,
Expand All @@ -29,16 +28,13 @@ export const TextArea = ({
componentID,
size,
isHidden,
instillFormat,
}: {
fieldKey: Nullable<string>;
instillAcceptFormats: string[];
shortDescription?: string;
disabled?: boolean;
isRequired?: boolean;
instillUpstreamTypes: string[];
componentID?: string;
instillFormat?: string;
} & AutoFormFieldBaseProps) => {
const smartHints = useInstillStore((s) => s.smartHints);
const [smartHintsPopoverIsOpen, setSmartHintsPopoverIsOpen] =
Expand Down Expand Up @@ -208,7 +204,6 @@ export const TextArea = ({
setHighlightedHintIndex={setHighlightedHintIndex}
inputRef={inputRef}
smartHintEnabledPos={smartHintEnabledPos}
instillUpstreamTypes={instillUpstreamTypes}
instillAcceptFormats={instillAcceptFormats}
/>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { getFieldPlaceholder } from "./getFieldPlaceholder";
import { FieldDescriptionTooltip } from "../common";

export const TextField = ({
fieldKey,
form,
path,
title,
Expand All @@ -29,16 +28,13 @@ export const TextField = ({
componentID,
size,
isHidden,
instillFormat,
}: {
fieldKey: Nullable<string>;
instillAcceptFormats: string[];
shortDescription?: string;
disabled?: boolean;
isRequired?: boolean;
instillUpstreamTypes: string[];
componentID?: string;
instillFormat?: string;
} & AutoFormFieldBaseProps) => {
const smartHints = useInstillStore((s) => s.smartHints);
const [smartHintsPopoverIsOpen, setSmartHintsPopoverIsOpen] =
Expand Down Expand Up @@ -216,7 +212,6 @@ export const TextField = ({
setHighlightedHintIndex={setHighlightedHintIndex}
inputRef={inputRef}
smartHintEnabledPos={smartHintEnabledPos}
instillUpstreamTypes={instillUpstreamTypes}
instillAcceptFormats={instillAcceptFormats}
/>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const AudioField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const AudiosField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const BooleanField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { useShallow } from "zustand/react/shallow";
import {
FieldMode,
GeneralUseFormReturn,
InstillStore,
Nullable,
useInstillStore,
} from "../../..";
import { FieldMode, InstillStore, Nullable, useInstillStore } from "../../..";
import { Icons, Tag, Tooltip } from "@instill-ai/design-system";
import {
ReferenceHintDataTypeTag,
Expand All @@ -19,7 +13,6 @@ const selector = (store: InstillStore) => ({

export const FieldHead = ({
mode,
form,
title,
path,
instillFormat,
Expand All @@ -29,7 +22,6 @@ export const FieldHead = ({
disabledReferenceHint,
}: {
mode: FieldMode;
form: GeneralUseFormReturn;
title: Nullable<string>;
path: string;
instillFormat: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const FileField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const FilesField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const ImageField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const ImagesField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const LongTextField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const NumberField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const NumbersField = ({
<div className="flex w-full flex-col gap-y-2">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const ObjectField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const TextField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const TextareaField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const TextsField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const VideoField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const VideosField = ({
<Form.Item className="w-full">
<FieldHead
mode={mode}
form={form}
title={title}
path={path}
instillFormat={instillFormat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ export function pickRegularFieldsFromInstillFormTree(
if (enableSmartHint) {
return (
<SmartHintFields.TextArea
fieldKey={tree.fieldKey}
key={tree.path}
path={tree.path}
form={form}
Expand All @@ -231,7 +230,6 @@ export function pickRegularFieldsFromInstillFormTree(
componentID={componentID}
size={size}
isHidden={tree.isHidden}
instillFormat={tree.instillFormat}
/>
);
}
Expand Down Expand Up @@ -271,7 +269,6 @@ export function pickRegularFieldsFromInstillFormTree(
return (
<SmartHintFields.TextField
key={tree.path}
fieldKey={tree.fieldKey}
path={tree.path}
form={form}
title={title}
Expand All @@ -284,7 +281,6 @@ export function pickRegularFieldsFromInstillFormTree(
componentID={componentID}
size={size}
isHidden={tree.isHidden}
instillFormat={tree.instillFormat}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ export function transformInstillJSONSchemaToZod({
(e) => e.instillUpstreamType === "reference"
);

const acceptTemplate = targetSchema.anyOf.some(
(e) => e.instillUpstreamType === "template"
);

if (instillUpstreamValue) {
if (instillUpstreamValue.enum) {
const enumValues = instillUpstreamValue.enum as [string, ...string[]];
Expand Down
1 change: 1 addition & 0 deletions packages/toolkit/src/lib/useEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function useEntity(): UseEntitySuccessReturn | UseEntityFailedReturn {
connectorName,
namespaceType.isSuccess,
router,
namespaceType.data,
]);

if (isSuccess) {
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/lib/vdp-sdk/organization/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GeneralRecord, Nullable } from "../../type";
import { Nullable } from "../../type";
import { createInstillAxiosClient } from "../helper";
import {
Organization,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/lib/vdp-sdk/organization/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GeneralRecord, Nullable } from "../../type";
import { Nullable } from "../../type";
import { User } from "../mgmt";
import { StripeSubscriptionDetail } from "../types";

Expand Down
9 changes: 8 additions & 1 deletion packages/toolkit/src/view/airbyte/OneOfConditionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const OneOfConditionSection = ({
// We store the uiFields in formTree and pass it to this component to preserve
// the state of UI fields

const [open, setOpen] = React.useState(false);
const [selectedConditionOption, setSelectedConditionOption] =
React.useState<Nullable<SelectOption>>(null);

Expand Down Expand Up @@ -207,6 +208,8 @@ export const OneOfConditionSection = ({
if (setFormIsDirty) {
setFormIsDirty(true);
}

setOpen(false);
},
[
formTree.path,
Expand All @@ -229,7 +232,11 @@ export const OneOfConditionSection = ({
will cause a flashed UI issue.
*/}
<Select.Root disabled={disableAll}>
<Select.Root
open={open}
onOpenChange={(open) => setOpen(open)}
disabled={disableAll}
>
<Select.Trigger className="w-full !rounded-none">
<p className="text-semantic-fg-primary">
{selectedConditionOption?.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { AirbyteDestinationFields } from "../airbyte";
import { LoadingSpin } from "../../components";
import { InstillErrors } from "../../constant/errors";

export type DataResourceFormProps = {
export type AirbyteDataResourceFormProps = {
dataResource: Nullable<ConnectorWithDefinition>;
dataDefinition: ConnectorDefinition;
accessToken: Nullable<string>;
Expand All @@ -53,7 +53,9 @@ type BackButtonProps =
enableBackButton: false;
};

export const DataResourceForm = (props: DataResourceFormProps) => {
export const AirbyteDataResourceForm = (
props: AirbyteDataResourceFormProps
) => {
const { amplitudeIsInit } = useAmplitudeCtx();
const {
disabledAll,
Expand Down
Loading

0 comments on commit 23ce0eb

Please sign in to comment.