Skip to content

Commit

Permalink
fix(INTERNAL-1206): editable props for dnd
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed Oct 14, 2024
1 parent f2ac532 commit 035000c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/components/Kanban/Kanban.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
flex: 1;
}

.KanbanSortableListItem_disable {
cursor: default;
}

.KanbanSortableListItem_ghost {
opacity: 0.2;
}

.KanbanLink {
display: block;
}
Expand Down
18 changes: 15 additions & 3 deletions src/components/Kanban/Kanban.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { KanbanColumn, KanbanContainer } from '@taskany/bricks/harmony';
import { QueryStatus } from '@tanstack/react-query';
import { nullable, useIntersectionLoader } from '@taskany/bricks';
import { ReactSortable } from 'react-sortablejs';
import cn from 'classnames';

import { trpc } from '../../utils/trpcClient';
import { FilterById, State } from '../../../trpc/inferredTypes';
Expand Down Expand Up @@ -36,7 +37,7 @@ const calculateCommonLoadingState = (map: Map<unknown, LoadingState>): LoadingSt
const loadingStates = new Set(map.values());

if (loadingStates.size === 1) {
return loadingStates.values().next().value;
return loadingStates.values().next().value || 'success';
}

if (loadingStates.has('loading')) {
Expand Down Expand Up @@ -66,6 +67,13 @@ const intersectionOptions = {
rootMargin: '0px 0px 300px',
};

const onSortableMove: ComponentProps<typeof ReactSortable>['onMove'] = (event) => {
if (event.dragged.classList.contains(s.KanbanSortableListItem_disable)) {
return false;
}
return -1;
};

const KanbanStateColumn: FC<KanbanStateColumnProps> = ({
state,
shownStates,
Expand Down Expand Up @@ -234,9 +242,11 @@ const KanbanStateColumn: FC<KanbanStateColumnProps> = ({
animation={150}
list={list}
setList={setList}
ghostClass={s.KanbanSortableListItem_ghost}
filter={`.${s.KanbanLink}.${s.KanbanSortableListItem_disable}`}
group="states"
onEnd={onDragEnd}
sort={false}
onMove={onSortableMove}
>
{list.map((goal) => {
return (
Expand All @@ -248,7 +258,9 @@ const KanbanStateColumn: FC<KanbanStateColumnProps> = ({
_shortId: goal._shortId,
title: goal.title,
})}
className={s.KanbanLink}
className={cn(s.KanbanLink, {
[s.KanbanSortableListItem_disable]: !goal._isEditable,
})}
>
<GoalsKanbanCard
id={goal.id}
Expand Down
26 changes: 22 additions & 4 deletions trpc/queries/goalV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>
)
.$castTo<boolean>()
.as('_isParticipant'),
exists(
selectFrom('_projectParticipants')
.select('A')
.whereRef('B', '=', 'Goal.projectId')
.where('A', '=', params.activityId),
)
.$castTo<boolean>()
.as('_isParentParticipant'),
exists(
selectFrom('Project')
.select('Project.activityId')
.whereRef('Project.id', '=', 'Goal.projectId')
.where('Project.activityId', '=', params.activityId),
)
.$castTo<boolean>()
.as('_isParentOwner'),
exists(
selectFrom('_goalWatchers')
.select('B')
Expand All @@ -132,9 +148,6 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>
.$castTo<boolean>()
.as('_isStarred'),
sql`(count(criteria.id) > 0)`.as('_hasAchievementCriteria'),
sql<boolean>`((${val(params.role === Role.ADMIN)} or "Goal"."activityId" = ${val(
params.activityId,
)}) and not "Goal"."personal")`.as('_isEditable'),
caseFn()
.when(fn.count('criteria.id'), '>', 0)
.then(fn.agg('array_agg', [sql`"criteria"`]).distinct())
Expand Down Expand Up @@ -276,13 +289,18 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>
)
.innerJoin('Project', 'Project.id', 'proj_goals.projectId')
.selectAll('proj_goals')
.select(({ selectFrom, fn }) => [
.select(({ selectFrom, fn, val }) => [
sql<string>`concat("proj_goals"."projectId", '-', "proj_goals"."scopeId")::text`.as('_shortId'),
jsonBuildObject({
comments: selectFrom('Comment')
.select(({ fn }) => [fn.count('Comment.id').as('count')])
.whereRef('Comment.goalId', '=', 'proj_goals.id'),
}).as('_count'),
sql<boolean>`${val(
params.role === Role.ADMIN,
)} or proj_goals."_isOwner" or proj_goals."_isIssuer" or proj_goals."_isParentOwner" or proj_goals."_isParentParticipant"`.as(
'_isEditable',
),
sql`to_jsonb(proj_goals.tags)`.as('tags'),
sql`to_jsonb(proj_goals.criteria)`.as('criteria'),
sql`to_jsonb(proj_goals.participants)`.as('participants'),
Expand Down
2 changes: 2 additions & 0 deletions trpc/router/projectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type ProjectGoal = ExtractTypeFromGenerated<Goal> & {
_isEditable: boolean;
_isIssuer: boolean;
_isParticipant: boolean;
_isParentParticipant: boolean;
_isParentOwner: boolean;
_hasAchievementCriteria: boolean;
};

Expand Down

0 comments on commit 035000c

Please sign in to comment.