Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions components/dashboard/src/Insights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { DownloadIcon } from "lucide-react";
import { Button } from "@podkit/buttons/Button";
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@podkit/dropdown/DropDown";
import { useInstallationConfiguration } from "./data/installation/installation-config-query";
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";

export const Insights = () => {
const toDate = useMemo(() => Timestamp.fromDate(new Date()), []);
Expand All @@ -49,6 +50,9 @@ export const Insights = () => {
const grouped = Object.groupBy(sessions, (ws) => ws.workspace?.id ?? "unknown");
const [page, setPage] = useState(0);

const isLackingPermissions =
errorMessage instanceof ApplicationError && errorMessage.code === ErrorCodes.PERMISSION_DENIED;

return (
<>
<Header title="Insights" subtitle="Insights into workspace sessions in your organization" />
Expand All @@ -59,7 +63,7 @@ export const Insights = () => {
"md:flex-row md:items-center md:space-x-4 md:space-y-0",
)}
>
<DownloadUsage to={toDate} />
<DownloadUsage to={toDate} disabled={isLackingPermissions} />
</div>

<div
Expand All @@ -71,7 +75,11 @@ export const Insights = () => {

{errorMessage && (
<Alert type="error" className="mt-4">
{errorMessage instanceof Error ? errorMessage.message : "An error occurred."}
{isLackingPermissions
? "You don't have permission to access this organization's insights."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? "You don't have permission to access this organization's insights."
? "You don't have `owner` permission to access this organization's insights."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioning the role makes this information for tangible and actionable.

Copy link
Member Author

@filiptronicek filiptronicek Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great! Gave it a bit more formatting pizzaz to match other places in the dashboard and pushed as b0f3011 (#20593).

image

: errorMessage instanceof Error
? errorMessage.message
: "An error occurred."}
</Alert>
)}

Expand Down Expand Up @@ -151,8 +159,9 @@ export const Insights = () => {

type DownloadUsageProps = {
to: Timestamp;
disabled?: boolean;
};
export const DownloadUsage = ({ to }: DownloadUsageProps) => {
export const DownloadUsage = ({ to, disabled }: DownloadUsageProps) => {
const { data: org } = useCurrentOrg();
const { toast } = useToast();
// When we start the download, we disable the button for a short time
Expand Down Expand Up @@ -184,7 +193,7 @@ export const DownloadUsage = ({ to }: DownloadUsageProps) => {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="secondary" className="gap-1" disabled={downloadDisabled}>
<Button variant="secondary" className="gap-1" disabled={disabled ?? downloadDisabled}>
<DownloadIcon strokeWidth={3} className="w-4" />
<span>Export as CSV</span>
</Button>
Expand Down
20 changes: 11 additions & 9 deletions components/dashboard/src/menu/OrganizationSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function OrganizationSelector() {
const orgs = useOrganizations();
const currentOrg = useCurrentOrg();
const members = useListOrganizationMembers().data ?? [];
const owner = useIsOwner();
const isOwner = useIsOwner();
const hasMemberPermission = useHasRolePermission(OrganizationRole.MEMBER);
const { data: billingMode } = useOrgBillingMode();
const getOrgURL = useGetOrgURL();
Expand Down Expand Up @@ -78,13 +78,15 @@ export default function OrganizationSelector() {
link: "/members",
});
if (isDedicated) {
linkEntries.push({
title: "Insights",
customContent: <LinkEntry>Insights</LinkEntry>,
active: false,
separator: false,
link: "/insights",
});
if (isOwner) {
linkEntries.push({
title: "Insights",
customContent: <LinkEntry>Insights</LinkEntry>,
active: false,
separator: false,
link: "/insights",
});
}
} else {
linkEntries.push({
title: "Usage",
Expand All @@ -95,7 +97,7 @@ export default function OrganizationSelector() {
});
}
// Show billing if user is an owner of current org
if (owner) {
if (isOwner) {
if (billingMode?.mode === "usage-based") {
linkEntries.push({
title: "Billing",
Expand Down
Loading