Skip to content

Commit

Permalink
Add filtering by undefined and fix searching by name (#2714)
Browse files Browse the repository at this point in the history
* empty settings page and route

* wow it was annoying to make the settings page

* did not end up needing to change breadcrumbs

* list providers

* debug adding notifications in the backend, debug provider object class in the frontend, and allow for undefined values as - in filters

* filter by name search was broken and tests were not behaving as expected

* go mod tidy

* filterByText formatting

* filter dialog formatting

* filter bugs and added filterSeparator to tests

* removed an oopsie yaml file

* one spot where filterSeparator was missing

* bad fix for undefined chip label

* SNAPS

* better test for displaying dash in chip, chip group height

* test changes

* snapshot

* remove override for chip text

* test updates

* remove screen.debug and make filterByText better

* make search and filter optional on data table
  • Loading branch information
joshri authored Sep 12, 2022
1 parent d0e288c commit 7b7ceff
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 378 deletions.
1 change: 1 addition & 0 deletions ui/components/ChipGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default styled(ChipGroup).attrs({ className: ChipGroup.name })`
.MuiChip-root {
margin-right: ${(props) => props.theme.spacing.xxs};
}
height: 40px;
padding: 4px 0px;
flex-wrap: nowrap;
overflow-x: auto;
Expand Down
87 changes: 45 additions & 42 deletions ui/components/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,31 +161,27 @@ function filterText(

return _.filter(rows, (row) => {
let matches = false;
for (const colName in row) {
const value = row[colName];

const field = _.find(fields, (f) => {
if (typeof f.value === "string") {
return f.value === colName;
}
fields.forEach((field) => {
if (!field.textSearchable) return matches;

if (f.sortValue) {
return f.sortValue(row) === value;
}
});

if (!field || !field.textSearchable) {
continue;
let value;
if (field.sortValue) {
value = field.sortValue(row);
} else {
value =
typeof field.value === "function"
? field.value(row)
: row[field.value];
}

// This allows us to look for a fragment in the string.
// For example, if the user searches for "pod", the "podinfo" kustomization should be returned.
for (const filterString of textFilters) {
if (_.includes(value, filterString)) {
matches = true;
for (let i = 0; i < textFilters.length; i++) {
matches = value.includes(textFilters[i]);
if (!matches) {
break;
}
}
}
});

return matches;
});
Expand Down Expand Up @@ -480,30 +476,37 @@ function UnstyledDataTable({
});
return (
<Flex wide tall column className={className}>
<Flex wide align between>
<Flex
wide
align
between={filters ? true : false}
start={filters ? false : true}
>
{checkboxes && <CheckboxActions checked={checked} rows={filtered} />}
<Flex wide align end>
<ChipGroup
chips={chips}
onChipRemove={handleChipRemove}
onClearAll={handleClearAll}
/>
<IconFlex align>
<SearchField onSubmit={handleTextSearchSubmit} />
<IconButton
onClick={() => setFilterDialogOpen(!filterDialogOpen)}
className={className}
variant={filterDialogOpen ? "contained" : "text"}
color="inherit"
>
<Icon
type={IconType.FilterIcon}
size="medium"
color="neutral30"
/>
</IconButton>
</IconFlex>
</Flex>
{filters && (
<Flex wide align end>
<ChipGroup
chips={chips}
onChipRemove={handleChipRemove}
onClearAll={handleClearAll}
/>
<IconFlex align>
<SearchField onSubmit={handleTextSearchSubmit} />
<IconButton
onClick={() => setFilterDialogOpen(!filterDialogOpen)}
className={className}
variant={filterDialogOpen ? "contained" : "text"}
color="inherit"
>
<Icon
type={IconType.FilterIcon}
size="medium"
color="neutral30"
/>
</IconButton>
</IconFlex>
</Flex>
)}
</Flex>
<Flex wide tall>
<TableContainer>
Expand Down
34 changes: 17 additions & 17 deletions ui/components/FilterDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SlideContent = styled.div`
padding-left: ${(props) => props.theme.spacing.large};
`;

export const filterSeparator = ":";
export const filterSeparator = ": ";

type FilterSectionProps = {
header: string;
Expand All @@ -48,7 +48,9 @@ const FilterSection = ({
formState,
onSectionSelect,
}: FilterSectionProps) => {
const compoundKeys = options.map((option) => `${header}:${option}`);
const compoundKeys = options.map(
(option) => `${header}${filterSeparator}${option}`
);
// every on an empty list is true so check that too
const all =
compoundKeys.length > 0 && compoundKeys.every((key) => formState[key]);
Expand Down Expand Up @@ -77,21 +79,19 @@ const FilterSection = ({
{convertHeaders(header)}
</Text>
</ListItem>
{options.sort().map((option: string, index: number) => {
return (
<ListItem key={index}>
<ListItemIcon>
<FormCheckbox
label=""
name={`${header}${filterSeparator}${option}`}
/>
</ListItemIcon>
<Text color="neutral40" size="small">
{_.toString(option)}
</Text>
</ListItem>
);
})}
{options.sort().map((option: string, index: number) => (
<ListItem key={index}>
<ListItemIcon>
<FormCheckbox
label=""
name={`${header}${filterSeparator}${option}`}
/>
</ListItemIcon>
<Text color="neutral40" size="small">
{_.toString(option) || "-"}
</Text>
</ListItem>
))}
</List>
</ListItem>
);
Expand Down
2 changes: 1 addition & 1 deletion ui/components/__tests__/ChipGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ChipGroup from "../ChipGroup";

describe("ChipGroup", () => {
const setActiveChips = jest.fn();
const chipList = ["app", "app2", "app3"];
const chipList = ["app", "app2", "app3", `appappapp`];

it("should render chips", () => {
render(
Expand Down
2 changes: 1 addition & 1 deletion ui/components/__tests__/DataTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("DataTable", () => {
const firstRow = screen.getAllByRole("row")[1];
expect(firstRow.innerHTML).toMatch(/podinfo/);
});
it("should render text when rows is empty", () => {
it("should render text when rows are empty", () => {
render(
withTheme(
withContext(
Expand Down
Loading

0 comments on commit 7b7ceff

Please sign in to comment.