Merge pull request #1798 from automatisch/fix-flow-counts
fix: show flow counts using useConnectionFlows
This commit is contained in:
@@ -1,21 +1,24 @@
|
|||||||
|
import * as React from 'react';
|
||||||
import { useLazyQuery, useMutation } from '@apollo/client';
|
import { useLazyQuery, useMutation } from '@apollo/client';
|
||||||
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
|
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
|
||||||
import ErrorIcon from '@mui/icons-material/Error';
|
import ErrorIcon from '@mui/icons-material/Error';
|
||||||
|
import Skeleton from '@mui/material/Skeleton';
|
||||||
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Card from '@mui/material/Card';
|
import Card from '@mui/material/Card';
|
||||||
import CardActionArea from '@mui/material/CardActionArea';
|
import CardActionArea from '@mui/material/CardActionArea';
|
||||||
import CircularProgress from '@mui/material/CircularProgress';
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import * as React from 'react';
|
|
||||||
|
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
||||||
import ConnectionContextMenu from 'components/AppConnectionContextMenu';
|
import ConnectionContextMenu from 'components/AppConnectionContextMenu';
|
||||||
import { DELETE_CONNECTION } from 'graphql/mutations/delete-connection';
|
import { DELETE_CONNECTION } from 'graphql/mutations/delete-connection';
|
||||||
import { TEST_CONNECTION } from 'graphql/queries/test-connection';
|
import { TEST_CONNECTION } from 'graphql/queries/test-connection';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import { ConnectionPropType } from 'propTypes/propTypes';
|
import { ConnectionPropType } from 'propTypes/propTypes';
|
||||||
import { CardContent, Typography } from './style';
|
import { CardContent, Typography } from './style';
|
||||||
|
import useConnectionFlows from 'hooks/useConnectionFlows';
|
||||||
|
|
||||||
const countTranslation = (value) => (
|
const countTranslation = (value) => (
|
||||||
<>
|
<>
|
||||||
@@ -23,9 +26,16 @@ const countTranslation = (value) => (
|
|||||||
<br />
|
<br />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
function AppConnectionRow(props) {
|
function AppConnectionRow(props) {
|
||||||
|
const formatMessage = useFormatMessage();
|
||||||
const enqueueSnackbar = useEnqueueSnackbar();
|
const enqueueSnackbar = useEnqueueSnackbar();
|
||||||
|
const { id, key, formattedData, verified, createdAt, reconnectable } =
|
||||||
|
props.connection;
|
||||||
const [verificationVisible, setVerificationVisible] = React.useState(false);
|
const [verificationVisible, setVerificationVisible] = React.useState(false);
|
||||||
|
const contextButtonRef = React.useRef(null);
|
||||||
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
||||||
|
|
||||||
const [testConnection, { called: testCalled, loading: testLoading }] =
|
const [testConnection, { called: testCalled, loading: testLoading }] =
|
||||||
useLazyQuery(TEST_CONNECTION, {
|
useLazyQuery(TEST_CONNECTION, {
|
||||||
fetchPolicy: 'network-only',
|
fetchPolicy: 'network-only',
|
||||||
@@ -36,23 +46,20 @@ function AppConnectionRow(props) {
|
|||||||
setTimeout(() => setVerificationVisible(false), 3000);
|
setTimeout(() => setVerificationVisible(false), 3000);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [deleteConnection] = useMutation(DELETE_CONNECTION);
|
const [deleteConnection] = useMutation(DELETE_CONNECTION);
|
||||||
const formatMessage = useFormatMessage();
|
|
||||||
const {
|
|
||||||
id,
|
|
||||||
key,
|
|
||||||
formattedData,
|
|
||||||
verified,
|
|
||||||
createdAt,
|
|
||||||
flowCount,
|
|
||||||
reconnectable,
|
|
||||||
} = props.connection;
|
|
||||||
const contextButtonRef = React.useRef(null);
|
|
||||||
const [anchorEl, setAnchorEl] = React.useState(null);
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { data, isLoading: isConnectionFlowsLoading } = useConnectionFlows({
|
||||||
|
connectionId: id,
|
||||||
|
});
|
||||||
|
const flowCount = data?.meta?.count;
|
||||||
|
|
||||||
const onContextMenuClick = () => setAnchorEl(contextButtonRef.current);
|
const onContextMenuClick = () => setAnchorEl(contextButtonRef.current);
|
||||||
|
|
||||||
const onContextMenuAction = React.useCallback(
|
const onContextMenuAction = React.useCallback(
|
||||||
async (event, action) => {
|
async (event, action) => {
|
||||||
if (action.type === 'delete') {
|
if (action.type === 'delete') {
|
||||||
@@ -68,6 +75,7 @@ function AppConnectionRow(props) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
enqueueSnackbar(formatMessage('connection.deletedMessage'), {
|
enqueueSnackbar(formatMessage('connection.deletedMessage'), {
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
SnackbarProps: {
|
SnackbarProps: {
|
||||||
@@ -81,9 +89,11 @@ function AppConnectionRow(props) {
|
|||||||
},
|
},
|
||||||
[deleteConnection, id, testConnection, formatMessage, enqueueSnackbar],
|
[deleteConnection, id, testConnection, formatMessage, enqueueSnackbar],
|
||||||
);
|
);
|
||||||
|
|
||||||
const relativeCreatedAt = DateTime.fromMillis(
|
const relativeCreatedAt = DateTime.fromMillis(
|
||||||
parseInt(createdAt, 10),
|
parseInt(createdAt, 10),
|
||||||
).toRelative();
|
).toRelative();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card sx={{ my: 2 }} data-test="app-connection-row">
|
<Card sx={{ my: 2 }} data-test="app-connection-row">
|
||||||
@@ -143,7 +153,13 @@ function AppConnectionRow(props) {
|
|||||||
sx={{ display: ['none', 'inline-block'] }}
|
sx={{ display: ['none', 'inline-block'] }}
|
||||||
>
|
>
|
||||||
{formatMessage('connection.flowCount', {
|
{formatMessage('connection.flowCount', {
|
||||||
count: countTranslation(flowCount),
|
count: countTranslation(
|
||||||
|
isConnectionFlowsLoading ? (
|
||||||
|
<Skeleton variant="text" width={15} />
|
||||||
|
) : (
|
||||||
|
flowCount
|
||||||
|
),
|
||||||
|
),
|
||||||
})}
|
})}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
@@ -4,7 +4,7 @@ import api from 'helpers/api';
|
|||||||
|
|
||||||
export default function useConnectionFlows(
|
export default function useConnectionFlows(
|
||||||
{ connectionId, page },
|
{ connectionId, page },
|
||||||
{ enabled },
|
{ enabled } = {},
|
||||||
) {
|
) {
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ['connectionFlows', connectionId, page],
|
queryKey: ['connectionFlows', connectionId, page],
|
||||||
|
Reference in New Issue
Block a user