Skip to content

Commit

Permalink
fix: Drawer should not apply any filters if cancel is cliked
Browse files Browse the repository at this point in the history
- also add TreeUl as prop
  • Loading branch information
lfjnascimento committed Jul 23, 2024
1 parent 23bcc92 commit 63e4ca3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
21 changes: 19 additions & 2 deletions dashboard/src/routes/TreeDetails/TreeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ const TreeDetails = (): JSX.Element => {
[filter],
);

//TODO: at some point `treeUrl` should be returned in `data`
const treeUrl = useMemo(() => {
let url = '';
if (!data) return '';
Object.entries(data.builds).some(([, build]) => {
if (build.git_repository_url) {
url = build.git_repository_url;
return true;
}
});
return url;
}, [data]);

useEffect(() => {
if (data) {
const configsData: IListingItem[] = Object.entries(
Expand Down Expand Up @@ -100,11 +113,15 @@ const TreeDetails = (): JSX.Element => {
<div className="flex flex-col pt-8">
<div className="flex flex-col pb-2">
<div className="flex justify-end">
<TreeDetailsFilter filter={filter} onFilter={setFilter} />
<TreeDetailsFilter
filter={filter}
onFilter={setFilter}
treeUrl={treeUrl}
/>
</div>
<TreeDetailsTab
treeDetailsData={treeDetailsData}
FilterListElement={filterListElement}
filterListElement={filterListElement}
/>
</div>
</div>
Expand Down
14 changes: 11 additions & 3 deletions dashboard/src/routes/TreeDetails/TreeDetailsFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type TFilter =
interface ITreeDetailsFilter {
filter: TFilter;
onFilter: (filter: TFilter) => void;
treeUrl: string;
}

export type TFilterKeys = (typeof filterFieldMap)[keyof typeof filterFieldMap];
Expand Down Expand Up @@ -87,6 +88,7 @@ const changeFilterValue = (
const TreeDetailsFilter = ({
filter,
onFilter,
treeUrl,
}: ITreeDetailsFilter): JSX.Element => {
const intl = useIntl();
const [diffFilter, setDiffFilter] = useState<TFilter>({});
Expand All @@ -106,6 +108,10 @@ const TreeDetailsFilter = ({
setDiffFilter({});
}, [filter, diffFilter, onFilter]);

const onClickCancel = useCallback(() => {
setDiffFilter({});
}, []);

const checkboxSectionsProps: ICheckboxSection[] = useMemo(() => {
return [
{
Expand Down Expand Up @@ -160,7 +166,11 @@ const TreeDetailsFilter = ({
);

return (
<FilterDrawer treeURL={treeUrl} onFilter={onClickFilterHandle}>
<FilterDrawer
treeURL={treeUrl}
onFilter={onClickFilterHandle}
onCancel={onClickCancel}
>
<FilterSummarySection {...summarySectionProps} />
{checkboxSectionsComponents}
</FilterDrawer>
Expand All @@ -169,8 +179,6 @@ const TreeDetailsFilter = ({

export default TreeDetailsFilter;

const treeUrl =
'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git';
const summarySectionProps = {
title: 'Tree',
columns: [
Expand Down

0 comments on commit 63e4ca3

Please sign in to comment.