Skip to content

Commit

Permalink
fix: unable to submit in operation set editor
Browse files Browse the repository at this point in the history
  • Loading branch information
guansss committed Apr 3, 2024
1 parent 9aa2605 commit 542cc25
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/components/operation-set/OperationSetEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function OperationSetForm({ operationSet, onSubmit }: FormProps) {
control,
handleSubmit,
setError,
formState: { errors, isDirty, isSubmitting },
formState: { errors, isSubmitting },
} = useForm<FormValues>({
defaultValues: operationSet || {
name: '',
Expand Down Expand Up @@ -220,7 +220,7 @@ function OperationSetForm({ operationSet, onSubmit }: FormProps) {
<div className="grow">
<OperationSelector
operationSet={operationSet}
ref={operationSelectorRef}
selectorRef={operationSelectorRef}
/>
</div>
</>
Expand Down Expand Up @@ -302,7 +302,7 @@ function OperationSetForm({ operationSet, onSubmit }: FormProps) {
)}

<Button
disabled={!isDirty || isSubmitting}
disabled={isSubmitting}
intent="primary"
loading={isSubmitting}
type="submit"
Expand All @@ -326,14 +326,17 @@ interface OperationSelectorProps {
operationSet: OperationSet

// 这个组件做成受控组件的话,输入输出比较难处理,所以做成非受控组件,用 ref 获取值
ref: Ref<OperationSelectorRef>
selectorRef: Ref<OperationSelectorRef>
}

interface OperationSelectorRef {
getValues(): { idsToAdd: number[]; idsToRemove: number[] }
}

function OperationSelector({ operationSet, ref }: OperationSelectorProps) {
function OperationSelector({
operationSet,
selectorRef,
}: OperationSelectorProps) {
const { operations, error } = useOperations({
operationIds: operationSet.copilotIds,
})
Expand All @@ -348,7 +351,7 @@ function OperationSelector({ operationSet, ref }: OperationSelectorProps) {
)

useImperativeHandle(
ref,
selectorRef,
() => ({
getValues() {
const idsToAdd: number[] = []
Expand Down

0 comments on commit 542cc25

Please sign in to comment.