mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 22:49:32 -02: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:
@@ -62,6 +62,7 @@ function DataListToolbar({
|
|||||||
id={`${qsConfig.namespace}-list-toolbar`}
|
id={`${qsConfig.namespace}-list-toolbar`}
|
||||||
clearAllFilters={clearAllFilters}
|
clearAllFilters={clearAllFilters}
|
||||||
collapseListedFiltersBreakpoint="lg"
|
collapseListedFiltersBreakpoint="lg"
|
||||||
|
clearFiltersButtonText={i18n._(t`Clear all filters`)}
|
||||||
>
|
>
|
||||||
<ToolbarContent>
|
<ToolbarContent>
|
||||||
{showSelectAll && (
|
{showSelectAll && (
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ const QS_CONFIG = getQSConfig(
|
|||||||
const buildSearchColumns = i18n => [
|
const buildSearchColumns = i18n => [
|
||||||
{
|
{
|
||||||
name: i18n._(t`Name`),
|
name: i18n._(t`Name`),
|
||||||
key: 'name',
|
key: 'name__icontains',
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,7 @@ const buildSearchColumns = i18n => [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Group`),
|
name: i18n._(t`Group`),
|
||||||
key: 'groups__name',
|
key: 'groups__name__icontains',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Inventory ID`),
|
name: i18n._(t`Inventory ID`),
|
||||||
@@ -124,7 +124,7 @@ function HostFilterLookup({
|
|||||||
const searchColumns = buildSearchColumns(i18n);
|
const searchColumns = buildSearchColumns(i18n);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
result: { count, hosts },
|
result: { count, hosts, relatedSearchableKeys, searchableKeys },
|
||||||
error: contentError,
|
error: contentError,
|
||||||
request: fetchHosts,
|
request: fetchHosts,
|
||||||
isLoading,
|
isLoading,
|
||||||
@@ -132,12 +132,21 @@ function HostFilterLookup({
|
|||||||
useCallback(
|
useCallback(
|
||||||
async orgId => {
|
async orgId => {
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
const params = parseQueryString(QS_CONFIG, location.search);
|
||||||
const { data } = await HostsAPI.read(
|
const [{ data }, { data: actions }] = await Promise.all([
|
||||||
mergeParams(params, { inventory__organization: orgId })
|
HostsAPI.read(
|
||||||
);
|
mergeParams(params, { inventory__organization: orgId })
|
||||||
|
),
|
||||||
|
HostsAPI.readOptions(),
|
||||||
|
]);
|
||||||
return {
|
return {
|
||||||
count: data.count,
|
count: data.count,
|
||||||
hosts: data.results,
|
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]
|
[location.search]
|
||||||
@@ -145,6 +154,8 @@ function HostFilterLookup({
|
|||||||
{
|
{
|
||||||
count: 0,
|
count: 0,
|
||||||
hosts: [],
|
hosts: [],
|
||||||
|
relatedSearchableKeys: [],
|
||||||
|
searchableKeys: [],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -185,7 +196,7 @@ function HostFilterLookup({
|
|||||||
|
|
||||||
function buildChips(filter = {}) {
|
function buildChips(filter = {}) {
|
||||||
const inputGroupChips = Object.keys(filter).reduce((obj, param) => {
|
const inputGroupChips = Object.keys(filter).reduce((obj, param) => {
|
||||||
const parsedKey = param.replace('__icontains', '').replace('or__', '');
|
const parsedKey = param.replace('or__', '');
|
||||||
const chipsArray = [];
|
const chipsArray = [];
|
||||||
|
|
||||||
if (Array.isArray(filter[param])) {
|
if (Array.isArray(filter[param])) {
|
||||||
@@ -316,6 +327,8 @@ function HostFilterLookup({
|
|||||||
key: 'modified',
|
key: 'modified',
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
toolbarSearchableKeys={searchableKeys}
|
||||||
|
toolbarRelatedSearchableKeys={relatedSearchableKeys}
|
||||||
/>
|
/>
|
||||||
</ModalList>
|
</ModalList>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const mockFormValues = {
|
|||||||
description: '',
|
description: '',
|
||||||
organization: { id: 1, name: 'mock organization' },
|
organization: { id: 1, name: 'mock organization' },
|
||||||
host_filter:
|
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 }],
|
instance_groups: [{ id: 123 }],
|
||||||
variables: '---',
|
variables: '---',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user