From 6bfb74e44f28c36d856ca692b46922df4fe68142 Mon Sep 17 00:00:00 2001 From: Maksim Sviridov Date: Thu, 25 May 2023 12:20:22 +0300 Subject: [PATCH] fix(IssueDependenciesForm): scopedId in input field --- .../IssueDependenciesForm.tsx | 14 ++++----- trpc/router/goal.ts | 29 +++++++++++++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/components/IssueDependenciesForm/IssueDependenciesForm.tsx b/src/components/IssueDependenciesForm/IssueDependenciesForm.tsx index fa1de1cf9..8330ad620 100644 --- a/src/components/IssueDependenciesForm/IssueDependenciesForm.tsx +++ b/src/components/IssueDependenciesForm/IssueDependenciesForm.tsx @@ -51,10 +51,10 @@ const StyledDropdownContainer = styled.div` const IssueDependenciesForm: React.FC = ({ issue, onChange }) => { const [kind, setKind] = useState(); const [target, setTarget] = useState(); - const [query, setQuery] = useState(''); + const [query, setQuery] = useState([]); const [completionVisible, setCompletionVisible] = useState(false); - const { data: goalsData } = trpc.goal.suggestions.useQuery(query); + const { data: goalsData } = trpc.goal.suggestions.useQuery(query.join('-')); const dependKeys = useMemo( () => ({ @@ -82,7 +82,7 @@ const IssueDependenciesForm: React.FC = ({ issue, on const onDependencyAdd = useCallback((g: NonNullable) => { setCompletionVisible(false); setTarget(g); - setQuery(g.id); + setQuery([g.projectId!, String(g.scopeId)]); }, []); const onKindChange = useCallback( @@ -97,7 +97,7 @@ const IssueDependenciesForm: React.FC = ({ issue, on ); const onSubmit = useCallback(() => { - setQuery(''); + setQuery(['']); setTarget(undefined); setKind(undefined); @@ -126,8 +126,8 @@ const IssueDependenciesForm: React.FC = ({ issue, on = ({ issue, on autoFocus placeholder={tr('Add dependency')} onChange={(e: ChangeEvent) => { - setQuery(e.currentTarget.value); + setQuery([e.currentTarget.value]); setCompletionVisible(true); }} {...props} diff --git a/trpc/router/goal.ts b/trpc/router/goal.ts index 16eea3cf5..75deee3d3 100644 --- a/trpc/router/goal.ts +++ b/trpc/router/goal.ts @@ -18,16 +18,33 @@ import { createGoal, changeGoalProject } from '../../src/utils/db'; export const goal = router({ suggestions: protectedProcedure.input(z.string()).query(async ({ input }) => { - return prisma.goal.findMany({ - take: 10, - where: { - OR: [ + const splittedInput = input.split('-'); + let selectParams = {}; + + if (splittedInput.length === 2 && Number.isNaN(+splittedInput[1])) { + selectParams = { + AND: [ { - id: { - contains: input, + projectId: { + contains: splittedInput[0], + mode: 'insensitive', + }, + }, + { + scopeId: { + contains: splittedInput[1], mode: 'insensitive', }, }, + ], + }; + } + + return prisma.goal.findMany({ + take: 10, + where: { + OR: [ + selectParams, { title: { contains: input,