-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/13: schedule details on task cards
- Loading branch information
Showing
9 changed files
with
245 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from "react"; | ||
import * as models from "../../models"; | ||
import ScheduleIcon from "@mui/icons-material/Schedule"; | ||
import { Box, Typography } from "@mui/material"; | ||
import taskScheduleDueStatus from "../../utilities/taskScheduleDueStatus"; | ||
import taskScheduleOverDueStatus from "../../utilities/taskScheduleOverDueStatus"; | ||
import humanReadableScheduleString from "../../utilities/humanReadableScheduleString"; | ||
|
||
type TaskScheduleIconTextProps = { | ||
schedule?: models.Schedule | null; | ||
showWarning?: boolean; | ||
dueTime?: number; | ||
appendText?: string; | ||
smallText?: boolean; | ||
}; | ||
|
||
const TaskScheduleIconText: React.FC<TaskScheduleIconTextProps> = ({ | ||
schedule, | ||
showWarning = true, | ||
dueTime = 1, | ||
appendText = "", | ||
smallText = false, | ||
}) => { | ||
if (!schedule) return null; | ||
let iconColor = ""; | ||
if (showWarning) { | ||
if (taskScheduleDueStatus(schedule, dueTime)) { | ||
iconColor = "orange"; | ||
} | ||
if (taskScheduleOverDueStatus(schedule)) { | ||
iconColor = "red"; | ||
} | ||
} | ||
return ( | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
alignItems: "center", | ||
gap: 1, | ||
}} | ||
> | ||
<ScheduleIcon | ||
sx={{ color: iconColor }} | ||
fontSize={smallText ? "small" : undefined} | ||
/> | ||
<Typography | ||
sx={{ | ||
fontWeight: "bold", | ||
fontSize: smallText ? "0.9rem" : undefined, | ||
}} | ||
> | ||
{humanReadableScheduleString(schedule)}{" "} | ||
<span | ||
style={{ | ||
fontWeight: "normal", | ||
color: "gray", | ||
fontSize: "0.9rem", | ||
}} | ||
> | ||
{" "} | ||
{appendText} | ||
</span> | ||
</Typography> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default TaskScheduleIconText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as models from "../models"; | ||
import taskScheduleDueStatus from "./taskScheduleDueStatus"; | ||
|
||
describe("taskScheduleDueStatus", () => { | ||
const isoDate = "2021-01-01T12:00:58.987Z"; | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
jest.setSystemTime(new Date(isoDate)); | ||
}); | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
jest.useRealTimers(); | ||
}); | ||
test("should return false if [models.TimeRelation.ANYTIME, models.TimeRelation.AFTER].includes(schedule?.relation as models.TimeRelation)", () => { | ||
const schedule = new models.Schedule({ | ||
relation: models.TimeRelation.ANYTIME, | ||
}); | ||
const result = taskScheduleDueStatus(schedule); | ||
expect(result).toEqual(false); | ||
const schedule2 = new models.Schedule({ | ||
relation: models.TimeRelation.AFTER, | ||
}); | ||
const result2 = taskScheduleDueStatus(schedule2); | ||
expect(result2).toEqual(false); | ||
}); | ||
test("should return false if !schedule", () => { | ||
const schedule = null; | ||
const result = taskScheduleDueStatus(schedule); | ||
expect(result).toEqual(false); | ||
}); | ||
test("return true if due in the next hour", () => { | ||
const schedule = new models.Schedule({ | ||
relation: models.TimeRelation.BEFORE, | ||
date: "2021-01-01", | ||
time: "12:59:58.987Z", | ||
}); | ||
const result = taskScheduleDueStatus(schedule, 1); | ||
expect(result).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as models from "../models"; | ||
|
||
const taskScheduleDueStatus = ( | ||
schedule: models.Schedule | null, | ||
hours: number = 1 | ||
) => { | ||
debugger; | ||
if ( | ||
[models.TimeRelation.ANYTIME, models.TimeRelation.AFTER].includes( | ||
schedule?.relation as models.TimeRelation | ||
) | ||
) { | ||
return false; | ||
} | ||
if (!schedule) { | ||
return false; | ||
} | ||
const now = new Date(); | ||
const scheduleDate = new Date(schedule?.date ?? ""); | ||
scheduleDate.setUTCHours(parseInt(schedule.time?.split(":")[0] ?? "0")); | ||
scheduleDate.setUTCMinutes(parseInt(schedule.time?.split(":")[1] ?? "0")); | ||
scheduleDate.setUTCHours(scheduleDate.getUTCHours() - hours); | ||
|
||
if (scheduleDate < now) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export default taskScheduleDueStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as models from "../models"; | ||
import taskScheduleOverDueStatus from "./taskScheduleOverDueStatus"; | ||
|
||
describe("taskScheduleOverDueStatus", () => { | ||
it("should return false if [models.TimeRelation.ANYTIME, models.TimeRelation.AFTER].includes(schedule?.relation as models.TimeRelation)", () => { | ||
const schedule = new models.Schedule({ | ||
relation: models.TimeRelation.ANYTIME, | ||
}); | ||
const result = taskScheduleOverDueStatus(schedule); | ||
expect(result).toEqual(false); | ||
const schedule2 = new models.Schedule({ | ||
relation: models.TimeRelation.AFTER, | ||
}); | ||
const result2 = taskScheduleOverDueStatus(schedule2); | ||
expect(result2).toEqual(false); | ||
}); | ||
|
||
it("should return false if !schedule", () => { | ||
const schedule = null; | ||
const result = taskScheduleOverDueStatus(schedule); | ||
expect(result).toEqual(false); | ||
}); | ||
|
||
it("should return true if overdue", () => { | ||
const schedule = new models.Schedule({ | ||
relation: models.TimeRelation.BEFORE, | ||
date: "2022-01-01", | ||
time: "10:00", | ||
}); | ||
const result = taskScheduleOverDueStatus(schedule); | ||
expect(result).toEqual(true); | ||
}); | ||
it("should return false if not overdue", () => { | ||
const schedule = new models.Schedule({ | ||
relation: models.TimeRelation.BEFORE, | ||
date: "2199-01-01", | ||
time: "10:00", | ||
}); | ||
const result = taskScheduleOverDueStatus(schedule); | ||
expect(result).toEqual(false); | ||
}); | ||
}); |
Oops, something went wrong.