Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EshaanAgg committed Mar 2, 2024
2 parents a98f8ca + 2217e9f commit d364436
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 77 deletions.
2 changes: 1 addition & 1 deletion benchexec/tablegenerator/react-table/build/main.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TaskFilterCard from "./TaskFilterCard";
import { faClose, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import equals from "deep-equal";
import { isNil } from "../../utils/utils";
import { decodeFilter, isNil } from "../../utils/utils";
const classNames = require("classnames");

export default class FilterBox extends React.PureComponent {
Expand Down Expand Up @@ -70,12 +70,12 @@ export default class FilterBox extends React.PureComponent {
if (id === "id") {
continue;
}
const [tool, title, col] = id.split("_");
const { tool, name: title, column } = decodeFilter(id);
const toolArr = out[tool] || [];
if (!toolArr[col]) {
toolArr[col] = { title, values: [value] };
if (!toolArr[column]) {
toolArr[column] = { title, values: [value] };
} else {
toolArr[col].values.push(value);
toolArr[column].values.push(value);
}
out[tool] = toolArr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
setHashSearch,
getHashSearch,
getHiddenColIds,
decodeFilter,
} from "../utils/utils";
import deepEqual from "deep-equal";
import { statusForEmptyRows } from "../utils/filters";
Expand Down Expand Up @@ -168,7 +169,7 @@ const Table = (props) => {
let additionalFilters = [];

if (newFilter.type === "status") {
const [tool, name, column] = newFilter.id.split("_");
const { tool, name, column } = decodeFilter(newFilter.id);
const value = newFilter.value;

if (value.trim() === "all") {
Expand Down Expand Up @@ -629,7 +630,7 @@ const Table = (props) => {
if (id === "id") {
setDisableTaskText(!isNil(values));
}
const [runset, , column] = id.split("_");
const { tool: runset, column } = decodeFilter(id);
const currentRunsetFilters = newFilteredColumnValues[runset] || {};

const isCategory =
Expand Down
75 changes: 9 additions & 66 deletions benchexec/tablegenerator/react-table/src/tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
makeFilterSerializer,
makeFilterDeserializer,
splitUrlPathForMatchingPrefix,
decodeFilter,
} from "../utils/utils";

describe("isStatusOk", () => {
Expand Down Expand Up @@ -107,75 +108,17 @@ describe("hashRouting helpers", () => {
});
});

describe("constructQueryString", () => {
test("should return empty string for empty input", () => {
const queryString = constructQueryString({});
expect(queryString).toBe("");
});

test("should construct query string properly", () => {
const params = { key1: "value1", key2: "value2" };
const queryString = constructQueryString(params);
expect(queryString).toBe("key1=value1&key2=value2");
});

test("should omit undefined and null values", () => {
const params = { key1: "value1", key2: undefined, key3: null };
const queryString = constructQueryString(params);
expect(queryString).toBe("key1=value1");
describe("setHashSearch", () => {
test("should translate object to queryparams", () => {
const params = { id: "1", name: "benchexec" };
const res = setHashSearch(params, {
returnString: true,
baseUrl: "localhost#table",
});
expect(res).toEqual("localhost#table?id=1&name=benchexec");
});
});

// describe("setHashSearch", () => {
// test("should set hash search without side effects", () => {
// const params = { key1: "value1", key2: "value2" };
// const queryString = constructQueryString(params);
// const hrefString = `http://localhost/?${queryString}`;

// const updatedUrl = setHashSearch(params, { returnString: true });
// expect(updatedUrl).toBe(hrefString);
// });

// test("should set hash search and update history", () => {
// const params = { key1: "value1", key2: "value2" };
// const queryString = constructQueryString(params);
// const hrefString = `http://localhost/?${queryString}`;

// const mockHistory = {
// push: jest.fn(),
// };

// setHashSearch(params, { history: mockHistory });
// expect(mockHistory.push).toHaveBeenCalledWith(hrefString);
// });

// test("should merge params with existing ones if keepOthers is true", () => {
// const params = { key1: "value1", key2: "value2" };
// const queryString = constructQueryString({
// ...params,
// existingKey: "existingValue",
// });
// const hrefString = `http://localhost/?${queryString}`;

// const updatedUrl = setHashSearch(params, {
// keepOthers: true,
// returnString: true,
// });
// expect(updatedUrl).toBe(hrefString);
// });

// test("should use the baseUrl if provided", () => {
// const params = { key1: "value1", key2: "value2" };
// const baseUrl = "http://customurl.com";
// const queryString = constructQueryString(params);
// const hrefString = `${baseUrl}?${queryString}`;

// const updatedUrl = setHashSearch(params, { baseUrl, returnString: true });
// expect(updatedUrl).toBe(hrefString);
// });
// });
});

describe("serialization", () => {
let serializer;
const statusValues = [
Expand Down
10 changes: 8 additions & 2 deletions benchexec/tablegenerator/react-table/src/utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
//
// SPDX-License-Identifier: Apache-2.0

import { isNil, getRawOrDefault, omit, isNumericColumn } from "./utils";
import {
isNil,
getRawOrDefault,
omit,
isNumericColumn,
decodeFilter,
} from "./utils";
/* Status that will be used to identify whether empty rows should be shown. Currently,
filtering for either categories or statuses creates filters for the other one as well.
Since empty rows don't have a status, they will be filtered out all the time.
Expand Down Expand Up @@ -158,7 +164,7 @@ const buildMatcher = (filters) => {
acc.id = { value, values };
return acc;
}
const [tool, , columnIdx] = id.split("_");
const { tool, column: columnIdx } = decodeFilter(id);
if (value === "diff") {
// this branch is noop as of now
if (!acc.diff) {
Expand Down
18 changes: 17 additions & 1 deletion benchexec/tablegenerator/react-table/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,22 @@ function makeStatusColumnFilter(
return statusColumnFilter.join(",");
}

/**
* Function to decode a filter ID string from the URL into its parts
* @param {String} filterID - The filter ID to be decoded
* @returns {Object} The decoded filter ID
* @throws {Error} If the filter ID is invalid
*/
export const decodeFilter = (filterID) => {
const splitedArray = filterID.split("_");
if (splitedArray.length !== 3) throw new Error("Invalid filter ID");
return {
tool: splitedArray[0],
name: splitedArray[1],
column: splitedArray[2],
};
};

const makeFilterSerializer =
({ statusValues: allStatusValues, categoryValues: allCategoryValues }) =>
(filter) => {
Expand All @@ -376,7 +392,7 @@ const makeFilterSerializer =
}
continue;
}
const [tool, name, column] = id.split("_");
const { tool, name, column } = decodeFilter(id);
const toolBucket = groupedFilters[tool] || {};
const columnBucket = toolBucket[column] || { name: escape(name) };

Expand Down

0 comments on commit d364436

Please sign in to comment.