mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 05:55:59 -03:30
Merge pull request #11208 from AlexSCorey/7741-GroupAdvanceSearchKeys
Groups Advanced Search Keys
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -56,6 +56,7 @@ function DataListToolbar({
|
|||||||
enableNegativeFiltering,
|
enableNegativeFiltering,
|
||||||
enableRelatedFuzzyFiltering,
|
enableRelatedFuzzyFiltering,
|
||||||
}) {
|
}) {
|
||||||
|
const { search } = useLocation();
|
||||||
const showExpandCollapse = onCompact && onExpand;
|
const showExpandCollapse = onCompact && onExpand;
|
||||||
const [isKebabOpen, setIsKebabOpen] = useState(false);
|
const [isKebabOpen, setIsKebabOpen] = useState(false);
|
||||||
const [isKebabModalOpen, setIsKebabModalOpen] = useState(false);
|
const [isKebabModalOpen, setIsKebabModalOpen] = useState(false);
|
||||||
@@ -81,7 +82,7 @@ function DataListToolbar({
|
|||||||
id={`${qsConfig.namespace}-list-toolbar`}
|
id={`${qsConfig.namespace}-list-toolbar`}
|
||||||
clearAllFilters={clearAllFilters}
|
clearAllFilters={clearAllFilters}
|
||||||
collapseListedFiltersBreakpoint="lg"
|
collapseListedFiltersBreakpoint="lg"
|
||||||
clearFiltersButtonText={t`Clear all filters`}
|
clearFiltersButtonText={Boolean(search) && t`Clear all filters`}
|
||||||
>
|
>
|
||||||
<ToolbarContent>
|
<ToolbarContent>
|
||||||
{onExpandAll && (
|
{onExpandAll && (
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
|||||||
import DataListToolbar from './DataListToolbar';
|
import DataListToolbar from './DataListToolbar';
|
||||||
import AddDropDownButton from '../AddDropDownButton/AddDropDownButton';
|
import AddDropDownButton from '../AddDropDownButton/AddDropDownButton';
|
||||||
|
|
||||||
|
jest.mock('react-router-dom', () => ({
|
||||||
|
...jest.requireActual('react-router-dom'),
|
||||||
|
useLocation: () => ({
|
||||||
|
pathname: '/organizations',
|
||||||
|
search: 'template.name__icontains=name',
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
describe('<DataListToolbar />', () => {
|
describe('<DataListToolbar />', () => {
|
||||||
let toolbar;
|
let toolbar;
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import { t } from '@lingui/macro';
|
|||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
ButtonVariant,
|
ButtonVariant,
|
||||||
|
Divider,
|
||||||
InputGroup,
|
InputGroup,
|
||||||
Select,
|
Select,
|
||||||
|
SelectGroup,
|
||||||
SelectOption,
|
SelectOption,
|
||||||
SelectVariant,
|
SelectVariant,
|
||||||
TextInput,
|
TextInput,
|
||||||
@@ -41,15 +43,9 @@ function AdvancedSearch({
|
|||||||
enableNegativeFiltering,
|
enableNegativeFiltering,
|
||||||
enableRelatedFuzzyFiltering,
|
enableRelatedFuzzyFiltering,
|
||||||
}) {
|
}) {
|
||||||
// TODO: blocked by pf bug, eventually separate these into two groups in the select
|
const relatedKeys = relatedSearchableKeys.filter(
|
||||||
// for now, I'm spreading set to get rid of duplicate keys...when they are grouped
|
(sKey) => !searchableKeys.map(({ key }) => key).includes(sKey)
|
||||||
// we might want to revisit that.
|
);
|
||||||
const allKeys = [
|
|
||||||
...new Set([
|
|
||||||
...(searchableKeys.map((k) => k.key) || []),
|
|
||||||
...(relatedSearchableKeys || []),
|
|
||||||
]),
|
|
||||||
];
|
|
||||||
|
|
||||||
const [isPrefixDropdownOpen, setIsPrefixDropdownOpen] = useState(false);
|
const [isPrefixDropdownOpen, setIsPrefixDropdownOpen] = useState(false);
|
||||||
const [isKeyDropdownOpen, setIsKeyDropdownOpen] = useState(false);
|
const [isKeyDropdownOpen, setIsKeyDropdownOpen] = useState(false);
|
||||||
@@ -165,19 +161,44 @@ function AdvancedSearch({
|
|||||||
isOpen={isKeyDropdownOpen}
|
isOpen={isKeyDropdownOpen}
|
||||||
placeholderText={t`Key`}
|
placeholderText={t`Key`}
|
||||||
isCreatable
|
isCreatable
|
||||||
|
isGrouped
|
||||||
onCreateOption={setKeySelection}
|
onCreateOption={setKeySelection}
|
||||||
maxHeight={maxSelectHeight}
|
maxHeight={maxSelectHeight}
|
||||||
noResultsFoundText={t`No results found`}
|
noResultsFoundText={t`No results found`}
|
||||||
>
|
>
|
||||||
{allKeys.map((optionKey) => (
|
{[
|
||||||
<SelectOption
|
...(searchableKeys.length
|
||||||
key={optionKey}
|
? [
|
||||||
value={optionKey}
|
<SelectGroup key="direct keys" label={t`Direct Keys`}>
|
||||||
id={`select-option-${optionKey}`}
|
{searchableKeys.map((k) => (
|
||||||
>
|
<SelectOption
|
||||||
{optionKey}
|
value={k.key}
|
||||||
</SelectOption>
|
key={k.key}
|
||||||
))}
|
id={`select-option-${k.key}`}
|
||||||
|
>
|
||||||
|
{k.key}
|
||||||
|
</SelectOption>
|
||||||
|
))}
|
||||||
|
</SelectGroup>,
|
||||||
|
<Divider key="divider" />,
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
...(relatedKeys.length
|
||||||
|
? [
|
||||||
|
<SelectGroup key="related keys" label={t`Related Keys`}>
|
||||||
|
{relatedKeys.map((rKey) => (
|
||||||
|
<SelectOption
|
||||||
|
value={rKey}
|
||||||
|
key={rKey}
|
||||||
|
id={`select-option-${rKey}`}
|
||||||
|
>
|
||||||
|
{rKey}
|
||||||
|
</SelectOption>
|
||||||
|
))}
|
||||||
|
</SelectGroup>,
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
]}
|
||||||
</Select>
|
</Select>
|
||||||
{relatedSearchKeySelected ? (
|
{relatedSearchKeySelected ? (
|
||||||
<RelatedLookupTypeInput
|
<RelatedLookupTypeInput
|
||||||
|
|||||||
Reference in New Issue
Block a user