Skip to content

Commit

Permalink
feat(Criteria): show linked goal progress instead of state
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed Aug 22, 2024
1 parent d049ff9 commit 2ebfb48
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
24 changes: 19 additions & 5 deletions src/components/GoalBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ComponentProps } from 'react';
import { nullable } from '@taskany/bricks';
import { Badge } from '@taskany/bricks/harmony';
import { Badge, CircleProgressBar } from '@taskany/bricks/harmony';

import { NextLink } from './NextLink';
import { StateDot } from './StateDot/StateDot';
Expand All @@ -12,16 +12,30 @@ interface GoalBadgeProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'co
strike?: boolean;
children?: React.ReactNode;
className?: string;
progress?: number | null;
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
}

export const GoalBadge: React.FC<GoalBadgeProps> = ({ href, title, children, className, onClick, state, ...attrs }) => {
export const GoalBadge: React.FC<GoalBadgeProps> = ({
href,
title,
children,
className,
onClick,
state,
progress,
...attrs
}) => {
return (
<Badge
className={className}
iconLeft={nullable(state, (s) => (
<StateDot view="stroke" state={s} size="l" />
))}
iconLeft={nullable(
progress,
(value) => (
<CircleProgressBar value={value} size="xs" />
),
nullable(state, (s) => <StateDot view="stroke" state={s} size="l" />),
)}
iconRight={children}
text={nullable(
href,
Expand Down
17 changes: 17 additions & 0 deletions src/components/GoalCriteria/GoalCriteria.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

.GoalCriteriaTable {
margin-top: var(--gap-sm);
margin-bottom: var(--gap-s);
}

.GoalCriteriaItemTitle {
Expand Down Expand Up @@ -87,4 +88,20 @@
.GoalCriteriaIsolate::after {
content: none;
display: none;
}

.GoalCriteriaProgress {
position: absolute;
bottom: -10px;
left: 0;
width: 100%;
z-index: 0;
}

.GoalCriteriaTitleCell {
position: relative;
}

.GoalCriteriaTable {
gap: var(--gap-sm);
}
8 changes: 6 additions & 2 deletions src/components/GoalCriteria/GoalCriteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface GoalCriteriaProps extends CriteriaProps {
state?: State | null;
project?: string;
owner?: ActivityByIdReturnType;
progress?: number | null;
};
}

Expand All @@ -83,6 +84,7 @@ export function mapCriteria<
projectId: string | null;
owner: ActivityByIdReturnType | null;
state: State | null;
completedCriteriaWeight?: number | null;
},
>(criteria: T, connectedGoal: G | null): UnionCriteria {
if (connectedGoal) {
Expand All @@ -94,6 +96,7 @@ export function mapCriteria<
shortId: connectedGoal._shortId,
project: connectedGoal.projectId ?? undefined,
owner: connectedGoal.owner ?? undefined,
progress: connectedGoal.completedCriteriaWeight ?? null,
},
title: connectedGoal.title,
isDone: criteria.isDone,
Expand Down Expand Up @@ -160,12 +163,13 @@ const GoalCriteria = ({ title, goal, weight, isDone }: Omit<GoalCriteriaProps, '

return (
<>
<TableCell width={200}>
<TableCell className={classes.GoalCriteriaTitleCell} width={200}>
<GoalBadge
title={title}
state={goal.state ?? undefined}
href={routes.goal(goal.shortId)}
onClick={handleGoalCriteriaClick}
progress={goal.progress}
strike={isDone}
/>
</TableCell>
Expand Down Expand Up @@ -417,7 +421,7 @@ export const CriteriaList: React.FC<CriteriaListProps> = ({
}) => {
const validityData = useCriteriaValidityData(list);
return (
<Table className={className}>
<Table className={classNames(classes.GoalCriteriaTable, className)}>
{list.map((criteria) => (
<Criteria
goalId={goalId}
Expand Down
2 changes: 1 addition & 1 deletion src/components/GoalTableList/GoalTableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const GoalTableList = <T extends GoalTableListItem>({
content: goal.achievedCriteriaWeight != null && goal.id != null && (
<GoalCriteriaPreview achievedWeight={goal.achievedCriteriaWeight} goalId={goal.id} />
),
width: 24,
width: 32,
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/IssueStats/IssueStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const IssueStats: React.FC<IssueStatsProps> = ({
{achivedCriteriaWeight != null && (
<Separator>
<div className={s.IssueComponentContainer}>
<CircleProgressBar value={achivedCriteriaWeight} size="l" />
<CircleProgressBar value={achivedCriteriaWeight} size="m" />
</div>
</Separator>
)}
Expand Down
1 change: 1 addition & 0 deletions trpc/queries/criteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const criteriaQuery = (params: CriteriaParams = {}) => {
_shortId: sql<string>`concat(${ref('criteriaGoal.projectId')}, '-', ${ref(
'criteriaGoal.scopeId',
)})`,
completedCriteriaWeight: sql<number | null>`"criteriaGoal"."completedCriteriaWeight"`,
state: fn.toJson('state'),
owner: jsonBuildObject({
id: sql<string>`activity.id`,
Expand Down

0 comments on commit 2ebfb48

Please sign in to comment.