mirror of
https://github.com/umami-software/umami.git
synced 2026-02-18 19:45:35 +01:00
Updated Dashboard Edits
This commit is contained in:
parent
12cf66861c
commit
3c82421ace
6 changed files with 21978 additions and 25 deletions
21928
package-lock.json
generated
Normal file
21928
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -59,7 +59,6 @@ export function DashboardEdit({ teamId }: { teamId: string }) {
|
||||||
setOrder(orderedWebsites.map(website => website?.id || 0));
|
setOrder(orderedWebsites.map(website => website?.id || 0));
|
||||||
setEdited(true);
|
setEdited(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleActiveWebsites(id: string) {
|
function handleActiveWebsites(id: string) {
|
||||||
setActive(prevActive =>
|
setActive(prevActive =>
|
||||||
prevActive.includes(id) ? prevActive.filter(a => a !== id) : [...prevActive, id],
|
prevActive.includes(id) ? prevActive.filter(a => a !== id) : [...prevActive, id],
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
'use client';
|
'use client';
|
||||||
import { Icon, Icons, Loading, Text } from 'react-basics';
|
import { Icon, Icons, Loading, Text, Button } from 'react-basics';
|
||||||
import PageHeader from '@/components/layout/PageHeader';
|
import PageHeader from '@/components/layout/PageHeader';
|
||||||
import Pager from '@/components/common/Pager';
|
import Pager from '@/components/common/Pager';
|
||||||
import WebsiteChartList from '../websites/[websiteId]/WebsiteChartList';
|
import WebsiteChartList from '../websites/[websiteId]/WebsiteChartList';
|
||||||
|
|
@ -7,20 +7,22 @@ import DashboardSettingsButton from '@/app/(main)/dashboard/DashboardSettingsBut
|
||||||
import DashboardEdit from '@/app/(main)/dashboard/DashboardEdit';
|
import DashboardEdit from '@/app/(main)/dashboard/DashboardEdit';
|
||||||
import EmptyPlaceholder from '@/components/common/EmptyPlaceholder';
|
import EmptyPlaceholder from '@/components/common/EmptyPlaceholder';
|
||||||
import { useMessages, useLocale, useTeamUrl, useWebsites } from '@/components/hooks';
|
import { useMessages, useLocale, useTeamUrl, useWebsites } from '@/components/hooks';
|
||||||
import useDashboard from '@/store/dashboard';
|
import useDashboard, { saveDashboard } from '@/store/dashboard';
|
||||||
import LinkButton from '@/components/common/LinkButton';
|
import LinkButton from '@/components/common/LinkButton';
|
||||||
|
|
||||||
export function DashboardPage() {
|
export function DashboardPage() {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { teamId, renderTeamUrl } = useTeamUrl();
|
const { teamId, renderTeamUrl } = useTeamUrl();
|
||||||
const { showCharts, editing, isEdited } = useDashboard();
|
const { showCharts, editing, isEdited, websiteActive } = useDashboard();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
||||||
const pageSize = isEdited ? 200 : 10;
|
const pageSize = isEdited ? 10 : 200;
|
||||||
|
const handleEdit = () => {
|
||||||
|
saveDashboard({ editing: true });
|
||||||
|
};
|
||||||
|
|
||||||
const { result, query, params, setParams } = useWebsites({ teamId }, { pageSize });
|
const { result, query, params, setParams } = useWebsites({ teamId }, { pageSize });
|
||||||
const { page } = params;
|
const { page } = params;
|
||||||
const hasData = !!result?.data?.length;
|
const hasData = !!result?.data?.length;
|
||||||
|
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
setParams({ ...params, page });
|
setParams({ ...params, page });
|
||||||
};
|
};
|
||||||
|
|
@ -28,7 +30,6 @@ export function DashboardPage() {
|
||||||
if (query.isLoading) {
|
if (query.isLoading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section style={{ marginBottom: 60 }}>
|
<section style={{ marginBottom: 60 }}>
|
||||||
<PageHeader title={formatMessage(labels.dashboard)}>
|
<PageHeader title={formatMessage(labels.dashboard)}>
|
||||||
|
|
@ -47,7 +48,8 @@ export function DashboardPage() {
|
||||||
{hasData && (
|
{hasData && (
|
||||||
<>
|
<>
|
||||||
{editing && <DashboardEdit teamId={teamId} />}
|
{editing && <DashboardEdit teamId={teamId} />}
|
||||||
{!editing && (
|
{!editing &&
|
||||||
|
(websiteActive.length != 0 ? (
|
||||||
<>
|
<>
|
||||||
<WebsiteChartList
|
<WebsiteChartList
|
||||||
websites={result?.data as any}
|
websites={result?.data as any}
|
||||||
|
|
@ -57,11 +59,20 @@ export function DashboardPage() {
|
||||||
<Pager
|
<Pager
|
||||||
page={page}
|
page={page}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
count={result?.count}
|
count={websiteActive.length}
|
||||||
onPageChange={handlePageChange}
|
onPageChange={handlePageChange}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
) : (
|
||||||
|
<EmptyPlaceholder message={formatMessage(messages.noWebsitesToggled)}>
|
||||||
|
<Button onClick={handleEdit}>
|
||||||
|
<Icon rotate={dir === 'rtl' ? 180 : 0}>
|
||||||
|
<Icons.ArrowRight />
|
||||||
|
</Icon>
|
||||||
|
<Text>{formatMessage(messages.goToEdit)}</Text>
|
||||||
|
</Button>
|
||||||
|
</EmptyPlaceholder>
|
||||||
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
import { useApi } from '@/components/hooks';
|
import { useApi } from '@/components/hooks';
|
||||||
import { DOMAIN_REGEX } from '@/lib/constants';
|
import { DOMAIN_REGEX } from '@/lib/constants';
|
||||||
import { useMessages } from '@/components/hooks';
|
import { useMessages } from '@/components/hooks';
|
||||||
|
import useDashboard, { saveDashboard } from '@/store/dashboard';
|
||||||
export function WebsiteAddForm({
|
export function WebsiteAddForm({
|
||||||
teamId,
|
teamId,
|
||||||
onSave,
|
onSave,
|
||||||
|
|
@ -22,8 +22,15 @@ export function WebsiteAddForm({
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
|
const settings = useDashboard();
|
||||||
|
const { websiteActive } = settings;
|
||||||
const { mutate, error, isPending } = useMutation({
|
const { mutate, error, isPending } = useMutation({
|
||||||
mutationFn: (data: any) => post('/websites', { ...data, teamId }),
|
mutationFn: (data: any) => post('/websites', { ...data, teamId }),
|
||||||
|
onSuccess: data => {
|
||||||
|
saveDashboard({
|
||||||
|
websiteActive: [...websiteActive, data.id],
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleSubmit = async (data: any) => {
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,9 @@ export default function WebsiteChartList({
|
||||||
const { websiteOrder, websiteActive } = useDashboard();
|
const { websiteOrder, websiteActive } = useDashboard();
|
||||||
const { renderTeamUrl } = useTeamUrl();
|
const { renderTeamUrl } = useTeamUrl();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
||||||
|
|
||||||
const ordered = useMemo(() => {
|
const ordered = useMemo(() => {
|
||||||
return websites
|
return websites
|
||||||
.filter(website => (websiteActive.length ? websiteActive.includes(website.id) : true))
|
.filter(website => websiteActive.includes(website.id))
|
||||||
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
|
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
|
||||||
.sort(firstBy('order'));
|
.sort(firstBy('order'));
|
||||||
}, [websites, websiteOrder, websiteActive]);
|
}, [websites, websiteOrder, websiteActive]);
|
||||||
|
|
|
||||||
|
|
@ -388,6 +388,11 @@ export const messages = defineMessages({
|
||||||
id: 'message.no-websites-configured',
|
id: 'message.no-websites-configured',
|
||||||
defaultMessage: 'You do not have any websites configured.',
|
defaultMessage: 'You do not have any websites configured.',
|
||||||
},
|
},
|
||||||
|
noWebsitesToggled: {
|
||||||
|
id: 'message.no-websites-toggled',
|
||||||
|
defaultMessage: 'You havent Toggled any websites',
|
||||||
|
},
|
||||||
|
|
||||||
noTeamWebsites: {
|
noTeamWebsites: {
|
||||||
id: 'message.no-team-websites',
|
id: 'message.no-team-websites',
|
||||||
defaultMessage: 'This team does not have any websites.',
|
defaultMessage: 'This team does not have any websites.',
|
||||||
|
|
@ -401,6 +406,10 @@ export const messages = defineMessages({
|
||||||
id: 'message.go-to-settings',
|
id: 'message.go-to-settings',
|
||||||
defaultMessage: 'Go to settings',
|
defaultMessage: 'Go to settings',
|
||||||
},
|
},
|
||||||
|
goToEdit: {
|
||||||
|
id: 'message.go-to-edit',
|
||||||
|
defaultMessage: 'Edit Dashboard',
|
||||||
|
},
|
||||||
activeUsers: {
|
activeUsers: {
|
||||||
id: 'message.active-users',
|
id: 'message.active-users',
|
||||||
defaultMessage: '{x} current {x, plural, one {visitor} other {visitors}}',
|
defaultMessage: '{x} current {x, plural, one {visitor} other {visitors}}',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue