mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 21:07:39 -02:30
Display search key along with value in tag
This commit is contained in:
@@ -45,28 +45,34 @@ const FilterTags = ({
|
|||||||
qsConfig
|
qsConfig
|
||||||
);
|
);
|
||||||
nonDefaultParams.forEach(key => {
|
nonDefaultParams.forEach(key => {
|
||||||
|
const label = key
|
||||||
|
.replace('__icontains', '')
|
||||||
|
.split('_')
|
||||||
|
.map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`)
|
||||||
|
.join(' ');
|
||||||
|
|
||||||
if (Array.isArray(queryParams[key])) {
|
if (Array.isArray(queryParams[key])) {
|
||||||
queryParams[key].forEach(val => queryParamsArr.push({ key, value: val }));
|
queryParams[key].forEach(val => queryParamsArr.push({ key, value: val, label }));
|
||||||
} else {
|
} else {
|
||||||
queryParamsArr.push({ key, value: queryParams[key] });
|
queryParamsArr.push({ key, value: queryParams[key], label });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
queryParamsArr.length > 0 && (
|
queryParamsArr.length > 0 && (
|
||||||
<FilterTagsRow>
|
<FilterTagsRow>
|
||||||
<ResultCount>{`${itemCount} results`}</ResultCount>
|
<ResultCount>{i18n._(t`${itemCount} results`)}</ResultCount>
|
||||||
<VerticalSeparator />
|
<VerticalSeparator />
|
||||||
<FilterLabel>{i18n._(t`Active Filters:`)}</FilterLabel>
|
<FilterLabel>{i18n._(t`Active Filters:`)}</FilterLabel>
|
||||||
<ChipGroup>
|
<ChipGroup>
|
||||||
{queryParamsArr.map(({ key, value }) => (
|
{queryParamsArr.map(({ key, label, value }) => (
|
||||||
<Chip
|
<Chip
|
||||||
className="searchTagChip"
|
className="searchTagChip"
|
||||||
key={`${key}__${value}`}
|
key={`${key}__${value}`}
|
||||||
isReadOnly={false}
|
isReadOnly={false}
|
||||||
onClick={() => onRemove(key, value)}
|
onClick={() => onRemove(key, value)}
|
||||||
>
|
>
|
||||||
{value}
|
<b>{label}:</b> {value}
|
||||||
</Chip>
|
</Chip>
|
||||||
))}
|
))}
|
||||||
<div className="pf-c-chip pf-m-overflow">
|
<div className="pf-c-chip pf-m-overflow">
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ describe('<ExpandCollapse />', () => {
|
|||||||
test('renders non-default param tags based on location history', () => {
|
test('renders non-default param tags based on location history', () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: [
|
initialEntries: [
|
||||||
'/foo?item.page=1&item.page_size=2&item.foo=bar&item.baz=bust',
|
'/foo?item.page=1&item.page_size=2&item.name__icontains=bar&item.job_type__icontains=project',
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
@@ -42,6 +42,10 @@ describe('<ExpandCollapse />', () => {
|
|||||||
);
|
);
|
||||||
const chips = wrapper.find('.pf-c-chip.searchTagChip');
|
const chips = wrapper.find('.pf-c-chip.searchTagChip');
|
||||||
expect(chips.length).toBe(2);
|
expect(chips.length).toBe(2);
|
||||||
|
const chipLabels = wrapper.find('.pf-c-chip__text b');
|
||||||
|
expect(chipLabels.length).toBe(2);
|
||||||
|
expect(chipLabels.at(0).text()).toEqual('Name:');
|
||||||
|
expect(chipLabels.at(1).text()).toEqual('Job Type:');
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user