-
Notifications
You must be signed in to change notification settings - Fork 3
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
[timeline] fix display of unit above #142
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a551ddf
fix: 🐛 [Timeline] Fixed display for month unit
luciob 3f5415d
refactor: 💡 [Timeline] Currently switch back to start/end unit
luciob ea9a047
fix: 🐛 [Timeline] Print unit above of length = rowHeight
luciob 703f12c
refactor: 💡 [Timeline] Changed calculation of above blocks
luciob f67d077
fix: 🐛 [TimeLine] Fixed display of unit above
CrisGrud 1761c2c
Merge branch 'main' of https://github.com/melfore/konva-timeline into…
CrisGrud 02c81d9
fix: 🐛 [timeLine] fixed start interval for week unit
CrisGrud 6f7b7b0
fix: 🐛 [TimeLine] fixed display unitAbove when TZ change
CrisGrud d6f31e5
fix: 🐛 [TimeLine] Fixed display of visibleTimeBlock with Tz
CrisGrud 9e8d987
refactor: 💡 Code refactored
CrisGrud 982e645
refactor: 💡 Added type for HourInfo and DayInfo
CrisGrud a134be6
refactor: 💡 Code refacotring
CrisGrud def605c
refactor: 💡 Code refactoring
CrisGrud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import React, { memo } from "react"; | |
|
||
import { KonvaGroup } from "../../@konva"; | ||
import { useTimelineContext } from "../../timeline/TimelineContext"; | ||
import { daysInMonth, getMonth, getStartMonthsDay, getYear } from "../../utils/time-resolution"; | ||
import GridCell from "../Cell"; | ||
import GridCellGroup from "../CellGroup"; | ||
|
||
|
@@ -10,12 +11,36 @@ interface GridCellsProps { | |
} | ||
|
||
const GridCells = ({ height }: GridCellsProps) => { | ||
const { aboveTimeBlocks, visibleTimeBlocks } = useTimelineContext(); | ||
const { | ||
interval, | ||
aboveTimeBlocks, | ||
visibleTimeBlocks, | ||
resolution: { unitAbove }, | ||
} = useTimelineContext(); | ||
const dayInfo: { thisMonth?: number; untilNow?: number; backHour: boolean; forNowHour: boolean }[] = []; | ||
if (unitAbove === "month" || unitAbove === "day") { | ||
aboveTimeBlocks.forEach((column, index) => { | ||
const hrs = column.end!.diff(column.start!, "hour").hours; | ||
const month = getMonth(column); | ||
const year = getYear(column); | ||
const currentMonthDays = daysInMonth(Number(month), Number(year)); | ||
const bchour = hrs > 24 ? true : false; | ||
if (index === 0) { | ||
const startDay = getStartMonthsDay(interval.start!); | ||
const daysToMonthEnd = currentMonthDays - Number(startDay) + 1; | ||
dayInfo.push({ thisMonth: daysToMonthEnd, untilNow: daysToMonthEnd, backHour: bchour, forNowHour: false }); | ||
return; | ||
} | ||
const forNowHour = dayInfo[index - 1].forNowHour ? true : dayInfo[index - 1].backHour ? true : false; | ||
const n = dayInfo[index - 1].untilNow! + currentMonthDays; | ||
dayInfo.push({ thisMonth: currentMonthDays, untilNow: n, backHour: bchour, forNowHour: forNowHour }); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use a memo here if possible |
||
|
||
return ( | ||
<KonvaGroup> | ||
{aboveTimeBlocks.map((column, index) => ( | ||
<GridCellGroup key={`cell-group-${index}`} column={column} height={height} index={index} /> | ||
<GridCellGroup key={`cell-group-${index}`} column={column} index={index} dayInfo={dayInfo} /> | ||
))} | ||
{visibleTimeBlocks.map((column, index) => ( | ||
<GridCell key={`cell-${index}`} column={column} height={height} index={index} /> | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ import { DateTime, Interval } from "luxon"; | |
import { addHeaderResource } from "../resources/utils/resources"; | ||
import { filterTasks, TaskData, validateTasks } from "../tasks/utils/tasks"; | ||
import { DEFAULT_GRID_COLUMN_WIDTH, DEFAULT_GRID_ROW_HEIGHT, MINIMUM_GRID_ROW_HEIGHT } from "../utils/dimensions"; | ||
import { logDebug, logWarn } from "../utils/logger"; | ||
import { logDebug, logError, logWarn } from "../utils/logger"; | ||
import { getValidRangeTime, getValidTime, InternalTimeRange, isValidRangeTime } from "../utils/time"; | ||
import { getIntervalFromInternalTimeRange } from "../utils/time"; | ||
import { getResolutionData, Resolution, ResolutionData } from "../utils/time-resolution"; | ||
|
@@ -206,7 +206,25 @@ export const TimelineProvider = ({ | |
[interval, resolution] | ||
); | ||
|
||
const aboveTimeBlocks = useMemo(() => interval.splitBy({ [resolution.unitAbove]: 1 }), [interval, resolution]); | ||
const aboveTimeBlocks = useMemo(() => { | ||
const { unitAbove } = resolution; | ||
const blocks: Interval[] = []; | ||
const intervalStart = interval.start!; | ||
const intervalEnd = interval.end!; | ||
|
||
let blockStart = intervalStart; | ||
while (blockStart < intervalEnd) { | ||
let blockEnd = blockStart.endOf(unitAbove); | ||
if (blockEnd > intervalEnd) { | ||
blockEnd = intervalEnd; | ||
} | ||
|
||
logError("Adding Block", `${blockStart.toFormat("dd/MM/yy HH:mm")} > ${blockEnd.toFormat("dd/MM/yy HH:mm")}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
blocks.push(Interval.fromDateTimes(blockStart, blockEnd)); | ||
blockStart = blockEnd.startOf(unitAbove).plus({ [unitAbove]: 1 }); | ||
} | ||
return blocks; | ||
}, [interval, resolution]); | ||
|
||
const columnWidth = useMemo(() => { | ||
logDebug("TimelineProvider", "Calculating columnWidth..."); | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a type for this data structure