Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const CopilotRequestForm: FC<{}> = () => {
const [formErrors, setFormErrors] = useState<any>({})
const [paymentType, setPaymentType] = useState<string>('')
const [projectFromQuery, setProjectFromQuery] = useState<Project>()
const isActiveProject = ['active', 'approved', 'draft', 'new']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable isActiveProject is intended to be a list of statuses, but the name suggests it might be a boolean. Consider renaming it to something like activeProjectStatuses to better reflect its purpose.


const { data: copilotRequestData }: CopilotRequestResponse = useCopilotRequest(routeParams.requestId)

Expand Down Expand Up @@ -114,7 +115,13 @@ const CopilotRequestForm: FC<{}> = () => {
label: string;
value: string;
}>> {
const response = await getProjects(inputValue)
const response = await getProjects(inputValue, {
filter: {
status: {
$in: [isActiveProject],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $in operator is typically used for arrays, but isActiveProject seems to be a single value. Consider using $eq if isActiveProject is a single status value.

},
},
})
return response.map(project => ({ label: project.name, value: project.id }))
}

Expand Down
4 changes: 2 additions & 2 deletions src/apps/copilots/src/services/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export const getProject = (projectId: string): Promise<Project> => {
return xhrGetAsync<Project>(url)
}

export const getProjects = (search?: string, filter?: any): Promise<Project[]> => {
const params = { name: `"${search}"`, ...filter }
export const getProjects = (search?: string, config?: {filter: any}): Promise<Project[]> => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the filter property in the config parameter to something more descriptive, such as projectFilter, to improve code readability and clarity.

const params = { name: search, ...config?.filter }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name parameter should be wrapped in quotes only if necessary. Ensure that the API expects the name parameter without quotes, or adjust accordingly.

const url = buildUrl(baseUrl, params)
return xhrGetAsync<Project[]>(url)
}