Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update special filter UI and create any/none/fuzzy query params #238

Merged
merged 21 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d8eb9c1
Update styling for all filter modal types
aswallace Sep 4, 2024
48333f8
Create new filter types and add redux logic
aswallace Sep 11, 2024
acf82e0
Update annotation filter form UI with new filter types and fuzzy search
aswallace Sep 11, 2024
e1e3786
Simplify empty file message
aswallace Sep 12, 2024
009bc03
Update file selection with new filter types
aswallace Sep 13, 2024
78d494e
Merge branch 'main' of github.com:AllenInstitute/aics-fms-file-explor…
aswallace Sep 13, 2024
8f19a76
Update unit tests and refactor duplicate code
aswallace Sep 13, 2024
3ef3afd
Temporarily undo empty list changes
aswallace Sep 13, 2024
67fa37c
Fix spacing issue
aswallace Sep 13, 2024
34ed706
Merge branch 'main' of github.com:AllenInstitute/aics-fms-file-explor…
aswallace Sep 16, 2024
9020dc5
Refactor slightly for clarity (hopefully)
aswallace Sep 16, 2024
69f2d81
Refactor annotation filter form to try to reduce duplicate code
aswallace Sep 18, 2024
1830a42
Fix variable names in unit test
aswallace Sep 18, 2024
181067e
Merge branch 'main' of github.com:AllenInstitute/aics-fms-file-explor…
aswallace Sep 25, 2024
e8adf10
Refactor by adding types to filter class
aswallace Sep 30, 2024
8b3a9f2
Remove unused entity type
aswallace Sep 30, 2024
87afdd8
Fix minor file selection bug
aswallace Sep 30, 2024
9ff7550
Simplify filter interactions
aswallace Sep 30, 2024
7b5729d
Remove unused reducers from state
aswallace Sep 30, 2024
e8dd8ff
Remove debugging code
aswallace Oct 2, 2024
d685394
Respond to PR feedback and add tests
aswallace Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
padding-bottom: 16px;
}

.choice-group {
margin-bottom: 6px;
}

.footer {
background-color: var(--primary-background-color);
padding: 16px 30px 16px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
.choice-group {
.toggle {
margin-bottom: 6px;
}

.choice-group input:disabled + label {
.toggle input:disabled + label {
cursor: not-allowed;
opacity: 0.5;
}

.choice-group :is(input, label, span) {
.toggle :is(input, label, span), .toggle-label {
color: var(--primary-text-color);
font-size: var(--l-paragraph-size);
font-weight: 500;
}

.choice-group label > span {
font-size: var(--xs-paragraph-size);
.toggle label:hover > span {
color: var(--highlight-text-color) !important;
}

.choice-group label:hover > span {
color: var(--highlight-text-color) !important;
.toggle-pill-off {
border-color: var(--border-color) !important;
background-color: unset !important;
}

.choice-group label::before, .choice-group label:hover::before {
background-color: var(--highlight-text-color);
border-color: var(--highlight-text-color);
.toggle-pill-off {
border-color: var(--border-color) !important;
}

.choice-group label::after {
background-color: var(--aqua);
border-color: var(--aqua);
.toggle-pill-off > span {
background-color: var(--border-color) !important;
}

.choice-group label:hover::after {
background-color: var(--bright-aqua) !important;
border-color: var(--bright-aqua) !important;
.toggle-pill-off:hover > span {
background-color: var(--primary-text-color) !important;
}

.choice-group > div > div {
display: flex;
.toggle-pill-on {
border: none !important;
background-color: var(--aqua) !important;
}

.choice-group > div > div > div:not(:first-child) {
margin-left: 6px;
.toggle-pill-on > span {
background-color: var(--highlight-hover-text-color) !important;
}

.container {
padding: 8px;
.toggle-pill-on:hover {
background-color: var(--dark-aqua) !important;
}

.list-picker {
padding: 0;
width: 100%;
.container {
padding: 8px;
}

.title {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Toggle } from "@fluentui/react";
import classNames from "classnames";
import * as React from "react";

import { ListItem } from "../../ListPicker/ListRow";
import SearchBox from "../../SearchBox";
import FileFilter from "../../../entity/FileFilter";
import FileFilter, { FilterType } from "../../../entity/FileFilter";

import styles from "./SearchBoxForm.module.css";

Expand All @@ -15,22 +16,44 @@ interface SearchBoxFormProps {
onDeselectAll: () => void;
onSelect?: (item: ListItem) => void;
onSelectAll: () => void;
onSearch: (filterValue: string) => void;
onSearch: (filterValue: string, type: FilterType) => void;
fieldName: string;
fuzzySearchEnabled?: boolean;
defaultValue: FileFilter | undefined;
}

/**
* This component renders a simple form for searching on text values
* with a toggle for exact vs fuzzy (non-exact) search matching
*/
export default function SearchBoxForm(props: SearchBoxFormProps) {
const [isFuzzySearching, setIsFuzzySearching] = React.useState(!!props?.fuzzySearchEnabled);

function onSearchSubmitted(value: string) {
props.onSearch(value, isFuzzySearching ? FilterType.FUZZY : FilterType.DEFAULT);
}

return (
<div className={classNames(props.className, styles.container)}>
<h3 className={styles.title}>{props.title}</h3>
<Toggle
label="Fuzzy search"
className={styles.toggle}
defaultChecked={isFuzzySearching}
onText="On"
inlineLabel
offText="Off"
onChange={(_, checked?) => setIsFuzzySearching(!!checked)}
title={`Turn ${isFuzzySearching ? "off" : "on"} fuzzy search (non-exact searching)`}
styles={{
label: styles.toggleLabel,
pill: isFuzzySearching ? styles.togglePillOn : styles.togglePillOff,
}}
/>
<SearchBox
defaultValue={props.defaultValue}
onReset={props.onDeselectAll}
onSearch={props.onSearch}
onSearch={onSearchSubmitted}
placeholder={"Search..."}
showSubmitButton={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,68 @@ import { render, fireEvent } from "@testing-library/react";
import { expect } from "chai";
import { noop } from "lodash";
import * as React from "react";
import sinon from "sinon";

import SearchBoxForm from "..";

describe("<SearchBoxForm/>", () => {
// TODO: Update with the fuzzy search toggle when filters are complete
it.skip("renders a list picker when 'List picker' option is selection", () => {
it("renders clickable fuzzy search toggle", () => {
// Arrange
const onSearch = sinon.spy();

const { getByText, getByRole } = render(
<SearchBoxForm
fieldName={"foo"}
onSelectAll={noop}
onDeselectAll={noop}
onSearch={onSearch}
defaultValue={undefined}
/>
);

// Consistency checks
expect(getByText("Off")).to.exist;
expect(onSearch.called).to.equal(false);

// Act
const { getByText, getByTestId } = render(
fireEvent.click(getByRole("switch"));
// Enter values
fireEvent.change(getByRole("searchbox"), {
target: {
value: "bar",
},
});
fireEvent.keyDown(getByRole("searchbox"), {
key: "Enter",
code: "Enter",
keyCode: 13,
charCode: 13,
});

// Assert
expect(getByText("On")).to.exist;
expect(onSearch.called).to.equal(true);
});

it("defaults to on when fuzzy searching prop is passed as true", () => {
// Arrange
const { getByText, getByRole } = render(
<SearchBoxForm
fieldName={"foo"}
onSelect={noop}
onSelectAll={noop}
onDeselect={noop}
onDeselectAll={noop}
items={[{ value: "foo", selected: false, displayValue: "foo" }]}
fuzzySearchEnabled={true}
onSearch={noop}
defaultValue={undefined}
/>
);
// Consistency check
expect(getByText("On")).to.exist;

// Sanity check
expect(() => getByTestId("list-picker")).to.throw();

// Select 'List picker' filter type
fireEvent.click(getByText("List picker"));
// Act
fireEvent.click(getByRole("switch"));

expect(() => getByTestId("list-picker")).to.not.throw();
// Assert
expect(getByText("Off")).to.exist;
});
});
Loading
Loading