Skip to content

Commit

Permalink
revert: saved object management changes
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Mar 5, 2024
1 parent 107dc53 commit d801828
Show file tree
Hide file tree
Showing 20 changed files with 21 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ export async function fetchExportByTypeAndSearch(
http: HttpStart,
types: string[],
search: string | undefined,
includeReferencesDeep: boolean = false,
body?: Record<string, unknown>
includeReferencesDeep: boolean = false
): Promise<Blob> {
return http.post('/api/saved_objects/_export', {
body: JSON.stringify({
...body,
type: types,
search,
includeReferencesDeep,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ import { HttpStart } from 'src/core/public';
export async function fetchExportObjects(
http: HttpStart,
objects: any[],
includeReferencesDeep: boolean = false,
body?: Record<string, unknown>
includeReferencesDeep: boolean = false
): Promise<Blob> {
return http.post('/api/saved_objects/_export', {
body: JSON.stringify({
...body,
objects,
includeReferencesDeep,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export interface SavedObjectCountOptions {
typesToInclude: string[];
namespacesToInclude?: string[];
searchString?: string;
workspaces?: string[];
}

export async function getSavedObjectCounts(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ interface ImportResponse {
export async function importFile(
http: HttpStart,
file: File,
{ createNewCopies, overwrite, workspaces }: ImportMode,
{ createNewCopies, overwrite }: ImportMode,
selectedDataSourceId?: string
) {
const formData = new FormData();
formData.append('file', file);
const query = createNewCopies ? { createNewCopies, workspaces } : { overwrite, workspaces };
const query = createNewCopies ? { createNewCopies } : { overwrite };
if (selectedDataSourceId) {
query.dataSourceId = selectedDataSourceId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,69 +303,4 @@ describe('resolveImportErrors', () => {
}
`);
});

test('make http calls with workspaces', async () => {
httpMock.post.mockResolvedValueOnce({
success: false,
successCount: 0,
errors: [{ type: 'a', id: '1', error: { type: 'conflict' } }],
});
httpMock.post.mockResolvedValueOnce({
success: true,
successCount: 1,
successResults: [{ type: 'a', id: '1' }],
});
getConflictResolutions.mockResolvedValueOnce({});
getConflictResolutions.mockResolvedValueOnce({
'a:1': { retry: true, options: { overwrite: true } },
});
await resolveImportErrors({
http: httpMock,
getConflictResolutions,
state: {
importCount: 0,
unmatchedReferences: [{ existingIndexPatternId: '2', newIndexPatternId: '3', list: [] }],
failedImports: [
{
obj: { type: 'a', id: '1', meta: {} },
error: { type: 'missing_references', references: [{ type: 'index-pattern', id: '2' }] },
},
],
importMode: { createNewCopies: false, overwrite: false },
},
workspaces: ['foo'],
});
expect(httpMock.post.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"/api/saved_objects/_resolve_import_errors",
Object {
"body": FormData {},
"headers": Object {
"Content-Type": undefined,
},
"query": Object {
"workspaces": Array [
"foo",
],
},
},
],
Array [
"/api/saved_objects/_resolve_import_errors",
Object {
"body": FormData {},
"headers": Object {
"Content-Type": undefined,
},
"query": Object {
"workspaces": Array [
"foo",
],
},
},
],
]
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,12 @@ async function callResolveImportErrorsApi(
file: File,
retries: any,
createNewCopies: boolean,
selectedDataSourceId?: string,
workspaces?: string[]
selectedDataSourceId?: string
): Promise<SavedObjectsImportResponse> {
const formData = new FormData();
formData.append('file', file);
formData.append('retries', JSON.stringify(retries));
const query = createNewCopies ? { createNewCopies, workspaces } : { workspaces };
const query = createNewCopies ? { createNewCopies } : {};
if (selectedDataSourceId) {
query.dataSourceId = selectedDataSourceId;
}
Expand Down Expand Up @@ -173,7 +172,6 @@ export async function resolveImportErrors({
getConflictResolutions,
state,
selectedDataSourceId,
workspaces,
}: {
http: HttpStart;
getConflictResolutions: (
Expand All @@ -188,7 +186,6 @@ export async function resolveImportErrors({
importMode: { createNewCopies: boolean; overwrite: boolean };
};
selectedDataSourceId: string;
workspaces?: string[];
}) {
const retryDecisionCache = new Map<string, RetryDecision>();
const replaceReferencesCache = new Map<string, Reference[]>();
Expand Down Expand Up @@ -278,8 +275,7 @@ export async function resolveImportErrors({
file!,
retries,
createNewCopies,
selectedDataSourceId,
workspaces
selectedDataSourceId
);
importCount = response.successCount; // reset the success count since we retry all successful results each time
failedImports = [];
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,6 @@ describe('Flyout', () => {
);
});

it('should call importFile / resolveImportErrors with workspaces', async () => {
const component = shallowRender({ ...defaultProps, workspaces: ['foo'] });

// Ensure all promises resolve
await new Promise((resolve) => process.nextTick(resolve));
// Ensure the state changes are reflected
component.update();

await component.instance().import();
expect(importFileMock.mock.calls[0][2]).toMatchInlineSnapshot(`
Object {
"createNewCopies": true,
"overwrite": true,
"workspaces": Array [
"foo",
],
}
`);

await component.instance().resolveImportErrors();
expect(resolveImportErrorsMock.mock.calls[0][0].workspaces).toEqual(['foo']);
});

describe('conflicts', () => {
beforeEach(() => {
importFileMock.mockImplementation(() => ({
Expand All @@ -229,7 +206,6 @@ describe('Flyout', () => {
},
],
}));
resolveImportErrorsMock.mockClear();
resolveImportErrorsMock.mockImplementation(() => ({
status: 'success',
importCount: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export interface FlyoutProps {
hideLocalCluster: boolean;
savedObjects: SavedObjectsClientContract;
notifications: NotificationsStart;
workspaces?: string[];
}

export interface FlyoutState {
Expand Down Expand Up @@ -190,21 +189,13 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
* Does the initial import of a file, resolveImportErrors then handles errors and retries
*/
import = async () => {
const { http, workspaces } = this.props;
const { http } = this.props;
const { file, importMode, selectedDataSourceId } = this.state;
this.setState({ status: 'loading', error: undefined });

// Import the file
try {
const response = await importFile(
http,
file!,
{
...importMode,
workspaces,
},
selectedDataSourceId
);
const response = await importFile(http, file!, importMode, selectedDataSourceId);
this.setState(processImportResponse(response), () => {
// Resolve import errors right away if there's no index patterns to match
// This will ask about overwriting each object, etc
Expand Down Expand Up @@ -260,15 +251,13 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
status: 'loading',
loadingMessage: undefined,
});
const { workspaces } = this.props;

try {
const updatedState = await resolveImportErrors({
http: this.props.http,
state: this.state,
getConflictResolutions: this.getConflictResolutions,
selectedDataSourceId: this.state.selectedDataSourceId,
workspaces,
});
this.setState(updatedState);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export interface ImportModeControlProps {
export interface ImportMode {
createNewCopies: boolean;
overwrite: boolean;
workspaces?: string[];
}

const createNewCopiesDisabled = {
Expand Down
Loading

0 comments on commit d801828

Please sign in to comment.