Skip to content

Commit

Permalink
Fix workspace list always render
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Apr 3, 2024
1 parent b914e9a commit 79b7271
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import useObservable from 'react-use/lib/useObservable';
import { of } from 'rxjs';
import { i18n } from '@osd/i18n';
import { debounce } from '../../../../../core/public';
import { debounce, WorkspaceObject } from '../../../../../core/public';
import { WorkspaceAttribute } from '../../../../../core/public';
import { useOpenSearchDashboards } from '../../../../../plugins/opensearch_dashboards_react/public';
import { switchWorkspace, updateWorkspace } from '../utils/workspace';
Expand All @@ -34,14 +34,19 @@ const WORKSPACE_LIST_PAGE_DESCRIPTIOIN = i18n.translate('workspace.list.descript
'Workspace allow you to save and organize library items, such as index patterns, visualizations, dashboards, saved searches, and share them with other OpenSearch Dashboards users. You can control which features are visible in each workspace, and which users and groups have read and write access to the library items in the workspace.',
});

const emptyWorkspaceList: WorkspaceObject[] = [];

export const WorkspaceList = () => {
const {
services: { workspaces, application, http },
} = useOpenSearchDashboards();

const initialSortField = 'name';
const initialSortDirection = 'asc';
const workspaceList = useObservable(workspaces?.workspaceList$ ?? of([]), []);
const workspaceList = useObservable(
workspaces?.workspaceList$ ?? of(emptyWorkspaceList),
emptyWorkspaceList
);
const [queryInput, setQueryInput] = useState<string>('');
const [pagination, setPagination] = useState({
pageIndex: 0,
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/workspace/public/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { useMemo } from 'react';
import { of } from 'rxjs';
import { ApplicationStart, PublicAppInfo } from '../../../core/public';

const emptyMap = new Map();

export function useApplications(application?: ApplicationStart) {
const applications = useObservable(application?.applications$ ?? of(new Map()), new Map());
const applications = useObservable(application?.applications$ ?? of(emptyMap), emptyMap);
return useMemo(() => {
const apps: PublicAppInfo[] = [];
applications.forEach((app) => {
Expand Down

0 comments on commit 79b7271

Please sign in to comment.