Skip to content

Commit

Permalink
[Workspace] Add Workspace filter to saved objects management page (#6458
Browse files Browse the repository at this point in the history
) (#6580)

* Add workspace filter into saved objects page (#211)

* Add workspace column/filter into saved objects page

Signed-off-by: Hailong Cui <ihailong@amazon.com>

fix failed test case

Signed-off-by: Hailong Cui <ihailong@amazon.com>

move workspace column to its own folder

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* default workspace

Signed-off-by: Hailong Cui <ihailong@amazon.com>

fix test case

Signed-off-by: Hailong Cui <ihailong@amazon.com>

add test case

Signed-off-by: Hailong Cui <ihailong@amazon.com>

remove hide import

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* address review comments

Signed-off-by: Hailong Cui <ihailong@amazon.com>

---------

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* replace default workspace with public workspace (#322)

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* Add workspace filter

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* revert query params change

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* udpate test case name to more clear

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* support public workspace

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* Add changelog

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* update fetchExportByTypeAndSearch parameter

Co-authored-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: Hailong Cui <ihailong@amazon.com>

* remove virtrual public workspace

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* update comments

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* fix public workspace query when permission is not enabled

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* home dashboards/listing page only show public workspace data

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* Add more test case

Signed-off-by: Hailong Cui <ihailong@amazon.com>

---------

Signed-off-by: Hailong Cui <ihailong@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Co-authored-by: SuZhou-Joe <suzhou@amazon.com>
(cherry picked from commit 9408e49)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent accdcf2 commit dd923b4
Show file tree
Hide file tree
Showing 18 changed files with 569 additions and 38 deletions.
8 changes: 7 additions & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ export type { Logos } from '../common';
export { PackageInfo, EnvironmentMode } from '../server/types';
/** @interal */
export { CoreContext, CoreSystem } from './core_system';
export { DEFAULT_APP_CATEGORIES, WORKSPACE_TYPE, cleanWorkspaceId } from '../utils';
export {
DEFAULT_APP_CATEGORIES,
WORKSPACE_TYPE,
cleanWorkspaceId,
PUBLIC_WORKSPACE_ID,
PUBLIC_WORKSPACE_NAME,
} from '../utils';
export {
AppCategory,
UiSettingsParams,
Expand Down
7 changes: 6 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,12 @@ export {
} from './metrics';

export { AppCategory, WorkspaceAttribute } from '../types';
export { DEFAULT_APP_CATEGORIES, WORKSPACE_TYPE } from '../utils';
export {
DEFAULT_APP_CATEGORIES,
PUBLIC_WORKSPACE_ID,
PUBLIC_WORKSPACE_NAME,
WORKSPACE_TYPE,
} from '../utils';

export {
SavedObject,
Expand Down
12 changes: 12 additions & 0 deletions src/core/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';

export const WORKSPACE_TYPE = 'workspace';

export const WORKSPACE_PATH_PREFIX = '/w';

/**
* public workspace has parity with global tenant,
* it includes saved objects with `public` as its workspace or without any workspce info
*/
export const PUBLIC_WORKSPACE_ID = 'public';

export const PUBLIC_WORKSPACE_NAME = i18n.translate('workspaces.public.workspace.default.name', {
defaultMessage: 'Global workspace',
});
7 changes: 6 additions & 1 deletion src/core/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ export {
IContextProvider,
} from './context';
export { DEFAULT_APP_CATEGORIES } from './default_app_categories';
export { WORKSPACE_PATH_PREFIX, WORKSPACE_TYPE } from './constants';
export {
WORKSPACE_PATH_PREFIX,
WORKSPACE_TYPE,
PUBLIC_WORKSPACE_ID,
PUBLIC_WORKSPACE_NAME,
} from './constants';
export { getWorkspaceIdFromUrl, formatUrlWithWorkspaceId, cleanWorkspaceId } from './workspace';
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,24 @@
* under the License.
*/

import { HttpStart } from 'src/core/public';
import { HttpStart, SavedObjectsBaseOptions } from 'src/core/public';
import { formatWorkspaceIdParams } from '../utils';

export async function fetchExportByTypeAndSearch(
http: HttpStart,
types: string[],
search: string | undefined,
includeReferencesDeep: boolean = false
includeReferencesDeep: boolean = false,
workspaces: SavedObjectsBaseOptions['workspaces']
): Promise<Blob> {
return http.post('/api/saved_objects/_export', {
body: JSON.stringify({
type: types,
search,
includeReferencesDeep,
}),
body: JSON.stringify(
formatWorkspaceIdParams({
workspaces,
type: types,
search,
includeReferencesDeep,
})
),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ export interface SavedObjectCountOptions {
typesToInclude: string[];
namespacesToInclude?: string[];
searchString?: string;
workspaces?: string[];
}

export async function getSavedObjectCounts(
http: HttpStart,
options: SavedObjectCountOptions
): Promise<Record<string, number>> {
return await http.post<Record<string, number>>(
): Promise<Record<string, Record<string, number>>> {
return await http.post<Record<string, Record<string, number>>>(
`/api/opensearch-dashboards/management/saved_objects/scroll/counts`,
{ body: JSON.stringify(options) }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('getQueryText', () => {
return [{ value: 'lala' }, { value: 'lolo' }];
} else if (field === 'namespaces') {
return [{ value: 'default' }];
} else if (field === 'workspaces') {
return [{ value: 'workspaces' }];
}
return [];
},
Expand All @@ -47,6 +49,7 @@ describe('getQueryText', () => {
queryText: 'foo bar',
visibleTypes: 'lala',
visibleNamespaces: 'default',
visibleWorkspaces: 'workspaces',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import { Query } from '@elastic/eui';
interface ParsedQuery {
queryText?: string;
visibleTypes?: string[];
visibleNamespaces?: string[];
visibleWorkspaces?: string[];
}

export function parseQuery(query: Query): ParsedQuery {
let queryText: string | undefined;
let visibleTypes: string[] | undefined;
let visibleNamespaces: string[] | undefined;
let visibleWorkspaces: string[] | undefined;

if (query) {
if (query.ast.getTermClauses().length) {
Expand All @@ -53,11 +56,15 @@ export function parseQuery(query: Query): ParsedQuery {
if (query.ast.getFieldClauses('namespaces')) {
visibleNamespaces = query.ast.getFieldClauses('namespaces')[0].value as string[];
}
if (query.ast.getFieldClauses('workspaces')) {
visibleWorkspaces = query.ast.getFieldClauses('workspaces')[0].value as string[];
}
}

return {
queryText,
visibleTypes,
visibleNamespaces,
visibleWorkspaces,
};
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd923b4

Please sign in to comment.