Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add status filters on overview page #840

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions packages/ui/src/components/StatusLegend/StatusLegend.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@
text-transform: uppercase;
}

.legend > li:before {
.legend > li {
display: flex;
align-items: center;
border-bottom: 2px solid transparent;
}

.legend > li.isSelected {
border-color: var(--status-menu-active-border);
color: var(--status-menu-active-text);
font-weight: 500;
}

.legend > li > a {
text-decoration: none;
margin: 0 0 -2px;
padding: 0.5em 1em;
color: var(--status-menu-text);
transition: border-bottom-color 200ms ease-in-out, color 0.1s ease;
display: flex;
align-items: center;
}

.legend > li > a:before {
content: '';
background-color: var(--item-bg);
border-radius: 50%;
Expand All @@ -16,8 +38,23 @@
margin-right: 0.5rem;
}

.legend > li + li {
margin-left: 2rem;
.legend > li > a span {
flex: 1;
white-space: nowrap;
}

.legend > li > a span:before {
display: block;
content: attr(title);
font-weight: 600;
height: 0;
overflow: hidden;
visibility: hidden;
}

.legend > li > a:hover,
.legend > li > a:active {
border-color: #7a8085;
}

.waiting {
Expand Down
28 changes: 21 additions & 7 deletions packages/ui/src/components/StatusLegend/StatusLegend.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { queueStatsStatusList } from '../../constants/queue-stats-status';
import { toCamelCase } from '../../utils/toCamelCase';
import s from './StatusLegend.module.css';
import { NavLink } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { toCamelCase } from '../../utils/toCamelCase';
import cn from 'clsx';
import { useQuery } from '../../hooks/useQuery';

export const StatusLegend = () => {
const { t } = useTranslation();
const query = useQuery();

return (
<ul className={s.legend}>
{queueStatsStatusList.map((status) => (
<li key={status} className={s[toCamelCase(status)]}>
{t(`QUEUE.STATUS.${status.toUpperCase()}`)}
</li>
))}
{queueStatsStatusList.map((status) => {
const displayStatus = t(`QUEUE.STATUS.${status.toUpperCase()}`).toLocaleUpperCase();

return (<li key={status} className={cn(s[toCamelCase(status)], {
[s.isSelected]: query.get('status') === status,
})}>
<NavLink
to={`/?status=${status}`}
key={`overview-${status}`}
>
<span title={displayStatus}>{displayStatus}</span>
</NavLink>
</li>);
})}
</ul>
);
};
5 changes: 2 additions & 3 deletions packages/ui/src/hooks/useSelectedStatuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export function useSelectedStatuses(): SelectedStatuses {

useEffect(() => {
const status = getActiveStatus(search);
if (activeQueueName) {
setSelectedStatuses({ ...selectedStatuses, [activeQueueName]: status });
}

setSelectedStatuses({ ...selectedStatuses, [activeQueueName]: status });
}, [search, activeQueueName]);

return selectedStatuses;
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/pages/OverviewPage/OverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import { QueueCard } from '../../components/QueueCard/QueueCard';
import { StatusLegend } from '../../components/StatusLegend/StatusLegend';
import { useQueues } from '../../hooks/useQueues';
import s from './OverviewPage.module.css';
import { useSelectedStatuses } from '../../hooks/useSelectedStatuses';

export const OverviewPage = () => {
const { actions, queues } = useQueues();
actions.pollQueues();

const selectedStatus = useSelectedStatuses();
const overviewPageStatus = selectedStatus[''];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectedStatus['']- can u explain this statment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my understanding that this would be the queue value for the overview page, see in the useActiveQueueName hook?

But I guess this is probably not a good idea to rely on this since the overview page isn't really a queue?


return (
<section>
<StatusLegend />

<ul className={s.overview}>
{queues?.map((queue) => (
{queues?.filter((queue) => overviewPageStatus === 'latest' || queue.counts[overviewPageStatus] > 0).map((queue) => (
<li key={queue.name}>
<QueueCard queue={queue} />
</li>
Expand Down
Loading