Skip to content

Commit

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

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

* Add workspace column/filter into saved objects page

Signed-off-by: Hailong Cui <[email protected]>

fix failed test case

Signed-off-by: Hailong Cui <[email protected]>

move workspace column to its own folder

Signed-off-by: Hailong Cui <[email protected]>

* default workspace

Signed-off-by: Hailong Cui <[email protected]>

fix test case

Signed-off-by: Hailong Cui <[email protected]>

add test case

Signed-off-by: Hailong Cui <[email protected]>

remove hide import

Signed-off-by: Hailong Cui <[email protected]>

* address review comments

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>

* replace default workspace with public workspace (opensearch-project#322)

Signed-off-by: Hailong Cui <[email protected]>

* Add workspace filter

Signed-off-by: Hailong Cui <[email protected]>

* revert query params change

Signed-off-by: Hailong Cui <[email protected]>

* udpate test case name to more clear

Signed-off-by: Hailong Cui <[email protected]>

* support public workspace

Signed-off-by: Hailong Cui <[email protected]>

* Add changelog

Signed-off-by: Hailong Cui <[email protected]>

* update fetchExportByTypeAndSearch parameter

Co-authored-by: SuZhou-Joe <[email protected]>
Signed-off-by: Hailong Cui <[email protected]>

* remove virtrual public workspace

Signed-off-by: Hailong Cui <[email protected]>

* update comments

Signed-off-by: Hailong Cui <[email protected]>

* fix public workspace query when permission is not enabled

Signed-off-by: Hailong Cui <[email protected]>

* home dashboards/listing page only show public workspace data

Signed-off-by: Hailong Cui <[email protected]>

* Add more test case

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: SuZhou-Joe <[email protected]>
  • Loading branch information
Hailong-am and SuZhou-Joe authored Apr 17, 2024
1 parent 7a46475 commit 9408e49
Show file tree
Hide file tree
Showing 19 changed files with 570 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [MD] Add dropdown header to data source single selector ([#6431](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6431))
- [Workspace] Add permission tab to workspace create update page ([#6378](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6378))
- [Workspace] Hide datasource and advanced settings menu in dashboard management when in workspace. ([#6455](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6455))
- [Workspace] Add workspaces filter to saved objects page. ([#6458](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6458))

### 🐛 Bug Fixes

Expand Down
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.

Loading

0 comments on commit 9408e49

Please sign in to comment.