-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor(dashboard): optimize execute
WfRun
components"
This reverts commit bfc0462.
- Loading branch information
Showing
9 changed files
with
171 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
dashboard/src/app/(authenticated)/(diagram)/components/Forms/components/BaseFormField.tsx
This file was deleted.
Oops, something went wrong.
20 changes: 13 additions & 7 deletions
20
dashboard/src/app/(authenticated)/(diagram)/components/Forms/components/FormFields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import { FormFieldProp } from '@/types' | ||
import { FC } from 'react' | ||
import React, { FC } from 'react' | ||
import { FormComponent } from './formType' | ||
import { VariableType, ThreadVarDef } from 'littlehorse-client/proto' | ||
import { FieldValues, UseFormRegister, FormState } from 'react-hook-form' | ||
|
||
export const FormFields: FC<FormFieldProp> = ({ variable: variables, register, formState }) => { | ||
if (!variables?.varDef?.type) return null | ||
|
||
const Component = FormComponent[variables.varDef.type] | ||
return <Component variable={variables} register={register} formState={formState} /> | ||
type Prop = { | ||
variables: ThreadVarDef | ||
register: UseFormRegister<FieldValues> | ||
formState: FormState<FieldValues> | ||
} | ||
export const FormFields: FC<Prop> = props => { | ||
const type = props.variables?.varDef?.type as VariableType | ||
if (!type) return | ||
const Component = FormComponent[type] | ||
return <Component {...props} /> | ||
} |
72 changes: 53 additions & 19 deletions
72
dashboard/src/app/(authenticated)/(diagram)/components/Forms/components/FormInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,77 @@ | ||
import { VARIABLE_TYPES } from '@/app/constants' | ||
import { Input } from '@/components/ui/input' | ||
import { Label } from '@/components/ui/label' | ||
import { FormFieldProp } from '@/types' | ||
import { VariableType } from 'littlehorse-client/proto' | ||
import { FC } from 'react' | ||
import { useFormContext } from 'react-hook-form' | ||
import { BaseFormField } from './BaseFormField' | ||
import { CircleAlert } from 'lucide-react' | ||
import { FC, useState } from 'react' | ||
import { accessLevels } from '../../../wfSpec/[...props]/components/Variables' | ||
|
||
export const FormInput: FC<FormFieldProp> = props => { | ||
const { register } = useFormContext() | ||
|
||
if (!props.variable?.varDef?.name) return null | ||
const [isDisabled, setIsDisabled] = useState(false) | ||
if (!props.variables?.varDef?.name) return null | ||
|
||
const { | ||
variable: { | ||
variables: { | ||
varDef: { type, name }, | ||
required, | ||
accessLevel, | ||
}, | ||
register, | ||
formState: { errors }, | ||
} = props | ||
|
||
const variableToType = (variable: VariableType) => { | ||
switch (variable) { | ||
case VariableType.INT: | ||
return 'number' | ||
case VariableType.DOUBLE: | ||
return 'number' | ||
case VariableType.BYTES: | ||
return 'number' | ||
case VariableType.STR: | ||
return 'text' | ||
default: | ||
return 'text' | ||
} | ||
} | ||
|
||
const setValue = (value: number | string) => { | ||
if (value === null) return value | ||
return variableToType(type) === 'number' ? parseFloat(value?.toString()) || undefined : value || undefined | ||
} | ||
|
||
return ( | ||
<BaseFormField variables={props.variable}> | ||
<div> | ||
<div className="mb-2 flex justify-between"> | ||
<Label htmlFor={name} className="flex items-center gap-2"> | ||
{name} | ||
<span className="rounded bg-green-300 p-1 text-xs">{accessLevels[accessLevel]}</span> | ||
{required ? ( | ||
<span className="rounded bg-red-300 p-1 text-xs">Required</span> | ||
) : ( | ||
<span className="rounded bg-gray-300 p-1 text-xs">Optional</span> | ||
)} | ||
</Label> | ||
</div> | ||
<Input | ||
type={type === VariableType.DOUBLE || type === VariableType.INT ? 'number' : 'text'} | ||
type={variableToType(type)} | ||
className={errors[name] ? 'mb-1 mt-2 border-red-700' : 'mb-4 mt-1'} | ||
id={name} | ||
step={type === VariableType.DOUBLE ? '0.01' : undefined} | ||
disabled={isDisabled} | ||
placeholder={`Enter ${VARIABLE_TYPES[type]?.toLowerCase()} value`} | ||
{...register(name, { | ||
required: required ? `${name} is required` : false, | ||
setValueAs: value => { | ||
if (value === '') return undefined | ||
|
||
if ((type === VariableType.DOUBLE || type === VariableType.INT) && value) { | ||
return parseFloat(value) | ||
} | ||
|
||
return value | ||
}, | ||
setValueAs: setValue, | ||
})} | ||
/> | ||
</BaseFormField> | ||
{errors[name] && ( | ||
<p className="mb-3 flex items-center gap-1 text-sm text-red-700"> | ||
<CircleAlert size={16} /> | ||
{errors[name]?.message} | ||
</p> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.