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

#1074 fix bug when editing filters #1123

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 39 additions & 34 deletions vuu-ui/packages/vuu-filters/src/filter-clause/ExpandoCombobox.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
.vuuExpandoCombobox {
--expando-combobox-height: var(--vuuExpandoCombobox-height, 24px);
--expando-combobox-fontSize: var(--vuuExpandoCombobox-fontSizew, 12px);
--expando-combobox-height: var(--vuuExpandoCombobox-height, 24px);
--expando-combobox-fontSize: var(--vuuExpandoCombobox-fontSizew, 12px);

--saltInput-outline: none;
--saltInput-fontSize: var(--expando-combobox-fontSize);
--saltInput-height: var(--expando-combobox-height);
--saltInput-minWidth: 4px;

display: inline-flex;
flex-direction: column;
height: var(--expando-combobox-height);
min-width: 4px;
padding: 0;
--saltInput-outline: none;
--saltInput-fontSize: var(--expando-combobox-fontSize);
--saltInput-height: var(--expando-combobox-height);
--saltInput-minWidth: 4px;

display: inline-flex;
flex-direction: column;
height: var(--expando-combobox-height);
min-width: 4px;
padding: 0;
}

.vuuExpandoCombobox .saltInput {
background-color: transparent;
position: absolute;
background-color: transparent;
position: absolute;
}

.vuuExpandoCombobox .vuuDropdown {
height: 100%;
height: 100%;
}

/** double up the selector just to increase specificity, won't need when we use cascade layers */
.vuuExpandoCombobox-Input.saltInput {
border: none;
left:0px;
margin:0;
min-height: 100%;
padding:0;
right: 0px;
width: auto;
border: none;
left: 0px;
margin: 0;
min-height: 100%;
padding: 0;
right: 0px;
width: auto;
}

.vuuExpandoCombobox .saltInput-input {
Expand All @@ -41,20 +40,26 @@
display: block;
flex: 1;
font: inherit;
margin:0;
min-width:0;
margin: 0;
min-width: 0;
outline: none;
padding: 0;

}

.vuuExpandoCombobox .saltInput-input::selection {
background-color: var(
--salt-text-background-selected,
var(--vuu-color-blue-40)
);
}

.vuuExpandoCombobox:before {
content: attr(data-text);
display: block;
font-size: var(--expando-combobox-fontSize);
height: 0px;
overflow: hidden;
/* visibility: hidden; */
white-space: pre-wrap;
/* position: absolute; */
}
content: attr(data-text);
display: block;
font-size: var(--expando-combobox-fontSize);
height: 0px;
overflow: hidden;
/* visibility: hidden; */
white-space: pre-wrap;
/* position: absolute; */
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const FilterClauseEditor = ({
onClear,
onClearKeyDown,
onDeselectValue,
onSelectionChangeColumn,
onSelectionChangeOperator,
onColumnSelect,
onOperatorSelect,
operator,
operatorRef,
selectedColumn,
Expand Down Expand Up @@ -129,7 +129,7 @@ export const FilterClauseEditor = ({
data-field="column"
initialHighlightedIndex={0}
itemToString={(column) => column.name}
onSelectionChange={onSelectionChangeColumn}
onListItemSelect={onColumnSelect}
ref={columnRef}
source={columns}
title="column"
Expand All @@ -144,7 +144,7 @@ export const FilterClauseEditor = ({
})}
data-field="operator"
initialHighlightedIndex={0}
onSelectionChange={onSelectionChangeOperator}
onListItemSelect={onOperatorSelect}
ref={operatorRef}
source={getOperators(selectedColumn)}
title="operator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ export const useFilterClauseEditor = ({
getFilterClauseValue(filterClause)
);

const handleSelectionChangeColumn = useCallback<
const handleColumnSelect = useCallback<
SingleSelectionHandler<ColumnDescriptor>
>(
(evt, column) => {
(_, column) => {
setSelectedColumn(column ?? undefined);
setOperator(undefined);
setValue(undefined);
Expand Down Expand Up @@ -242,8 +242,8 @@ export const useFilterClauseEditor = ({
[onCancel, setOperator]
);

const handleSelectionChangeOperator = useCallback<SingleSelectionHandler>(
(evt, selected) => {
const handleOperatorSelect = useCallback<SingleSelectionHandler>(
(_, selected) => {
const op = selected;
if (op === undefined || isValidFilterClauseOp(op)) {
setOperator(op);
Expand Down Expand Up @@ -293,35 +293,17 @@ export const useFilterClauseEditor = ({
// If value is valid, move on to next field
const input = evt.target as HTMLInputElement;
const field = input.closest("[data-field]") as HTMLElement;
if (field.dataset.field === "column") {
const column = findColumn(input.value);
if (column) {
setSelectedColumn(column);
focusNextElement();
}
} else if (field.dataset.field === "value") {
if (operator === "starts") {
// // don't let this bubble to the Toolbar, it would be
// // interpreted as selection
evt.stopPropagation();
const newValue = input.value;
setValue(newValue);
onChange({
column: selectedColumn?.name,
op: operator,
value: newValue,
});
}
if (field.dataset.field === "value" && operator === "starts") {
// // don't let this bubble to the Toolbar, it would be
// // interpreted as selection
evt.stopPropagation();
const newValue = input.value;
setValue(newValue);
handleChangeValue(newValue);
}
}
},
[
findColumn,
onChange,
operator,
removeAndNavigateToNextInputIfAtBoundary,
selectedColumn?.name,
]
[handleChangeValue, operator, removeAndNavigateToNextInputIfAtBoundary]
);

const handleClear = useCallback(
Expand Down Expand Up @@ -371,8 +353,8 @@ export const useFilterClauseEditor = ({
onClear: handleClear,
onClearKeyDown: handleClearKeyDown,
onDeselectValue: handleDeselectValue,
onSelectionChangeColumn: handleSelectionChangeColumn,
onSelectionChangeOperator: handleSelectionChangeOperator,
onColumnSelect: handleColumnSelect,
onOperatorSelect: handleOperatorSelect,
operator,
operatorRef,
selectedColumn,
Expand Down
12 changes: 9 additions & 3 deletions vuu-ui/packages/vuu-ui-controls/src/combo-box/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useCollectionItems,
} from "../common-hooks";
import { DropdownBase, DropdownBaseProps } from "../dropdown";
import { List, ListProps } from "../list";
import { List, ListControlProps, ListProps } from "../list";
import { ChevronIcon } from "../list/ChevronIcon";
import { useCombobox } from "./useCombobox";

Expand All @@ -31,7 +31,10 @@ export interface ComboBoxProps<
Omit<ComponentSelectionProps<Item, S>, "onSelect">,
Pick<ListProps<Item, S>, "ListItem" | "itemToString" | "source" | "width"> {
InputProps?: InputProps;
ListProps?: Omit<ListProps<Item>, "ListItem" | "itemToString" | "source">;
ListProps?: Omit<
ListProps<Item>,
"ListItem" | "itemToString" | "source" | "onSelect" | "onSelectionChange"
>;
allowBackspaceClearsSelection?: boolean;
allowFreeText?: boolean;
defaultValue?: string;
Expand All @@ -40,6 +43,7 @@ export interface ComboBoxProps<
itemsToString?: (items: Item[]) => string;
onDeselect?: () => void;
onSetSelectedText?: (text: string) => void;
onListItemSelect?: ListProps<Item, S>["onSelect"];
disableFilter?: boolean;
value?: string;
}
Expand Down Expand Up @@ -78,6 +82,7 @@ export const ComboBox = forwardRef(function Combobox<
onDeselect,
onOpenChange: onOpenChangeProp,
onSelectionChange,
onListItemSelect,
selected: selectedProp,
selectionKeys,
selectionStrategy,
Expand Down Expand Up @@ -154,6 +159,7 @@ export const ComboBox = forwardRef(function Combobox<
isOpen: isOpenProp,
itemToString,
itemsToString,
onListItemSelect,
onOpenChange: onOpenChangeProp,
onSelectionChange,
onSetSelectedText,
Expand Down Expand Up @@ -207,7 +213,7 @@ export const ComboBox = forwardRef(function Combobox<
highlightedIndex={highlightedIndex}
itemTextHighlightPattern={String(inputProps.value) || undefined}
listHandlers={listHandlers}
onSelectionChange={onSelectionChange}
onSelectionChange={onSelectionChange} // not really needed, since onClick in listHandlers will be used instead.
Copy link
Contributor Author

@junaidzm13 junaidzm13 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heswell let me know if I should get rid of this, I've checked onSelectionChange is not used if listHandlers is not undefined. And it is not undefined here since we use useList hook to get these for Combobox.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, lets get rid of it

ref={listRef}
selected={selected}
selectionStrategy={selectionStrategy}
Expand Down
3 changes: 3 additions & 0 deletions vuu-ui/packages/vuu-ui-controls/src/combo-box/useCombobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface ComboboxHookProps<
| "itemsToString"
| "onDeselect"
| "onSetSelectedText"
| "onListItemSelect"
| "value"
>,
Omit<ComponentSelectionProps<Item, S>, "onSelect">,
Expand Down Expand Up @@ -91,6 +92,7 @@ export const useCombobox = <Item, S extends SelectionStrategy>({
itemsToString,
itemToString = defaultItemToString as (item: Item) => string,
listRef,
onListItemSelect,
onOpenChange,
onSelectionChange,
onSetSelectedText,
Expand Down Expand Up @@ -293,6 +295,7 @@ export const useCombobox = <Item, S extends SelectionStrategy>({
label: "combobox",
onKeyboardNavigation: handleKeyboardNavigation,
onSelectionChange: handleSelectionChange,
onSelect: onListItemSelect,
selected: collectionHook.itemToCollectionItemId(selectedProp as any),
selectionKeys,
selectionStrategy,
Expand Down
Loading