Skip to content

Commit 9a5f85d

Browse files
authored
Implement copy to manual parameters from datasets parameters for datasets V2 (#1023)
1 parent 8129747 commit 9a5f85d

File tree

1 file changed

+22
-4
lines changed
  • apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/DatasetParams/InputsMapper

1 file changed

+22
-4
lines changed

apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/DatasetParams/InputsMapper/index.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { useCallback } from 'react'
12
import { useDocumentParameters } from '$/hooks/useDocumentParameters'
23
import {
34
Dataset,
45
DocumentVersion,
56
DatasetV2,
67
DatasetVersion,
8+
PlaygroundInput,
79
} from '@latitude-data/core/browser'
810
import {
911
ClientOnly,
@@ -13,7 +15,6 @@ import {
1315
} from '@latitude-data/web-ui'
1416

1517
import { InputsMapperItem, OnSelectRowCellFn } from './InputsMapperItem'
16-
import { useCallback } from 'react'
1718
import { type DatasetMappedValue } from '../useDatasetRowsForParameters'
1819

1920
export function InputMapper({
@@ -35,14 +36,31 @@ export function InputMapper({
3536
selectedDataset: Dataset | DatasetV2 | undefined
3637
datasetVersion: DatasetVersion
3738
}) {
38-
const { setSource } = useDocumentParameters({
39+
const {
40+
setSource,
41+
manual: { setInputs: setManualInputs },
42+
} = useDocumentParameters({
3943
document,
4044
commitVersionUuid: commit.uuid,
4145
datasetVersion,
4246
})
43-
// TODO: Implement this
44-
const copyToManual = useCallback(() => {}, [])
47+
const copyToManual = useCallback(() => {
48+
const manualInputs = parameters.reduce(
49+
(acc, param) => {
50+
const name = param.param
51+
acc[name] = {
52+
value: String(param.value),
53+
metadata: { includeInPrompt: true },
54+
}
55+
return acc
56+
},
57+
{} as Record<string, PlaygroundInput<'manual'>>,
58+
)
59+
60+
setManualInputs(manualInputs)
61+
}, [parameters, setManualInputs])
4562
const disabled = !selectedDataset || isLoading
63+
4664
return (
4765
<ClientOnly>
4866
<div className='flex flex-col gap-3'>

0 commit comments

Comments
 (0)