Skip to content

Commit

Permalink
Merge branch 'master' into reporting/add-new-data-render-error-attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Oct 12, 2021
2 parents f1b988b + adb49b7 commit eb27e2a
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,14 @@ export function TransactionDistribution({
status={status}
/>

{hasData && (
<>
<EuiSpacer size="s" />

<WaterfallWithSummary
urlParams={urlParams}
waterfall={waterfall}
isLoading={waterfallStatus === FETCH_STATUS.LOADING}
traceSamples={traceSamples}
/>
</>
)}
<EuiSpacer size="s" />

<WaterfallWithSummary
urlParams={urlParams}
waterfall={waterfall}
isLoading={waterfallStatus === FETCH_STATUS.LOADING}
traceSamples={traceSamples}
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,42 @@ describe('CurationSuggestionLogic', () => {
);
});

describe('when a suggestion is a "delete" suggestion', () => {
const deleteSuggestion = {
...suggestion,
operation: 'delete',
promoted: [],
curation_id: 'cur-6155e69c7a2f2e4f756303fd',
};

it('will show a confirm message before applying, and redirect a user back to the curations page, rather than the curation details page', async () => {
jest.spyOn(global, 'confirm').mockReturnValueOnce(true);
http.put.mockReturnValueOnce(
Promise.resolve({
results: [{ ...suggestion, status: 'accepted', curation_id: undefined }],
})
);
mountLogic({
suggestion: deleteSuggestion,
});
CurationSuggestionLogic.actions.acceptSuggestion();
await nextTick();

expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
});

it('will do nothing if the user does not confirm', async () => {
jest.spyOn(global, 'confirm').mockReturnValueOnce(false);
mountLogic({
suggestion: deleteSuggestion,
});
CurationSuggestionLogic.actions.acceptSuggestion();
await nextTick();
expect(http.put).not.toHaveBeenCalled();
expect(navigateToUrl).not.toHaveBeenCalled();
});
});

itHandlesErrors(http.put, () => {
CurationSuggestionLogic.actions.acceptSuggestion();
});
Expand Down Expand Up @@ -404,6 +440,42 @@ describe('CurationSuggestionLogic', () => {
);
});

describe('when a suggestion is a "delete" suggestion', () => {
const deleteSuggestion = {
...suggestion,
operation: 'delete',
promoted: [],
curation_id: 'cur-6155e69c7a2f2e4f756303fd',
};

it('will show a confirm message before applying, and redirect a user back to the curations page, rather than the curation details page', async () => {
jest.spyOn(global, 'confirm').mockReturnValueOnce(true);
http.put.mockReturnValueOnce(
Promise.resolve({
results: [{ ...suggestion, status: 'accepted', curation_id: undefined }],
})
);
mountLogic({
suggestion: deleteSuggestion,
});
CurationSuggestionLogic.actions.acceptAndAutomateSuggestion();
await nextTick();

expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
});

it('will do nothing if the user does not confirm', async () => {
jest.spyOn(global, 'confirm').mockReturnValueOnce(false);
mountLogic({
suggestion: deleteSuggestion,
});
CurationSuggestionLogic.actions.acceptAndAutomateSuggestion();
await nextTick();
expect(http.put).not.toHaveBeenCalled();
expect(navigateToUrl).not.toHaveBeenCalled();
});
});

itHandlesErrors(http.put, () => {
CurationSuggestionLogic.actions.acceptAndAutomateSuggestion();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export const CurationSuggestionLogic = kea<
const { engineName } = EngineLogic.values;
const { suggestion } = values;

if (suggestion!.operation === 'delete') {
const confirmed = await confirmDialog('Are you sure you want to delete this curation?');
if (!confirmed) return;
}

try {
const updatedSuggestion = await updateSuggestion(
http,
Expand All @@ -155,11 +160,16 @@ export const CurationSuggestionLogic = kea<
{ defaultMessage: 'Suggestion was succefully applied.' }
)
);
KibanaLogic.values.navigateToUrl(
generateEnginePath(ENGINE_CURATION_PATH, {
curationId: updatedSuggestion.curation_id,
})
);
if (suggestion!.operation === 'delete') {
// Because if a curation is deleted, there will be no curation detail page to navigate to afterwards.
KibanaLogic.values.navigateToUrl(generateEnginePath(ENGINE_CURATIONS_PATH));
} else {
KibanaLogic.values.navigateToUrl(
generateEnginePath(ENGINE_CURATION_PATH, {
curationId: updatedSuggestion.curation_id,
})
);
}
} catch (e) {
flashAPIErrors(e);
}
Expand All @@ -169,6 +179,11 @@ export const CurationSuggestionLogic = kea<
const { engineName } = EngineLogic.values;
const { suggestion } = values;

if (suggestion!.operation === 'delete') {
const confirmed = await confirmDialog('Are you sure you want to delete this curation?');
if (!confirmed) return;
}

try {
const updatedSuggestion = await updateSuggestion(
http,
Expand All @@ -187,11 +202,16 @@ export const CurationSuggestionLogic = kea<
}
)
);
KibanaLogic.values.navigateToUrl(
generateEnginePath(ENGINE_CURATION_PATH, {
curationId: updatedSuggestion.curation_id,
})
);
if (suggestion!.operation === 'delete') {
// Because if a curation is deleted, there will be no curation detail page to navigate to afterwards.
KibanaLogic.values.navigateToUrl(generateEnginePath(ENGINE_CURATIONS_PATH));
} else {
KibanaLogic.values.navigateToUrl(
generateEnginePath(ENGINE_CURATION_PATH, {
curationId: updatedSuggestion.curation_id,
})
);
}
} catch (e) {
flashAPIErrors(e);
}
Expand Down Expand Up @@ -325,3 +345,10 @@ const getCuration = async (http: HttpSetup, engineName: string, curationId: stri
query: { skip_record_analytics: 'true' },
});
};

const confirmDialog = (msg: string) => {
return new Promise(function (resolve) {
const confirmed = window.confirm(msg);
return resolve(confirmed);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { shallow } from 'enzyme';

import { CurationsTable, EmptyState } from '../components';

import { SuggestionsTable } from '../components/suggestions_table';

import { CurationsOverview } from './curations_overview';

describe('CurationsOverview', () => {
Expand Down Expand Up @@ -44,4 +46,18 @@ describe('CurationsOverview', () => {

expect(wrapper.find(CurationsTable)).toHaveLength(1);
});

it('renders a suggestions table when the user has a platinum license', () => {
setMockValues({ curations: [], hasPlatinumLicense: true });
const wrapper = shallow(<CurationsOverview />);

expect(wrapper.find(SuggestionsTable).exists()).toBe(true);
});

it('doesn\t render a suggestions table when the user has no platinum license', () => {
setMockValues({ curations: [], hasPlatinumLicense: false });
const wrapper = shallow(<CurationsOverview />);

expect(wrapper.find(SuggestionsTable).exists()).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import { useValues } from 'kea';

import { EuiSpacer } from '@elastic/eui';

import { LicensingLogic } from '../../../../shared/licensing';
import { CurationsTable, EmptyState } from '../components';
import { SuggestionsTable } from '../components/suggestions_table';
import { CurationsLogic } from '../curations_logic';

export const CurationsOverview: React.FC = () => {
const { curations } = useValues(CurationsLogic);
const { hasPlatinumLicense } = useValues(LicensingLogic);

// TODO
const shouldShowSuggestions = true;
const shouldShowSuggestions = hasPlatinumLicense;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { HOSTS_URL } from '../../urls/navigation';

const defaultPageSize = 25;
describe('Pagination', () => {
beforeEach(() => {
before(() => {
cleanKibana();
loginAndWaitForPage(HOSTS_URL);
openTimelineUsingToggle();
Expand All @@ -41,20 +41,13 @@ describe('Pagination', () => {

it('should be able to change items count per page with the dropdown', () => {
const itemsPerPage = 100;
cy.intercept('POST', '/internal/bsearch').as('refetch');

cy.get(TIMELINE_EVENTS_COUNT_PER_PAGE_BTN).first().click();
cy.get(TIMELINE_EVENTS_COUNT_PER_PAGE_OPTION(itemsPerPage)).click();
cy.wait('@refetch').its('response.statusCode').should('eq', 200);
cy.get(TIMELINE_EVENTS_COUNT_PER_PAGE).should('contain.text', itemsPerPage);
});

it('should be able to go to next / previous page', () => {
cy.intercept('POST', '/internal/bsearch').as('refetch');
cy.get(`${TIMELINE_FLYOUT} ${TIMELINE_EVENTS_COUNT_NEXT_PAGE}`).first().click();
cy.wait('@refetch').its('response.statusCode').should('eq', 200);

cy.get(`${TIMELINE_FLYOUT} ${TIMELINE_EVENTS_COUNT_PREV_PAGE}`).first().click();
cy.wait('@refetch').its('response.statusCode').should('eq', 200);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { createMemoryHistory } from 'history';
import { render } from '../../lib/helper/rtl_helpers';
import { fireEvent } from '@testing-library/dom';

describe('UptimeDatePicker component', () => {
// FLAKY: https://github.com/elastic/kibana/issues/114396
describe.skip('UptimeDatePicker component', () => {
it('renders properly with mock data', async () => {
const { findByText } = render(<UptimeDatePicker />);
expect(await findByText('Last 15 minutes')).toBeInTheDocument();
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/uptime/server/lib/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../common/constants';
import { DynamicSettings } from '../../common/runtime_types';
import { SavedObjectsType, SavedObjectsErrorHelpers } from '../../../../../src/core/server';
Expand Down Expand Up @@ -43,6 +44,14 @@ export const umDynamicSettings: SavedObjectsType = {
*/
},
},
management: {
importableAndExportable: true,
icon: 'uptimeApp',
getTitle: () =>
i18n.translate('xpack.uptime.uptimeSettings.index', {
defaultMessage: 'Uptime Settings - Index',
}),
},
};

export const savedObjectsAdapter: UMSavedObjectsAdapter = {
Expand Down

0 comments on commit eb27e2a

Please sign in to comment.