mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Decode host filter chip values and fix boolean search filter chip bug
This commit is contained in:
@@ -84,12 +84,13 @@ const buildSearchColumns = i18n => [
|
|||||||
key: 'groups__name',
|
key: 'groups__name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Inventory`),
|
name: i18n._(t`Inventory ID`),
|
||||||
key: 'inventory',
|
key: 'inventory',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Enabled`),
|
name: i18n._(t`Enabled`),
|
||||||
key: 'enabled',
|
key: 'enabled',
|
||||||
|
isBoolean: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n._(t`Instance ID`),
|
name: i18n._(t`Instance ID`),
|
||||||
@@ -103,10 +104,6 @@ const buildSearchColumns = i18n => [
|
|||||||
name: i18n._(t`Insights system ID`),
|
name: i18n._(t`Insights system ID`),
|
||||||
key: 'insights_system_id',
|
key: 'insights_system_id',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: i18n._(t`Ansible facts modified`),
|
|
||||||
key: 'ansible_facts_modified',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function HostFilterLookup({
|
function HostFilterLookup({
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ export function toSearchParams(string = '') {
|
|||||||
if (string === '') {
|
if (string === '') {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return string
|
return string
|
||||||
.replace(/^\?/, '')
|
.replace(/^\?/, '')
|
||||||
.replace(/&/, ' and ')
|
.replace(/&/g, ' and ')
|
||||||
.split(/ and | or /)
|
.split(/ and | or /)
|
||||||
.map(s => s.split('='))
|
.map(s => s.split('='))
|
||||||
.reduce((searchParams, [key, value]) => {
|
.reduce((searchParams, [k, v]) => {
|
||||||
|
const key = decodeURIComponent(k);
|
||||||
|
const value = decodeURIComponent(v);
|
||||||
if (searchParams[key] === undefined) {
|
if (searchParams[key] === undefined) {
|
||||||
searchParams[key] = value;
|
searchParams[key] = value;
|
||||||
} else if (Array.isArray(searchParams[key])) {
|
} else if (Array.isArray(searchParams[key])) {
|
||||||
@@ -61,13 +62,9 @@ export function toHostFilter(searchParams = {}) {
|
|||||||
return Object.keys(searchParams)
|
return Object.keys(searchParams)
|
||||||
.flatMap(key => {
|
.flatMap(key => {
|
||||||
if (Array.isArray(searchParams[key])) {
|
if (Array.isArray(searchParams[key])) {
|
||||||
return searchParams[key].map(
|
return searchParams[key].map(val => `${key}=${val}`);
|
||||||
val => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return `${encodeURIComponent(key)}=${encodeURIComponent(
|
return `${key}=${searchParams[key]}`;
|
||||||
searchParams[key]
|
|
||||||
)}`;
|
|
||||||
})
|
})
|
||||||
.join(' and ');
|
.join(' and ');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,13 +97,16 @@ function Search({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getLabelFromValue = (value, colKey) => {
|
const getLabelFromValue = (value, colKey) => {
|
||||||
|
let label = value;
|
||||||
const currentSearchColumn = columns.find(({ key }) => key === colKey);
|
const currentSearchColumn = columns.find(({ key }) => key === colKey);
|
||||||
if (currentSearchColumn?.options?.length) {
|
if (currentSearchColumn?.options?.length) {
|
||||||
return currentSearchColumn.options.find(
|
[, label] = currentSearchColumn.options.find(
|
||||||
([optVal]) => optVal === value
|
([optVal]) => optVal === value
|
||||||
)[1];
|
);
|
||||||
|
} else if (currentSearchColumn?.booleanLabels) {
|
||||||
|
label = currentSearchColumn.booleanLabels[value];
|
||||||
}
|
}
|
||||||
return value.toString();
|
return label.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
const getChipsByKey = () => {
|
const getChipsByKey = () => {
|
||||||
@@ -227,7 +230,7 @@ function Search({
|
|||||||
aria-label={name}
|
aria-label={name}
|
||||||
onToggle={setIsFilterDropdownOpen}
|
onToggle={setIsFilterDropdownOpen}
|
||||||
onSelect={(event, selection) => onReplaceSearch(key, selection)}
|
onSelect={(event, selection) => onReplaceSearch(key, selection)}
|
||||||
selections={chipsByKey[key].chips[0]}
|
selections={chipsByKey[key].chips[0]?.label}
|
||||||
isOpen={isFilterDropdownOpen}
|
isOpen={isFilterDropdownOpen}
|
||||||
placeholderText={`Filter By ${name}`}
|
placeholderText={`Filter By ${name}`}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ const SmartInventoryFormFields = withI18n()(({ i18n }) => {
|
|||||||
id="variables"
|
id="variables"
|
||||||
name="variables"
|
name="variables"
|
||||||
label={i18n._(t`Variables`)}
|
label={i18n._(t`Variables`)}
|
||||||
promptId="variables"
|
|
||||||
tooltip={i18n._(
|
tooltip={i18n._(
|
||||||
t`Enter inventory variables using either JSON or YAML syntax.
|
t`Enter inventory variables using either JSON or YAML syntax.
|
||||||
Use the radio button to toggle between the two. Refer to the
|
Use the radio button to toggle between the two. Refer to the
|
||||||
|
|||||||
Reference in New Issue
Block a user