CEC-5150: search on fleets in bulk action (#454)

* CEC-5150: search on fleets in bulk action

* add deps

* add deps

* sonar

* sonar

* break out fetch
This commit is contained in:
Tristan Timblin
2023-10-02 13:11:48 -07:00
committed by GitHub
parent 8d867a7a1e
commit f4d45abfca
8 changed files with 127 additions and 64 deletions

13
src/utils/truncateCSV.js Normal file
View File

@@ -0,0 +1,13 @@
export default function truncateCSV(strings = [], max = Infinity) {
const count = strings.length;
if (max === 0) {
return `${count}`;
}
if (count <= max) {
return strings.join(", ");
}
return `${strings.slice(0, max).join(", ")}, +${count - max} more`;
}

View File

@@ -0,0 +1,18 @@
import truncateCSV from "./truncateCSV";
const tests = [
[["ocean", "pear", "ronin", "alaska"], 4, "ocean, pear, ronin, alaska"],
[["ocean", "pear", "ronin", "alaska"], 3, "ocean, pear, ronin, +1 more"],
[["ocean", "pear", "ronin", "alaska"], 2, "ocean, pear, +2 more"],
[["ocean", "pear", "ronin", "alaska"], 0, "4"],
[["ocean", "pear", "ronin", "alaska"], 6, "ocean, pear, ronin, alaska"],
[["ocean", "pear", "ronin", "alaska"], Infinity, "ocean, pear, ronin, alaska"],
];
describe("truncateCSV", () => {
it("properly concatenates", () => {
tests.forEach(([strings, max, expected]) => {
expect(truncateCSV(strings, max)).toBe(expected);
});
});
});