Skip to content

Commit

Permalink
refactor: extract sticky header from jobPage & queuePage
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Aug 9, 2023
1 parent e866635 commit b185014
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
12 changes: 12 additions & 0 deletions packages/ui/src/components/StickyHeader/StickyHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { PropsWithChildren } from 'react';
import s from './StickyHeader.module.css';

export const StickyHeader = ({
actions,
children,
}: PropsWithChildren<{ actions: React.ReactElement }>) => (
<div className={s.stickyHeader}>
{children}
{!!actions && <div className={s.actionContainer}>{actions}</div>}
</div>
);
26 changes: 14 additions & 12 deletions packages/ui/src/pages/JobPage/JobPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import React from 'react';
import { Link, useHistory } from 'react-router-dom';
import { ArrowLeftIcon } from '../../components/Icons/ArrowLeft';
import { JobCard } from '../../components/JobCard/JobCard';
import { StickyHeader } from '../../components/StickyHeader/StickyHeader';
import { useJob } from '../../hooks/useJob';
import { useSelectedStatuses } from '../../hooks/useSelectedStatuses';
import { links } from '../../utils/links';
import s from '../QueuePage/QueuePage.module.css';
import buttonS from '../../components/Button/Button.module.css';

export const JobPage = ({ queue }: { queue: AppQueue | null }) => {
Expand All @@ -32,17 +32,19 @@ export const JobPage = ({ queue }: { queue: AppQueue | null }) => {

return (
<section>
<div className={s.stickyHeader}>
<div className={s.actionContainer}>
<Link
className={cn(buttonS.button, buttonS.default)}
to={links.queuePage(queue.name, selectedStatuses)}
>
<ArrowLeftIcon />
</Link>
<div>Status: {status.toLocaleUpperCase()}</div>
</div>
</div>
<StickyHeader
actions={
<>
<Link
className={cn(buttonS.button, buttonS.default)}
to={links.queuePage(queue.name, selectedStatuses)}
>
<ArrowLeftIcon />
</Link>
<div>Status: {status.toLocaleUpperCase()}</div>
</>
}
/>
<JobCard
key={job.id}
job={job}
Expand Down
41 changes: 22 additions & 19 deletions packages/ui/src/pages/QueuePage/QueuePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { JobCard } from '../../components/JobCard/JobCard';
import { Pagination } from '../../components/Pagination/Pagination';
import { QueueActions } from '../../components/QueueActions/QueueActions';
import { StatusMenu } from '../../components/StatusMenu/StatusMenu';
import { StickyHeader } from '../../components/StickyHeader/StickyHeader';
import { useActiveQueue } from '../../hooks/useActiveQueue';
import { useJob } from '../../hooks/useJob';
import { useQueues } from '../../hooks/useQueues';
import { useSelectedStatuses } from '../../hooks/useSelectedStatuses';
import { links } from '../../utils/links';
import s from './QueuePage.module.css';

export const QueuePage = () => {
const selectedStatus = useSelectedStatuses();
Expand All @@ -28,25 +28,28 @@ export const QueuePage = () => {

return (
<section>
<div className={s.stickyHeader}>
<StickyHeader
actions={
<>
<div>
{queue.jobs.length > 0 && !queue.readOnlyMode && (
<QueueActions
queue={queue}
actions={actions}
status={selectedStatus[queue.name]}
allowRetries={
(selectedStatus[queue.name] == 'failed' || queue.allowCompletedRetries) &&
queue.allowRetries
}
/>
)}
</div>
<Pagination pageCount={queue.pagination.pageCount} />
</>
}
>
<StatusMenu queue={queue} actions={actions} />
<div className={s.actionContainer}>
<div>
{queue.jobs.length > 0 && !queue.readOnlyMode && (
<QueueActions
queue={queue}
actions={actions}
status={selectedStatus[queue.name]}
allowRetries={
(selectedStatus[queue.name] == 'failed' || queue.allowCompletedRetries) &&
queue.allowRetries
}
/>
)}
</div>
<Pagination pageCount={queue.pagination.pageCount} />
</div>
</div>
</StickyHeader>
{queue.jobs.map((job) => (
<JobCard
key={job.id}
Expand Down

0 comments on commit b185014

Please sign in to comment.