mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-06 01:15:42 +01:00
Fixed search field disappearing when results are empty. Closes #2879.
This commit is contained in:
parent
2c0ba65ba0
commit
9b88611a38
@ -14,12 +14,8 @@ export default function ReportsDataTable({
|
|||||||
}) {
|
}) {
|
||||||
const queryResult = useReports({ websiteId, teamId });
|
const queryResult = useReports({ websiteId, teamId });
|
||||||
|
|
||||||
if (queryResult?.result?.data?.length === 0) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult}>
|
<DataTable queryResult={queryResult} renderEmpty={() => children}>
|
||||||
{({ data }) => <ReportsTable data={data} showDomain={!websiteId} />}
|
{({ data }) => <ReportsTable data={data} showDomain={!websiteId} />}
|
||||||
</DataTable>
|
</DataTable>
|
||||||
);
|
);
|
||||||
|
@ -15,12 +15,8 @@ export function TeamsDataTable({
|
|||||||
const { user } = useLogin();
|
const { user } = useLogin();
|
||||||
const queryResult = useTeams(user.id);
|
const queryResult = useTeams(user.id);
|
||||||
|
|
||||||
if (queryResult?.result?.data?.length === 0) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult}>
|
<DataTable queryResult={queryResult} renderEmpty={() => children}>
|
||||||
{({ data }) => {
|
{({ data }) => {
|
||||||
return <TeamsTable data={data} allowEdit={allowEdit} showActions={showActions} />;
|
return <TeamsTable data={data} allowEdit={allowEdit} showActions={showActions} />;
|
||||||
}}
|
}}
|
||||||
|
@ -12,12 +12,8 @@ export function UsersDataTable({
|
|||||||
}) {
|
}) {
|
||||||
const queryResult = useUsers();
|
const queryResult = useUsers();
|
||||||
|
|
||||||
if (queryResult?.result?.data?.length === 0) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult}>
|
<DataTable queryResult={queryResult} renderEmpty={() => children}>
|
||||||
{({ data }) => <UsersTable data={data} showActions={showActions} />}
|
{({ data }) => <UsersTable data={data} showActions={showActions} />}
|
||||||
</DataTable>
|
</DataTable>
|
||||||
);
|
);
|
||||||
|
@ -18,12 +18,8 @@ export function WebsitesDataTable({
|
|||||||
}) {
|
}) {
|
||||||
const queryResult = useWebsites({ teamId });
|
const queryResult = useWebsites({ teamId });
|
||||||
|
|
||||||
if (queryResult?.result?.data?.length === 0) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult}>
|
<DataTable queryResult={queryResult} renderEmpty={() => children}>
|
||||||
{({ data }) => (
|
{({ data }) => (
|
||||||
<WebsitesTable
|
<WebsitesTable
|
||||||
teamId={teamId}
|
teamId={teamId}
|
||||||
|
@ -13,12 +13,8 @@ export default function SessionsDataTable({
|
|||||||
}) {
|
}) {
|
||||||
const queryResult = useWebsiteSessions(websiteId);
|
const queryResult = useWebsiteSessions(websiteId);
|
||||||
|
|
||||||
if (queryResult?.result?.data?.length === 0) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult} allowSearch={false}>
|
<DataTable queryResult={queryResult} allowSearch={false} renderEmpty={() => children}>
|
||||||
{({ data }) => <SessionsTable data={data} showDomain={!websiteId} />}
|
{({ data }) => <SessionsTable data={data} showDomain={!websiteId} />}
|
||||||
</DataTable>
|
</DataTable>
|
||||||
);
|
);
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { Banner, Loading, SearchField } from 'react-basics';
|
import { Loading, SearchField } from 'react-basics';
|
||||||
import { useMessages, useNavigation } from 'components/hooks';
|
import { useMessages, useNavigation } from 'components/hooks';
|
||||||
import Empty from 'components/common/Empty';
|
import Empty from 'components/common/Empty';
|
||||||
import Pager from 'components/common/Pager';
|
import Pager from 'components/common/Pager';
|
||||||
import { PagedQueryResult } from 'lib/types';
|
import { PagedQueryResult } from 'lib/types';
|
||||||
import styles from './DataTable.module.css';
|
import styles from './DataTable.module.css';
|
||||||
|
import { LoadingPanel } from 'components/common/LoadingPanel';
|
||||||
|
|
||||||
const DEFAULT_SEARCH_DELAY = 600;
|
const DEFAULT_SEARCH_DELAY = 600;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ export interface DataTableProps {
|
|||||||
searchDelay?: number;
|
searchDelay?: number;
|
||||||
allowSearch?: boolean;
|
allowSearch?: boolean;
|
||||||
allowPaging?: boolean;
|
allowPaging?: boolean;
|
||||||
|
renderEmpty?: () => ReactNode;
|
||||||
children: ReactNode | ((data: any) => ReactNode);
|
children: ReactNode | ((data: any) => ReactNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ export function DataTable({
|
|||||||
searchDelay = 600,
|
searchDelay = 600,
|
||||||
allowSearch = true,
|
allowSearch = true,
|
||||||
allowPaging = true,
|
allowPaging = true,
|
||||||
|
renderEmpty,
|
||||||
children,
|
children,
|
||||||
}: DataTableProps) {
|
}: DataTableProps) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
@ -29,7 +32,7 @@ export function DataTable({
|
|||||||
result,
|
result,
|
||||||
params,
|
params,
|
||||||
setParams,
|
setParams,
|
||||||
query: { error, isLoading },
|
query: { error, isLoading, isFetched },
|
||||||
} = queryResult || {};
|
} = queryResult || {};
|
||||||
const { page, pageSize, count, data } = result || {};
|
const { page, pageSize, count, data } = result || {};
|
||||||
const { query } = params || {};
|
const { query } = params || {};
|
||||||
@ -46,10 +49,6 @@ export function DataTable({
|
|||||||
router.push(renderUrl({ page }));
|
router.push(renderUrl({ page }));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return <Banner variant="error">{formatMessage(messages.error)}</Banner>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{allowSearch && (hasData || query) && (
|
{allowSearch && (hasData || query) && (
|
||||||
@ -62,12 +61,15 @@ export function DataTable({
|
|||||||
placeholder={formatMessage(labels.search)}
|
placeholder={formatMessage(labels.search)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
<LoadingPanel data={data} isLoading={isLoading} isFetched={isFetched} error={error}>
|
||||||
<div
|
<div
|
||||||
className={classNames(styles.body, { [styles.status]: isLoading || noResults || !hasData })}
|
className={classNames(styles.body, {
|
||||||
|
[styles.status]: isLoading || noResults || !hasData,
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
{hasData ? (typeof children === 'function' ? children(result) : children) : null}
|
{hasData ? (typeof children === 'function' ? children(result) : children) : null}
|
||||||
{isLoading && <Loading position="page" />}
|
{isLoading && <Loading position="page" />}
|
||||||
{!isLoading && !hasData && !query && <Empty />}
|
{!isLoading && !hasData && !query && (renderEmpty ? renderEmpty() : <Empty />)}
|
||||||
{!isLoading && noResults && <Empty message={formatMessage(messages.noResultsFound)} />}
|
{!isLoading && noResults && <Empty message={formatMessage(messages.noResultsFound)} />}
|
||||||
</div>
|
</div>
|
||||||
{allowPaging && hasData && (
|
{allowPaging && hasData && (
|
||||||
@ -79,6 +81,7 @@ export function DataTable({
|
|||||||
onPageChange={handlePageChange}
|
onPageChange={handlePageChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
</LoadingPanel>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user