Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract status colors and badges into common types and components #89

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/common/status-color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MantineColor } from "@mantine/styles";
import { StatusType } from "../../types/status";

export const getStatusTypeColor = (statusType: StatusType): MantineColor => {
switch (statusType) {
case StatusType.TODO:
return "gray.6"
case StatusType.IN_PROGRESS:
return "blue.8"
case StatusType.DONE:
return "green.9"
default:
return "gray.6"
}
}
34 changes: 5 additions & 29 deletions src/components/BacklogView/Issue/IssueCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { Draggable } from "react-beautiful-dnd"
import { DetailView } from "../../DetailView/DetailView"
import { IssueIcon } from "./IssueIcon"
import { DeleteButton } from "./DeleteButton"
import { StatusType } from "../../../../types/status";
import { StoryPointsBadge } from "../../common/StoryPoints/StoryPointsBadge";

export function IssueCard({
issueKey,
Expand All @@ -34,7 +36,6 @@ export function IssueCard({
projectId,
...props
}: Issue & { index: number }) {
let storyPointsColor: string
const [opened, setOpened] = useState(false)
const queryClient = useQueryClient()
const { ref, hovered } = useHover()
Expand All @@ -51,20 +52,6 @@ export function IssueCard({
transition: "background-color .1s ease-in",
}

switch (status) {
case "To Do":
storyPointsColor = "gray.6"
break
case "In Progress":
storyPointsColor = "blue.8"
break
case "Done":
storyPointsColor = "green.9"
break
default:
storyPointsColor = "gray.6"
}

return (
<>
<Draggable key={issueKey} draggableId={issueKey} index={index}>
Expand Down Expand Up @@ -107,7 +94,7 @@ export function IssueCard({
size="sm"
mr={5}
color="blue"
td={status === "Done" ? "line-through" : "none"}
td={status === StatusType.DONE ? "line-through" : "none"}
sx={{
":hover": {
textDecoration: "underline",
Expand Down Expand Up @@ -177,19 +164,8 @@ export function IssueCard({
</Grid.Col>
<Grid.Col span={3}>
<Box sx={{ alignSelf: "flex-start" }}>
<Badge
w="24px"
p="0px"
bg={
storyPointsEstimate !== undefined &&
storyPointsEstimate !== null
? storyPointsColor
: "transparent"
}
variant="filled"
>
{storyPointsEstimate}
</Badge>
{storyPointsEstimate &&
<StoryPointsBadge statusType={status as StatusType} storyPointsEstimate={storyPointsEstimate} />}
</Box>
</Grid.Col>
</Grid>
Expand Down
23 changes: 14 additions & 9 deletions src/components/BacklogView/IssuesWrapper/SprintsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
storyPointsAccumulator,
} from "../helpers/backlogHelpers"
import { DraggableIssuesWrapper } from "./DraggableIssuesWrapper"
import {StatusType} from "../../../../types/status";
import {StoryPointsBadge} from "../../common/StoryPoints/StoryPointsBadge";

export function SprintsPanel({
sprintsWithIssues,
Expand Down Expand Up @@ -77,15 +79,18 @@ function SprintAccordionControl({
</Badge>
)}
<Flex gap={4} p="xs" ml="auto">
<Badge px="6px" color="gray.6" variant="filled" size="sm">
{storyPointsAccumulator(issues, "To Do")}
</Badge>
<Badge px="6px" color="blue.8" variant="filled" size="sm">
{storyPointsAccumulator(issues, "In Progress")}
</Badge>
<Badge px="6px" color="green.9" variant="filled" size="sm">
{storyPointsAccumulator(issues, "Done")}
</Badge>
<StoryPointsBadge
statusType={StatusType.TODO}
storyPointsEstimate={storyPointsAccumulator(issues, StatusType.TODO)}
/>
<StoryPointsBadge
statusType={StatusType.IN_PROGRESS}
storyPointsEstimate={storyPointsAccumulator(issues, StatusType.IN_PROGRESS)}
/>
<StoryPointsBadge
statusType={StatusType.DONE}
storyPointsEstimate={storyPointsAccumulator(issues, StatusType.DONE)}
/>
</Flex>
</Group>
<Text size="sm" color="gray.7">
Expand Down
3 changes: 2 additions & 1 deletion src/components/BacklogView/helpers/backlogHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Issue, Sprint } from "types"
import { Dispatch, SetStateAction } from "react"
import { StatusType } from "../../../../types/status";

export const storyPointsAccumulator = (issues: Issue[], status: string) =>
export const storyPointsAccumulator = (issues: Issue[], status: StatusType) =>
issues.reduce((accumulator, currentValue) => {
if (currentValue.storyPointsEstimate && currentValue.status === status) {
return accumulator + currentValue.storyPointsEstimate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { Issue } from "../../../../../types"
import { DetailView } from "../../../DetailView/DetailView"
import { IssueIcon } from "../../../BacklogView/Issue/IssueIcon"
import { DeleteButton } from "../../../BacklogView/Issue/DeleteButton"
import { StatusType } from "../../../../../types/status";
import { StoryPointsBadge } from "../../../common/StoryPoints/StoryPointsBadge";

export function ChildIssueCard({
issueKey,
Expand All @@ -33,7 +35,6 @@ export function ChildIssueCard({
projectId,
...props
}: Issue & { index: number }) {
let storyPointsColor: string
const [opened, setOpened] = useState(false)
const queryClient = useQueryClient()
const { hovered } = useHover()
Expand All @@ -50,20 +51,6 @@ export function ChildIssueCard({
transition: "background-color .1s ease-in",
}

switch (status) {
case "To Do":
storyPointsColor = "gray.6"
break
case "In Progress":
storyPointsColor = "blue.8"
break
case "Done":
storyPointsColor = "green.9"
break
default:
storyPointsColor = "gray.6"
}

return (
<>
<Paper onClick={() => setOpened(true)} sx={{ position: "relative" }}>
Expand Down Expand Up @@ -98,7 +85,7 @@ export function ChildIssueCard({
size="sm"
mr={5}
color="blue"
td={status === "Done" ? "line-through" : "none"}
td={status === StatusType.DONE ? "line-through" : "none"}
sx={{
":hover": {
textDecoration: "underline",
Expand Down Expand Up @@ -137,18 +124,8 @@ export function ChildIssueCard({
}}
>
<Box sx={{ alignSelf: "flex-start" }}>
<Badge
p="7px"
bg={
storyPointsEstimate !== undefined &&
storyPointsEstimate !== null
? storyPointsColor
: "transparent"
}
variant="filled"
>
{storyPointsEstimate}
</Badge>
{storyPointsEstimate &&
<StoryPointsBadge statusType={status as StatusType} storyPointsEstimate={storyPointsEstimate} />}
</Box>
</Grid.Col>
<Grid.Col
Expand Down
40 changes: 0 additions & 40 deletions src/components/EpicDetailView/Components/StoryPointsHoverCard.tsx

This file was deleted.

60 changes: 23 additions & 37 deletions src/components/EpicDetailView/EpicDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ import {
inProgressAccumulator,
storyPointsAccumulator,
} from "./helpers/storyPointsHelper"
import { StoryPointsHoverCard } from "./Components/StoryPointsHoverCard";
import { StoryPointsHoverCard } from "../common/StoryPoints/StoryPointsHoverCard";
import { CommentSection } from "../DetailView/Components/CommentSection";
import { getIssueTypes, setStatus } from "../CreateIssue/queryFunctions";
import { StatusType } from "../../../types/status";
import { getStatusTypeColor } from "../../common/status-color"

export function EpicDetailView({
issueKey,
Expand Down Expand Up @@ -131,9 +133,10 @@ export function EpicDetailView({
},
})

const tasksOpen = inProgressAccumulator(childIssues, "To Do")
const tasksInProgress = inProgressAccumulator(childIssues, "In Progress")
const tasksDone = inProgressAccumulator(childIssues, "Done")
const tasksTodo = inProgressAccumulator(childIssues, StatusType.TODO)
const tasksInProgress = inProgressAccumulator(childIssues, StatusType.IN_PROGRESS)
const tasksDone = inProgressAccumulator(childIssues, StatusType.DONE)
const totalTaskCount = tasksTodo + tasksInProgress + tasksDone

useEffect(() => {
resizeDivider()
Expand Down Expand Up @@ -186,13 +189,6 @@ export function EpicDetailView({
radius="md"
size={20}
label="hello"
styles={{
label: {
color: "black",
fontSize: "14px",
fontWeight: "normal",
},
}}
sx={{
width: "400px",
marginRight: "5px",
Expand All @@ -201,56 +197,46 @@ export function EpicDetailView({
}}
sections={[
{
value:
(tasksDone / (tasksDone + tasksOpen + tasksInProgress)) *
100,
color: "#10df10",
value: (tasksDone / totalTaskCount) * 100,
color: getStatusTypeColor(StatusType.DONE),
label: `${tasksDone}`,
tooltip: `${tasksDone} Done`,
},
{
value:
(tasksInProgress /
(tasksDone + tasksOpen + tasksInProgress)) *
100,
color: "#6ba5d8",
value: (tasksInProgress / totalTaskCount) * 100,
color: getStatusTypeColor(StatusType.IN_PROGRESS),
label: `${tasksInProgress}`,
tooltip: `${tasksInProgress} In progress`,
},
{
value:
(tasksOpen / (tasksDone + tasksOpen + tasksInProgress)) *
100,
color: "rgb(225,223,223)",
label: `${tasksOpen}`,
tooltip: `${tasksOpen} ToDo`,
value: (tasksTodo / totalTaskCount) * 100,
color: getStatusTypeColor(StatusType.TODO),
label: `${tasksTodo}`,
tooltip: `${tasksTodo} ToDo`,
},
{
value: 100,
color: "rgb(225,223,223)",
color: getStatusTypeColor(StatusType.TODO),
label: `0`,
tooltip: "Currently no child issues",
},
]}
/>
<StoryPointsHoverCard
statusType="To Do"
color="gray.6"
count={storyPointsAccumulator(childIssues, "To Do")}
statusType={StatusType.TODO}
count={storyPointsAccumulator(childIssues, StatusType.TODO)}
/>
<StoryPointsHoverCard
statusType="In Progress"
color="blue.8"
count={storyPointsAccumulator(childIssues, "In Progress")}
statusType={StatusType.IN_PROGRESS}
count={storyPointsAccumulator(childIssues, StatusType.IN_PROGRESS)}
/>
<StoryPointsHoverCard
statusType="Done"
color="green.9"
count={storyPointsAccumulator(childIssues, "Done")}
statusType={StatusType.DONE}
count={storyPointsAccumulator(childIssues, StatusType.DONE)}
/>
</Group>

<Group sx={{ marginLeft: "-10px"}} grow>
<Group sx={{ marginLeft: "-10px" }} grow>
<ChildIssues issues={childIssues} />
</Group>
</Stack>
Expand Down
5 changes: 3 additions & 2 deletions src/components/EpicDetailView/helpers/storyPointsHelper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Issue } from "../../../../types"
import { StatusType } from "../../../../types/status";

export const storyPointsAccumulator = (issues: Issue[], status: string) =>
export const storyPointsAccumulator = (issues: Issue[], status: StatusType) =>
issues.reduce(
(accumulator, currentValue) => accumulator + (currentValue.status === status ? currentValue.storyPointsEstimate ?? 0 : 0) ?? 0,
0,
)

export const inProgressAccumulator = (issues: Issue[], status: string) =>
export const inProgressAccumulator = (issues: Issue[], status: StatusType) =>
issues.reduce(
(accumulator, currentValue) => accumulator + (currentValue.status === status ? 1 : 0),
0,
Expand Down
Loading