Skip to content

Commit

Permalink
workspace filter
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Aug 10, 2023
1 parent 72dc3df commit d80db63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import { WorkspacesStart, WorkspacesSetup } from './workspace';
export { PackageInfo, EnvironmentMode } from '../server/types';
/** @interal */
export { CoreContext, CoreSystem } from './core_system';
export { DEFAULT_APP_CATEGORIES, GLOBAL_WORKSPACE_ID } from '../utils';
export { DEFAULT_APP_CATEGORIES } from '../utils';
export {
AppCategory,
UiSettingsParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,23 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
}

private get workspaceIdQuery() {
const { availableWorkspace } = this.state;
return availableWorkspace?.map((ws) => ws.id) ?? [GLOBAL_WORKSPACE_ID];
// return this.state.workspaceId
? Array.from(new Set([PUBLIC_WORKSPACE, this.state.workspaceId]))
: undefined;
const { availableWorkspace, workspaceId } = this.state;
// workspace is turned off
if (!availableWorkspace?.length) {
return undefined;
}
if (!workspaceId) {
return availableWorkspace.map((ws) => ws.id);
} else if (workspaceId === PUBLIC_WORKSPACE) {
return [PUBLIC_WORKSPACE];
} else {
return [workspaceId, PUBLIC_WORKSPACE];
}
}

private get wsNameIdLookup() {
const { availableWorkspace } = this.state;
// Assumption: workspace name is unique across the system
return availableWorkspace?.reduce((map, ws) => {
return map.set(ws.name, ws.id);
}, new Map<string, string>());
Expand Down Expand Up @@ -239,7 +247,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
}
if (visibleWorkspaces?.length) {
filteredCountOptions.workspaces = visibleWorkspaces.map(
(wsName) => this.wsNameIdLookup?.get(wsName) || GLOBAL_WORKSPACE_ID
(wsName) => this.wsNameIdLookup?.get(wsName) || PUBLIC_WORKSPACE
);
}

Expand Down Expand Up @@ -275,12 +283,6 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
countOptions.namespacesToInclude = availableNamespaces;
}

if (visibleWorkspaces?.length) {
countOptions.workspaces = visibleWorkspaces.map(
(wsName) => this.wsNameIdLookup?.get(wsName) || GLOBAL_WORKSPACE_ID
);
}

// Fetch all the saved objects that exist so we can accurately populate the counts within
// the table filter dropdown.
const savedObjectCounts = await getSavedObjectCounts(this.props.http, countOptions);
Expand All @@ -307,13 +309,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
);

this.workspacesSubscription = workspaceClient.workspaceList$.subscribe((workspaceList) => {
// TOOD remove this one
const availableWorkspace = workspaceList.concat({
id: GLOBAL_WORKSPACE_ID,
name: GLOBAL_WORKSPACE_ID,
});

this.setState({ availableWorkspace });
this.setState({ availableWorkspace: workspaceList });
});
};

Expand Down Expand Up @@ -345,7 +341,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb

if (visibleWorkspaces?.length) {
const workspaceIds: string[] = visibleWorkspaces.map(
(wsName) => this.wsNameIdLookup?.get(wsName) || GLOBAL_WORKSPACE_ID
(wsName) => this.wsNameIdLookup?.get(wsName) || PUBLIC_WORKSPACE
);
findOptions.workspaces = workspaceIds;
}
Expand Down Expand Up @@ -990,14 +986,17 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
// Add workspace filter
if (availableWorkspace?.length) {
const wsCounts = savedObjectCounts.workspaces || {};
// this will include public workspace
const wsFilterOptions = availableWorkspace.map((ws) => {
return {
name: ws.name,
value: ws.name,
view: `${ws.name} (${wsCounts[ws.id] || 0})`,
};
});
const wsFilterOptions = availableWorkspace
.filter((ws) => {
return this.workspaceIdQuery?.includes(ws.id);
})
.map((ws) => {
return {
name: ws.name,
value: ws.name,
view: `${ws.name} (${wsCounts[ws.id] || 0})`,
};
});

filters.push({
type: 'field_value_selection',
Expand Down

0 comments on commit d80db63

Please sign in to comment.