Merge pull request #444 from automatisch/issue-440

feat: add no result found UI on executions
This commit is contained in:
Ömer Faruk Aydın
2022-08-12 20:31:21 +03:00
committed by GitHub
3 changed files with 21 additions and 5 deletions

View File

@@ -9,7 +9,7 @@ import { CardContent } from './style';
type NoResultFoundProps = { type NoResultFoundProps = {
text?: string; text?: string;
to: string; to?: string;
} }
export default function NoResultFound(props: NoResultFoundProps): React.ReactElement { export default function NoResultFound(props: NoResultFoundProps): React.ReactElement {
@@ -21,6 +21,8 @@ export default function NoResultFound(props: NoResultFoundProps): React.ReactEle
linkProps, linkProps,
ref, ref,
) { ) {
if (!to) return <div>{linkProps.children}</div>;
return <Link ref={ref} to={to} {...linkProps} />; return <Link ref={ref} to={to} {...linkProps} />;
}), }),
[to], [to],
@@ -30,7 +32,7 @@ export default function NoResultFound(props: NoResultFoundProps): React.ReactEle
<Card elevation={0}> <Card elevation={0}>
<CardActionArea component={ActionAreaLink} {...props}> <CardActionArea component={ActionAreaLink} {...props}>
<CardContent> <CardContent>
<AddCircleIcon color="primary" /> {!!to && <AddCircleIcon color="primary" />}
<Typography variant="body1"> <Typography variant="body1">
{text} {text}

View File

@@ -51,6 +51,7 @@
"flows.noFlows": "You don't have any flows yet.", "flows.noFlows": "You don't have any flows yet.",
"flowEditor.goBack": "Go back to flows", "flowEditor.goBack": "Go back to flows",
"executions.title": "Executions", "executions.title": "Executions",
"executions.noExecutions": "There is no execution data point to show.",
"execution.executedAt": "executed {datetime}", "execution.executedAt": "executed {datetime}",
"profileSettings.title": "My Profile", "profileSettings.title": "My Profile",
"profileSettings.email": "Email", "profileSettings.email": "Email",

View File

@@ -3,15 +3,19 @@ import { Link, useSearchParams } from 'react-router-dom';
import { useQuery } from '@apollo/client'; import { useQuery } from '@apollo/client';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
import CircularProgress from '@mui/material/CircularProgress';
import Divider from '@mui/material/Divider';
import Pagination from '@mui/material/Pagination'; import Pagination from '@mui/material/Pagination';
import PaginationItem from '@mui/material/PaginationItem'; import PaginationItem from '@mui/material/PaginationItem';
import type { IExecution } from '@automatisch/types'; import type { IExecution } from '@automatisch/types';
import NoResultFound from 'components/NoResultFound';
import ExecutionRow from 'components/ExecutionRow'; import ExecutionRow from 'components/ExecutionRow';
import Container from 'components/Container'; import Container from 'components/Container';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
import useFormatMessage from 'hooks/useFormatMessage' import useFormatMessage from 'hooks/useFormatMessage'
import { GET_EXECUTIONS } from 'graphql/queries/get-executions'; import { GET_EXECUTIONS } from 'graphql/queries/get-executions';
import * as URLS from 'config/urls';
const EXECUTION_PER_PAGE = 10; const EXECUTION_PER_PAGE = 10;
@@ -25,7 +29,7 @@ export default function Executions(): React.ReactElement {
const [searchParams, setSearchParams] = useSearchParams(); const [searchParams, setSearchParams] = useSearchParams();
const page = parseInt(searchParams.get('page') || '', 10) || 1; const page = parseInt(searchParams.get('page') || '', 10) || 1;
const { data, refetch } = useQuery(GET_EXECUTIONS, { const { data, refetch, loading } = useQuery(GET_EXECUTIONS, {
variables: getLimitAndOffset(page), variables: getLimitAndOffset(page),
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
pollInterval: 5000, pollInterval: 5000,
@@ -38,17 +42,26 @@ export default function Executions(): React.ReactElement {
}, [refetch, page]) }, [refetch, page])
const executions: IExecution[] = edges?.map(({ node }: { node: IExecution }) => node); const executions: IExecution[] = edges?.map(({ node }: { node: IExecution }) => node);
const hasExecutions = executions?.length;
return ( return (
<Box sx={{ py: 3 }}> <Box sx={{ py: 3 }}>
<Container> <Container>
<Grid container sx={{ mb: [2, 5] }} columnSpacing={1.5} rowSpacing={3}> <Grid container sx={{ mb: [0, 3] }} columnSpacing={1.5} rowSpacing={3}>
<Grid container item xs sm alignItems="center" order={{ xs: 0, height: 80 }}> <Grid container item xs sm alignItems="center" order={{ xs: 0, height: 80 }}>
<PageTitle>{formatMessage('executions.title')}</PageTitle> <PageTitle>{formatMessage('executions.title')}</PageTitle>
</Grid> </Grid>
</Grid> </Grid>
{executions?.map((execution) => (<ExecutionRow key={execution.id} execution={execution} />))} <Divider sx={{ mt: [2, 0], mb: 2 }} />
{loading && <CircularProgress sx={{ display: 'block', margin: '20px auto' }} />}
{!loading && !hasExecutions && (<NoResultFound
text={formatMessage('executions.noExecutions')}
/>)}
{!loading && executions?.map((execution) => (<ExecutionRow key={execution.id} execution={execution} />))}
{pageInfo && pageInfo.totalPages > 1 && <Pagination {pageInfo && pageInfo.totalPages > 1 && <Pagination
sx={{ display: 'flex', justifyContent: 'center', mt: 3 }} sx={{ display: 'flex', justifyContent: 'center', mt: 3 }}