This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
250 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/ui/src/demoMocks/network/mutations/remove-jobs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { | ||
RemoveJobsMutation, | ||
RemoveJobsMutationVariables, | ||
} from '@/typings/gql'; | ||
import { networkMockData } from '../data'; | ||
|
||
export const removeJobsMock = ( | ||
args: RemoveJobsMutationVariables, | ||
): Promise<RemoveJobsMutation> => { | ||
const found: any[] = []; | ||
networkMockData.jobs = networkMockData.jobs.filter((job) => { | ||
const target = args.jobs.includes(job.id) && job.queue === args.queue; | ||
if (target) { | ||
found.push(target); | ||
} | ||
return !Boolean(target); | ||
}); | ||
return Promise.resolve({ | ||
removeJobs: found, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { | ||
RetryJobsMutation, | ||
RetryJobsMutationVariables, | ||
} from '@/typings/gql'; | ||
|
||
export const retryJobsMock = ( | ||
_args: RetryJobsMutationVariables, | ||
): Promise<RetryJobsMutation> => { | ||
return Promise.resolve({ | ||
retryJobs: [], | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { gqlClient } from '@/network/gql-client'; | ||
import type { | ||
RemoveJobsMutation, | ||
RemoveJobsMutationVariables, | ||
} from '@/typings/gql'; | ||
import { gql } from 'graphql-request'; | ||
|
||
export const removeJobs = ( | ||
args: RemoveJobsMutationVariables, | ||
): Promise<RemoveJobsMutation> => | ||
gqlClient.request( | ||
gql` | ||
mutation RemoveJobs($queue: String!, $jobs: [ID!]!) { | ||
removeJobs(queue: $queue, jobs: $jobs) { | ||
id | ||
} | ||
} | ||
`, | ||
args, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { gqlClient } from '@/network/gql-client'; | ||
import type { | ||
RetryJobsMutation, | ||
RetryJobsMutationVariables, | ||
} from '@/typings/gql'; | ||
import { gql } from 'graphql-request'; | ||
|
||
export const retryJobs = ( | ||
args: RetryJobsMutationVariables, | ||
): Promise<RetryJobsMutation> => | ||
gqlClient.request( | ||
gql` | ||
mutation RetryJobs($queue: String!, $jobs: [ID!]!) { | ||
retryJobs(queue: $queue, jobs: $jobs) { | ||
id | ||
} | ||
} | ||
`, | ||
args, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from 'react'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { useSelectedJobsStore } from '@/stores/selected-jobs'; | ||
import ReplayIcon from '@material-ui/icons/Replay'; | ||
import DeleteIcon from '@material-ui/icons/Delete'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import { useFiltersStore } from '@/stores/filters'; | ||
import { JobStatus } from '@/typings/gql'; | ||
import { useNetwork } from '@/hooks/use-network'; | ||
import { useAbstractMutation } from '@/hooks/use-abstract-mutation'; | ||
import { useActiveQueueStore } from '@/stores/active-queue'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
title: { | ||
marginRight: theme.spacing(3), | ||
}, | ||
})); | ||
|
||
export default function TableToolbar() { | ||
const cls = useStyles(); | ||
const activeStatus = useFiltersStore((state) => state.status); | ||
const queue = useActiveQueueStore((state) => state.active as string); | ||
const { mutations } = useNetwork(); | ||
const [selectedJobs, clearSelectedJobs] = useSelectedJobsStore((state) => [ | ||
state.selected, | ||
state.clear, | ||
]); | ||
const selectedCount = selectedJobs.size; | ||
const removeMutation = useAbstractMutation({ | ||
mutation: mutations.removeJobs, | ||
confirm: { | ||
description: 'Delete selected jobs', | ||
}, | ||
invalidateSharedQueries: true, | ||
toast: 'Jobs have been removed', | ||
onSuccess: clearSelectedJobs, | ||
}); | ||
const retryMutation = useAbstractMutation({ | ||
mutation: mutations.retryJobs, | ||
confirm: { | ||
description: 'Retry selected jobs', | ||
}, | ||
invalidateSharedQueries: true, | ||
toast: 'Retried', | ||
onSuccess: clearSelectedJobs, | ||
}); | ||
return ( | ||
<Toolbar> | ||
{selectedCount > 0 ? ( | ||
<> | ||
<Typography | ||
className={cls.title} | ||
color="inherit" | ||
variant="subtitle1" | ||
component="div" | ||
> | ||
{selectedCount} selected | ||
</Typography> | ||
{activeStatus === JobStatus.Failed && ( | ||
<Tooltip title="Retry selected jobs"> | ||
<IconButton | ||
onClick={() => | ||
retryMutation.mutate({ | ||
queue, | ||
jobs: Array.from(selectedJobs), | ||
}) | ||
} | ||
> | ||
<ReplayIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
)} | ||
<Tooltip title="Delete selected jobs"> | ||
<IconButton | ||
onClick={() => | ||
removeMutation.mutate({ | ||
queue, | ||
jobs: Array.from(selectedJobs), | ||
}) | ||
} | ||
color="secondary" | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
</> | ||
) : ( | ||
<Typography variant="h6" component="div"> | ||
Jobs | ||
</Typography> | ||
)} | ||
</Toolbar> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { useRunPaginationSideEffects } from './pagination'; | ||
import { useRunRefetchJobsLockSideEffects } from './refetch-jobs-lock'; | ||
import { useRunSelectedJobsSideEffects } from './selected-jobs'; | ||
|
||
export const useRunStoreSideEffects = () => { | ||
useRunPaginationSideEffects(); | ||
useRunRefetchJobsLockSideEffects(); | ||
useRunSelectedJobsSideEffects(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters