Skip to content

Commit

Permalink
fix(IssueDependenciesForm): scopedId in input field
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed May 25, 2023
1 parent d32b37a commit 6bfb74e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/components/IssueDependenciesForm/IssueDependenciesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ const StyledDropdownContainer = styled.div`
const IssueDependenciesForm: React.FC<IssueDependenciesFormProps> = ({ issue, onChange }) => {
const [kind, setKind] = useState<dependencyKind>();
const [target, setTarget] = useState<GoalByIdReturnType>();
const [query, setQuery] = useState('');
const [query, setQuery] = useState<string[]>([]);
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(
() => ({
Expand Down Expand Up @@ -82,7 +82,7 @@ const IssueDependenciesForm: React.FC<IssueDependenciesFormProps> = ({ issue, on
const onDependencyAdd = useCallback((g: NonNullable<GoalByIdReturnType>) => {
setCompletionVisible(false);
setTarget(g);
setQuery(g.id);
setQuery([g.projectId!, String(g.scopeId)]);
}, []);

const onKindChange = useCallback(
Expand All @@ -97,7 +97,7 @@ const IssueDependenciesForm: React.FC<IssueDependenciesFormProps> = ({ issue, on
);

const onSubmit = useCallback(() => {
setQuery('');
setQuery(['']);
setTarget(undefined);
setKind(undefined);

Expand Down Expand Up @@ -126,8 +126,8 @@ const IssueDependenciesForm: React.FC<IssueDependenciesFormProps> = ({ issue, on

<StyledCompletion>
<ComboBox
text={query}
value={query}
text={query.join('-')}
value={query.join('-')}
placement="top-start"
offset={[-4, 38]}
visible={completionVisible}
Expand All @@ -138,7 +138,7 @@ const IssueDependenciesForm: React.FC<IssueDependenciesFormProps> = ({ issue, on
autoFocus
placeholder={tr('Add dependency')}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setQuery(e.currentTarget.value);
setQuery([e.currentTarget.value]);
setCompletionVisible(true);
}}
{...props}
Expand Down
29 changes: 23 additions & 6 deletions trpc/router/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6bfb74e

Please sign in to comment.