Skip to content

Commit

Permalink
fix(topbar): only close drawer on application change with new callback (
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornwedell authored Nov 21, 2024
1 parent fa445ed commit acdf7ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 9 additions & 2 deletions components/topbar/src/application-drawer-v1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const ApplicationDrawerV1 = ({
applicationId,
content,
onChange,
onChangeAndClose,
applicationArea,
}: ApplicationDrawerProps & { applicationArea: ApplicationArea }) => {
const { t } = useTranslation();
Expand All @@ -216,9 +217,15 @@ export const ApplicationDrawerV1 = ({

const onClickItem = (id: string) => {
if (id !== currentSelection?.id) {
onChange(id);
if (onChangeAndClose) {
onChangeAndClose(id);
setIsOpen(false);
} else {
onChange?.(id);
}
} else {
setIsOpen(false);
}
setIsOpen(false);
};

return (
Expand Down
11 changes: 9 additions & 2 deletions components/topbar/src/application-drawer-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,23 @@ export const ApplicationDrawerV2 = ({
applicationId,
content,
onChange,
onChangeAndClose,
}: ApplicationDrawerProps & { applicationArea: ApplicationArea }) => {
const [isOpen, setIsOpen] = useState(false);
const styles = useApplicationDrawerV2Styles();
const currentSelection = findCurrent(applicationId, content);

const onClickItem = (id: string) => {
if (id !== currentSelection?.id) {
onChange(id);
if (onChangeAndClose) {
onChangeAndClose(id);
setIsOpen(false);
} else {
onChange?.(id);
}
} else {
setIsOpen(false);
}
setIsOpen(false);
};

return (
Expand Down
7 changes: 6 additions & 1 deletion components/topbar/src/application-drawer.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ export type ApplicationDrawerProps = {
title: JSX.Element;
content?: ApplicationDrawerContent[];
applicationId: string;
onChange: (id: string) => void;
onChange?: (id: string) => void;
/**
* Supply this function if you want the drawer to close the drawer after the action.
* Supplying this function will cause onChange callback function to be ignored.
*/
onChangeAndClose?: (id: string) => void;
};

0 comments on commit acdf7ee

Please sign in to comment.