Skip to content

Commit

Permalink
Closing drawer on navigation, and fixed small filtering bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
arivepr committed Sep 5, 2023
1 parent 58dcec0 commit d40694e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 27 additions & 22 deletions src/components/NotificationsDrawer/DrawerPanelContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Icon } from '@patternfly/react-core/dist/dynamic/components/Icon';
import { Badge } from '@patternfly/react-core/dist/dynamic/components/Badge';
import { Checkbox } from '@patternfly/react-core/dist/dynamic/components/Checkbox';
import { Flex, FlexItem } from '@patternfly/react-core/dist/dynamic/layouts/Flex';
import { Dropdown, DropdownGroup, DropdownItem } from '@patternfly/react-core/dist/dynamic/components/Dropdown';
import { Dropdown, DropdownGroup, DropdownItem, DropdownList } from '@patternfly/react-core/dist/dynamic/components/Dropdown';
import { MenuToggle, MenuToggleElement } from '@patternfly/react-core/dist/dynamic/components/MenuToggle';
import { Divider } from '@patternfly/react-core/dist/dynamic/components/Divider';
import { Button } from '@patternfly/react-core/dist/dynamic/components/Button';
Expand Down Expand Up @@ -96,6 +96,11 @@ const DrawerPanelBase = ({ innerRef }: DrawerPanelProps) => {
: setActiveFilters([...activeFilters, chosenFilter]);
};

const onNavigateTo = (link: string) => {
navigate(link);
onNotificationsDrawerClose();
};

const dropdownItems = [
<DropdownItem key="read all" onClick={onMarkAllAsRead} isDisabled={notifications.length === 0}>
Mark visible as read
Expand All @@ -104,7 +109,7 @@ const DrawerPanelBase = ({ innerRef }: DrawerPanelProps) => {
Mark visible as unread
</DropdownItem>,
<Divider key="divider" />,
<DropdownItem key="event log" onClick={() => navigate('/settings/notifications/eventlog')}>
<DropdownItem key="event log" onClick={() => onNavigateTo('/settings/notifications/eventlog')}>
<Flex>
<FlexItem>View event log</FlexItem>
<FlexItem align={{ default: 'alignRight' }}>
Expand All @@ -115,7 +120,7 @@ const DrawerPanelBase = ({ innerRef }: DrawerPanelProps) => {
</Flex>
</DropdownItem>,
isOrgAdmin && (
<DropdownItem key="notification settings" onClick={() => navigate('/settings/notifications/configure-events')}>
<DropdownItem key="notification settings" onClick={() => onNavigateTo('/settings/notifications/configure-events')}>
<Flex>
<FlexItem>Configure notification settings</FlexItem>
<FlexItem align={{ default: 'alignRight' }}>
Expand All @@ -126,7 +131,7 @@ const DrawerPanelBase = ({ innerRef }: DrawerPanelProps) => {
</Flex>
</DropdownItem>
),
<DropdownItem key="notification preferences" onClick={() => navigate('/settings/notifications/user-preferences')}>
<DropdownItem key="notification preferences" onClick={() => onNavigateTo('/settings/notifications/user-preferences')}>
<Flex>
<FlexItem>Manage my notification preferences</FlexItem>
<FlexItem align={{ default: 'alignRight' }}>
Expand All @@ -141,18 +146,20 @@ const DrawerPanelBase = ({ innerRef }: DrawerPanelProps) => {
const filterDropdownItems = () => {
return [
<DropdownGroup key="filter-label" label="Show notifications for...">
{filterConfig.map((source) => (
<DropdownItem key={source.value} onClick={() => onFilterSelect(source.value)}>
<Checkbox isChecked={activeFilters.includes(source.value)} id={source.value} className="pf-v5-u-mr-sm" />
{source.title}
<DropdownList>
{filterConfig.map((source) => (
<DropdownItem key={source.value} onClick={() => onFilterSelect(source.value)} isDisabled={notifications.length === 0}>
<Checkbox isChecked={activeFilters.includes(source.value)} id={source.value} className="pf-v5-u-mr-sm" />
{source.title}
</DropdownItem>
))}
<Divider />
<DropdownItem key="reset-filters" onClick={() => setActiveFilters([])}>
<Button variant="link" isDisabled={activeFilters.length === 0} isInline>
Reset filters
</Button>
</DropdownItem>
))}
<Divider />
<DropdownItem key="reset-filters" onClick={() => setActiveFilters([])}>
<Button variant="link" isDisabled={activeFilters.length === 0} isInline>
Reset filters
</Button>
</DropdownItem>
</DropdownList>
</DropdownGroup>,
];
};
Expand All @@ -162,13 +169,11 @@ const DrawerPanelBase = ({ innerRef }: DrawerPanelProps) => {
return <EmptyNotifications />;
}

const sortedNotifications = orderBy(
filteredNotifications?.length > 0 ? filteredNotifications : notifications,
['read', 'created'],
['asc', 'asc']
);
const sortedNotifications = orderBy(activeFilters?.length > 0 ? filteredNotifications : notifications, ['read', 'created'], ['asc', 'asc']);

return sortedNotifications.map((notification) => <NotificationItem key={notification.id} notification={notification} />);
return sortedNotifications.map((notification) => (
<NotificationItem key={notification.id} notification={notification} onNavigateTo={onNavigateTo} />
));
};

return (
Expand Down Expand Up @@ -215,7 +220,7 @@ const DrawerPanelBase = ({ innerRef }: DrawerPanelProps) => {
}}
id="notifications-actions-dropdown"
>
{dropdownItems.map((dropdownItem) => dropdownItem)}
<DropdownList>{dropdownItems}</DropdownList>
</Dropdown>
</NotificationDrawerHeader>
<NotificationDrawerBody>
Expand Down
10 changes: 6 additions & 4 deletions src/components/NotificationsDrawer/NotificationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import DateFormat from '@redhat-cloud-services/frontend-components/DateFormat';
import { useDispatch } from 'react-redux';
import { NotificationData } from '../../redux/store';
import { markNotificationAsRead, markNotificationAsUnread } from '../../redux/actions';
import { useNavigate } from 'react-router-dom';

const NotificationItem = ({ notification }: { notification: NotificationData }) => {
interface NotificationItemProps {
notification: NotificationData;
onNavigateTo: (link: string) => void;
}
const NotificationItem: React.FC<NotificationItemProps> = ({ notification, onNavigateTo }) => {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const dispatch = useDispatch();
const navigate = useNavigate();

const onCheckboxToggle = () => {
dispatch(!notification.read ? markNotificationAsRead(notification.id) : markNotificationAsUnread(notification.id));
Expand All @@ -29,7 +31,7 @@ const NotificationItem = ({ notification }: { notification: NotificationData })

const notificationDropdownItems = [
<DropdownItem key="read" onClick={onCheckboxToggle}>{`Mark as ${!notification.read ? 'read' : 'unread'}`}</DropdownItem>,
<DropdownItem key="manage-event" onClick={() => navigate('settings/notifications/configure-events')}>
<DropdownItem key="manage-event" onClick={() => onNavigateTo('settings/notifications/configure-events')}>
Manage this event
</DropdownItem>,
];
Expand Down

0 comments on commit d40694e

Please sign in to comment.