Skip to content

Replace usage menu item with insights on Dedicated #20587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const DownloadInsightsToast = ({ organizationId, from, to, organizationNa
if (isLoading) {
return (
<div>
<span>Preparing usage export</span>
<span>Preparing insights export</span>
<br />
<span className="text-sm">Exporting page {progress}</span>
</div>
Expand All @@ -64,15 +64,15 @@ export const DownloadInsightsToast = ({ organizationId, from, to, organizationNa
<div className="flex flex-row items-start space-x-2">
<AlertTriangle className="w-5 h-5 mt-0.5" />
<div>
<span>Error exporting your usage data:</span>
<span>Error exporting your insights data:</span>
<pre className="mt-2 whitespace-normal text-sm">{error.message}</pre>
</div>
</div>
);
}

if (!data || !data.blob || data.count === 0) {
return <span>No usage data for the selected period.</span>;
return <span>No insights data for the selected period.</span>;
}

const readableSize = prettyBytes(data.blob.size);
Expand All @@ -81,7 +81,7 @@ export const DownloadInsightsToast = ({ organizationId, from, to, organizationNa
return (
<div className="flex flex-row items-start justify-between space-x-2">
<div>
<span>Usage export complete.</span>
<span>Insights export complete.</span>
<p className="dark:text-gray-500">
{readableSize} &middot; {formattedCount} {data.count !== 1 ? "entries" : "entry"} exported
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ type Args = Pick<ListWorkspaceSessionsRequest, "organizationId" | "from" | "to">
onProgress?: (percentage: number) => void;
};

export type DownloadUsageCSVResponse = {
export type DownloadInsightsCSVResponse = {
blob: Blob | null;
filename: string;
count: number;
};

const downloadUsageCSV = async ({
const downloadInsightsCSV = async ({
organizationId,
from,
to,
organizationName,
signal,
onProgress,
}: Args): Promise<DownloadUsageCSVResponse> => {
}: Args): Promise<DownloadInsightsCSVResponse> => {
const start = dayjs(from?.toDate()).format("YYYYMMDD");
const end = dayjs(to?.toDate()).format("YYYYMMDD");
const filename = `gitpod-sessions-${organizationName}-${start}-${end}.csv`;
Expand Down Expand Up @@ -197,16 +197,16 @@ export const transformSessionRecord = (session: WorkspaceSession) => {

export const useDownloadSessionsCSV = (args: Args) => {
const client = useQueryClient();
const key = getDownloadUsageCSVQueryKey(args);
const key = getDownloadInsightsCSVQueryKey(args);

const abort = useCallback(() => {
client.removeQueries([key]);
}, [client, key]);

const query = useQuery<DownloadUsageCSVResponse, Error>(
const query = useQuery<DownloadInsightsCSVResponse, Error>(
key,
async ({ signal }) => {
return downloadUsageCSV({ ...args, signal });
return downloadInsightsCSV({ ...args, signal });
},
{
retry: false,
Expand All @@ -221,6 +221,6 @@ export const useDownloadSessionsCSV = (args: Args) => {
};
};

const getDownloadUsageCSVQueryKey = (args: Args) => {
return noPersistence(["usage-export", args]);
const getDownloadInsightsCSVQueryKey = (args: Args) => {
return noPersistence(["insights-export", args]);
};
24 changes: 17 additions & 7 deletions components/dashboard/src/menu/OrganizationSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,23 @@ export default function OrganizationSelector() {
separator: true,
link: "/members",
});
linkEntries.push({
title: "Usage",
customContent: <LinkEntry>Usage</LinkEntry>,
active: false,
separator: false,
link: "/usage",
});
if (isDedicated) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

linkEntries.push({
title: "Insights",
customContent: <LinkEntry>Insights</LinkEntry>,
active: false,
separator: false,
link: "/insights",
});
} else {
linkEntries.push({
title: "Usage",
customContent: <LinkEntry>Usage</LinkEntry>,
active: false,
separator: false,
link: "/usage",
});
}
// Show billing if user is an owner of current org
if (owner) {
if (billingMode?.mode === "usage-based") {
Expand Down
Loading