mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
fix: add ascending sorting (#260)
This commit is contained in:
parent
980dfcefcb
commit
30ba213f07
@ -97,8 +97,39 @@ export const sortFeaturesByExpiredAtAscending = features => {
|
|||||||
const diffA = getDiffInDays(dateA, now);
|
const diffA = getDiffInDays(dateA, now);
|
||||||
const diffB = getDiffInDays(dateB, now);
|
const diffB = getDiffInDays(dateB, now);
|
||||||
|
|
||||||
if (!expired(diffA, a.type)) return -1;
|
if (!expired(diffA, a.type) && expired(diffB, b.type)) {
|
||||||
if (!expired(diffB, b.type)) return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expired(diffA, a.type) && !expired(diffB, b.type)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const expiredByA = diffA - toggleExpiryByTypeMap[a.type];
|
||||||
|
const expiredByB = diffB - toggleExpiryByTypeMap[b.type];
|
||||||
|
|
||||||
|
return expiredByB - expiredByA;
|
||||||
|
});
|
||||||
|
return sorted;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sortFeaturesByExpiredAtDescending = features => {
|
||||||
|
const sorted = [...features];
|
||||||
|
const now = new Date();
|
||||||
|
sorted.sort((a, b) => {
|
||||||
|
const dateA = parseISO(a.createdAt);
|
||||||
|
const dateB = parseISO(b.createdAt);
|
||||||
|
|
||||||
|
const diffA = getDiffInDays(dateA, now);
|
||||||
|
const diffB = getDiffInDays(dateB, now);
|
||||||
|
|
||||||
|
if (!expired(diffA, a.type) && expired(diffB, b.type)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expired(diffA, a.type) && !expired(diffB, b.type)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
const expiredByA = diffA - toggleExpiryByTypeMap[a.type];
|
const expiredByA = diffA - toggleExpiryByTypeMap[a.type];
|
||||||
const expiredByB = diffB - toggleExpiryByTypeMap[b.type];
|
const expiredByB = diffB - toggleExpiryByTypeMap[b.type];
|
||||||
@ -108,8 +139,6 @@ export const sortFeaturesByExpiredAtAscending = features => {
|
|||||||
return sorted;
|
return sorted;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sortFeaturesByExpiredAtDescending = features => sortFeaturesByExpiredAtAscending([...features]).reverse();
|
|
||||||
|
|
||||||
export const sortFeaturesByStatusAscending = features => {
|
export const sortFeaturesByStatusAscending = features => {
|
||||||
const sorted = [...features];
|
const sorted = [...features];
|
||||||
sorted.sort((a, b) => {
|
sorted.sort((a, b) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user