Skip to content

Commit

Permalink
Respond to PR feedback and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aswallace committed Oct 2, 2024
1 parent e8dd8ff commit d685394
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/core/components/AnnotationFilterForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ export default function AnnotationFilterForm(props: AnnotationFilterFormProps) {
annotationService
);

const fuzzySearchEnabled = React.useMemo(() => {
return !!fuzzyFilters?.some((filter) => filter.name === props.annotation.name);
}, [fuzzyFilters, props.annotation]);
const fuzzySearchEnabled = React.useMemo(
() => !!fuzzyFilters?.some((filter) => filter.name === props.annotation.name),
[fuzzyFilters, props.annotation]
);

const filtersForAnnotation = React.useMemo(
() => allFilters.filter((filter) => filter.name === props.annotation.name),
[allFilters, props.annotation]
);

// Assume all filters use same type
const defaultFilterType = React.useMemo(() => {
return filtersForAnnotation?.[0]?.type ?? FilterType.DEFAULT;
}, [filtersForAnnotation]);
const defaultFilterType = React.useMemo(
() => filtersForAnnotation?.[0]?.type ?? FilterType.DEFAULT,
[filtersForAnnotation]
);

const [filterType, setFilterType] = React.useState<FilterType>(defaultFilterType);

Expand Down Expand Up @@ -96,7 +98,7 @@ export default function AnnotationFilterForm(props: AnnotationFilterFormProps) {
);
};

const _onFilterTypeOptionChange = (option: IChoiceGroupOption | undefined) => {
const onFilterTypeOptionChange = (option: IChoiceGroupOption | undefined) => {
// Verify that filter type is changing to avoid dispatching unnecessary clean-up actions
if (!!option?.key && option?.key !== filterType) {
setFilterType(option.key as FilterType);
Expand Down Expand Up @@ -230,7 +232,7 @@ export default function AnnotationFilterForm(props: AnnotationFilterFormProps) {
text: "No value (blank)",
},
]}
onChange={(_, option) => _onFilterTypeOptionChange(option)}
onChange={(_, option) => onFilterTypeOptionChange(option)}
/>
</div>
{filterType === FilterType.DEFAULT || filterType === FilterType.FUZZY ? (
Expand Down
76 changes: 76 additions & 0 deletions packages/core/entity/FileFilter/test/FileFilter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { expect } from "chai";

import FileFilter, { FilterType } from "../";
import IncludeFilter from "../IncludeFilter";
import ExcludeFilter from "../ExcludeFilter";
import FuzzyFilter from "../FuzzyFilter";

describe("FileFilter", () => {
describe("equals", () => {
it("is backwards compatible when no type argument is provided", () => {
// Arrange
const fileFilterNoType = new FileFilter("Annotation name", "test value");
const fileFilterWithType = new FileFilter(
"Annotation name",
"test value",
FilterType.DEFAULT
);

// Act/Assert
expect(fileFilterNoType.equals(fileFilterWithType));
});
it("returns true for include filter subtype and parent class", () => {
// Arrange
const fileFilterIncludeConstructor = new IncludeFilter("Annotation name");
const fileFilterParentConstructor = new FileFilter(
"Annotation name",
"",
FilterType.ANY
);

// Act/Assert
expect(fileFilterIncludeConstructor.equals(fileFilterParentConstructor));
});
it("returns true for exclude filter subtype and parent class", () => {
// Arrange
const fileFilterExcludeConstructor = new ExcludeFilter("Annotation name");
const fileFilterParentConstructor = new FileFilter(
"Annotation name",
"",
FilterType.EXCLUDE
);

// Act/Assert
expect(fileFilterExcludeConstructor.equals(fileFilterParentConstructor));
});
it("returns true for fuzzy filter subtype and parent class", () => {
// Arrange
const fileFilterFuzzyConstructor = new FuzzyFilter(
"Annotation name",
"annotation value"
);
const fileFilterParentConstructor = new FileFilter(
"Annotation name",
"annotation value",
FilterType.FUZZY
);

// Act/Assert
expect(fileFilterFuzzyConstructor.equals(fileFilterParentConstructor));
});
it("returns false for different filter subtypes", () => {
// Arrange
const fileFilter = new FileFilter("Annotation name", "annotation value");
const fileFilterFuzzyConstructor = new FuzzyFilter(
"Annotation name",
"annotation value"
);
const fileFilterExcludeConstructor = new ExcludeFilter("Annotation name");
const fileFilterIncludeConstructor = new IncludeFilter("Annotation name");

// Act/Assert
expect(!fileFilterFuzzyConstructor.equals(fileFilter));
expect(!fileFilterIncludeConstructor.equals(fileFilterExcludeConstructor));
});
});
});

0 comments on commit d685394

Please sign in to comment.