Decode host filter chip values and fix boolean search filter chip bug

This commit is contained in:
Marliana Lara 2020-07-22 15:09:45 -04:00
parent 8e6d475a9d
commit af218aaa0b
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
4 changed files with 15 additions and 19 deletions

View File

@ -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({

View File

@ -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 ');
}

View File

@ -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}`}
>

View File

@ -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