Skip to content

Commit

Permalink
Merge branch 'workspace-pr-integr' into feature/list-data-source-with…
Browse files Browse the repository at this point in the history
…out-workspace
  • Loading branch information
SuZhou-Joe committed Apr 16, 2024
2 parents b1494b1 + 1a353cc commit 4097e94
Show file tree
Hide file tree
Showing 39 changed files with 3,353 additions and 105 deletions.
1 change: 1 addition & 0 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ export class SavedObjectsClient {
namespaces: 'namespaces',
preference: 'preference',
workspaces: 'workspaces',
enabledOperators: 'enabledOperators',
};

const renamedQuery = renameKeys<SavedObjectsFindOptions, any>(renameMap, {
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ export class SavedObjectsRepository {
workspaces,
workspacesSearchOperator,
ACLSearchParams,
enabledOperators,
} = options;

if (!type && !typeToNamespacesMap) {
Expand Down Expand Up @@ -877,6 +878,7 @@ export class SavedObjectsRepository {
workspaces,
workspacesSearchOperator,
ACLSearchParams,
enabledOperators,
}),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,25 @@ describe('#getQueryParams', () => {
);
});
});

describe('`enabledOperators` parameter', () => {
it('does not include flags when `enabledOperators` is not specified', () => {
const result = getQueryParams({
registry,
search,
});
expectResult(result, expect.not.objectContaining({ flags: expect.anything() }));
});

it('includes flags when `enabledOperators` specified', () => {
const result = getQueryParams({
registry,
search,
enabledOperators: 'all',
});
expectResult(result, expect.objectContaining({ flags: expect.stringMatching('all') }));
});
});
});

describe('when using prefix search (query.bool.should)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ interface QueryParams {
workspaces?: SavedObjectsFindOptions['workspaces'];
workspacesSearchOperator?: 'AND' | 'OR';
ACLSearchParams?: SavedObjectsFindOptions['ACLSearchParams'];
enabledOperators?: SavedObjectsFindOptions['enabledOperators'];
}

export function getClauseForReference(reference: HasReferenceQueryParams) {
Expand Down Expand Up @@ -229,6 +230,7 @@ export function getQueryParams({
workspaces,
workspacesSearchOperator = 'AND',
ACLSearchParams,
enabledOperators,
}: QueryParams) {
const types = getTypes(
registry,
Expand Down Expand Up @@ -261,6 +263,7 @@ export function getQueryParams({
searchFields,
rootSearchFields,
defaultSearchOperator,
enabledOperators,
});

if (useMatchPhrasePrefix) {
Expand Down Expand Up @@ -432,18 +435,21 @@ const getSimpleQueryStringClause = ({
searchFields,
rootSearchFields,
defaultSearchOperator,
enabledOperators,
}: {
search: string;
types: string[];
searchFields?: string[];
rootSearchFields?: string[];
defaultSearchOperator?: string;
enabledOperators?: SavedObjectsFindOptions['enabledOperators'];
}) => {
return {
simple_query_string: {
query: search,
...getSimpleQueryStringTypeFields(types, searchFields, rootSearchFields),
...(defaultSearchOperator ? { default_operator: defaultSearchOperator } : {}),
...(enabledOperators ? { flags: enabledOperators } : {}),
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface GetSearchDslOptions {
workspaces?: SavedObjectsFindOptions['workspaces'];
workspacesSearchOperator?: 'AND' | 'OR';
ACLSearchParams?: SavedObjectsFindOptions['ACLSearchParams'];
enabledOperators?: SavedObjectsFindOptions['enabledOperators'];
}

export function getSearchDsl(
Expand All @@ -78,6 +79,7 @@ export function getSearchDsl(
workspaces,
workspacesSearchOperator,
ACLSearchParams,
enabledOperators,
} = options;

if (!type) {
Expand All @@ -103,6 +105,7 @@ export function getSearchDsl(
workspaces,
workspacesSearchOperator,
ACLSearchParams,
enabledOperators,
}),
...getSortingParams(mappings, type, sortField, sortOrder),
};
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/saved_objects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export interface SavedObjectsFindOptions {
search?: string;
/** The fields to perform the parsed query against. See OpenSearch Simple Query String `fields` argument for more information */
searchFields?: string[];
/** The enabled operators for OpenSearch Simple Query String. See OpenSearch Simple Query String `flags` argument for more information */
enabledOperators?: string;
/**
* The fields to perform the parsed query against. Unlike the `searchFields` argument, these are expected to be root fields and will not
* be modified. If used in conjunction with `searchFields`, both are concatenated together.
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/saved_objects_management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ export {
ISavedObjectsManagementServiceRegistry,
SavedObjectsManagementServiceRegistryEntry,
} from './services';
export { ProcessedImportResponse, processImportResponse, FailedImport } from './lib';
export {
ProcessedImportResponse,
processImportResponse,
FailedImport,
duplicateSavedObjects,
getSavedObjectLabel,
} from './lib';
export { SavedObjectRelation, SavedObjectWithMetadata, SavedObjectMetadata } from './types';
export { SAVED_OBJECT_DELETE_TRIGGER, savedObjectDeleteTrigger } from './triggers';
export { SavedObjectDeleteContext } from './ui_actions_bootstrap';

export { SavedObjectsDuplicateModal, DuplicateMode } from './management_section';
export function plugin(initializerContext: PluginInitializerContext) {
return new SavedObjectsManagementPlugin();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { httpServiceMock } from '../../../../core/public/mocks';
import { duplicateSavedObjects } from './duplicate_saved_objects';

describe('copy saved objects', () => {
it('make http call with body provided', async () => {
const httpClient = httpServiceMock.createStartContract();
const objects = [
{ type: 'dashboard', id: '1' },
{ type: 'visualization', id: '2' },
];
const includeReferencesDeep = true;
const targetWorkspace = '1';
await duplicateSavedObjects(httpClient, objects, includeReferencesDeep, targetWorkspace);
expect(httpClient.post).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"/api/workspaces/_duplicate_saved_objects",
Object {
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
},
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`);

await duplicateSavedObjects(httpClient, objects, undefined, targetWorkspace);
expect(httpClient.post).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"/api/workspaces/_duplicate_saved_objects",
Object {
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
},
],
Array [
"/api/workspaces/_duplicate_saved_objects",
Object {
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
},
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
Object {
"type": "return",
"value": undefined,
},
],
}
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { HttpStart } from 'src/core/public';

export async function duplicateSavedObjects(
http: HttpStart,
objects: any[],
includeReferencesDeep: boolean = true,
targetWorkspace: string
) {
return await http.post('/api/workspaces/_duplicate_saved_objects', {
body: JSON.stringify({
objects,
includeReferencesDeep,
targetWorkspace,
}),
});
}
1 change: 1 addition & 0 deletions src/plugins/saved_objects_management/public/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ export { extractExportDetails, SavedObjectsExportResultDetails } from './extract
export { createFieldList } from './create_field_list';
export { getAllowedTypes } from './get_allowed_types';
export { filterQuery } from './filter_query';
export { duplicateSavedObjects } from './duplicate_saved_objects';
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
*/

export { mountManagementSection } from './mount_section';
export { SavedObjectsDuplicateModal, DuplicateMode } from './objects_table';
Loading

0 comments on commit 4097e94

Please sign in to comment.