Skip to content

Commit

Permalink
add cancel to filter editor
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Mar 27, 2024
1 parent 2f94871 commit ca3adcf
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ describe("FilterEditor", () => {
cy.realPress("Enter");

selectMenuOption("AND");
cy.findByRole("button", { name: "AND" }).should("be.visible");
cy.findAllByRole("button", { name: "AND" }).should("have.length", 1);
cy.findByRole("button", { name: "and" }).should("be.visible");
cy.findAllByRole("button", { name: "and" }).should("have.length", 1);
});
it("THEN second clause is created and column focused", () => {
cy.mount(<NewFilter />);
Expand Down Expand Up @@ -182,10 +182,6 @@ describe("FilterEditor", () => {
});
});

// describe("Tab navigation", () => {

// })

describe("Arrow key navigation", () => {
describe("within a single clause filter", () => {
describe("WHEN clause complete and Save button focused, then Shift+Tab pressed", () => {
Expand Down Expand Up @@ -262,7 +258,7 @@ describe("FilterEditor", () => {
cy.findAllByRole("combobox").eq(2).should("be.focused");
cy.realPress("ArrowRight");
cy.realPress("ArrowRight");
cy.findByRole("button", { name: "OR" }).should("be.focused");
cy.findByRole("button", { name: "or" }).should("be.focused");
cy.realPress("ArrowRight");
cy.realPress("ArrowRight");
cy.findAllByRole("combobox").eq(3).should("be.focused");
Expand Down Expand Up @@ -291,7 +287,7 @@ describe("FilterEditor", () => {
cy.realPress("ArrowLeft");
cy.findAllByRole("combobox").eq(3).should("be.focused");
cy.realPress("ArrowLeft");
cy.findByRole("button", { name: "OR" }).should("be.focused");
cy.findByRole("button", { name: "or" }).should("be.focused");
cy.realPress("ArrowLeft");
cy.findAllByRole("combobox").eq(2).should("be.focused");
cy.realPress("ArrowLeft");
Expand Down
8 changes: 2 additions & 6 deletions vuu-ui/packages/vuu-filters/src/filter-bar/useFilterBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ export const useFilterBar = ({
interactedFilterState?.state === "rename" &&
interactedFilterState.filter
) {
const { filter, index } = interactedFilterState;
const { filter } = interactedFilterState;
const indexOfEditedFilter = onRenameFilter(filter, editedValue);
console.log({ index, indexOfEditedFilter });

setInteractedFilterState(undefined);
focusFilterPill(indexOfEditedFilter);
Expand Down Expand Up @@ -253,9 +252,6 @@ export const useFilterBar = ({

const handlePillClick = useCallback<MouseEventHandler<HTMLButtonElement>>(
(e) => {
console.log("Pill Click", {
e,
});
const isEditing = (e.target as HTMLElement).querySelector(
".vuuEditableLabel-editing"
);
Expand Down Expand Up @@ -296,7 +292,7 @@ export const useFilterBar = ({
if (interactedFilterState) {
const { index } = interactedFilterState;
if (index === -1) {
console.log("focus add button");
addButtonRef.current?.focus();
} else {
focusFilterPill(index);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { FilterCombinatorOp } from "@finos/vuu-filter-types";
import {
CycleStateButton,
CycleStateButtonProps,
} from "@finos/vuu-ui-controls";
import { CycleStateButton } from "@finos/vuu-ui-controls";
import { KeyboardEventHandler, useCallback } from "react";

import "./FilterClauseCombinator.css";
Expand All @@ -24,7 +21,7 @@ export const FilterClauseCombinator = ({
onKeyDown,
operator,
}: FilterClauseCombinatorProps) => {
const handleChange = useCallback<CycleStateButtonProps["onChange"]>(
const handleChange = useCallback(
(value) => {
onChange(value as FilterCombinatorOp);
},
Expand Down
12 changes: 7 additions & 5 deletions vuu-ui/packages/vuu-filters/src/filter-editor/FilterEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { TableSchema } from "@finos/vuu-data-types";
import { Filter } from "@finos/vuu-filter-types";
import { ColumnDescriptor } from "@finos/vuu-table-types";
import { SplitButton } from "@finos/vuu-ui-controls";
import { HTMLAttributes, useCallback } from "react";
import { HTMLAttributes } from "react";
import { FilterClause, FilterClauseProps } from "../filter-clause/FilterClause";
import { FilterClauseModel } from "../FilterModel";
import {
FilterClauseCombinator,
FilterClauseCombinatorChangeHandler,
} from "./FilterClauseCombinator";
import { FilterClauseCombinator } from "./FilterClauseCombinator";
import { useFilterEditor } from "./useFilterEditor";

import "./FilterEditor.css";
import { Button } from "@salt-ds/core";

const classBase = "vuuFilterEditor";

Expand Down Expand Up @@ -41,6 +39,7 @@ export const FilterEditor = ({
filterModel,
setContainer,
onCancelFilterClause,
onCancelFilterEdit,
onChangeFilterCombinator,
onKeyDownCombinator,
saveButtonRef,
Expand Down Expand Up @@ -93,6 +92,9 @@ export const FilterEditor = ({
>
Save
</SplitButton>
<Button onClick={onCancelFilterEdit} variant="secondary">
Cancel
</Button>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,16 @@ export const useFilterEditor = ({
[filterModel]
);

const handleCancelFilterEdit = useCallback(() => {
onCancel(filter);
}, [filter, onCancel]);

return {
columnsByName,
filterModel,
isValid,
onCancelFilterClause: handleCancelFilterClause,
onCancelFilterEdit: handleCancelFilterEdit,
onChangeFilterCombinator,
onKeyDownCombinator: handleKeyDownNavigationFromCombinator,
saveButtonProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import {
ColumnDescriptor,
TableCellRendererProps,
} from "@finos/vuu-table-types";
import { CycleStateButtonProps, WarnCommit } from "@finos/vuu-ui-controls";
import {
CycleStateButtonProps,

Check failure on line 6 in vuu-ui/packages/vuu-table/src/cell-renderers/toggle-cell/ToggleCell.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'CycleStateButtonProps' is defined but never used. Allowed unused vars must match /^_$/u
CycleStateCommitHandler,
WarnCommit,
} from "@finos/vuu-ui-controls";
import {
dataColumnAndKeyUnchanged,
dispatchCustomEvent,
Expand Down Expand Up @@ -39,7 +43,7 @@ export const ToggleCell = memo(function ToggleCell({
const dataIdx = columnMap[column.name];
const value = row[dataIdx] as string;

const handleCommit = useCallback<CycleStateButtonProps["onCommit"]>(
const handleCommit = useCallback<CycleStateCommitHandler>(
(evt, value) => {
return onCommit(value).then((response) => {
if (response === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import { ForwardedRef, forwardRef, SyntheticEvent, useCallback } from "react";

const classBase = "vuuCycleStateButton";

export type CycleStateCommitHandler = (
evt: SyntheticEvent,
value: VuuRowDataItemType
) => CommitResponse;

export interface CycleStateButtonProps extends Omit<ButtonProps, "onChange"> {
onChange: (value: VuuRowDataItemType) => void;
onCommit?: (evt: SyntheticEvent, value: VuuRowDataItemType) => CommitResponse;
onChange?: (value: VuuRowDataItemType) => void;
onCommit?: CycleStateCommitHandler;
values: string[];
value: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MenuActionHandler } from "@finos/vuu-data-types";
import {
CycleStateButton,
CycleStateButtonProps,

Check failure on line 4 in vuu-ui/sample-apps/feature-basket-trading/src/basket-toolbar/BasketToolbar.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'CycleStateButtonProps' is defined but never used. Allowed unused vars must match /^_$/u
CycleStateCommitHandler,
ExpandoInput,
useEditableText,
} from "@finos/vuu-ui-controls";
Expand Down Expand Up @@ -75,7 +76,7 @@ export const BasketToolbar = ({
type: "number",
});

const handleSideCommit = useCallback<CycleStateButtonProps["onCommit"]>(
const handleSideCommit = useCallback<CycleStateCommitHandler>(
(_, value) => {
if (onCommit) {
return onCommit?.("side", value);
Expand Down

0 comments on commit ca3adcf

Please sign in to comment.