Skip to content

Commit

Permalink
Add async loading of workspaces (#10487)
Browse files Browse the repository at this point in the history
* Add async loading of workspaces in sidebar

* Fix popup

* Fix ellipsis character
  • Loading branch information
juliachvyrova authored Feb 22, 2022
1 parent e23c29d commit 303d103
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions airbyte-webapp/src/packages/cloud/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"workspaces.subtitle": "Workspaces let you collaborate with team members and share sources across your team under a shared billing account.",
"workspaces.create": "Create workspace",
"workspaces.createNew": "Create new workspace",
"workspaces.loading": "Loading…",

"settings.accountSettings.logoutLabel": "Sign out",
"settings.accountSettings.logoutText": "Sign out",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ export function useListCloudWorkspaces(): CloudWorkspace[] {
) as QueryObserverSuccessResult<CloudWorkspace[]>).data;
}

export function useListCloudWorkspacesAsync(): QueryObserverResult<
CloudWorkspace[]
> {
const service = useGetWorkspaceService();
const user = useCurrentUser();

return useQuery<CloudWorkspace[]>(
workspaceKeys.lists(),
() => service.listByUser(user.userId),
{ suspense: false }
);
}

export function useCreateWorkspace() {
const service = useGetWorkspaceService();
const queryClient = useQueryClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useMemo } from "react";
import styled from "styled-components";
import { components } from "react-select";
import { FormattedMessage } from "react-intl";
import { FormattedMessage, useIntl } from "react-intl";
import { MenuListComponentProps } from "react-select/src/components/Menu";

import { Popout } from "components";
import { IDataItem } from "components/base/DropDown/components/Option";
import {
useListCloudWorkspaces,
useWorkspaceService,
useListCloudWorkspacesAsync,
} from "packages/cloud/services/workspaces/WorkspacesService";
import { useCurrentWorkspace } from "services/workspaces/WorkspacesService";

Expand Down Expand Up @@ -102,14 +102,15 @@ const WorkspacesList: React.FC<MenuWithRequestButtonProps> = ({
const WorkspacePopout: React.FC<{
children: (props: { onOpen: () => void; value: any }) => React.ReactNode;
}> = ({ children }) => {
const workspaceList = useListCloudWorkspaces();
const { formatMessage } = useIntl();
const { data: workspaceList, isLoading } = useListCloudWorkspacesAsync();
const { selectWorkspace } = useWorkspaceService();
const workspace = useCurrentWorkspace();

const options = useMemo(
() =>
workspaceList
.filter((w) => w.workspaceId !== workspace.workspaceId)
?.filter((w) => w.workspaceId !== workspace.workspaceId)
.map((workspace) => ({
value: workspace.workspaceId,
label: workspace.name,
Expand All @@ -129,6 +130,12 @@ const WorkspacePopout: React.FC<{
}}
isSearchable={false}
options={options}
isLoading={isLoading}
loadingMessage={() =>
formatMessage({
id: "workspaces.loading",
})
}
value={workspace.slug}
onChange={({ value }) => selectWorkspace(value)}
/>
Expand Down

0 comments on commit 303d103

Please sign in to comment.