Skip to content

Commit

Permalink
feat(ExternalTask): view history changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed Sep 12, 2024
1 parent 43ffd37 commit 75a997f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/components/HistoryRecord/HistoryRecord.i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": "dependencies",
"criteria": "",
"goal as criteria": "goal",
"task as criteria": "task",
"marked criteria": "",
"priority": "priority",
"from": "from",
Expand All @@ -25,6 +26,8 @@
"as criteria": "",
"goal complete": "completed goal",
"goal in progress": "returns goal to work",
"task complete": "completed task",
"task in progress": "returns task to work",
"partner project": "",
"author and more made changes in": "{author} and {count} more made changes in{space}{subject}",
"author and the other author made changes in": "{author} and {oneMoreAuthor} made changes in{space}{subject}",
Expand Down
3 changes: 3 additions & 0 deletions src/components/HistoryRecord/HistoryRecord.i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": "зависимости",
"criteria": "критерий",
"goal as criteria": "цель",
"task as criteria": "задача",
"marked criteria": "отметил(а) критерий",
"priority": "приоритет",
"from": "с",
Expand All @@ -25,6 +26,8 @@
"as criteria": "как критерий",
"goal complete": "выполнил(а) цель",
"goal in progress": "вернул(а) цель в работу",
"task complete": "выполнил(а) задачу",
"task in progress": "вернул(а) задачу в работу",
"partner project": "партнерский проект",
"author and more made changes in": "{author} и еще {count} внесли изменения в{space}{subject}",
"author and the other author made changes in": "{author} и {oneMoreAuthor} внесли изменения в{space}{subject}",
Expand Down
88 changes: 70 additions & 18 deletions src/components/HistoryRecord/HistoryRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Goal,
Ghost,
Priority,
ExternalTask,
} from '@prisma/client';
import { nullable } from '@taskany/bricks';
import {
Expand All @@ -31,6 +32,7 @@ import { getUserName, prepareUserDataFromActivity, safeUserData } from '../../ut
import { UserBadge } from '../UserBadge/UserBadge';
import { ProjectBadge } from '../ProjectBadge';
import { getStateProps, GoalBadge } from '../GoalBadge';
import { JiraTaskBadge } from '../JiraTaskBadge/JiraTaskBadge';
import { routes } from '../../hooks/router';
import { State } from '../State';

Expand All @@ -42,10 +44,13 @@ type WholeSubject =
| 'estimate'
| 'description'
| 'priority'
| 'goalAsCriteria'
| 'criteriaState'
| 'goalComplete'
| 'goalInProgress'
| 'goalAsCriteria'
| 'taskComplete'
| 'taskInProgress'
| 'taskAsCriteria'
| keyof HistoryRecordSubject;

interface HistoryRecordInnerProps {
Expand Down Expand Up @@ -151,10 +156,13 @@ const useHistoryTranslates = () => {
priority: tr('priority'),
criteria: tr('criteria'),
partnerProject: tr('partner project'),
goalAsCriteria: tr('goal as criteria'),
criteriaState: tr('marked criteria'),
goalAsCriteria: tr('goal as criteria'),
goalComplete: tr('goal complete'),
goalInProgress: tr('goal in progress'),
taskAsCriteria: tr('task as criteria'),
taskComplete: tr('task complete'),
taskInProgress: tr('task in progress'),
complete: '',
uncomplete: '',
};
Expand Down Expand Up @@ -402,21 +410,35 @@ const HistoryRecordParticipant: React.FC<

type CriteriaItem = GoalAchieveCriteria & {
criteriaGoal: (Goal & { state?: StateData }) | null;
externalTask: ExternalTask | null;
strike?: boolean;
};

const HistoryRecordCriteriaItem: React.FC<CriteriaItem> = ({ criteriaGoal, title, strike }) => {
const HistoryRecordCriteriaItem: React.FC<CriteriaItem> = ({ criteriaGoal, externalTask, title, strike }) => {
if (criteriaGoal) {
return (
<>
<GoalBadge
className={cn(s.HistoryBadge, s.HistoryRecordTextPrimary)}
title={criteriaGoal.title}
state={getStateProps(criteriaGoal.state)}
href={routes.goal(`${criteriaGoal.projectId}-${criteriaGoal.scopeId}`)}
strike={strike}
/>
</>
<GoalBadge
className={cn(s.HistoryBadge, s.HistoryRecordTextPrimary)}
title={criteriaGoal.title}
state={getStateProps(criteriaGoal.state)}
href={routes.goal(`${criteriaGoal.projectId}-${criteriaGoal.scopeId}`)}
strike={strike}
/>
);
}

if (externalTask) {
return (
<JiraTaskBadge
className={cn(s.HistoryBadge, s.HistoryRecordTextPrimary)}
state={{
title: externalTask.state,
color: externalTask.stateColor,
}}
title={externalTask.title}
href={routes.jiraTask(externalTask.externalKey)}
strike={strike}
/>
);
}

Expand All @@ -427,6 +449,19 @@ const HistoryRecordCriteriaItem: React.FC<CriteriaItem> = ({ criteriaGoal, title
);
};

const trKeyMap: Record<'criteriaGoal' | 'externalTask', Record<'default' | 'inProgress' | 'complete', WholeSubject>> = {
criteriaGoal: {
default: 'goalAsCriteria',
inProgress: 'goalInProgress',
complete: 'goalComplete',
},
externalTask: {
default: 'taskAsCriteria',
inProgress: 'taskInProgress',
complete: 'taskComplete',
},
};

const HistoryRecordCriteria: React.FC<
HistoryChangeProps<CriteriaItem> & {
action: HistoryRecordAction;
Expand All @@ -440,14 +475,22 @@ const HistoryRecordCriteria: React.FC<
useEffect(() => {
recordCtx.setSubjectText((prev) => {
const target = from || to;
if (target?.criteriaGoal != null) {
const translateMap =
// eslint-disable-next-line no-nested-ternary
target?.criteriaGoal != null
? trKeyMap.criteriaGoal
: target?.externalTask != null
? trKeyMap.externalTask
: null;

if (translateMap) {
if (isChangeAction) {
if (action === 'complete') {
return 'goalComplete';
return translateMap.complete;
}
return 'goalInProgress';
return translateMap.inProgress;
}
return 'goalAsCriteria';
return translateMap.default;
}

if (isChangeAction) {
Expand All @@ -467,7 +510,7 @@ const HistoryRecordCriteria: React.FC<
to={nullable(to, (val) => (
<>
<HistoryRecordCriteriaItem {...val} strike={action === 'remove'} />
{val?.criteriaGoal && <HistoryRecordText> {tr('as criteria')}</HistoryRecordText>}
{val?.criteriaGoal && <HistoryRecordText>{tr('as criteria')}</HistoryRecordText>}
{nullable(isChangeAction, () => (
<HistoryRecordText>
{' '}
Expand All @@ -480,7 +523,16 @@ const HistoryRecordCriteria: React.FC<
);
};

type OuterSubjects = Exclude<WholeSubject, 'goalAsCriteria' | 'criteriaState' | 'goalComplete' | 'goalInProgress'>;
type BanSubjects =
| 'goalAsCriteria'
| 'criteriaState'
| 'goalComplete'
| 'goalInProgress'
| 'taskAsCriteria'
| 'taskComplete'
| 'taskInProgress';

type OuterSubjects = Exclude<WholeSubject, BanSubjects>;

/**
* let it be like this, with `any` props annotation
Expand Down
29 changes: 27 additions & 2 deletions trpc/queries/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { sql } from 'kysely';

import { db } from '../connection/kysely';
import { ExtractTypeFromGenerated } from '../utils';
import { Goal, GoalAchieveCriteria, GoalHistory, Priority, Project, State, Tag } from '../../generated/kysely/types';
import {
Goal,
GoalAchieveCriteria,
GoalHistory,
Priority,
Project,
State,
Tag,
ExternalTask,
} from '../../generated/kysely/types';

import { Activity, getUserActivity } from './activity';
import { tagQuery } from './tag';
Expand Down Expand Up @@ -50,7 +59,8 @@ export interface HistoryRecordMeta {
owner: Activity;
participants: Activity;
state: ExtractTypeFromGenerated<State>;
criteria: ExtractTypeFromGenerated<GoalAchieveCriteria> & { criteriaGoal: ExtendedGoal };
criteria: ExtractTypeFromGenerated<GoalAchieveCriteria> &
({ criteriaGoal: ExtendedGoal } | { externalTask: ExtractTypeFromGenerated<ExternalTask> });
partnerProject: ExtractTypeFromGenerated<Project>;
priority: ExtractTypeFromGenerated<Priority>;
title: string;
Expand Down Expand Up @@ -180,6 +190,14 @@ export const extraDataForEachRecord = async <T extends HisrotyRecord>(
() => goalBaseQuery().as('criteriaGoal'),
(join) => join.onRef('GoalAchieveCriteria.criteriaGoalId', '=', 'criteriaGoal.id'),
)
.leftJoinLateral(
({ selectFrom }) =>
selectFrom('ExternalTask')
.selectAll()
.whereRef('GoalAchieveCriteria.externalTaskId', '=', 'ExternalTask.id')
.as('externalTask'),
(join) => join.onTrue(),
)
.selectAll('GoalAchieveCriteria')
.select((eb) => [
eb
Expand All @@ -189,6 +207,13 @@ export const extraDataForEachRecord = async <T extends HisrotyRecord>(
.else(null)
.end()
.as('criteriaGoal'),
eb
.case()
.when('GoalAchieveCriteria.externalTaskId', 'is not', null)
.then(sql`to_json("externalTask")`)
.else(null)
.end()
.as('externalTask'),
])
.where('GoalAchieveCriteria.id', 'in', ids)
.$castTo<HistoryRecordMeta['criteria']>();
Expand Down

0 comments on commit 75a997f

Please sign in to comment.