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

feat: forward and back button for organize column search #1641

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 1 addition & 15 deletions packages/components/src/SearchInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@
}
}

.search-match {
pointer-events: none;
position: absolute;
right: $spacer-5;
top: 15%;
bottom: 15%;
height: 70%;
display: flex;
align-items: center;
padding: 0 $spacer-2;
border-radius: 1rem;
background-color: rgba($white, 0.25);
}

.search-change-selection {
position: absolute;
right: $spacer-1;
Expand All @@ -76,7 +62,7 @@
padding: 1px 5px;
}

.match_count {
.search-match {
background-color: rgba($white, 0.2);
border-radius: 10px;
padding: 1px 5px;
Expand Down
55 changes: 34 additions & 21 deletions packages/components/src/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { vsArrowLeft, vsArrowRight, vsSearch } from '@deephaven/icons';
import classNames from 'classnames';
import Button from './Button';
import './SearchInput.scss';
import { GLOBAL_SHORTCUTS } from './shortcuts';
import { ContextActions } from './context-actions';

interface QueryParams {
queriedColumnIndex: number | undefined;
changeQueriedColumnIndex: (direction: 'forward' | 'back') => void;
}
interface SearchInputProps {
value: string;
placeholder: string;
Expand All @@ -20,7 +18,10 @@ interface SearchInputProps {
matchCount: number;
id: string;
'data-testid'?: string;
queryParams?: QueryParams;
cursor?: {
index: number;
next: (direction: 'forward' | 'back') => void;
};
}

class SearchInput extends PureComponent<SearchInputProps> {
Expand All @@ -33,7 +34,7 @@ class SearchInput extends PureComponent<SearchInputProps> {
},
id: '',
'data-testid': undefined,
queryParams: undefined,
cursor: undefined,
};

constructor(props: SearchInputProps) {
Expand Down Expand Up @@ -79,44 +80,53 @@ class SearchInput extends PureComponent<SearchInputProps> {
id,
onKeyDown,
'data-testid': dataTestId,
queryParams,
cursor,
} = this.props;

let matchCountSection;
const contextActions = [
{
action: () => cursor?.next('forward'),
shortcut: GLOBAL_SHORTCUTS.NEXT,
},
{
action: () => cursor?.next('back'),
shortcut: GLOBAL_SHORTCUTS.PREVIOUS,
},
];

if (queryParams && matchCount > 1) {
if (cursor && matchCount > 1) {
matchCountSection = (
<>
<Button
kind="ghost"
className="search-change-button"
type="button"
onClick={() => {
queryParams.changeQueriedColumnIndex('back');
cursor.next('back');
}}
icon={vsArrowLeft}
tooltip="Next match"
tooltip={`Previous match (${GLOBAL_SHORTCUTS.PREVIOUS.getDisplayText()})`}
/>
<span className="search-change-text">
{queryParams.queriedColumnIndex !== undefined &&
`${queryParams.queriedColumnIndex + 1} of `}
{cursor.index !== undefined && `${cursor.index + 1} of `}
{matchCount}
</span>
<Button
kind="ghost"
className="search-change-button"
type="button"
onClick={() => {
queryParams.changeQueriedColumnIndex('forward');
cursor.next('forward');
}}
icon={vsArrowRight}
tooltip="Next match"
tooltip={`Next match (${GLOBAL_SHORTCUTS.NEXT.getDisplayText()})`}
/>
</>
);
} else {
matchCountSection = matchCount > 0 && (
<span className="match_count">{matchCount}</span>
<span className="search-match">{matchCount}</span>
);
}

Expand All @@ -137,12 +147,15 @@ class SearchInput extends PureComponent<SearchInputProps> {
/>

{matchCount != null ? (
<div
className="search-change-selection"
ref={this.searchChangeSelection}
>
{matchCountSection}
</div>
<>
<div
className="search-change-selection"
ref={this.searchChangeSelection}
>
{matchCountSection}
</div>
<ContextActions actions={contextActions} />
</>
) : (
<span className="search-icon">
<FontAwesomeIcon icon={vsSearch} />
Expand Down
14 changes: 14 additions & 0 deletions packages/components/src/shortcuts/GlobalShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ const GLOBAL_SHORTCUTS = {
macShortcut: [KEY.ESCAPE],
isEditable: false,
}),
NEXT: ShortcutRegistry.createAndAdd({
id: 'GLOBAL.NEXT',
name: 'Next',
shortcut: [KEY.ENTER],
macShortcut: [KEY.ENTER],
isEditable: false,
}),
PREVIOUS: ShortcutRegistry.createAndAdd({
id: 'GLOBAL.PREVIOUS',
name: 'Previous',
shortcut: [MODIFIER.SHIFT, KEY.ENTER],
macShortcut: [MODIFIER.SHIFT, KEY.ENTER],
isEditable: false,
}),
};

export default GLOBAL_SHORTCUTS;
Original file line number Diff line number Diff line change
Expand Up @@ -1201,9 +1201,9 @@ class VisibilityOrderingBuilder extends Component<
treeItems
);

const queryParams = {
queriedColumnIndex,
changeQueriedColumnIndex: (direction: 'forward' | 'back') =>
const cursor = {
index: queriedColumnIndex as number,
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need this cast, and in fact it's pointing out an error - you could be passing index: undefined here, which is not what SearchInput is expecting.
Instead, you should just check if it is not set and just return undefined for that instead of the parameter, e.g.:

    const cursor =
      queriedColumnIndex != null
        ? {
            index: queriedColumnIndex,
            next: (direction: 'forward' | 'back') =>
              this.changeSelectedColumn(direction),
          }
        : undefined;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I unresolved one of your previous comments. I didn't think it through properly but queriedColumnIndex should be able to be undefined. When the user searches initially there is no index yet. But cursor should still be passed in since we need the next function for the forward and back buttons

next: (direction: 'forward' | 'back') =>
this.changeSelectedColumn(direction),
};

Expand All @@ -1229,7 +1229,7 @@ class VisibilityOrderingBuilder extends Component<
value={searchFilter}
matchCount={searchFilter ? matchCount : undefined}
onChange={this.handleSearchInputChange}
queryParams={queryParams}
cursor={cursor}
/>
</div>
<div className="top-menu">
Expand Down
Loading