feat: universal Search.

This commit is contained in:
elforjani3
2021-08-07 22:26:57 +02:00
parent fad9052da8
commit 3bd3619271
7 changed files with 139 additions and 53 deletions

View File

@@ -0,0 +1,12 @@
import intl from 'react-intl-universal';
export default [
{
name: 'Type1',
placeholder: 'Id tempor anim culpa esse id laboris.',
},
{
name: 'Type2',
placeholder: 'Laborum aliqua eiusmod voluptate aliqua',
},
];

View File

@@ -0,0 +1,50 @@
import React from 'react';
import { Omnibar } from '@blueprintjs/select';
import { MenuItem, Spinner } from '@blueprintjs/core';
import { FormattedMessage as T, Icon, ListSelect } from 'components';
import withSearch from 'containers/GeneralSearch/withSearch';
import { compose } from 'utils';
function UniversalSearch({
results,
onClose,
// withSearch
globalSearchShow,
closeGlobalSearch,
...props
}) {
const SearchRenderer = (
{ name, code, amount },
{ handleClick, modifiers, query },
) => {
return (
<MenuItem
text={`${name} - ${code}`}
label={amount}
onClick={handleClick}
/>
);
};
const handleClose = () => {
closeGlobalSearch(false);
};
return (
<Omnibar
className={'navbar--omnibar'}
items={results}
itemRenderer={SearchRenderer}
noResults={<MenuItem disabled={true} text={<T id={'no_results'} />} />}
resetOnSelect={true}
onClose={handleClose}
{...props}
/>
);
}
export default compose(withSearch)(UniversalSearch);

View File

@@ -58,6 +58,7 @@ import AccountsSuggestField from './AccountsSuggestField';
import MaterialProgressBar from './MaterialProgressBar'; import MaterialProgressBar from './MaterialProgressBar';
import { MoneyFieldCell } from './DataTableCells'; import { MoneyFieldCell } from './DataTableCells';
import Card from './Card'; import Card from './Card';
import UniversalSearch from './UniversalSearch';
import { ItemsMultiSelect } from './Items'; import { ItemsMultiSelect } from './Items';
@@ -131,5 +132,6 @@ export {
MaterialProgressBar, MaterialProgressBar,
MoneyFieldCell, MoneyFieldCell,
ItemsMultiSelect, ItemsMultiSelect,
Card Card,
UniversalSearch,
}; };

View File

@@ -1,40 +1,63 @@
import React from 'react'; import React from 'react';
import { Omnibar } from '@blueprintjs/select'; import { Intent, Spinner } from '@blueprintjs/core';
import { MenuItem } from '@blueprintjs/core'; import {
import { FormattedMessage as T } from 'components'; UniversalSearch,
ListSelect,
If,
FormattedMessage as T,
} from 'components';
import { defaultTo } from 'lodash';
import intl from 'react-intl-universal';
import { useAccounts } from 'hooks/query';
import UniversalSearchOptions from 'common/universalSearchOptions';
import { compose } from 'utils'; import { compose } from 'utils';
import withSearch from 'containers/GeneralSearch/withSearch'; import withSearch from 'containers/GeneralSearch/withSearch';
function Search({ function Search({ globalSearchShow }) {
resultSearch, const [query, setQuery] = React.useState();
globalSearchShow, const [labelState, setLabelState] = React.useState();
openGlobalSearch,
closeGlobalSearch,
}) {
const items = [];
const renderSearch = (search, { handleClick }) => ( const { data: accounts, isFetching: isAccountsFetching } = useAccounts({
<MenuItem search_keyword: query,
key={search.year} });
text={search.title}
label={search.title} const handleClick = (placeholder) => {
onClick={handleClick} setLabelState(placeholder);
};
const MenuSelectType = (
<div style={{ display: 'flex' }}>
<If condition={isAccountsFetching}>
<Spinner tagName="div" intent={Intent.NONE} size={20} value={null} />
</If>
<ListSelect
items={UniversalSearchOptions}
onItemSelect={(holder) => handleClick(holder)}
filterable={false}
selectedItem={labelState?.name}
selectedItemProp={'name'}
textProp={'name'}
defaultText={intl.get('type')}
popoverProps={{ minimal: false, captureDismiss: true }}
buttonProps={{
minimal: true,
}}
/> />
</div>
); );
return ( return (
<div> <UniversalSearch
<Omnibar results={accounts}
className={'navbar-omnibar'}
isOpen={globalSearchShow} isOpen={globalSearchShow}
noResults={<MenuItem disabled={true} text={<T id={'no_results'} />} />} onQueryChange={(q) => setQuery(q)}
onClose={() => closeGlobalSearch(false)} inputProps={{
resetOnSelect={true} rightElement: MenuSelectType,
itemRenderer={renderSearch} placeholder: `${defaultTo(labelState?.placeholder, '')}`,
items={items} }}
// onItemSelect={onItemsSelect()}
/> />
</div>
); );
} }

View File

@@ -2,8 +2,6 @@ import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit'; import { createReducer } from '@reduxjs/toolkit';
const initialState = { const initialState = {
searches: {},
searchTitle: 'Title',
isOpen: false, isOpen: false,
}; };
@@ -14,5 +12,5 @@ export default createReducer(initialState, {
[t.CLOSE_SEARCH]: (state, action) => { [t.CLOSE_SEARCH]: (state, action) => {
state.isOpen = false; state.isOpen = false;
} },
}); });

View File

@@ -1,5 +1,5 @@
export default { export default {
SEARCH_SUCCESS:'SEARCH_SUCCESS', SEARCH_TYPE: 'SEARCH_TYPE',
OPEN_SEARCH: 'OPEN_SEARCH', OPEN_SEARCH: 'OPEN_SEARCH',
CLOSE_SEARCH: 'CLOSE_SEARCH', CLOSE_SEARCH: 'CLOSE_SEARCH',
}; };

View File

@@ -257,7 +257,6 @@ $dashboard-views-bar-height: 44px;
margin: 0; margin: 0;
} }
h3 { h3 {
} }
.button--view-edit { .button--view-edit {
@@ -512,12 +511,12 @@ $dashboard-views-bar-height: 44px;
height: $dashboard-views-bar-height; height: $dashboard-views-bar-height;
} }
.bp3-tab[aria-selected="true"]{ .bp3-tab[aria-selected='true'] {
box-shadow: inset 0 -2px 0 #0052cc; box-shadow: inset 0 -2px 0 #0052cc;
} }
} }
.navbar-omnibar { .navbar--omnibar {
-webkit-filter: blur(0); -webkit-filter: blur(0);
filter: blur(0); filter: blur(0);
opacity: 1; opacity: 1;
@@ -528,7 +527,11 @@ $dashboard-views-bar-height: 44px;
box-shadow: 0 0 0 1px rgba(16, 22, 26, 0.1), 0 4px 8px rgba(16, 22, 26, 0.2), box-shadow: 0 0 0 1px rgba(16, 22, 26, 0.1), 0 4px 8px rgba(16, 22, 26, 0.2),
0 18px 46px 6px rgba(16, 22, 26, 0.2); 0 18px 46px 6px rgba(16, 22, 26, 0.2);
background-color: #fff; background-color: #fff;
width: 500px; width: 600px;
.bp3-input {
padding-left: 40px !important;
}
} }
.menu--logged-user-dropdown { .menu--logged-user-dropdown {
@@ -539,5 +542,3 @@ $dashboard-views-bar-height: 44px;
} }
} }
} }