mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
selectively add icontains to only text-based searches
This commit is contained in:
parent
ec3edb07e8
commit
86029934ad
@ -15,6 +15,8 @@ import Search from '../Search';
|
||||
import Sort from '../Sort';
|
||||
import VerticalSeparator from '../VerticalSeparator';
|
||||
|
||||
import { QSConfig } from '@types';
|
||||
|
||||
const AWXToolbar = styled.div`
|
||||
--awx-toolbar--BackgroundColor: var(--pf-global--BackgroundColor--light-100);
|
||||
--awx-toolbar--BorderColor: #ebebeb;
|
||||
@ -98,6 +100,7 @@ class DataListToolbar extends React.Component {
|
||||
sortedColumnKey,
|
||||
additionalControls,
|
||||
i18n,
|
||||
qsConfig,
|
||||
} = this.props;
|
||||
|
||||
const showExpandCollapse = onCompact && onExpand;
|
||||
@ -120,6 +123,7 @@ class DataListToolbar extends React.Component {
|
||||
)}
|
||||
<ToolbarItem css="flex-grow: 1;">
|
||||
<Search
|
||||
qsConfig={qsConfig}
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
sortedColumnKey={sortedColumnKey}
|
||||
@ -160,6 +164,7 @@ class DataListToolbar extends React.Component {
|
||||
}
|
||||
|
||||
DataListToolbar.propTypes = {
|
||||
qsConfig: QSConfig.isRequired,
|
||||
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
showSelectAll: PropTypes.bool,
|
||||
isAllSelected: PropTypes.bool,
|
||||
|
||||
@ -14,6 +14,8 @@ import {
|
||||
} from '@patternfly/react-core';
|
||||
import { SearchIcon } from '@patternfly/react-icons';
|
||||
|
||||
import { QSConfig } from '@types';
|
||||
|
||||
import styled from 'styled-components';
|
||||
|
||||
const TextInput = styled(PFTextInput)`
|
||||
@ -110,10 +112,18 @@ class Search extends React.Component {
|
||||
e.preventDefault();
|
||||
|
||||
const { searchKey, searchValue } = this.state;
|
||||
const { onSearch } = this.props;
|
||||
const { onSearch, qsConfig } = this.props;
|
||||
|
||||
// TODO: probably not _always_ add icontains. I don't think icontains works for numbers.
|
||||
onSearch(`${searchKey}__icontains`, searchValue);
|
||||
const isNonStringField = key => qsConfig
|
||||
.integerFields
|
||||
.filter(field => field === key).length || qsConfig.dateFields
|
||||
.filter(field => field === key).length;
|
||||
|
||||
// TODO: this will probably become more sophisticated, where date
|
||||
// fields and string fields are passed to a formatter
|
||||
const actualSearchKey = isNonStringField(searchKey) ? searchKey : `${searchKey}__icontains`;
|
||||
|
||||
onSearch(actualSearchKey, searchValue);
|
||||
|
||||
this.setState({ searchValue: '' });
|
||||
}
|
||||
@ -202,6 +212,7 @@ class Search extends React.Component {
|
||||
}
|
||||
|
||||
Search.propTypes = {
|
||||
qsConfig: QSConfig.isRequired,
|
||||
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
onSearch: PropTypes.func,
|
||||
sortedColumnKey: PropTypes.string,
|
||||
|
||||
@ -183,6 +183,7 @@ class JobList extends Component {
|
||||
showExpandCollapse
|
||||
isAllSelected={isAllSelected}
|
||||
onSelectAll={this.handleSelectAll}
|
||||
qsConfig={QS_CONFIG}
|
||||
additionalControls={[
|
||||
<ToolbarDeleteButton
|
||||
key="delete"
|
||||
|
||||
@ -190,6 +190,7 @@ class OrganizationAccess extends React.Component {
|
||||
renderToolbar={props => (
|
||||
<DataListToolbar
|
||||
{...props}
|
||||
qsConfig={QS_CONFIG}
|
||||
additionalControls={
|
||||
canEdit
|
||||
? [
|
||||
|
||||
@ -181,6 +181,7 @@ class OrganizationsList extends Component {
|
||||
showSelectAll
|
||||
isAllSelected={isAllSelected}
|
||||
onSelectAll={this.handleSelectAll}
|
||||
qsConfig={QS_CONFIG}
|
||||
additionalControls={[
|
||||
<ToolbarDeleteButton
|
||||
key="delete"
|
||||
|
||||
@ -207,6 +207,7 @@ class TemplatesList extends Component {
|
||||
showExpandCollapse
|
||||
isAllSelected={isAllSelected}
|
||||
onSelectAll={this.handleSelectAll}
|
||||
qsConfig={QS_CONFIG}
|
||||
additionalControls={[
|
||||
<ToolbarDeleteButton
|
||||
key="delete"
|
||||
|
||||
@ -161,7 +161,8 @@ export const encodeNonDefaultQueryString = (config, params) => {
|
||||
export function getQSConfig(
|
||||
namespace,
|
||||
defaultParams = { page: 1, page_size: 5, order_by: 'name' },
|
||||
integerFields = ['page', 'page_size']
|
||||
integerFields = ['page', 'page_size'],
|
||||
dateFields = ['modified', 'created']
|
||||
) {
|
||||
if (!namespace) {
|
||||
throw new Error('a QS namespace is required');
|
||||
@ -170,6 +171,7 @@ export function getQSConfig(
|
||||
namespace,
|
||||
defaultParams,
|
||||
integerFields,
|
||||
dateFields
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user