mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Add includeTeams param for fetching websites.
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
This commit is contained in:
parent
433ce98719
commit
9ccafc390a
6 changed files with 34 additions and 36 deletions
|
|
@ -1,24 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "@umami/components",
|
"name": "@umami/components",
|
||||||
"version": "0.116.0",
|
"version": "0.121.0",
|
||||||
"description": "Umami React components.",
|
"description": "Umami React components.",
|
||||||
"author": "Mike Cao <mike@mikecao.com>",
|
"author": "Mike Cao <mike@mikecao.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"types": "./index.d.ts",
|
"types": "./index.d.ts"
|
||||||
"dependencies": {
|
|
||||||
"chart.js": "^4.5.0",
|
|
||||||
"chartjs-adapter-date-fns": "^3.0.0",
|
|
||||||
"colord": "^2.9.2",
|
|
||||||
"jsonwebtoken": "^9.0.2",
|
|
||||||
"lucide-react": "^0.542.0",
|
|
||||||
"pure-rand": "^7.0.1",
|
|
||||||
"react-simple-maps": "^2.3.0",
|
|
||||||
"react-use-measure": "^2.0.4",
|
|
||||||
"react-window": "^1.8.6",
|
|
||||||
"serialize-error": "^12.0.0",
|
|
||||||
"thenby": "^1.3.4",
|
|
||||||
"uuid": "^11.1.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import {
|
||||||
import { useMessages, useNavigation } from '@/components/hooks';
|
import { useMessages, useNavigation } from '@/components/hooks';
|
||||||
import { SideMenu } from '@/components/common/SideMenu';
|
import { SideMenu } from '@/components/common/SideMenu';
|
||||||
import { WebsiteSelect } from '@/components/input/WebsiteSelect';
|
import { WebsiteSelect } from '@/components/input/WebsiteSelect';
|
||||||
|
import { Text } from '@umami/react-zen';
|
||||||
|
|
||||||
export function WebsiteNav({ websiteId }: { websiteId: string }) {
|
export function WebsiteNav({ websiteId }: { websiteId: string }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
@ -147,13 +148,27 @@ export function WebsiteNav({ websiteId }: { websiteId: string }) {
|
||||||
router.push(renderUrl(`/websites/${value}`));
|
router.push(renderUrl(`/websites/${value}`));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderValue = (value: any) => {
|
||||||
|
return (
|
||||||
|
<Text truncate style={{ maxWidth: 160, lineHeight: 1 }}>
|
||||||
|
{value?.selectedItem?.name}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const selectedKey = items
|
const selectedKey = items
|
||||||
.flatMap(e => e.items)
|
.flatMap(e => e.items)
|
||||||
.find(({ path }) => path && pathname.endsWith(path.split('?')[0]))?.id;
|
.find(({ path }) => path && pathname.endsWith(path.split('?')[0]))?.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SideMenu items={items} selectedKey={selectedKey} allowMinimize={false} muteItems={false}>
|
<SideMenu items={items} selectedKey={selectedKey} allowMinimize={false} muteItems={false}>
|
||||||
<WebsiteSelect websiteId={websiteId} teamId={teamId} onChange={handleChange} />
|
<WebsiteSelect
|
||||||
|
websiteId={websiteId}
|
||||||
|
teamId={teamId}
|
||||||
|
onChange={handleChange}
|
||||||
|
renderValue={renderValue}
|
||||||
|
buttonProps={{ style: { outline: 'none' } }}
|
||||||
|
/>
|
||||||
</SideMenu>
|
</SideMenu>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { parseRequest, getQueryFilters } from '@/lib/request';
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
...pagingParams,
|
...pagingParams,
|
||||||
|
includeTeams: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { auth, query, error } = await parseRequest(request, schema);
|
const { auth, query, error } = await parseRequest(request, schema);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { unauthorized, json } from '@/lib/response';
|
import { unauthorized, json } from '@/lib/response';
|
||||||
import { getUserWebsites } from '@/queries/prisma/website';
|
import { getAllUserWebsitesIncludingTeamOwner, getUserWebsites } from '@/queries/prisma/website';
|
||||||
import { pagingParams, searchParams } from '@/lib/schema';
|
import { pagingParams, searchParams } from '@/lib/schema';
|
||||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||||
|
|
||||||
|
|
@ -8,6 +8,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
...pagingParams,
|
...pagingParams,
|
||||||
...searchParams,
|
...searchParams,
|
||||||
|
includeTeams: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { auth, query, error } = await parseRequest(request, schema);
|
const { auth, query, error } = await parseRequest(request, schema);
|
||||||
|
|
@ -24,7 +25,9 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
|
||||||
|
|
||||||
const filters = await getQueryFilters(query);
|
const filters = await getQueryFilters(query);
|
||||||
|
|
||||||
const websites = await getUserWebsites(userId, filters);
|
if (query.includeTeams) {
|
||||||
|
return json(await getAllUserWebsitesIncludingTeamOwner(auth.user.id, filters));
|
||||||
|
}
|
||||||
|
|
||||||
return json(websites);
|
return json(await getUserWebsites(userId, filters));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,25 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Select, SelectProps, ListItem, Text } from '@umami/react-zen';
|
import { Select, SelectProps, ListItem } from '@umami/react-zen';
|
||||||
import {
|
import { useUserWebsitesQuery, useMessages, useLoginQuery } from '@/components/hooks';
|
||||||
useUserWebsitesQuery,
|
|
||||||
useWebsiteQuery,
|
|
||||||
useMessages,
|
|
||||||
useLoginQuery,
|
|
||||||
} from '@/components/hooks';
|
|
||||||
import { Empty } from '@/components/common/Empty';
|
import { Empty } from '@/components/common/Empty';
|
||||||
|
|
||||||
export function WebsiteSelect({
|
export function WebsiteSelect({
|
||||||
websiteId,
|
websiteId,
|
||||||
teamId,
|
teamId,
|
||||||
onChange,
|
onChange,
|
||||||
|
includeTeams,
|
||||||
...props
|
...props
|
||||||
}: {
|
}: {
|
||||||
websiteId?: string;
|
websiteId?: string;
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
|
includeTeams?: boolean;
|
||||||
} & SelectProps) {
|
} & SelectProps) {
|
||||||
const { formatMessage, messages } = useMessages();
|
const { formatMessage, messages } = useMessages();
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const { data: website } = useWebsiteQuery(websiteId);
|
|
||||||
const { user } = useLoginQuery();
|
const { user } = useLoginQuery();
|
||||||
const { data, isLoading } = useUserWebsitesQuery(
|
const { data, isLoading } = useUserWebsitesQuery(
|
||||||
{ userId: user?.id, teamId },
|
{ userId: user?.id, teamId },
|
||||||
{ search, pageSize: 5 },
|
{ search, pageSize: 5, includeTeams },
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSearch = (value: string) => {
|
const handleSearch = (value: string) => {
|
||||||
|
|
@ -37,11 +33,9 @@ export function WebsiteSelect({
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
{...props}
|
{...props}
|
||||||
placeholder=""
|
|
||||||
items={data?.['data'] || []}
|
items={data?.['data'] || []}
|
||||||
value={websiteId}
|
value={websiteId}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
buttonProps={{ variant: 'outline' }}
|
|
||||||
allowSearch={true}
|
allowSearch={true}
|
||||||
searchValue={search}
|
searchValue={search}
|
||||||
onSearch={handleSearch}
|
onSearch={handleSearch}
|
||||||
|
|
@ -50,11 +44,6 @@ export function WebsiteSelect({
|
||||||
listProps={{
|
listProps={{
|
||||||
renderEmptyState: () => <Empty message={formatMessage(messages.noResultsFound)} />,
|
renderEmptyState: () => <Empty message={formatMessage(messages.noResultsFound)} />,
|
||||||
}}
|
}}
|
||||||
renderValue={() => (
|
|
||||||
<Text truncate weight="bold" style={{ maxWidth: 160, lineHeight: 1 }}>
|
|
||||||
{website?.name}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{({ id, name }: any) => <ListItem key={id}>{name}</ListItem>}
|
{({ id, name }: any) => <ListItem key={id}>{name}</ListItem>}
|
||||||
</Select>
|
</Select>
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ export * from '@/components/common/SectionHeader';
|
||||||
export * from '@/components/common/SideMenu';
|
export * from '@/components/common/SideMenu';
|
||||||
export * from '@/components/common/TypeConfirmationForm';
|
export * from '@/components/common/TypeConfirmationForm';
|
||||||
|
|
||||||
|
export * from '@/components/input/ActionButton';
|
||||||
|
export * from '@/components/input/DateFilter';
|
||||||
|
export * from '@/components/input/DownloadButton';
|
||||||
|
export * from '@/components/input/ExportButton';
|
||||||
export * from '@/components/input/FilterButtons';
|
export * from '@/components/input/FilterButtons';
|
||||||
export * from '@/components/input/TeamsButton';
|
export * from '@/components/input/TeamsButton';
|
||||||
export * from '@/components/input/ProfileButton';
|
export * from '@/components/input/ProfileButton';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue