From 0a191b80d3579e3282ed80bee36518e89f5cfdf4 Mon Sep 17 00:00:00 2001 From: Rob Donigian Date: Thu, 19 Dec 2024 17:10:35 -0500 Subject: [PATCH] add ai assist to engagement detail page --- .../BooleanProperty/BooleanProperty.tsx | 30 +++++----- .../EditEngagement/EditEngagementDialog.tsx | 55 +++++++++++++++++-- .../Header/LanguageEngagementHeader.tsx | 8 +++ 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/components/BooleanProperty/BooleanProperty.tsx b/src/components/BooleanProperty/BooleanProperty.tsx index 546ed66129..9cb01ba057 100644 --- a/src/components/BooleanProperty/BooleanProperty.tsx +++ b/src/components/BooleanProperty/BooleanProperty.tsx @@ -1,8 +1,7 @@ import { Chip, ChipProps, Skeleton } from '@mui/material'; import { ReactElement } from 'react'; -import { makeStyles } from 'tss-react/mui'; import { Except, SetRequired } from 'type-fest'; -import { SecuredProp } from '~/common'; +import { extendSx, SecuredProp } from '~/common'; import { Redacted } from '../Redacted'; export interface BooleanPropertyProps extends SetRequired { @@ -11,24 +10,27 @@ export interface BooleanPropertyProps extends SetRequired { wrap?: (node: ReactElement) => ReactElement; } -const useStyles = makeStyles()(({ palette, shape }) => ({ - root: { - background: palette.info.main, - color: palette.info.contrastText, - borderRadius: shape.borderRadius, - height: 26, - }, -})); - export const BooleanProperty = ({ redacted, data, wrap, + sx, ...rest }: BooleanPropertyProps) => { - const { classes } = useStyles(); - - const chip = ; + const chip = ( + ({ + background: palette.info.main, + color: palette.info.contrastText, + borderRadius: shape.borderRadius, + height: 26, + }), + ...extendSx(sx), + ]} + /> + ); const out = !data ? ( {chip} diff --git a/src/scenes/Engagement/EditEngagement/EditEngagementDialog.tsx b/src/scenes/Engagement/EditEngagement/EditEngagementDialog.tsx index 30e96e2840..9d12118387 100644 --- a/src/scenes/Engagement/EditEngagement/EditEngagementDialog.tsx +++ b/src/scenes/Engagement/EditEngagement/EditEngagementDialog.tsx @@ -6,6 +6,8 @@ import { ComponentType, useMemo } from 'react'; import { Except, Merge } from 'type-fest'; import { invalidateProps } from '~/api'; import { + AIAssistList, + AIAssistTypeLabels, InternshipDomainLabels, InternshipPositionLabels, InternshipProgramLabels, @@ -62,6 +64,7 @@ export type EditableEngagementField = ExtractStrict< | 'lukePartnership' | 'paratextRegistryId' | 'openToInvestorVisit' + | 'usingAIAssistedTranslation' >; interface EngagementFieldProps { @@ -153,14 +156,41 @@ const fieldMapping: Record< paratextRegistryId: ({ props }) => ( ), + usingAIAssistedTranslation: ({ props }) => ( + + item === null ? 'null' : item.toString() + )} + getLabel={(value: string): string => + AIAssistTypeLabels[value] ?? 'Unknown' + } + variant="toggle-grouped" + /> + ), }; +// interface EngagementFormValues { +// engagement: Merge< +// UpdateLanguageEngagement & UpdateInternshipEngagement, +// { +// mentorId?: UserLookupItemFragment | null; +// countryOfOriginId?: DisplayLocationFragment | null; +// } +// >; +// } + interface EngagementFormValues { engagement: Merge< - UpdateLanguageEngagement & UpdateInternshipEngagement, + Omit< + UpdateLanguageEngagement & UpdateInternshipEngagement, + 'usingAIAssistedTranslation' + >, { mentorId?: UserLookupItemFragment | null; countryOfOriginId?: DisplayLocationFragment | null; + usingAIAssistedTranslation?: string; } >; } @@ -207,10 +237,13 @@ export const EditEngagementDialog = ({ : UpdateLanguageEngagementDocument ); + type OverrideUsingAIAssistedTranslation = { + [K in keyof T]: K extends 'usingAIAssistedTranslation' ? string : T[K]; + }; + const initialValues = useMemo(() => { - const fullInitialValuesFields: Except< - EngagementFormValues['engagement'], - 'id' + const fullInitialValuesFields: OverrideUsingAIAssistedTranslation< + Except > = { startDateOverride: engagement.dateRangeOverride.value.start, endDateOverride: engagement.dateRangeOverride.value.end, @@ -222,6 +255,10 @@ export const EditEngagementDialog = ({ firstScripture: engagement.firstScripture.value, paratextRegistryId: engagement.paratextRegistryId.value, openToInvestorVisit: engagement.openToInvestorVisit.value, + usingAIAssistedTranslation: + engagement.usingAIAssistedTranslation.value === null + ? 'null' + : engagement.usingAIAssistedTranslation.value!.toString(), } : { methodologies: engagement.methodologies.value, @@ -301,11 +338,21 @@ export const EditEngagementDialog = ({ } }} onSubmit={async ({ engagement: values }, form) => { + const { usingAIAssistedTranslation } = values; + + const convertedAIAssist: boolean | null = + String(usingAIAssistedTranslation) === 'true' + ? true + : String(usingAIAssistedTranslation) === 'false' + ? false + : null; + const input = { engagement: { ...values, mentorId: getLookupId(values.mentorId), countryOfOriginId: getLookupId(values.countryOfOriginId), + usingAIAssistedTranslation: convertedAIAssist, }, changeset: engagement.changeset?.id, }; diff --git a/src/scenes/Engagement/LanguageEngagement/Header/LanguageEngagementHeader.tsx b/src/scenes/Engagement/LanguageEngagement/Header/LanguageEngagementHeader.tsx index 33ecb90ef4..b8510913ba 100644 --- a/src/scenes/Engagement/LanguageEngagement/Header/LanguageEngagementHeader.tsx +++ b/src/scenes/Engagement/LanguageEngagement/Header/LanguageEngagementHeader.tsx @@ -99,6 +99,7 @@ export const LanguageEngagementHeader = ({ 'firstScripture', 'lukePartnership', 'openToInvestorVisit', + 'usingAIAssistedTranslation', ]) } > @@ -162,6 +163,13 @@ export const LanguageEngagementHeader = ({ empty="Enter Paratext Registry ID" /> + {node}} + sx={{ backgroundColor: '#FF9800' }} + />