Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9bebe42c
Commit
9bebe42c
authored
Mar 15, 2019
by
Rajat Jain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split sortEpics into assignDates method
parent
2e8d75f3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
34 deletions
+151
-34
ee/app/assets/javascripts/roadmap/constants.js
ee/app/assets/javascripts/roadmap/constants.js
+4
-0
ee/app/assets/javascripts/roadmap/utils/roadmap_utils.js
ee/app/assets/javascripts/roadmap/utils/roadmap_utils.js
+35
-34
ee/spec/javascripts/roadmap/utils/roadmap_utils_spec.js
ee/spec/javascripts/roadmap/utils/roadmap_utils_spec.js
+112
-0
No files found.
ee/app/assets/javascripts/roadmap/constants.js
View file @
9bebe42c
...
...
@@ -42,3 +42,7 @@ export const PRESET_DEFAULTS = {
TIMEFRAME_LENGTH
:
7
,
},
};
export
const
PAST_DATE
=
new
Date
(
new
Date
().
getFullYear
()
-
100
,
0
,
1
);
export
const
FUTURE_DATE
=
new
Date
(
new
Date
().
getFullYear
()
+
100
,
0
,
1
);
ee/app/assets/javascripts/roadmap/utils/roadmap_utils.js
View file @
9bebe42c
...
...
@@ -6,6 +6,8 @@ import {
EXTEND_AS
,
TIMELINE_CELL_MIN_WIDTH
,
DAYS_IN_WEEK
,
PAST_DATE
,
FUTURE_DATE
,
}
from
'
../constants
'
;
const
monthsForQuarters
=
{
...
...
@@ -408,45 +410,44 @@ export const getEpicsPathForPreset = ({
return
epicsPath
;
};
export
const
sortEpics
=
(
epics
,
sortedBy
)
=>
{
const
sortByStartDate
=
sortedBy
.
indexOf
(
'
start_date
'
)
>
-
1
;
const
sortOrderAsc
=
sortedBy
.
indexOf
(
'
asc
'
)
>
-
1
;
const
pastDate
=
new
Date
(
new
Date
().
getFullYear
()
-
100
,
0
,
1
);
const
futureDate
=
new
Date
(
new
Date
().
getFullYear
()
+
100
,
0
,
1
);
epics
.
sort
((
a
,
b
)
=>
{
/**
* This function takes two epics and return sortable dates depending on the '
* type of sorting order -- startDate or endDate.
*/
export
function
assignDates
(
a
,
b
,
{
dateUndefined
,
outOfRange
,
originalDate
,
date
,
proxyDate
})
{
let
aDate
;
let
bDate
;
if
(
sortByStartDate
)
{
if
(
a
.
startDateUndefined
)
{
// Set proxy date to be far in the past
// to ensure sort order is
correct.
aDate
=
past
Date
;
if
(
a
[
dateUndefined
]
)
{
// Set proxy date to be either far in the past or
// far in the future to ensure sort order is
//
correct.
aDate
=
proxy
Date
;
}
else
{
aDate
=
a
.
startDateOutOfRange
?
a
.
originalStartDate
:
a
.
startDate
;
aDate
=
a
[
outOfRange
]
?
a
[
originalDate
]
:
a
[
date
]
;
}
if
(
b
.
startDateUndefined
)
{
bDate
=
pastDate
;
}
else
{
bDate
=
b
.
startDateOutOfRange
?
b
.
originalStartDate
:
b
.
startDate
;
}
}
else
{
if
(
a
.
endDateUndefined
)
{
// Set proxy date to be far into the future
// to ensure sort order is correct.
aDate
=
futureDate
;
if
(
b
[
dateUndefined
])
{
bDate
=
proxyDate
;
}
else
{
aDate
=
a
.
endDateOutOfRange
?
a
.
originalEndDate
:
a
.
endDate
;
bDate
=
b
[
outOfRange
]
?
b
[
originalDate
]
:
b
[
date
]
;
}
if
(
b
.
endDateUndefined
)
{
bDate
=
futureDate
;
}
else
{
bDate
=
b
.
endDateOutOfRange
?
b
.
originalEndDate
:
b
.
endDate
;
}
}
return
[
aDate
,
bDate
];
}
export
const
sortEpics
=
(
epics
,
sortedBy
)
=>
{
const
sortByStartDate
=
sortedBy
.
indexOf
(
'
start_date
'
)
>
-
1
;
const
sortOrderAsc
=
sortedBy
.
indexOf
(
'
asc
'
)
>
-
1
;
epics
.
sort
((
a
,
b
)
=>
{
const
[
aDate
,
bDate
]
=
assignDates
(
a
,
b
,
{
dateUndefined
:
sortByStartDate
?
'
startDateUndefined
'
:
'
endDateUndefined
'
,
outOfRange
:
sortByStartDate
?
'
startDateOutOfRange
'
:
'
endDateOutOfRange
'
,
originalDate
:
sortByStartDate
?
'
originalStartDate
'
:
'
originalEndDate
'
,
date
:
sortByStartDate
?
'
startDate
'
:
'
endDate
'
,
proxyDate
:
sortByStartDate
?
PAST_DATE
:
FUTURE_DATE
,
});
// Sort in ascending or descending order
if
(
aDate
.
getTime
()
<
bDate
.
getTime
())
{
...
...
ee/spec/javascripts/roadmap/utils/roadmap_utils_spec.js
View file @
9bebe42c
...
...
@@ -8,6 +8,7 @@ import {
extendTimeframeForAvailableWidth
,
getEpicsPathForPreset
,
sortEpics
,
assignDates
,
}
from
'
ee/roadmap/utils/roadmap_utils
'
;
import
{
PRESET_TYPES
}
from
'
ee/roadmap/constants
'
;
...
...
@@ -434,3 +435,114 @@ describe('sortEpics', () => {
});
});
});
describe
(
'
assignDates
'
,
()
=>
{
const
startDateProps
=
{
dateUndefined
:
'
startDateUndefined
'
,
outOfRange
:
'
startDateOutOfRange
'
,
originalDate
:
'
originalStartDate
'
,
date
:
'
startDate
'
,
proxyDate
:
new
Date
(
'
1900
'
),
};
const
endDateProps
=
{
dateUndefined
:
'
endDateUndefined
'
,
outOfRange
:
'
endDateOutOfRange
'
,
originalDate
:
'
originalEndDate
'
,
date
:
'
endDate
'
,
proxyDate
:
new
Date
(
'
2200
'
),
};
it
(
'
returns proxyDate if startDate is undefined
'
,
()
=>
{
const
epic1
=
{
startDateUndefined
:
true
};
const
epic2
=
{
startDateUndefined
:
false
};
let
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
startDateProps
);
expect
(
aDate
).
toEqual
(
startDateProps
.
proxyDate
);
expect
(
bDate
).
not
.
toEqual
(
startDateProps
.
proxyDate
);
epic1
.
startDateUndefined
=
false
;
epic2
.
startDateUndefined
=
true
;
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
startDateProps
);
expect
(
aDate
).
not
.
toEqual
(
startDateProps
.
proxyDate
);
expect
(
bDate
).
toEqual
(
startDateProps
.
proxyDate
);
});
it
(
'
returns proxyDate if endDate is undefined
'
,
()
=>
{
const
epic1
=
{
endDateUndefined
:
true
};
const
epic2
=
{
endDateUndefined
:
false
};
let
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
endDateProps
);
expect
(
aDate
).
toEqual
(
endDateProps
.
proxyDate
);
expect
(
bDate
).
not
.
toEqual
(
endDateProps
.
proxyDate
);
epic1
.
endDateUndefined
=
false
;
epic2
.
endDateUndefined
=
true
;
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
endDateProps
);
expect
(
aDate
).
not
.
toEqual
(
endDateProps
.
proxyDate
);
expect
(
bDate
).
toEqual
(
endDateProps
.
proxyDate
);
});
it
(
'
assigns originalStartDate if date is out of range
'
,
()
=>
{
const
epic1
=
{
startDateUndefined
:
false
,
originalStartDate
:
new
Date
(
'
2000
'
),
startDate
:
new
Date
(
'
2010
'
),
startDateOutOfRange
:
true
,
};
const
epic2
=
{
...
epic1
,
originalStartDate
:
new
Date
(
'
2005
'
)
};
const
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
startDateProps
);
expect
(
aDate
).
toEqual
(
epic1
.
originalStartDate
);
expect
(
bDate
).
toEqual
(
epic2
.
originalStartDate
);
});
it
(
'
assigns originalEndDate if date is out of range
'
,
()
=>
{
const
epic1
=
{
endDateUndefined
:
false
,
originalEndDate
:
new
Date
(
'
2000
'
),
endDate
:
new
Date
(
'
2010
'
),
endDateOutOfRange
:
true
,
};
const
epic2
=
{
...
epic1
,
originalEndDate
:
new
Date
(
'
2005
'
)
};
const
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
endDateProps
);
expect
(
aDate
).
toEqual
(
epic1
.
originalEndDate
);
expect
(
bDate
).
toEqual
(
epic2
.
originalEndDate
);
});
it
(
'
assigns startDate if date is in the range
'
,
()
=>
{
const
epic1
=
{
startDateUndefined
:
false
,
originalStartDate
:
new
Date
(
'
2000
'
),
startDate
:
new
Date
(
'
2010
'
),
startDateOutOfRange
:
false
,
};
const
epic2
=
{
...
epic1
,
startDate
:
new
Date
(
'
2005
'
)
};
const
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
startDateProps
);
expect
(
aDate
).
toEqual
(
epic1
.
startDate
);
expect
(
bDate
).
toEqual
(
epic2
.
startDate
);
});
it
(
'
assigns endDate if date is in the range
'
,
()
=>
{
const
epic1
=
{
endDateUndefined
:
false
,
originalEndDate
:
new
Date
(
'
2000
'
),
endDate
:
new
Date
(
'
2010
'
),
endDateOutOfRange
:
false
,
};
const
epic2
=
{
...
epic1
,
endDate
:
new
Date
(
'
2005
'
)
};
const
[
aDate
,
bDate
]
=
assignDates
(
epic1
,
epic2
,
endDateProps
);
expect
(
aDate
).
toEqual
(
epic1
.
endDate
);
expect
(
bDate
).
toEqual
(
epic2
.
endDate
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment