Skip to content

Commit

Permalink
implement input and switch to booleanColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
rdonigian committed Dec 20, 2024
1 parent d4aa4e5 commit 28650ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 54 deletions.
8 changes: 3 additions & 5 deletions src/components/EngagementDataGrid/EngagementColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,17 @@ export const EngagementColumns: Array<GridColDef<Engagement>> = [
row.__typename === 'LanguageEngagement'
? row.milestoneReached.value
: null,
filterable: false,
},
{
headerName: 'AI',
field: 'usingAIAssistedTranslation',
...booleanColumn(),
valueGetter: (_, row) =>
row.__typename === 'LanguageEngagement'
? row.usingAIAssistedTranslation.value === null
? 'Unknown'
: row.usingAIAssistedTranslation.value
? 'Yes'
: 'No'
? row.usingAIAssistedTranslation.value
: null,
filterable: false,
},
{
headerName: 'Type',
Expand Down
56 changes: 7 additions & 49 deletions src/scenes/Engagement/EditEngagement/EditEngagementDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import {
labelFrom,
MethodologyToApproach,
} from '~/common';
import {
AIAssistList,
AIAssistTypeLabels,
} from '~/components/EngagementDataGrid';
import { TriStateBooleanField } from '~/components/form/TriStateBooleanField';
import {
DialogForm,
DialogFormProps,
Expand Down Expand Up @@ -159,40 +156,16 @@ const fieldMapping: Record<
<TextField {...props} label="Paratext Registry ID" />
),
usingAIAssistedTranslation: ({ props }) => (
<EnumField
{...props}
label="AI Assisted Translation"
options={AIAssistList.map((item) =>
item === null ? 'null' : item.toString()
)}
getLabel={(value: string): string =>
AIAssistTypeLabels[value] ?? 'Unknown'
}
variant="toggle-grouped"
/>
<TriStateBooleanField {...props} label="AI Assisted Translation" />
),
};

// interface EngagementFormValues {
// engagement: Merge<
// UpdateLanguageEngagement & UpdateInternshipEngagement,
// {
// mentorId?: UserLookupItemFragment | null;
// countryOfOriginId?: DisplayLocationFragment | null;
// }
// >;
// }

interface EngagementFormValues {
engagement: Merge<
Omit<
UpdateLanguageEngagement & UpdateInternshipEngagement,
'usingAIAssistedTranslation'
>,
UpdateLanguageEngagement & UpdateInternshipEngagement,
{
mentorId?: UserLookupItemFragment | null;
countryOfOriginId?: DisplayLocationFragment | null;
usingAIAssistedTranslation?: string;
}
>;
}
Expand Down Expand Up @@ -239,13 +212,10 @@ export const EditEngagementDialog = ({
: UpdateLanguageEngagementDocument
);

type OverrideUsingAIAssistedTranslation<T> = {
[K in keyof T]: K extends 'usingAIAssistedTranslation' ? string : T[K];
};

const initialValues = useMemo(() => {
const fullInitialValuesFields: OverrideUsingAIAssistedTranslation<
Except<EngagementFormValues['engagement'], 'id'>
const fullInitialValuesFields: Except<
EngagementFormValues['engagement'],
'id'
> = {
startDateOverride: engagement.dateRangeOverride.value.start,
endDateOverride: engagement.dateRangeOverride.value.end,
Expand All @@ -258,9 +228,7 @@ export const EditEngagementDialog = ({
paratextRegistryId: engagement.paratextRegistryId.value,
openToInvestorVisit: engagement.openToInvestorVisit.value,
usingAIAssistedTranslation:
engagement.usingAIAssistedTranslation.value === null
? 'null'
: engagement.usingAIAssistedTranslation.value!.toString(),
engagement.usingAIAssistedTranslation.value,
}
: {
methodologies: engagement.methodologies.value,
Expand Down Expand Up @@ -340,21 +308,11 @@ 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,
};
Expand Down

0 comments on commit 28650ba

Please sign in to comment.