mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
85a7c55fdf
This PR adds support for projects as a first class citizen, and toggling features on in different environments.
88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
import { useState } from 'react';
|
|
import {
|
|
sortFeaturesByNameAscending,
|
|
sortFeaturesByNameDescending,
|
|
sortFeaturesByLastSeenAscending,
|
|
sortFeaturesByLastSeenDescending,
|
|
sortFeaturesByCreatedAtAscending,
|
|
sortFeaturesByCreatedAtDescending,
|
|
sortFeaturesByExpiredAtAscending,
|
|
sortFeaturesByExpiredAtDescending,
|
|
sortFeaturesByStatusAscending,
|
|
sortFeaturesByStatusDescending,
|
|
} from '../component/Reporting/utils';
|
|
|
|
import {
|
|
LAST_SEEN,
|
|
NAME,
|
|
CREATED,
|
|
EXPIRED,
|
|
STATUS,
|
|
REPORT,
|
|
} from '../component/Reporting/constants';
|
|
|
|
const useSort = () => {
|
|
const [sortData, setSortData] = useState({
|
|
sortKey: NAME,
|
|
ascending: true,
|
|
});
|
|
|
|
const handleSortName = features => {
|
|
if (sortData.ascending) {
|
|
return sortFeaturesByNameAscending(features);
|
|
}
|
|
|
|
return sortFeaturesByNameDescending(features);
|
|
};
|
|
|
|
const handleSortLastSeen = features => {
|
|
if (sortData.ascending) {
|
|
return sortFeaturesByLastSeenAscending(features);
|
|
}
|
|
return sortFeaturesByLastSeenDescending(features);
|
|
};
|
|
|
|
const handleSortCreatedAt = features => {
|
|
if (sortData.ascending) {
|
|
return sortFeaturesByCreatedAtAscending(features);
|
|
}
|
|
return sortFeaturesByCreatedAtDescending(features);
|
|
};
|
|
|
|
const handleSortExpiredAt = features => {
|
|
if (sortData.ascending) {
|
|
return sortFeaturesByExpiredAtAscending(features);
|
|
}
|
|
return sortFeaturesByExpiredAtDescending(features);
|
|
};
|
|
|
|
const handleSortStatus = features => {
|
|
if (sortData.ascending) {
|
|
return sortFeaturesByStatusAscending(features);
|
|
}
|
|
return sortFeaturesByStatusDescending(features);
|
|
};
|
|
|
|
const sort = features => {
|
|
switch (sortData.sortKey) {
|
|
case NAME:
|
|
return handleSortName(features);
|
|
case LAST_SEEN:
|
|
return handleSortLastSeen(features);
|
|
case CREATED:
|
|
return handleSortCreatedAt(features);
|
|
case EXPIRED:
|
|
case REPORT:
|
|
return handleSortExpiredAt(features);
|
|
case STATUS:
|
|
return handleSortStatus(features);
|
|
default:
|
|
return features;
|
|
}
|
|
};
|
|
|
|
return [sort, setSortData];
|
|
};
|
|
|
|
export default useSort;
|