Skip to content

Commit 75cf184

Browse files
authored
feat: forward and back buttons for organize column search (#1620)
Closes #1529
1 parent 93eebff commit 75cf184

7 files changed

Lines changed: 303 additions & 13 deletions

File tree

packages/components/src/SearchInput.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,31 @@
5555
border-radius: 1rem;
5656
background-color: rgba($white, 0.25);
5757
}
58+
59+
.search-change-selection {
60+
position: absolute;
61+
right: $spacer-1;
62+
top: 15%;
63+
bottom: 15%;
64+
height: 70%;
65+
}
66+
67+
.search-change-button {
68+
background: none;
69+
border: none;
70+
padding: 1px 2px;
71+
}
72+
73+
.search-change-text {
74+
background-color: rgba($white, 0.2);
75+
border-radius: 10px;
76+
padding: 1px 5px;
77+
}
78+
79+
.match_count {
80+
background-color: rgba($white, 0.2);
81+
border-radius: 10px;
82+
padding: 1px 5px;
83+
margin: 0 5px;
84+
}
5885
}

packages/components/src/SearchInput.tsx

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import React, { PureComponent } from 'react';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3-
import { vsSearch } from '@deephaven/icons';
3+
import { vsArrowLeft, vsArrowRight, vsSearch } from '@deephaven/icons';
44
import classNames from 'classnames';
5+
import Button from './Button';
56
import './SearchInput.scss';
67

8+
interface QueryParams {
9+
queriedColumnIndex: number | undefined;
10+
changeQueriedColumnIndex: (direction: 'forward' | 'back') => void;
11+
}
712
interface SearchInputProps {
813
value: string;
914
placeholder: string;
@@ -15,6 +20,7 @@ interface SearchInputProps {
1520
matchCount: number;
1621
id: string;
1722
'data-testid'?: string;
23+
queryParams?: QueryParams;
1824
}
1925

2026
class SearchInput extends PureComponent<SearchInputProps> {
@@ -27,19 +33,40 @@ class SearchInput extends PureComponent<SearchInputProps> {
2733
},
2834
id: '',
2935
'data-testid': undefined,
36+
queryParams: undefined,
3037
};
3138

3239
constructor(props: SearchInputProps) {
3340
super(props);
3441
this.inputField = React.createRef();
42+
this.searchChangeSelection = React.createRef();
3543
}
3644

37-
inputField: React.RefObject<HTMLInputElement>;
45+
componentDidMount(): void {
46+
this.setInputPaddingRight();
47+
}
48+
49+
componentDidUpdate(): void {
50+
this.setInputPaddingRight();
51+
}
3852

3953
focus(): void {
4054
this.inputField.current?.focus();
4155
}
4256

57+
inputField: React.RefObject<HTMLInputElement>;
58+
59+
searchChangeSelection: React.RefObject<HTMLDivElement>;
60+
61+
setInputPaddingRight(): void {
62+
const inputField = this.inputField.current;
63+
const searchChangeSelection = this.searchChangeSelection.current;
64+
if (inputField && searchChangeSelection) {
65+
const paddingRight = searchChangeSelection.getBoundingClientRect().width;
66+
inputField.style.paddingRight = `${paddingRight}px`;
67+
}
68+
}
69+
4370
render(): JSX.Element {
4471
const {
4572
value,
@@ -52,7 +79,47 @@ class SearchInput extends PureComponent<SearchInputProps> {
5279
id,
5380
onKeyDown,
5481
'data-testid': dataTestId,
82+
queryParams,
5583
} = this.props;
84+
85+
let matchCountSection;
86+
87+
if (queryParams && matchCount > 1) {
88+
matchCountSection = (
89+
<>
90+
<Button
91+
kind="ghost"
92+
className="search-change-button"
93+
type="button"
94+
onClick={() => {
95+
queryParams.changeQueriedColumnIndex('back');
96+
}}
97+
icon={vsArrowLeft}
98+
tooltip="Next match"
99+
/>
100+
<span className="search-change-text">
101+
{queryParams.queriedColumnIndex !== undefined &&
102+
`${queryParams.queriedColumnIndex + 1} of `}
103+
{matchCount}
104+
</span>
105+
<Button
106+
kind="ghost"
107+
className="search-change-button"
108+
type="button"
109+
onClick={() => {
110+
queryParams.changeQueriedColumnIndex('forward');
111+
}}
112+
icon={vsArrowRight}
113+
tooltip="Next match"
114+
/>
115+
</>
116+
);
117+
} else {
118+
matchCountSection = matchCount > 0 && (
119+
<span className="match_count">{matchCount}</span>
120+
);
121+
}
122+
56123
return (
57124
<div className={classNames('search-group', className)}>
58125
<input
@@ -68,12 +135,19 @@ class SearchInput extends PureComponent<SearchInputProps> {
68135
id={id}
69136
data-testid={dataTestId}
70137
/>
71-
{matchCount != null && (
72-
<span className="search-match">{matchCount}</span>
138+
139+
{matchCount != null ? (
140+
<div
141+
className="search-change-selection"
142+
ref={this.searchChangeSelection}
143+
>
144+
{matchCountSection}
145+
</div>
146+
) : (
147+
<span className="search-icon">
148+
<FontAwesomeIcon icon={vsSearch} />
149+
</span>
73150
)}
74-
<span className="search-icon">
75-
<FontAwesomeIcon icon={vsSearch} />
76-
</span>
77151
</div>
78152
);
79153
}

packages/iris-grid/src/sidebar/visibility-ordering-builder/VisibilityOrderingBuilder.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,3 +1184,31 @@ test('On drag start/end', () => {
11841184
expect(mockGroupHandler).toBeCalledWith([]);
11851185
expect(mockMoveHandler).toBeCalledWith([{ from: 0, to: 1 }]);
11861186
});
1187+
1188+
test('changeSelectedColumn moves queried column index and loops', () => {
1189+
const builder = React.createRef<VisibilityOrderingBuilder>();
1190+
render(<Builder builderRef={builder} />);
1191+
1192+
builder.current?.searchColumns('TestColumn');
1193+
expect(builder.current?.state.selectedColumns.size).toEqual(10);
1194+
1195+
builder.current?.changeSelectedColumn('forward');
1196+
expect(builder.current?.state.queriedColumnIndex).toEqual(9);
1197+
1198+
builder.current?.changeSelectedColumn('forward');
1199+
expect(builder.current?.state.queriedColumnIndex).toEqual(0);
1200+
});
1201+
1202+
test('adjustQueriedIndex sets queriedColumnRange to prevIndex = 9 and nextIndex = 0', () => {
1203+
const builder = React.createRef<VisibilityOrderingBuilder>();
1204+
render(<Builder builderRef={builder} />);
1205+
1206+
builder.current?.searchColumns('TestColumn');
1207+
1208+
builder.current?.adjustQueriedIndex('Test');
1209+
1210+
expect(builder.current?.state.queriedColumnRange).toEqual({
1211+
prevIndex: 9,
1212+
nextIndex: 0,
1213+
});
1214+
});

0 commit comments

Comments
 (0)