Skip to content

Commit

Permalink
feat(Goal): show team info on goal page
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed Jan 20, 2023
1 parent da0c10b commit ae0c2c7
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 56 deletions.
9 changes: 9 additions & 0 deletions graphql/resolvers/Goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ export const query = (t: ObjectDefinitionBlock<'Query'>) => {
},
tags: true,
state: true,
team: {
include: {
flow: {
include: {
states: true,
},
},
},
},
project: {
include: {
flow: {
Expand Down
1 change: 1 addition & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ type Team {
flowId: String
goals: [Goal]
id: Int!
key: String
parent: Team
participants: [Activity]
projects: [Project]
Expand Down
1 change: 1 addition & 0 deletions graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const Team = objectType({
definition(t) {
t.field(TeamModel.id);
t.field(TeamModel.slug);
t.field(TeamModel.key);
t.field(TeamModel.title);
t.field(TeamModel.description);
t.field(TeamModel.activityId);
Expand Down
3 changes: 2 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@
"Change color and create": "to change color. Click on it to create."
},
"IssueTitle": {
"Project": "Project"
"Project": "Project",
"Team": "Team"
},
"IssueStats": {
"comments": {
Expand Down
3 changes: 2 additions & 1 deletion i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@
"Change color and create": "чтобы сменить цвет. Нажми на тэк чтобы создать."
},
"IssueTitle": {
"Project": "Проект"
"Project": "Проект",
"Team": "Команда"
},
"IssueStats": {
"comments": {
Expand Down
8 changes: 6 additions & 2 deletions src/components/GoalPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ModalHeader, ModalContent } from './Modal';
import { ModalPreview } from './ModalPreview';
import { IssueKey } from './IssueKey';
import { IssueTitle } from './IssueTitle';
import { IssueProject } from './IssueProject';
import { IssueParent } from './IssueParent';
import { IssueTags } from './IssueTags';
import { Button } from './Button';
import { StateDot } from './StateDot';
Expand Down Expand Up @@ -126,8 +126,12 @@ const GoalPreview: React.FC<GoalPreviewProps> = ({ goal: partialGoal, visible, o
</IssueKey>
))}

{nullable(goal.team, (team) => (
<IssueParent kind="team" as="span" mode="compact" parent={team} size="m" />
))}

{nullable(goal.project, (project) => (
<IssueProject as="span" mode="compact" project={project} size="m" />
<IssueParent kind="project" as="span" mode="compact" parent={project} size="m" />
))}

<IssueStats mode="compact" comments={goal.comments?.length || 0} updatedAt={goal.updatedAt} />
Expand Down
69 changes: 69 additions & 0 deletions src/components/IssueParent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';
import styled from 'styled-components';
import { useTranslations } from 'next-intl';
import NextLink from 'next/link';

import { gapM, gapS, gray9 } from '../design/@generated/themes';
import { routes } from '../hooks/router';
import { nullable } from '../utils/nullable';

import { Text } from './Text';
import { Link } from './Link';

interface IssueParentProps {
kind: 'project' | 'team';
parent: {
key?: string;
slug?: string;
title: string;
};
mode?: 'compact' | 'default';
as?: React.ComponentProps<typeof Text>['as'];
size?: React.ComponentProps<typeof Text>['size'];
}

const sizeGapMap = {
xxs: gapS,
xs: gapS,
s: gapS,
m: gapS,
l: gapM,
xl: gapM,
xxl: gapM,
};

const StyledIssueParentTitle = styled(Text)`
display: inline-block;
padding-top: ${({ size = 'l' }) => sizeGapMap[size]};
`;

export const IssueParent: React.FC<IssueParentProps> = ({ parent, kind, as, mode, size = 'l' }) => {
const t = useTranslations('IssueTitle');

const kindTitleMap = {
project: t('Project'),
team: t('Team'),
};

const kindContentMap = {
project: nullable(parent.key, (key) => (
<NextLink passHref href={routes.project(key)}>
<Link inline>{parent.title}</Link>
</NextLink>
)),
team: nullable(parent.slug, (slug) => (
<NextLink passHref href={routes.team(slug)}>
<Link inline>{parent.title}</Link>
</NextLink>
)),
};

const pre = mode === 'compact' ? '' : `${kindTitleMap[kind]} — `;

return (
<StyledIssueParentTitle as={as} size={size} weight="bold" color={gray9}>
{pre}
{kindContentMap[kind]}
</StyledIssueParentTitle>
);
};
50 changes: 0 additions & 50 deletions src/components/IssueProject.tsx

This file was deleted.

8 changes: 6 additions & 2 deletions src/pages/goals/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Button } from '../../components/Button';
import { Reactions } from '../../components/Reactions';
import { CommentView } from '../../components/CommentView';
import { StateDot } from '../../components/StateDot';
import { IssueProject } from '../../components/IssueProject';
import { IssueParent } from '../../components/IssueParent';
import { IssueTags } from '../../components/IssueTags';
import { useHighlightedComment } from '../../hooks/useHighlightedComment';
import { useGoalUpdate } from '../../hooks/useGoalUpdate';
Expand Down Expand Up @@ -243,8 +243,12 @@ const GoalPage = ({
))}
</IssueKey>

{nullable(goal.team, (team) => (
<IssueParent kind="team" parent={team} />
))}

{nullable(goal.project, (project) => (
<IssueProject project={project} />
<IssueParent kind="project" parent={project} />
))}

<IssueTitle title={goal.title} />
Expand Down
17 changes: 17 additions & 0 deletions src/utils/entityFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ export const goalFetcher = createFetcher((_, id: string) => ({
},
createdAt: true,
updatedAt: true,
team: {
id: true,
key: true,
slug: true,
title: true,
description: true,
flowId: true,
flow: {
id: true,
states: {
id: true,
title: true,
default: true,
hue: true,
},
},
},
project: {
id: true,
key: true,
Expand Down

0 comments on commit ae0c2c7

Please sign in to comment.