Skip to content

Commit

Permalink
chore: import template configuration as well (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
geclos authored Sep 17, 2024
1 parent 0ccb20f commit 1cc824b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type CreateEvaluationData = {
title: string
description: string
prompt: string
configuration: EvaluationResultConfiguration
}

export default function CreateEvaluationModal({
Expand All @@ -37,7 +38,7 @@ export default function CreateEvaluationModal({
handleTypeChange,
handleRangeFromChange,
handleRangeToChange,
} = useEvaluationConfiguration()
} = useEvaluationConfiguration(initialData?.configuration)

const router = useRouter()

Expand Down Expand Up @@ -149,11 +150,15 @@ export default function CreateEvaluationModal({
)
}

export function useEvaluationConfiguration() {
export function useEvaluationConfiguration(
init?: EvaluationResultConfiguration,
) {
const [configuration, setConfiguration] =
useState<EvaluationResultConfiguration>({
type: EvaluationResultableType.Text,
})
useState<EvaluationResultConfiguration>(
init || {
type: EvaluationResultableType.Text,
},
)

const handleTypeChange = useCallback((value: EvaluationResultableType) => {
if (value === EvaluationResultableType.Number) {
Expand Down Expand Up @@ -228,6 +233,12 @@ export function useEvaluationConfiguration() {
[],
)

useEffect(() => {
if (!init) return

setConfiguration(init)
}, [init])

return {
configuration,
handleTypeChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import { useState } from 'react'

import { EvaluationTemplateWithCategory } from '@latitude-data/core/browser'
import {
EvaluationResultableType,
EvaluationTemplateWithCategory,
} from '@latitude-data/core/browser'
import { Container } from '@latitude-data/web-ui'

import ActiveEvaluations from './ActiveEvaluations'
Expand All @@ -27,6 +30,7 @@ export default function Evaluations({
title: 'New Evaluation',
description: '',
prompt: '',
configuration: { type: EvaluationResultableType.Text },
})
}
/>
Expand All @@ -38,6 +42,7 @@ export default function Evaluations({
title: template.name,
description: template.description,
prompt: template.prompt,
configuration: template.configuration,
})
}
/>
Expand Down

0 comments on commit 1cc824b

Please sign in to comment.