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