From bef8d7426f033c4aa4a5ad9eee89343e42a2e474 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 5 Oct 2021 15:54:31 -0400 Subject: [PATCH] Groups Advanced search keys, and removes Clear all filters text after advanced search --- .../DataListToolbar/DataListToolbar.js | 5 +- .../DataListToolbar/DataListToolbar.test.js | 8 +++ .../src/components/Search/AdvancedSearch.js | 57 +++++++++++++------ 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/awx/ui/src/components/DataListToolbar/DataListToolbar.js b/awx/ui/src/components/DataListToolbar/DataListToolbar.js index bd3eca8b04..4842814c34 100644 --- a/awx/ui/src/components/DataListToolbar/DataListToolbar.js +++ b/awx/ui/src/components/DataListToolbar/DataListToolbar.js @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import styled from 'styled-components'; - +import { useLocation } from 'react-router-dom'; import { t } from '@lingui/macro'; import { Button, @@ -56,6 +56,7 @@ function DataListToolbar({ enableNegativeFiltering, enableRelatedFuzzyFiltering, }) { + const { search } = useLocation(); const showExpandCollapse = onCompact && onExpand; const [isKebabOpen, setIsKebabOpen] = useState(false); const [isKebabModalOpen, setIsKebabModalOpen] = useState(false); @@ -81,7 +82,7 @@ function DataListToolbar({ id={`${qsConfig.namespace}-list-toolbar`} clearAllFilters={clearAllFilters} collapseListedFiltersBreakpoint="lg" - clearFiltersButtonText={t`Clear all filters`} + clearFiltersButtonText={Boolean(search) && t`Clear all filters`} > {onExpandAll && ( diff --git a/awx/ui/src/components/DataListToolbar/DataListToolbar.test.js b/awx/ui/src/components/DataListToolbar/DataListToolbar.test.js index 6ff3001740..932cdaa012 100644 --- a/awx/ui/src/components/DataListToolbar/DataListToolbar.test.js +++ b/awx/ui/src/components/DataListToolbar/DataListToolbar.test.js @@ -5,6 +5,14 @@ import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; import DataListToolbar from './DataListToolbar'; import AddDropDownButton from '../AddDropDownButton/AddDropDownButton'; +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useLocation: () => ({ + pathname: '/organizations', + search: 'template.name__icontains=name', + }), +})); + describe('', () => { let toolbar; diff --git a/awx/ui/src/components/Search/AdvancedSearch.js b/awx/ui/src/components/Search/AdvancedSearch.js index 861c0cd33a..89a09528df 100644 --- a/awx/ui/src/components/Search/AdvancedSearch.js +++ b/awx/ui/src/components/Search/AdvancedSearch.js @@ -5,8 +5,10 @@ import { t } from '@lingui/macro'; import { Button, ButtonVariant, + Divider, InputGroup, Select, + SelectGroup, SelectOption, SelectVariant, TextInput, @@ -41,15 +43,9 @@ function AdvancedSearch({ enableNegativeFiltering, enableRelatedFuzzyFiltering, }) { - // TODO: blocked by pf bug, eventually separate these into two groups in the select - // for now, I'm spreading set to get rid of duplicate keys...when they are grouped - // we might want to revisit that. - const allKeys = [ - ...new Set([ - ...(searchableKeys.map((k) => k.key) || []), - ...(relatedSearchableKeys || []), - ]), - ]; + const relatedKeys = relatedSearchableKeys.filter( + (sKey) => !searchableKeys.map(({ key }) => key).includes(sKey) + ); const [isPrefixDropdownOpen, setIsPrefixDropdownOpen] = useState(false); const [isKeyDropdownOpen, setIsKeyDropdownOpen] = useState(false); @@ -165,19 +161,44 @@ function AdvancedSearch({ isOpen={isKeyDropdownOpen} placeholderText={t`Key`} isCreatable + isGrouped onCreateOption={setKeySelection} maxHeight={maxSelectHeight} noResultsFoundText={t`No results found`} > - {allKeys.map((optionKey) => ( - - {optionKey} - - ))} + {[ + ...(searchableKeys.length + ? [ + + {searchableKeys.map((k) => ( + + {k.key} + + ))} + , + , + ] + : []), + ...(relatedKeys.length + ? [ + + {relatedKeys.map((rKey) => ( + + {rKey} + + ))} + , + ] + : []), + ]} {relatedSearchKeySelected ? (