-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal(Data files): Select data files in Test options (#441)
- Loading branch information
1 parent
963dd6e
commit c01750a
Showing
16 changed files
with
136 additions
and
18 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import { ImmerStateCreator } from '@/utils/typescript' | ||
import { Variable, TestData } from '@/types/testData' | ||
import { Variable, TestData, DataFile } from '@/types/testData' | ||
|
||
interface Actions { | ||
setVariables: (variables: Variable[]) => void | ||
setFiles: (files: DataFile[]) => void | ||
} | ||
|
||
export type TestDataStore = TestData & Actions | ||
|
||
export const createTestDataSlice: ImmerStateCreator<TestDataStore> = (set) => ({ | ||
variables: [], | ||
files: [], | ||
|
||
setVariables: (variables: Variable[]) => | ||
set((state) => { | ||
state.variables = variables | ||
}), | ||
setFiles: (files: DataFile[]) => | ||
set((state) => { | ||
state.files = files | ||
}), | ||
}) |
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
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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { FieldGroup } from '@/components/Form' | ||
import { TestDataSchema } from '@/schemas/generator' | ||
import { useGeneratorStore } from '@/store/generator' | ||
import { useStudioUIStore } from '@/store/ui' | ||
import { TestData } from '@/types/testData' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { CheckboxGroup, Text } from '@radix-ui/themes' | ||
import { useCallback, useEffect } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
|
||
export function DataFiles() { | ||
const availableFiles = useStudioUIStore((store) => store.dataFiles) | ||
const files = useGeneratorStore((store) => store.files) | ||
const setFiles = useGeneratorStore((store) => store.setFiles) | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
watch, | ||
setValue, | ||
formState: { errors }, | ||
} = useForm<Pick<TestData, 'files'>>({ | ||
resolver: zodResolver(TestDataSchema.pick({ files: true })), | ||
shouldFocusError: false, | ||
defaultValues: { | ||
files, | ||
}, | ||
}) | ||
|
||
const options = [...availableFiles.values()].map((file) => ({ | ||
label: file.displayName, | ||
value: file.displayName, | ||
})) | ||
const value = watch('files').map(({ name }) => name) | ||
|
||
const onSubmit = useCallback( | ||
(data: Pick<TestData, 'files'>) => { | ||
setFiles(data.files) | ||
}, | ||
[setFiles] | ||
) | ||
|
||
// Submit onChange | ||
useEffect(() => { | ||
const subscription = watch(() => handleSubmit(onSubmit)()) | ||
return () => subscription.unsubscribe() | ||
}, [watch, handleSubmit, onSubmit]) | ||
|
||
const handleChange = (value: string[]) => { | ||
setValue( | ||
'files', | ||
value.map((fileName) => ({ | ||
name: fileName, | ||
})) | ||
) | ||
} | ||
|
||
const filesField = register('files') | ||
|
||
return ( | ||
<div> | ||
<Text size="2" as="p" mb="2"> | ||
Make your test more realistic and prevent server-side caching from | ||
affecting your results by using data files. | ||
</Text> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<FieldGroup name="files" label="Files" errors={errors}> | ||
<CheckboxGroup.Root | ||
value={value} | ||
onValueChange={handleChange} | ||
onBlur={filesField.onBlur} | ||
ref={filesField.ref} | ||
> | ||
{options.map((option) => ( | ||
<CheckboxGroup.Item key={option.value} value={option.value}> | ||
{option.label} | ||
</CheckboxGroup.Item> | ||
))} | ||
</CheckboxGroup.Root> | ||
</FieldGroup> | ||
</form> | ||
</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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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