Skip to content

Commit

Permalink
feat: filter deps and criterias
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed Dec 21, 2023
1 parent 03cf34f commit 21cbf7f
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 249 deletions.
6 changes: 6 additions & 0 deletions cypress/fixtures/langs.json
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,12 @@
"en": "Low"
}
},
"PrivateDepsWarning": {
"Goal has private dependencies": {
"ru": "",
"en": ""
}
},
"ProjectAccessUser": {
"Access": {
"ru": "Доступ",
Expand Down
1 change: 1 addition & 0 deletions src/components/GoalHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const GoalHeader: FC<GoalHeaderProps> = ({
priority={g.priority?.title}
achivedCriteriaWeight={g._hasAchievementCriteria ? g._achivedCriteriaWeight : undefined}
comments={g._count?.comments ?? 0}
hasPrivateDeps={g._hasPrivateDeps}
onCommentsClick={onCommentsClick}
updatedAt={date}
/>
Expand Down
9 changes: 9 additions & 0 deletions src/components/IssueStats/IssueStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getPriorityText } from '../PriorityText/PriorityText';
import { UserGroup } from '../UserGroup';
import { RelativeTime } from '../RelativeTime/RelativeTime';
import { CommentsCountBadge } from '../CommentsCountBadge';
import { PrivateDepsWarning } from '../PrivateDepsWarning/PrivateDepsWarning';

interface IssueStatsProps {
updatedAt: Date;
Expand All @@ -21,6 +22,7 @@ interface IssueStatsProps {
estimateType?: DateType | null;
priority?: string | null;
achivedCriteriaWeight?: number | null;
hasPrivateDeps?: boolean;
mode?: 'compact' | 'default';
onCommentsClick?: () => void;
}
Expand Down Expand Up @@ -57,6 +59,7 @@ export const IssueStats: React.FC<IssueStatsProps> = ({
comments,
achivedCriteriaWeight,
updatedAt,
hasPrivateDeps,
mode,
onCommentsClick,
}) => {
Expand Down Expand Up @@ -108,6 +111,12 @@ export const IssueStats: React.FC<IssueStatsProps> = ({
</Link>
</DotSep>
))}

{nullable(hasPrivateDeps, () => (
<DotSep>
<PrivateDepsWarning />
</DotSep>
))}
</StyledIssueStats>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Goal has private dependencies": "Goal has private dependencies"
}
17 changes: 17 additions & 0 deletions src/components/PrivateDepsWarning/PrivateDepsWarning.i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable */
// Do not edit, use generator to update
import { i18n, fmt, I18nLangSet } from 'easy-typed-intl';
import getLang from '../../../utils/getLang';

import ru from './ru.json';
import en from './en.json';

export type I18nKey = keyof typeof ru & keyof typeof en;
type I18nLang = 'ru' | 'en';

const keyset: I18nLangSet<I18nKey> = {};

keyset['ru'] = ru;
keyset['en'] = en;

export const tr = i18n<I18nLang, I18nKey>(keyset, fmt, getLang);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Goal has private dependencies": "У цели есть приватные зависимости"
}
16 changes: 16 additions & 0 deletions src/components/PrivateDepsWarning/PrivateDepsWarning.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import styled from 'styled-components';
import { Popup } from '@taskany/bricks';
import { IconExclamationCircleOutline } from '@taskany/icons';
import { warn0 } from '@taskany/colors';

import { tr } from './PrivateDepsWarning.i18n';

const StyledWarningIcon = styled(IconExclamationCircleOutline)`
display: flex;
`;

export const PrivateDepsWarning = () => (
<Popup tooltip target={<StyledWarningIcon size="s" color={warn0} />} view="warning" placement="top">
{tr('Goal has private dependencies')}
</Popup>
);
76 changes: 75 additions & 1 deletion src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { GoalHistory, Comment, Activity, User, Goal, Role, Prisma, Reaction, Sta
import { TRPCError } from '@trpc/server';

import { GoalCommon, dependencyKind, exceptionsDependencyKind } from '../schema/goal';
import { addCalculatedGoalsFields, addCommonCalculatedGoalFields } from '../../trpc/queries/goals';
import {
addCalculatedGoalsFields,
addCommonCalculatedGoalFields,
nonArchievedGoalsPartialQuery,
} from '../../trpc/queries/goals';
import { HistoryRecordWithActivity, HistoryRecordSubject, castToSubject } from '../types/history';
import { ReactionsMap } from '../types/reactions';
import { getProjectSchema } from '../../trpc/queries/project';
Expand Down Expand Up @@ -164,6 +168,76 @@ export const createPersonalProject = async ({
});
};

export const countPrivateDependencies = async ({
projectId,
scopeId,
}: {
projectId: string;
scopeId: number;
}): Promise<{
goalAchiveCriteria: number;
dependsOn: number;
relatedTo: number;
blocks: number;
}> => {
const depsWhere = {
NOT: {
project: {
accessUsers: {
none: {},
},
},
},
...nonArchievedGoalsPartialQuery,
};

const data = await prisma.goal.findFirst({
where: {
projectId,
scopeId,
archived: false,
},
include: {
_count: {
select: {
goalAchiveCriteria: {
where: {
criteriaGoal: {
id: {},
},
NOT: {
criteriaGoal: {
project: {
accessUsers: {
none: {},
},
},
},
},
OR: [{ deleted: false }, { deleted: null }],
},
},
dependsOn: {
where: depsWhere,
},
relatedTo: {
where: depsWhere,
},
blocks: {
where: depsWhere,
},
},
},
},
});

if (!data) {
throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Goal is absent' });
}

return data._count;
};

export const changeGoalProject = async (id: string, newProjectId: string) => {
return prisma.$executeRaw`
UPDATE "Goal"
Expand Down
15 changes: 15 additions & 0 deletions trpc/queries/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ export const getProjectAccessFilter = (activityId: string, role: Role) => {
},
};
};

export const goalAchiveCriteriaFilter = (activityId: string, role: Role) => ({
OR: [
{
criteriaGoal: null,
},
{
criteriaGoal: {
project: {
...getProjectAccessFilter(activityId, role),
},
},
},
],
});
Loading

0 comments on commit 21cbf7f

Please sign in to comment.