Skip to content

Commit

Permalink
Merge branch 'master' into ilm/surfacing-policy-error-state
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 1, 2021
2 parents d3b3c35 + fb19aab commit cd9c479
Show file tree
Hide file tree
Showing 110 changed files with 5,717 additions and 2,412 deletions.
7 changes: 7 additions & 0 deletions src/plugins/dashboard/public/application/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ export function DashboardApp({
};
}, [dashboardStateManager, dashboardContainer, onAppLeave, embeddable]);

// clear search session when leaving dashboard route
useEffect(() => {
return () => {
data.search.session.clear();
};
}, [data.search.session]);

return (
<div className="app-container dshAppContainer">
{savedDashboard && dashboardStateManager && dashboardContainer && viewMode && (
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/saved_objects_management/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@
* Public License, v 1.
*/

export { SavedObjectRelation, SavedObjectWithMetadata, SavedObjectMetadata } from './types';
export {
SavedObjectWithMetadata,
SavedObjectMetadata,
SavedObjectRelation,
SavedObjectRelationKind,
SavedObjectInvalidRelation,
SavedObjectGetRelationshipsResponse,
} from './types';
16 changes: 15 additions & 1 deletion src/plugins/saved_objects_management/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,26 @@ export type SavedObjectWithMetadata<T = unknown> = SavedObject<T> & {
meta: SavedObjectMetadata;
};

export type SavedObjectRelationKind = 'child' | 'parent';

/**
* Represents a relation between two {@link SavedObject | saved object}
*/
export interface SavedObjectRelation {
id: string;
type: string;
relationship: 'child' | 'parent';
relationship: SavedObjectRelationKind;
meta: SavedObjectMetadata;
}

export interface SavedObjectInvalidRelation {
id: string;
type: string;
relationship: SavedObjectRelationKind;
error: string;
}

export interface SavedObjectGetRelationshipsResponse {
relations: SavedObjectRelation[];
invalidRelations: SavedObjectInvalidRelation[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Public License, v 1.
*/

import { SavedObjectGetRelationshipsResponse } from '../types';
import { httpServiceMock } from '../../../../core/public/mocks';
import { getRelationships } from './get_relationships';

Expand All @@ -22,13 +23,17 @@ describe('getRelationships', () => {
});

it('should handle successful responses', async () => {
httpMock.get.mockResolvedValue([1, 2]);
const serverResponse: SavedObjectGetRelationshipsResponse = {
relations: [],
invalidRelations: [],
};
httpMock.get.mockResolvedValue(serverResponse);

const response = await getRelationships(httpMock, 'dashboard', '1', [
'search',
'index-pattern',
]);
expect(response).toEqual([1, 2]);
expect(response).toEqual(serverResponse);
});

it('should handle errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

import { HttpStart } from 'src/core/public';
import { get } from 'lodash';
import { SavedObjectRelation } from '../types';
import { SavedObjectGetRelationshipsResponse } from '../types';

export async function getRelationships(
http: HttpStart,
type: string,
id: string,
savedObjectTypes: string[]
): Promise<SavedObjectRelation[]> {
): Promise<SavedObjectGetRelationshipsResponse> {
const url = `/api/kibana/management/saved_objects/relationships/${encodeURIComponent(
type
)}/${encodeURIComponent(id)}`;
try {
return await http.get<SavedObjectRelation[]>(url, {
return await http.get<SavedObjectGetRelationshipsResponse>(url, {
query: {
savedObjectTypes,
},
Expand Down
Loading

0 comments on commit cd9c479

Please sign in to comment.