-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added resumeOrder to education entries
This comprises mainly some changes to `EducationForm` and `EducationDisplay`, but also some refactoring and some new tests to catch regressions on `EmploymentForm`: a bug relating to edit indices was found and fixed here.
- Loading branch information
1 parent
11299d2
commit 1e4646a
Showing
9 changed files
with
259 additions
and
60 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
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 |
---|---|---|
@@ -1,26 +1,35 @@ | ||
// @flow | ||
import moment from 'moment'; | ||
import _ from 'lodash'; | ||
|
||
import type { WorkHistoryEntry } from '../flow/profileTypes'; | ||
import type { WorkHistoryEntry, EducationEntry } from '../flow/profileTypes'; | ||
|
||
export function resumeOrder(entries: WorkHistoryEntry[], dateFieldName: string): WorkHistoryEntry[] { | ||
let sortFunc = (a, b) => { | ||
let adate = moment(a[dateFieldName]); | ||
let bdate = moment(b[dateFieldName]); | ||
if ( adate.isBefore(bdate) ) { | ||
return 1; | ||
} | ||
if ( adate.isAfter(bdate) ) { | ||
return -1; | ||
} | ||
return 0; | ||
export function momentCompareDesc(a: moment$Moment, b: moment$Moment): number { | ||
if ( a.isBefore(b) ) { | ||
return 1; | ||
} | ||
if ( a.isAfter(b) ) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
export function dateOrderDesc(entries: [number, Object][], dateFieldName: string): any { | ||
let clone = _.clone(entries); | ||
let sortFunc = ([, a], [, b]) => { | ||
return momentCompareDesc(moment(a[dateFieldName]), moment(b[dateFieldName])); | ||
}; | ||
return entries.sort(sortFunc); | ||
return clone.sort(sortFunc); | ||
} | ||
|
||
export function workEntriesByDate(entries: Array<WorkHistoryEntry>): Array<WorkHistoryEntry> { | ||
let tuples = entries.map((entry, index) => [index, entry]); | ||
let out = []; | ||
out.push(...dateOrderDesc(tuples.filter(([,entry]) => entry.end_date === null), 'start_date')); | ||
out.push(...dateOrderDesc(tuples.filter(([,entry]) => entry.end_date !== null), 'end_date')); | ||
return out; | ||
} | ||
|
||
export function sortWorkEntriesByDate(entries: Array<WorkHistoryEntry>): Array<WorkHistoryEntry> { | ||
let sorted = []; | ||
sorted.push(...resumeOrder(entries.filter(entry => entry.end_date === null), 'start_date')); | ||
sorted.push(...resumeOrder(entries.filter(entry => entry.end_date !== null), 'end_date')); | ||
return sorted; | ||
export function educationEntriesByDate(entries: Array<EducationEntry>): Array<EducationEntry> { | ||
return dateOrderDesc(entries.map((entry, index) => [index, entry]), 'graduation_date'); | ||
} |
Oops, something went wrong.