Skip to content

Commit

Permalink
fix: remove unnecessary & unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnflank committed Sep 20, 2021
1 parent 291fae3 commit facd0fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 49 deletions.
20 changes: 9 additions & 11 deletions src/components/Canary/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ export function aggregate(title, items) {
};
}

export const getAggregatedGroupedChecks = (groupedChecks) => {
const groupKeys = Object.keys(groupedChecks);
const aggregated = groupKeys.map((key) => {
const aggr = aggregate(key, groupedChecks[key]);
aggr.groupKey = key;
aggr.subRows = groupedChecks[key];
return aggr;
});

return aggregated;
};
export const getAggregatedGroupedChecks = (groupedChecks) =>
Object.entries(groupedChecks).reduce((acc, [k, v]) => {
acc[k] = {
...aggregate(k, v),
subRows: v,
name: k
};
return acc;
}, {});
38 changes: 0 additions & 38 deletions src/components/Canary/sorting.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getAggregatedGroupedChecks } from "./aggregate";

export const sortValues = ["none", "asc", "desc"];

export const getHealthPercentageScore = (check) => {
Expand Down Expand Up @@ -31,39 +29,3 @@ export const getLatency = (check) => {
}
return Number.POSITIVE_INFINITY;
};

// sorting functions for each of the columns
export const sortingFunctions = {
check: (a, b) =>
a.description === b.description
? 0
: a.description > b.description
? 1
: -1,
health: (a, b) => getHealthPercentageScore(b) - getHealthPercentageScore(a),
uptime: (a, b) => getUptimeScore(b) - getUptimeScore(a),
latency: (a, b) => getLatency(a) - getLatency(b)
};

// sort checks based on a column's sorting function
export const sortChecks = (checks, sortFunc, sortDirection) => {
let newChecks = [...checks];
newChecks = newChecks.sort(sortingFunctions[sortFunc]);
if (sortDirection === "desc") {
newChecks = newChecks.reverse();
}
return newChecks;
};

// sorts aggregated groupedChecks based on a sorting function
// returns a sorted string array (of group key names).
export const sortGroupedChecks = (groupedChecks, sortFunc, sortDirection) => {
let aggregated = getAggregatedGroupedChecks(groupedChecks);
// perform sorting based on aggregated values
aggregated = aggregated.sort(sortingFunctions[sortFunc]);
let sortedKeys = aggregated.map((group) => group.groupKey);
if (sortDirection === "desc") {
sortedKeys = sortedKeys.reverse();
}
return sortedKeys;
};

0 comments on commit facd0fb

Please sign in to comment.