-
Notifications
You must be signed in to change notification settings - Fork 642
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
feat(milestones):add dates to milestones section #6020
Changes from 3 commits
473d579
e1815fe
e0e689e
e4795b2
a4f6784
96043ea
2efce7d
e0693bd
bb4f8b3
f44f44e
2572a9b
034bfde
e644c96
9174b5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import createReactClass from 'create-react-class'; | |
import { filter } from 'lodash-es'; | ||
|
||
import CourseDateUtils from '../../utils/course_date_utils'; | ||
import DateCalculator from '../../utils/date_calculator'; | ||
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. Is this still needed? 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. Nope,I forgot to remove the DateCalculator. I'll go ahead and remove it now, sorry about that. |
||
|
||
const md = require('../../utils/markdown_it.js').default(); | ||
|
||
|
@@ -12,9 +13,11 @@ const Milestones = createReactClass({ | |
|
||
propTypes: { | ||
timelineStart: PropTypes.string.isRequired, | ||
timelineEnd: PropTypes.string.isRequired, | ||
weeks: PropTypes.array.isRequired, | ||
allWeeks: PropTypes.array.isRequired, | ||
course: PropTypes.object.isRequired | ||
course: PropTypes.object.isRequired, | ||
weekDates: PropTypes.array.isRequired | ||
}, | ||
|
||
milestoneBlockType: 2, | ||
|
@@ -28,19 +31,26 @@ const Milestones = createReactClass({ | |
const weekNumberOffset = CourseDateUtils.weeksBeforeTimeline(this.props.course); | ||
const blocks = []; | ||
|
||
this.props.allWeeks.map((week) => { | ||
|
||
this.props.allWeeks.map((week,navIndex) => { | ||
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. Where does this come from? In Timeline.jsx, it the result of some complex code in the render cycle for handling empty weeks. 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. The |
||
if (week.empty) return null; | ||
|
||
const milestoneBlocks = filter(week.blocks, block => block.kind === this.milestoneBlockType); | ||
return milestoneBlocks.map((block) => { | ||
if ( | ||
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. It looks we're doing something similar in both this component and the Timeline, checking for whether to map a particular block to 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. Actually, the problem I encountered is that in the selector, I needed the index for the weeks to display, so I used To handle this, when creating the const dateCalc = new DateCalculator(course.timeline_start, course.timeline_end, index, {
zeroIndexed: true
}); I found that the last indexes didn't have any dates, causing it to be empty when trying to render in the milestones and timeline. To fix this, I added a check for that in both files. |
||
!this.props.weekDates[navIndex]?.start || | ||
!this.props.weekDates[navIndex]?.end || | ||
this.props.weekDates[navIndex]?.start > this.props.weekDates[navIndex]?.end | ||
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. This is quite verbose, but it's not obvious what this if statement is for. What situation(s) for a block are being checked for here? 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. This check was added to prevent any date from showing after the timeline's end date in the milestone. 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. Hmm... I don't think that' necessary. The Timeline can handle dates that are after the end date (in which case, they get highlighted in red). I think in the Milestones component, it would be better to show dates that stretch beyond the end date, when that happens. 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. 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. I don't think any special formatting is needed in the Milestones component. 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. Yes, I have updated it. Could you please check it? |
||
) { | ||
return null; | ||
} | ||
let classNames = 'module__data'; | ||
if (this.weekIsCompleted(week, currentWeek)) { classNames += ' completed'; } | ||
const rawHtml = md.render(block.content || ''); | ||
const completionNote = this.weekIsCompleted(week, currentWeek) ? '- Complete' : undefined; | ||
return blocks.push( | ||
<div key={block.id} className="section-header"> | ||
<div className={classNames}> | ||
<p>Week {week.weekNumber + weekNumberOffset} {completionNote}</p> | ||
<p>Week {week.weekNumber + weekNumberOffset} ({this.props.weekDates[navIndex]?.start} - {this.props.weekDates[navIndex]?.end}) {completionNote}</p> | ||
<div className="markdown" dangerouslySetInnerHTML={{ __html: rawHtml }} /> | ||
<hr /> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,8 @@ const Timeline = createReactClass({ | |
editableTitles: PropTypes.bool, | ||
enableReorderable: PropTypes.func, | ||
enableEditTitles: PropTypes.func, | ||
current_user: PropTypes.object | ||
current_user: PropTypes.object, | ||
weekDates: PropTypes.array, | ||
}, | ||
|
||
getInitialState() { | ||
|
@@ -388,16 +389,24 @@ const Timeline = createReactClass({ | |
navClassName += ' is-current'; | ||
} | ||
|
||
const dateCalc = new DateCalculator(this.props.course.timeline_start, this.props.course.timeline_end, navIndex, { zeroIndexed: true }); | ||
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. If this was the only use of DateCalculator, it no longer needs to be imported in the file. |
||
const navWeekKey = `week-${navIndex}`; | ||
const navWeekLink = `#week-${navIndex + 1 + weeksBeforeTimeline}`; | ||
const startDate = this.props.weekDates[navIndex]?.start; | ||
const endDate = this.props.weekDates[navIndex]?.end; | ||
|
||
if ( | ||
!startDate || | ||
!endDate | ||
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. Why were these checks not necessary in the current implementation? |
||
) { | ||
return null; | ||
} | ||
|
||
// if using custom titles, show only titles, otherwise, show default titles and dates | ||
let navItem; | ||
if (usingCustomTitles) { | ||
let navTitle = ''; | ||
if (weekInfo.emptyWeek) { | ||
const datesStr = `${dateCalc.start()} - ${dateCalc.end()}`; | ||
const datesStr = `${startDate} - ${endDate}`; | ||
navTitle = I18n.t('timeline.week_number', { number: datesStr }); | ||
} else { | ||
navTitle = weekInfo.title ? weekInfo.title : I18n.t('timeline.week_number', { number: navIndex + 1 + weeksBeforeTimeline }); | ||
|
@@ -411,7 +420,7 @@ const Timeline = createReactClass({ | |
navItem = ( | ||
<li className={navClassName} key={navWeekKey}> | ||
<a href={navWeekLink}>{I18n.t('timeline.week_number', { number: navIndex + 1 + weeksBeforeTimeline })}</a> | ||
<span className="pull-right">{dateCalc.start()} - {dateCalc.end()}</span> | ||
<span className="pull-right">{startDate} - {endDate}</span> | ||
</li> | ||
); | ||
} | ||
|
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.
Please remove this.