diff --git a/src/plugins/management/public/components/feature_cards/__snapshots__/feature_cards.test.tsx.snap b/src/plugins/management/public/components/feature_cards/__snapshots__/feature_cards.test.tsx.snap index d777d7d9e2c0..0718fb98bf4f 100644 --- a/src/plugins/management/public/components/feature_cards/__snapshots__/feature_cards.test.tsx.snap +++ b/src/plugins/management/public/components/feature_cards/__snapshots__/feature_cards.test.tsx.snap @@ -3,7 +3,23 @@ exports[` render with complex navLinks 1`] = `
+
+
+

+

+
+
+
diff --git a/src/plugins/saved_objects_management/public/lib/get_saved_object_counts.ts b/src/plugins/saved_objects_management/public/lib/get_saved_object_counts.ts index 374f2720b537..b46389fe54f3 100644 --- a/src/plugins/saved_objects_management/public/lib/get_saved_object_counts.ts +++ b/src/plugins/saved_objects_management/public/lib/get_saved_object_counts.ts @@ -35,6 +35,7 @@ export interface SavedObjectCountOptions { namespacesToInclude?: string[]; searchString?: string; workspaces?: string[]; + availableWorkspaces?: string[]; } export async function getSavedObjectCounts( diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx index bee992e0196d..a33a59786617 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx @@ -812,7 +812,7 @@ describe('SavedObjectsTable', () => { }); }); - it('all visible workspaces in find options when not in any workspace', async () => { + it('no workspaces in find options when not in any workspace', async () => { findObjectsMock.mockClear(); const applications = applicationServiceMock.createStartContract(); applications.capabilities = { @@ -851,8 +851,8 @@ describe('SavedObjectsTable', () => { await waitFor(() => { expect(findObjectsMock).toBeCalledWith( http, - expect.objectContaining({ - workspaces: expect.arrayContaining(['workspace1', 'workspace2']), + expect.not.objectContaining({ + workspaces, }) ); }); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx index 162daab66e56..38f69a05b35c 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx @@ -187,15 +187,14 @@ export class SavedObjectsTable extends Component ws.id); + return undefined; } else { return [currentWorkspaceId]; } @@ -250,6 +249,7 @@ export class SavedObjectsTable extends Component ws.id), }); if (availableNamespaces.length) { @@ -286,6 +286,7 @@ export class SavedObjectsTable extends Component ws.id), }); if (availableNamespaces.length) { @@ -958,9 +959,7 @@ export class SavedObjectsTable extends Component { - return this.workspaceIdQuery?.includes(ws.id); - }) + .filter((ws) => (currentWorkspaceId ? currentWorkspaceId === ws.id : true)) .map((ws) => { return { name: ws.name, diff --git a/src/plugins/saved_objects_management/public/utils.test.ts b/src/plugins/saved_objects_management/public/utils.test.ts index 3b714a169219..eebfdec8f61d 100644 --- a/src/plugins/saved_objects_management/public/utils.test.ts +++ b/src/plugins/saved_objects_management/public/utils.test.ts @@ -17,4 +17,28 @@ describe('Utils', () => { const obj = formatWorkspaceIdParams({ foo: 'bar', workspaces: ['foo'] }); expect(obj).toEqual({ foo: 'bar', workspaces: ['foo'] }); }); + + it('formatWorkspaceIdParams with availableWorkspaces exists', async () => { + const obj = formatWorkspaceIdParams({ foo: 'bar', availableWorkspaces: ['foo'] }); + expect(obj).toEqual({ foo: 'bar', availableWorkspaces: ['foo'] }); + }); + + it('formatWorkspaceIdParams with availableWorkspaces is empty array', async () => { + const obj = formatWorkspaceIdParams({ foo: 'bar', availableWorkspaces: [] }); + expect(obj).toEqual({ foo: 'bar' }); + }); + + it('formatWorkspaceIdParams with availableWorkspaces is null/undefined', async () => { + const obj = formatWorkspaceIdParams({ foo: 'bar', availableWorkspaces: null }); + expect(obj).toEqual({ foo: 'bar' }); + }); + + it('formatWorkspaceIdParams with both workspaces and availableWorkspaces are not empty', async () => { + const obj = formatWorkspaceIdParams({ + foo: 'bar', + availableWorkspaces: ['foo', 'bar'], + workspaces: ['foo'], + }); + expect(obj).toEqual({ foo: 'bar', availableWorkspaces: ['foo', 'bar'], workspaces: ['foo'] }); + }); }); diff --git a/src/plugins/saved_objects_management/public/utils.ts b/src/plugins/saved_objects_management/public/utils.ts index 84727ab6a356..937e7767702d 100644 --- a/src/plugins/saved_objects_management/public/utils.ts +++ b/src/plugins/saved_objects_management/public/utils.ts @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -export function formatWorkspaceIdParams( - obj: T -): T | Omit { - const { workspaces, ...others } = obj; - if (workspaces) { +export function formatWorkspaceIdParams< + T extends { workspaces?: string[] | null; availableWorkspaces?: string[] | null } +>(obj: T): T | Omit { + const { workspaces, availableWorkspaces, ...others } = obj; + if (workspaces || (availableWorkspaces && availableWorkspaces.length)) { return obj; } return others; diff --git a/src/plugins/saved_objects_management/server/routes/scroll_count.ts b/src/plugins/saved_objects_management/server/routes/scroll_count.ts index fc5237805378..c200d6c82dd1 100644 --- a/src/plugins/saved_objects_management/server/routes/scroll_count.ts +++ b/src/plugins/saved_objects_management/server/routes/scroll_count.ts @@ -42,6 +42,7 @@ export const registerScrollForCountRoute = (router: IRouter) => { namespacesToInclude: schema.maybe(schema.arrayOf(schema.string())), searchString: schema.maybe(schema.string()), workspaces: schema.maybe(schema.arrayOf(schema.string())), + availableWorkspaces: schema.maybe(schema.arrayOf(schema.string())), }), }, }, @@ -59,7 +60,9 @@ export const registerScrollForCountRoute = (router: IRouter) => { const requestHasNamespaces = Array.isArray(req.body.namespacesToInclude) && req.body.namespacesToInclude.length; - const requestHasWorkspaces = Array.isArray(req.body.workspaces) && req.body.workspaces.length; + const requestHasWorkspaces = + (Array.isArray(req.body.workspaces) && req.body.workspaces.length) || + (Array.isArray(req.body.availableWorkspaces) && req.body.availableWorkspaces.length); if (requestHasNamespaces) { counts.namespaces = {}; @@ -114,7 +117,7 @@ export const registerScrollForCountRoute = (router: IRouter) => { } } - const workspacesToInclude = req.body.workspaces || []; + const workspacesToInclude = req.body.workspaces || req.body.availableWorkspaces || []; for (const ws of workspacesToInclude) { if (!counts.workspaces[ws]) { counts.workspaces[ws] = 0;