Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

implement showActions to pixels/links for viewonly users.

Francis Cao2f998ff9d8d4
diff --git a/src/app/(main)/links/LinksDataTable.tsx b/src/app/(main)/links/LinksDataTable.tsx
index 0b3d660bb..87da5984c 100644
--- a/src/app/(main)/links/LinksDataTable.tsx
+++ b/src/app/(main)/links/LinksDataTable.tsx
@@ -2,13 +2,13 @@ import { DataGrid } from '@/components/common/DataGrid';
import { useLinksQuery, useNavigation } from '@/components/hooks';
import { LinksTable } from './LinksTable';
-export function LinksDataTable() {
+export function LinksDataTable({ showActions = false }: { showActions?: boolean }) {
const { teamId } = useNavigation();
const query = useLinksQuery({ teamId });
return (
<DataGrid query={query} allowSearch={true} autoFocus={false} allowPaging={true}>
- {({ data }) => <LinksTable data={data} />}
+ {({ data }) => <LinksTable data={data} showActions={showActions} />}
</DataGrid>
);
}
diff --git a/src/app/(main)/links/LinksPage.tsx b/src/app/(main)/links/LinksPage.tsx
index a6e4c7c4e..cdaf8fced 100644
--- a/src/app/(main)/links/LinksPage.tsx
+++ b/src/app/(main)/links/LinksPage.tsx
@@ -4,21 +4,30 @@ import { LinksDataTable } from '@/app/(main)/links/LinksDataTable';
import { PageBody } from '@/components/common/PageBody';
import { PageHeader } from '@/components/common/PageHeader';
import { Panel } from '@/components/common/Panel';
-import { useMessages, useNavigation } from '@/components/hooks';
+import { useLoginQuery, useMessages, useNavigation, useTeamMembersQuery } from '@/components/hooks';
+import { ROLES } from '@/lib/constants';
import { LinkAddButton } from './LinkAddButton';
export function LinksPage() {
+ const { user } = useLoginQuery();
const { formatMessage, labels } = useMessages();
const { teamId } = useNavigation();
+ const { data } = useTeamMembersQuery(teamId);
+
+ const showActions =
+ (teamId &&
+ data?.data.filter(team => team.userId === user.id && team.role !== ROLES.teamViewOnly)
+ .length > 0) ||
+ (!teamId && user.role !== ROLES.viewOnly);
return (
<PageBody>
<Column gap="6" margin="2">
<PageHeader title={formatMessage(labels.links)}>
- <LinkAddButton teamId={teamId} />
+ {showActions && <LinkAddButton teamId={teamId} />}
</PageHeader>
<Panel>
- <LinksDataTable />
+ <LinksDataTable showActions={showActions} />
</Panel>
</Column>
</PageBody>
diff --git a/src/app/(main)/links/LinksTable.tsx b/src/app/(main)/links/LinksTable.tsx
index a3b4a86ad..62eb0fb86 100644
--- a/src/app/(main)/links/LinksTable.tsx
+++ b/src/app/(main)/links/LinksTable.tsx
@@ -6,7 +6,11 @@ import { useMessages, useNavigation, useSlug } from '@/components/hooks';
import { LinkDeleteButton } from './LinkDeleteButton';
import { LinkEditButton } from './LinkEditButton';
-export function LinksTable(props: DataTableProps) {
+export interface LinksTableProps extends DataTableProps {
+ showActions?: boolean;
+}
+
+export function LinksTable({ showActions, ...props }: LinksTableProps) {
const { formatMessage, labels } = useMessages();
const { websiteId, renderUrl } = useNavigation();
const { getSlugUrl } = useSlug('link');
@@ -36,16 +40,18 @@ export function LinksTable(props: DataTableProps) {
<DataColumn id="created" label={formatMessage(labels.created)} width="200px">
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
</DataColumn>
- <DataColumn id="action" align="end" width="100px">
- {({ id, name }: any) => {
- return (
- <Row>
- <LinkEditButton linkId={id} />
- <LinkDeleteButton linkId={id} websiteId={websiteId} name={name} />
- </Row>
- );
- }}
- </DataColumn>
+ {showActions && (
+ <DataColumn id="action" align="end" width="100px">
+ {({ id, name }: any) => {
+ return (
+ <Row>
+ <LinkEditButton linkId={id} />
+ <LinkDeleteButton linkId={id} websiteId={websiteId} name={name} />
+ </Row>
+ );
+ }}
+ </DataColumn>
+ )}
</DataTable>
);
}
diff --git a/src/app/(main)/pixels/PixelsDataTable.tsx b/src/app/(main)/pixels/PixelsDataTable.tsx
index 51b8c5a0b..6a9a9162d 100644
--- a/src/app/(main)/pixels/PixelsDataTable.tsx
+++ b/src/app/(main)/pixels/PixelsDataTable.tsx
@@ -2,13 +2,13 @@ import { DataGrid } from '@/components/common/DataGrid';
import { useNavigation, usePixelsQuery } from '@/components/hooks';
import { PixelsTable } from './PixelsTable';
-export function PixelsDataTable() {
+export function PixelsDataTable({ showActions = false }: { showActions?: boolean }) {
const { teamId } = useNavigation();
const query = usePixelsQuery({ teamId });
return (
<DataGrid query={query} allowSearch={true} autoFocus={false} allowPaging={true}>
- {({ data }) => <PixelsTable data={data} />}
+ {({ data }) => <PixelsTable data={data} showActions={showActions} />}
</DataGrid>
);
}
diff --git a/src/app/(main)/pixels/PixelsPage.tsx b/src/app/(main)/pixels/PixelsPage.tsx
index 4f6acefe5..91ddcdcda 100644
--- a/src/app/(main)/pixels/PixelsPage.tsx
+++ b/src/app/(main)/pixels/PixelsPage.tsx
@@ -3,22 +3,31 @@ import { Column } from '@umami/react-zen';
import { PageBody } from '@/components/common/PageBody';
import { PageHeader } from '@/components/common/PageHeader';
import { Panel } from '@/components/common/Panel';
-import { useMessages, useNavigation } from '@/components/hooks';
+import { useLoginQuery, useMessages, useNavigation, useTeamMembersQuery } from '@/components/hooks';
+import { ROLES } from '@/lib/constants';
import { PixelAddButton } from './PixelAddButton';
import { PixelsDataTable } from './PixelsDataTable';
export function PixelsPage() {
+ const { user } = useLoginQuery();
const { formatMessage, labels } = useMessages();
const { teamId } = useNavigation();
+ const { data } = useTeamMembersQuery(teamId);
+
+ const showActions =
+ (teamId &&
+ data?.data.filter(team => team.userId === user.id && team.role !== ROLES.teamViewOnly)
+ .length > 0) ||
+ (!teamId && user.role !== ROLES.viewOnly);
return (
<PageBody>
<Column gap="6" margin="2">
<PageHeader title={formatMessage(labels.pixels)}>
- <PixelAddButton teamId={teamId} />
+ {showActions && <PixelAddButton teamId={teamId} />}
</PageHeader>
<Panel>
- <PixelsDataTable />
+ <PixelsDataTable showActions={showActions} />
</Panel>
</Column>
</PageBody>
diff --git a/src/app/(main)/pixels/PixelsTable.tsx b/src/app/(main)/pixels/PixelsTable.tsx
index 48a845896..57aff4db1 100644
--- a/src/app/(main)/pixels/PixelsTable.tsx
+++ b/src/app/(main)/pixels/PixelsTable.tsx
@@ -6,10 +6,15 @@ import { useMessages, useNavigation, useSlug } from '@/components/hooks';
import { PixelDeleteButton } from './PixelDeleteButton';
import { PixelEditButton } from './PixelEditButton';
-export function PixelsTable(props: DataTableProps) {
+export interface PixelsTableProps extends DataTableProps {
+ showActions?: boolean;
+}
+
+export function PixelsTable({ showActions, ...props }: PixelsTableProps) {
const { formatMessage, labels } = useMessages();
const { renderUrl } = useNavigation();
const { getSlugUrl } = useSlug('pixel');
+ console.log(showActions);
return (
<DataTable {...props}>
@@ -31,18 +36,20 @@ export function PixelsTable(props: DataTableProps) {
<DataColumn id="created" label={formatMessage(labels.created)}>
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
</DataColumn>
- <DataColumn id="action" align="end" width="100px">
- {(row: any) => {
- const { id, name } = row;
+ {showActions && (
+ <DataColumn id="action" align="end" width="100px">
+ {(row: any) => {
+ const { id, name } = row;
- return (
- <Row>
- <PixelEditButton pixelId={id} />
- <PixelDeleteButton pixelId={id} name={name} />
- </Row>
- );
- }}
- </DataColumn>
+ return (
+ <Row>
+ <PixelEditButton pixelId={id} />
+ <PixelDeleteButton pixelId={id} name={name} />
+ </Row>
+ );
+ }}
+ </DataColumn>
+ )}
</DataTable>
);
}
diff --git a/src/app/(main)/websites/WebsitesPage.tsx b/src/app/(main)/websites/WebsitesPage.tsx
index 31de7047c..6f3548a97 100644
--- a/src/app/(main)/websites/WebsitesPage.tsx
+++ b/src/app/(main)/websites/WebsitesPage.tsx
@@ -3,22 +3,31 @@ import { Column } from '@umami/react-zen';
import { PageBody } from '@/components/common/PageBody';
import { PageHeader } from '@/components/common/PageHeader';
import { Panel } from '@/components/common/Panel';
-import { useMessages, useNavigation } from '@/components/hooks';
+import { useLoginQuery, useMessages, useNavigation, useTeamMembersQuery } from '@/components/hooks';
+import { ROLES } from '@/lib/constants';
import { WebsiteAddButton } from './WebsiteAddButton';
import { WebsitesDataTable } from './WebsitesDataTable';
export function WebsitesPage() {
+ const { user } = useLoginQuery();
const { teamId } = useNavigation();
const { formatMessage, labels } = useMessages();
+ const { data } = useTeamMembersQuery(teamId);
+
+ const showActions =
+ (teamId &&
+ data?.data.filter(team => team.userId === user.id && team.role !== ROLES.teamViewOnly)
+ .length > 0) ||
+ (!teamId && user.role !== ROLES.viewOnly);
return (
<PageBody>
<Column gap="6" margin="2">
<PageHeader title={formatMessage(labels.websites)}>
- <WebsiteAddButton teamId={teamId} />
+ {showActions && <WebsiteAddButton teamId={teamId} />}
</PageHeader>
<Panel>
- <WebsitesDataTable teamId={teamId} />
+ <WebsitesDataTable teamId={teamId} showActions={showActions} />
</Panel>
</Column>
</PageBody>