Skip to content

Commit

Permalink
chore: remove unneeded nodes utils (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov authored Dec 6, 2024
1 parent 26d00e9 commit 1d250e8
Showing 1 changed file with 0 additions and 49 deletions.
49 changes: 0 additions & 49 deletions src/store/reducers/nodes/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
import {EFlag} from '../../../types/api/enums';
import {HOUR_IN_SECONDS} from '../../../utils/constants';
import {calcUptimeInSeconds} from '../../../utils/dataFormatters/dataFormatters';
import {prepareSearchValue} from '../../../utils/filters';
import {NodesUptimeFilterValues} from '../../../utils/nodes';
import {ProblemFilterValues} from '../settings/settings';
import type {ProblemFilterValue} from '../settings/types';

import type {NodesPreparedEntity} from './types';

// ==== Filters ====

const filterNodesByProblemsStatus = (
nodesList: NodesPreparedEntity[] = [],
problemFilter: ProblemFilterValue,
) => {
if (problemFilter === ProblemFilterValues.ALL) {
return nodesList;
}

return nodesList.filter(({SystemState}) => {
return SystemState && SystemState !== EFlag.Green;
});
};

export const filterNodesByUptime = <T extends {StartTime?: string}>(
nodesList: T[] = [],
nodesUptimeFilter: NodesUptimeFilterValues,
Expand All @@ -34,33 +15,3 @@ export const filterNodesByUptime = <T extends {StartTime?: string}>(
return !StartTime || calcUptimeInSeconds(StartTime) < HOUR_IN_SECONDS;
});
};

const filterNodesBySearchValue = (nodesList: NodesPreparedEntity[] = [], searchValue: string) => {
if (!searchValue) {
return nodesList;
}
const re = prepareSearchValue(searchValue);

return nodesList.filter((node) => {
return node.Host ? re.test(node.Host) || re.test(String(node.NodeId)) : true;
});
};

export function filterNodes(
nodesList: NodesPreparedEntity[] = [],
{
uptimeFilter,
searchValue,
problemFilter,
}: {
uptimeFilter: NodesUptimeFilterValues;
searchValue: string;
problemFilter: ProblemFilterValue;
},
) {
let result = filterNodesByUptime(nodesList, uptimeFilter);
result = filterNodesByProblemsStatus(result, problemFilter);
result = filterNodesBySearchValue(result, searchValue);

return result;
}

0 comments on commit 1d250e8

Please sign in to comment.