-
Notifications
You must be signed in to change notification settings - Fork 21
[Work in progress] feat: added ai workflow list component to create or update default reviewer #1298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
[Work in progress] feat: added ai workflow list component to create or update default reviewer #1298
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,7 @@ | ||
| import { | ||
| useCallback, | ||
| useEffect, | ||
| useMemo, | ||
| useState, | ||
| } from 'react' | ||
| import type { FC } from 'react' | ||
| import { useNavigate, useParams } from 'react-router-dom' | ||
| import type { NavigateFunction } from 'react-router-dom' | ||
| import { Controller, useForm } from 'react-hook-form' | ||
| import type { | ||
| ControllerRenderProps, | ||
| UseFormReturn, | ||
| } from 'react-hook-form' | ||
| import { useCallback, useEffect, useMemo, useState } from 'react' | ||
| import { NavigateFunction, useNavigate, useParams } from 'react-router-dom' | ||
| import { Controller, ControllerRenderProps, useForm, UseFormReturn } from 'react-hook-form' | ||
| import _ from 'lodash' | ||
| import classNames from 'classnames' | ||
|
|
||
|
|
@@ -25,13 +15,14 @@ import { | |
| LinkButton, | ||
| } from '~/libs/ui' | ||
|
|
||
| import { FormAddWrapper } from '../common/FormAddWrapper' | ||
| import { FormAddDefaultReviewer } from '../../models' | ||
| import { formAddDefaultReviewerSchema } from '../../utils' | ||
| import { | ||
| useManageAddDefaultReviewer, | ||
| useManageAddDefaultReviewerProps, | ||
| } from '../../hooks' | ||
| import { FormAddWrapper } from '../common/FormAddWrapper' | ||
| import { FormAddDefaultReviewer } from '../../models' | ||
| import { formAddDefaultReviewerSchema } from '../../utils' | ||
| import { getAiWorkflows } from '../../services/ai-workflows.service' | ||
|
|
||
| import styles from './DefaultReviewersAddForm.module.scss' | ||
|
|
||
|
|
@@ -127,6 +118,7 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => { | |
| formState: { errors, isDirty }, | ||
| }: UseFormReturn<FormAddDefaultReviewer> = useForm({ | ||
| defaultValues: { | ||
| aiWorkflowId: '', | ||
| baseCoefficient: 0, | ||
| fixedAmount: 0, | ||
| incrementalCoefficient: 0, | ||
|
|
@@ -165,11 +157,22 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => { | |
| [doAddDefaultReviewer, doUpdateDefaultReviewer, isEdit, navigate], | ||
| ) | ||
|
|
||
| const [aiWorkflows, setAiWorkflows] = useState<{ label: string; value: string }[]>([]) | ||
|
|
||
| useEffect(() => { | ||
| getAiWorkflows() | ||
| .then((workflows: { id: string; name: string }[]) => { | ||
| const options = workflows.map((wf: { id: string; name: string }) => ({ label: wf.name, value: wf.id })) | ||
| setAiWorkflows(options) | ||
| }) | ||
| }, []) | ||
|
|
||
| const isMemberReview = watch('isMemberReview') | ||
|
|
||
| useEffect(() => { | ||
| if (defaultReviewerInfo) { | ||
| reset({ | ||
| aiWorkflowId: defaultReviewerInfo.aiWorkflowId ?? '', | ||
| baseCoefficient: defaultReviewerInfo.baseCoefficient ?? 0, | ||
| fixedAmount: defaultReviewerInfo.fixedAmount ?? 0, | ||
| incrementalCoefficient: defaultReviewerInfo.incrementalCoefficient ?? 0, | ||
|
|
@@ -460,17 +463,18 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => { | |
| ) | ||
| }} | ||
| /> | ||
|
|
||
| <div className={styles.inputField}> | ||
| <Controller | ||
| name='isAIReviewer' | ||
| name='shouldOpenOpportunity' | ||
| control={control} | ||
| render={function render(controlProps: { | ||
| field: ControllerRenderProps<FormAddDefaultReviewer, 'isAIReviewer'> | ||
| }) { | ||
| field: ControllerRenderProps<FormAddDefaultReviewer, 'shouldOpenOpportunity'> | ||
| }) { | ||
| return ( | ||
| <InputCheckbox | ||
| name='isAIReviewer' | ||
| label='Is AI Reviewer' | ||
| name='shouldOpenOpportunity' | ||
| label='Should Open Opportunity' | ||
| onChange={function onChange(event: Event) { | ||
| const target = event.target as HTMLInputElement | null | ||
| controlProps.field.onChange(target?.checked ?? false) | ||
|
|
@@ -482,28 +486,31 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => { | |
| }} | ||
| /> | ||
| </div> | ||
| <div className={styles.inputField}> | ||
| {!isMemberReview && ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| <Controller | ||
| name='shouldOpenOpportunity' | ||
| name='aiWorkflowId' | ||
| control={control} | ||
| render={function render(controlProps: { | ||
| field: ControllerRenderProps<FormAddDefaultReviewer, 'shouldOpenOpportunity'> | ||
| field: ControllerRenderProps<FormAddDefaultReviewer, 'aiWorkflowId'> | ||
| }) { | ||
| return ( | ||
| <InputCheckbox | ||
| name='shouldOpenOpportunity' | ||
| label='Should Open Opportunity' | ||
| onChange={function onChange(event: Event) { | ||
| const target = event.target as HTMLInputElement | null | ||
| controlProps.field.onChange(target?.checked ?? false) | ||
| }} | ||
| checked={controlProps.field.value} | ||
| <InputSelectReact | ||
| name='aiWorkflowId' | ||
| label='AI Workflow' | ||
| placeholder='Select AI Workflow' | ||
| options={aiWorkflows} | ||
| value={controlProps.field.value} | ||
| onChange={controlProps.field.onChange} | ||
| onBlur={controlProps.field.onBlur} | ||
| classNameWrapper={styles.inputField} | ||
| disabled={isLoading} | ||
| dirty | ||
| error={_.get(errors, 'aiWorkflowId.message')} | ||
| /> | ||
| ) | ||
| }} | ||
| /> | ||
| </div> | ||
| )} | ||
| </FormAddWrapper> | ||
| <ConfirmModal | ||
| title='Delete Confirmation' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { EnvironmentConfig } from '~/config' | ||
| import { xhrGetAsync } from '~/libs/core' | ||
|
|
||
| export interface AiWorkflow { | ||
| id: string; | ||
| name: string; | ||
| } | ||
|
|
||
| export async function getAiWorkflows(): Promise<AiWorkflow[]> { | ||
| const response = await xhrGetAsync<AiWorkflow[]>(`${EnvironmentConfig.API.V6}/workflows`) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| return response | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[⚠️
correctness]Consider adding error handling for the
getAiWorkflowspromise to manage potential failures, such as network issues or server errors. This will improve the robustness of the component.