mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Merge pull request #8510 from keithjgrant/7952-host-filter-lookup-fix
Host filter lookup fix
Reviewed-by: Tiago Góes <tiago.goes2009@gmail.com>
https://github.com/tiagodread
This commit is contained in:
commit
31c85dd89f
@ -62,6 +62,7 @@ function DataListToolbar({
|
||||
id={`${qsConfig.namespace}-list-toolbar`}
|
||||
clearAllFilters={clearAllFilters}
|
||||
collapseListedFiltersBreakpoint="lg"
|
||||
clearFiltersButtonText={i18n._(t`Clear all filters`)}
|
||||
>
|
||||
<ToolbarContent>
|
||||
{showSelectAll && (
|
||||
|
||||
@ -72,7 +72,7 @@ const QS_CONFIG = getQSConfig(
|
||||
const buildSearchColumns = i18n => [
|
||||
{
|
||||
name: i18n._(t`Name`),
|
||||
key: 'name',
|
||||
key: 'name__icontains',
|
||||
isDefault: true,
|
||||
},
|
||||
{
|
||||
@ -81,7 +81,7 @@ const buildSearchColumns = i18n => [
|
||||
},
|
||||
{
|
||||
name: i18n._(t`Group`),
|
||||
key: 'groups__name',
|
||||
key: 'groups__name__icontains',
|
||||
},
|
||||
{
|
||||
name: i18n._(t`Inventory ID`),
|
||||
@ -124,7 +124,7 @@ function HostFilterLookup({
|
||||
const searchColumns = buildSearchColumns(i18n);
|
||||
|
||||
const {
|
||||
result: { count, hosts },
|
||||
result: { count, hosts, relatedSearchableKeys, searchableKeys },
|
||||
error: contentError,
|
||||
request: fetchHosts,
|
||||
isLoading,
|
||||
@ -132,12 +132,21 @@ function HostFilterLookup({
|
||||
useCallback(
|
||||
async orgId => {
|
||||
const params = parseQueryString(QS_CONFIG, location.search);
|
||||
const { data } = await HostsAPI.read(
|
||||
mergeParams(params, { inventory__organization: orgId })
|
||||
);
|
||||
const [{ data }, { data: actions }] = await Promise.all([
|
||||
HostsAPI.read(
|
||||
mergeParams(params, { inventory__organization: orgId })
|
||||
),
|
||||
HostsAPI.readOptions(),
|
||||
]);
|
||||
return {
|
||||
count: data.count,
|
||||
hosts: data.results,
|
||||
relatedSearchableKeys: (
|
||||
actions?.related_search_fields || []
|
||||
).map(val => val.slice(0, -8)),
|
||||
searchableKeys: Object.keys(actions?.actions.GET || {}).filter(
|
||||
key => actions.actions?.GET[key].filterable
|
||||
),
|
||||
};
|
||||
},
|
||||
[location.search]
|
||||
@ -145,6 +154,8 @@ function HostFilterLookup({
|
||||
{
|
||||
count: 0,
|
||||
hosts: [],
|
||||
relatedSearchableKeys: [],
|
||||
searchableKeys: [],
|
||||
}
|
||||
);
|
||||
|
||||
@ -185,7 +196,7 @@ function HostFilterLookup({
|
||||
|
||||
function buildChips(filter = {}) {
|
||||
const inputGroupChips = Object.keys(filter).reduce((obj, param) => {
|
||||
const parsedKey = param.replace('__icontains', '').replace('or__', '');
|
||||
const parsedKey = param.replace('or__', '');
|
||||
const chipsArray = [];
|
||||
|
||||
if (Array.isArray(filter[param])) {
|
||||
@ -316,6 +327,8 @@ function HostFilterLookup({
|
||||
key: 'modified',
|
||||
},
|
||||
]}
|
||||
toolbarSearchableKeys={searchableKeys}
|
||||
toolbarRelatedSearchableKeys={relatedSearchableKeys}
|
||||
/>
|
||||
</ModalList>
|
||||
</Modal>
|
||||
|
||||
@ -26,7 +26,7 @@ const mockFormValues = {
|
||||
description: '',
|
||||
organization: { id: 1, name: 'mock organization' },
|
||||
host_filter:
|
||||
'name__icontains=mock and name__icontains=foo and groups__name=mock group',
|
||||
'name__icontains=mock and name__icontains=foo and groups__name__icontains=mock group',
|
||||
instance_groups: [{ id: 123 }],
|
||||
variables: '---',
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user