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

Search from nav with options in SoftConfig #438

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3475d4d
Good basic tests of leftIcon in admin > tests > select
cnrudd Sep 17, 2020
63d159a
Small refactor of select tests.
cnrudd Sep 17, 2020
8323cfd
Functioning search input based on routes, but needs some refinement.
cnrudd Sep 17, 2020
a710e1c
Merge branch 'develop' into homePageSearchInput
cnrudd Sep 18, 2020
4e99493
Merge branch 'develop' into homePageSearchInput
cnrudd Sep 21, 2020
c8a8190
Improve global search so that it uses grouped options.
cnrudd Sep 21, 2020
557d8ba
Merge branch 'develop' into homePageSearchInput
cnrudd Sep 24, 2020
27b3507
Added globalsearch hotkey and made it maintain focus for efficient br…
cnrudd Sep 24, 2020
bbd0bd4
Refactored global search into own component.
cnrudd Sep 25, 2020
1360b18
Whitespace cleanup.
cnrudd Sep 25, 2020
d8c1197
Small refactor.
cnrudd Sep 25, 2020
f26b087
Added tracking to search selection.
cnrudd Sep 25, 2020
959d755
Merge branch 'develop' into homePageSearchInput
cnrudd Sep 26, 2020
0d6e583
Merge branch 'develop' into searchFromNav
cnrudd Oct 22, 2020
8a3072a
Move search options to softConfig
cnrudd Oct 22, 2020
2e5aece
Merge branch 'develop' into searchFromNav
cnrudd Nov 5, 2020
642b2a7
Better comment.
cnrudd Nov 5, 2020
46ea1d4
Merge branch 'develop' into searchFromNav
cnrudd Nov 16, 2020
96c1942
Set new filterFn prop so that it reverts to default react-select filt…
cnrudd Nov 17, 2020
6ac4b70
Merge branch 'develop' into searchFromNav
cnrudd Nov 27, 2020
e9438d3
Fix use of createFilter func.
cnrudd Nov 27, 2020
0a8451a
Fix aquisition of select's input element.
cnrudd Nov 30, 2020
7a7e38a
Better method name.
cnrudd Nov 30, 2020
5daed9c
Revert to using reactselect ref.
cnrudd Dec 1, 2020
1c12f2f
Merge branch 'develop' into searchFromNav
cnrudd Dec 15, 2020
96e92ff
Use new focus & blur methods on Select Model.
cnrudd Dec 15, 2020
5c66c01
Merge branch 'develop' into searchFromNav
cnrudd May 7, 2021
95503cd
Update Model class
cnrudd May 7, 2021
38478f3
Merge branch 'develop' into searchFromNav
cnrudd May 7, 2021
85b57c4
Merge branch 'develop' into searchFromNav
cnrudd Jun 5, 2023
0c446c7
Update Search to ts, add config content to bottom in comment.
cnrudd Jun 5, 2023
3f95454
Merge branch 'refs/heads/develop' into searchFromNav
cnrudd May 22, 2024
273b5c9
fix merge
cnrudd May 22, 2024
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
2 changes: 2 additions & 0 deletions client-app/src/desktop/AppComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import xhLogo from '../core/img/xh-toolbox-logo.png';
import '../core/Toolbox.scss';
import './App.scss';
import {AppModel} from './AppModel';
import {search} from './search/Search';

export const AppComponent = hoistCmp({
displayName: 'App',
Expand All @@ -23,6 +24,7 @@ export const AppComponent = hoistCmp({
title: null,
leftItems: [tabSwitcher({enableOverflow: true})],
rightItems: [
search({width: 300}),
webSocketIndicator({iconOnly: true, marginRight: 4}),
appBarSeparator()
],
Expand Down
93 changes: 93 additions & 0 deletions client-app/src/desktop/search/Search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {createRef} from 'react';
import {createFilter} from 'react-select';
import {isEmpty} from 'lodash';
import {XH, HoistModel, hoistCmp, creates, PlainObject} from '@xh/hoist/core';
import {HoistInputModel} from '@xh/hoist/cmp/input';
import {select} from '@xh/hoist/desktop/cmp/input';
import {bindable, makeObservable} from '@xh/hoist/mobx';
import {getLayoutProps} from '@xh/hoist/utils/react';
import {useHotkeys} from '@xh/hoist/desktop/hooks';
import {Icon} from '@xh/hoist/icon';
import {wait} from '@xh/hoist/promise';

export const search = hoistCmp.factory({
model: creates(() => new Model()),
render({model, ...props}) {
const {globalSearchOptions, selectRef} = model;

if (isEmpty(globalSearchOptions)) return null;

return useHotkeys(
select({
ref: selectRef,
...getLayoutProps(props),
leftIcon: Icon.search(),
bind: 'globalSearchSelection',
options: globalSearchOptions,
placeholder: 'Search for a component...(s)',
hideDropdownIndicator: true,
enableClear: true,
valueField: 'route',
filterFn: createFilter(null),
onChange: val => model.forwardToTopic(val)
}),
[
{
global: true,
combo: 's',
label: 'Go to search',
onKeyUp: () => model.focus()
}
]
);
}
});

class Model extends HoistModel {
@bindable
globalSearchSelection;

selectRef = createRef<HoistInputModel>();

get globalSearchOptions(): PlainObject[] {
return XH.getConf('searchOptions', []);
}

constructor() {
super();
makeObservable(this);
}

forwardToTopic(val) {
if (val) {
if (val.startsWith('launch.')) {
this.openExternal(val);
} else {
XH.navigate(val.split('|')[0]);
}

XH.track({
category: 'Global Search',
message: 'Selected result',
data: {topic: val}
});
}

// keeps focus on select box to facilate typing a new query
this.blur();
wait(100).then(() => this.focus());
}

openExternal(val) {
const path = val.replace('launch.examples.', '');
window.open(`/${path}`);
}

focus() {
this.selectRef?.current.focus();
}

blur() {
this.selectRef?.current.blur();
}
}
Loading
Loading