Skip to content
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

Avoid spinner when switching tabs in dashboard #6894

Merged
merged 3 commits into from
Mar 6, 2023
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
2 changes: 2 additions & 0 deletions frontend/javascripts/admin/admin_rest_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,8 @@ export async function getPricingPlanStatus(): Promise<APIPricingPlanStatus> {
return Request.receiveJSON("/api/pricing/status");
}

export const cachedGetPricingPlanStatus = _.memoize(getPricingPlanStatus);
Copy link
Member

@hotzenklotz hotzenklotz Mar 3, 2023

Choose a reason for hiding this comment

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

Caching is not without its own problems. The status might update (e.g. new people will join, more datasets will be uploaded taking up space etc...)
How long does this cache live? Until the next page refresh, right? So, the above points might not be a such a big issue after all.

The approach is fine by me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Until the next page refresh, right?

Yes, exactly. When visiting the orga page, the non-cached version is used. So, only the dashboard is affected. If outdated data is noticed, the user will likely hit refresh to fix it.


// ### BuildInfo webknossos
export function getBuildInfo(): Promise<APIBuildInfo> {
return Request.receiveJSON("/api/buildinfo", {
Expand Down
7 changes: 5 additions & 2 deletions frontend/javascripts/dashboard/dashboard_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { APIOrganization, APIPricingPlanStatus, APIUser } from "types/api_f
import type { OxalisState } from "oxalis/store";
import { enforceActiveUser } from "oxalis/model/accessors/user_accessor";
import {
getPricingPlanStatus,
cachedGetPricingPlanStatus,
getUser,
updateNovelUserExperienceInfos,
} from "admin/admin_rest_api";
Expand Down Expand Up @@ -120,7 +120,10 @@ class DashboardView extends PureComponent<PropsWithRouter, State> {
const user =
this.props.userId != null ? await getUser(this.props.userId) : this.props.activeUser;

const pricingPlanStatus = await getPricingPlanStatus();
// Use a cached version of this route to avoid that a tab switch in the dashboard
// causes a whole-page spinner. Since the different tabs are controlled by the
// router, the DashboardView re-mounts.
const pricingPlanStatus = await cachedGetPricingPlanStatus();

this.setState({
user,
Expand Down
4 changes: 4 additions & 0 deletions frontend/stylesheets/_utils.less
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ td.nowrap * {
.min-height-0 {
min-height: 0;
}

.text-center {
Copy link
Member

Choose a reason for hiding this comment

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

This is not used in the PR. Do you still want to merge it?

Copy link
Member Author

@philippotto philippotto Mar 3, 2023

Choose a reason for hiding this comment

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

I noticed that the spinner in question was centered by using a text-center class which didn't exist (which didn't work obviously). That's why I added this class.

Copy link
Member

Choose a reason for hiding this comment

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

Ah. Good point. Maybe a Bootstrap leftover: https://getbootstrap.com/docs/5.0/utilities/text/#text-alignment

text-align: center;
}