Add webhook delele to list

This commit is contained in:
Krzysztof Bialoglowicz 2019-10-10 08:09:29 +02:00
parent 834addf3c0
commit d802ae90ce
3 changed files with 83 additions and 86 deletions

View file

@ -19,7 +19,7 @@ import { useIntl } from "react-intl";
import Skeleton from "@saleor/components/Skeleton"; import Skeleton from "@saleor/components/Skeleton";
import TablePagination from "@saleor/components/TablePagination"; import TablePagination from "@saleor/components/TablePagination";
import { maybe, renderCollection } from "@saleor/misc"; import { maybe, renderCollection, stopPropagation } from "@saleor/misc";
import { ListProps } from "@saleor/types"; import { ListProps } from "@saleor/types";
import { Webhooks_webhooks_edges_node } from "../../types/Webhooks"; import { Webhooks_webhooks_edges_node } from "../../types/Webhooks";
@ -125,15 +125,18 @@ const WebhooksList = withStyles(styles, { name: "PluginList" })(
)} )}
</TableCell> </TableCell>
<TableCell className={classes.colAction}> <TableCell className={classes.colAction}>
<div <IconButton
color="primary"
onClick={webhook ? onRowClick(webhook.id) : undefined} onClick={webhook ? onRowClick(webhook.id) : undefined}
> >
<EditIcon /> <EditIcon />
</div> </IconButton>
<IconButton <IconButton
color="primary" color="primary"
onClick={ onClick={
webhook ? () => onRemove(webhook.id) : undefined webhook
? stopPropagation(() => onRemove(webhook.id))
: undefined
} }
> >
<DeleteIcon /> <DeleteIcon />

View file

@ -13,7 +13,7 @@ import WebhooksList from "../WebhooksList/WebhooksList";
export interface WebhooksListPageProps extends PageListProps { export interface WebhooksListPageProps extends PageListProps {
webhooks: Webhooks_webhooks_edges_node[]; webhooks: Webhooks_webhooks_edges_node[];
onBack: () => void; onBack: () => void;
onRemove: () => void; onRemove: (id: string) => void;
} }
const WebhooksListPage: React.StatelessComponent<WebhooksListPageProps> = ({ const WebhooksListPage: React.StatelessComponent<WebhooksListPageProps> = ({

View file

@ -20,8 +20,7 @@ import {
webhooksAddUrl, webhooksAddUrl,
webhooksListUrl, webhooksListUrl,
WebhooksListUrlQueryParams, WebhooksListUrlQueryParams,
webhooksUrl, webhooksUrl
WebhookUrlDialog
} from "../urls"; } from "../urls";
interface WebhooksListProps { interface WebhooksListProps {
@ -50,27 +49,19 @@ export const WebhooksList: React.StatelessComponent<WebhooksListProps> = ({
true true
); );
const openModal = (action: WebhookUrlDialog, id?: string) => return (
navigate( <TypedWebhooksListQuery displayLoader variables={paginationState}>
webhooksListUrl({ {({ data, loading, refetch }) => {
...params,
action,
id
})
);
const onWebhookDelete = (data: WebhookDelete) => { const onWebhookDelete = (data: WebhookDelete) => {
if (data.webhookDelete.errors.length === 0) { if (data.webhookDelete.errors.length === 0) {
notify({ notify({
text: intl.formatMessage(commonMessages.savedChanges) text: intl.formatMessage(commonMessages.savedChanges)
}); });
navigate(webhooksListUrl()); navigate(webhooksListUrl());
refetch();
} }
}; };
return ( return (
<TypedWebhooksListQuery displayLoader variables={paginationState}>
{({ data, loading }) => (
<TypedWebhookDelete onCompleted={onWebhookDelete}> <TypedWebhookDelete onCompleted={onWebhookDelete}>
{(webhookDelete, webhookDeleteOpts) => { {(webhookDelete, webhookDeleteOpts) => {
const { loadNextPage, loadPreviousPage, pageInfo } = paginate( const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
@ -78,7 +69,7 @@ export const WebhooksList: React.StatelessComponent<WebhooksListProps> = ({
paginationState, paginationState,
params params
); );
const handleRemove = (id: string) => const handleRemove = (id: string) => {
navigate( navigate(
webhooksListUrl({ webhooksListUrl({
...params, ...params,
@ -86,12 +77,14 @@ export const WebhooksList: React.StatelessComponent<WebhooksListProps> = ({
id id
}) })
); );
const handleRemoveConfirm = () => };
const handleRemoveConfirm = () => {
webhookDelete({ webhookDelete({
variables: { variables: {
id id: params.id
} }
}); });
};
const deleteTransitionState = getMutationState( const deleteTransitionState = getMutationState(
webhookDeleteOpts.called, webhookDeleteOpts.called,
@ -133,7 +126,8 @@ export const WebhooksList: React.StatelessComponent<WebhooksListProps> = ({
); );
}} }}
</TypedWebhookDelete> </TypedWebhookDelete>
)} );
}}
</TypedWebhooksListQuery> </TypedWebhooksListQuery>
); );
}; };