Skip to content

Commit

Permalink
filter bar v1
Browse files Browse the repository at this point in the history
  • Loading branch information
joshri committed Feb 11, 2022
1 parent 96c0c35 commit 581127a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 deletions.
64 changes: 49 additions & 15 deletions ui/components/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function UnstyledFilterBar({
<Icon type={IconType.FilterIcon} size="medium" color="neutral30" />
</Button>
<Popover
className="filter-popover"
open={showFilters}
anchorEl={anchorEl}
anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
Expand All @@ -79,21 +80,54 @@ function UnstyledFilterBar({
<Divider />
<List>
{Object.keys(filterList).map((header: string, index: number) => {
<ListItem key={index}>
<Text>{header}</Text>
<List>
{filterList[header].map((option: string, index: number) => {
return (
<ListItem key={index}>
<ListItemIcon>
<Checkbox />
</ListItemIcon>
<Text>{option}</Text>
</ListItem>
);
})}
</List>
</ListItem>;
return (
<>
<ListItem key={index}>
<Flex column>
<Text size="large">{header}</Text>
<List>
{filterList[header].map(
(option: string, index: number) => {
if (search) {
for (let i = 0; i < search.length; i++) {
if (
search[i].toLowerCase() !==
option[i].toLowerCase()
) {
return;
}
}
}
return (
<ListItem key={index}>
<ListItemIcon>
<Checkbox
onChange={(e) => {
e.target.checked
? setActiveFilters([
...activeFilters,
option,
])
: setActiveFilters(
activeFilters.filter(
(filterCheck) =>
filterCheck !== option
)
);
}}
/>
</ListItemIcon>
<Text>{option}</Text>
</ListItem>
);
}
)}
</List>
</Flex>
</ListItem>
<Divider />
</>
);
})}
</List>
</Popover>
Expand Down
9 changes: 6 additions & 3 deletions ui/stories/FilterBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
} as Meta;

const Template: Story<Props> = (args) => {
const [storyFilters, setStoryFilters] = React.useState(args.activeFilters);
const [storyFilters, setStoryFilters] = React.useState([]);

return (
<FilterBar
Expand All @@ -29,6 +29,9 @@ const Template: Story<Props> = (args) => {
export const Default = Template.bind({});
Default.args = {
className: "",
activeFilters: ["Ready", "Helm Release"],
filterList: { Name: ["app", "app2", "app3"], Status: ["Ready", "Failed"] },
filterList: {
Name: ["app", "app2", "app3"],
Status: ["Ready", "Failed"],
Type: ["Application", "Helm Release"],
},
};

0 comments on commit 581127a

Please sign in to comment.