Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into d/2021-08-26-…
Browse files Browse the repository at this point in the history
…ff-any
  • Loading branch information
Dosant committed Sep 9, 2021
2 parents 450ebef + 72dfb9c commit 7033024
Show file tree
Hide file tree
Showing 27 changed files with 822 additions and 397 deletions.
6 changes: 6 additions & 0 deletions packages/kbn-config/src/deprecation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface DeprecatedConfigDetails {
title?: string;
/* The message to be displayed for the deprecation. */
message: string;
/**
* levels:
* - warning: will not break deployment upon upgrade
* - critical: needs to be addressed before upgrade.
*/
level?: 'warning' | 'critical';
/* (optional) set false to prevent the config service from logging the deprecation message. */
silent?: boolean;
/* (optional) link to the documentation for more details on the deprecation. */
Expand Down
6 changes: 3 additions & 3 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export class DocLinksService {
kibanaSettings: `${KIBANA_DOCS}apm-settings-in-kibana.html`,
supportedServiceMaps: `${KIBANA_DOCS}service-maps.html#service-maps-supported`,
customLinks: `${KIBANA_DOCS}custom-links.html`,
droppedTransactionSpans: `${APM_DOCS}get-started/${DOC_LINK_VERSION}/transaction-spans.html#dropped-spans`,
upgrading: `${APM_DOCS}server/${DOC_LINK_VERSION}/upgrading.html`,
metaData: `${APM_DOCS}get-started/${DOC_LINK_VERSION}/metadata.html`,
droppedTransactionSpans: `${APM_DOCS}get-started/master/transaction-spans.html#dropped-spans`,
upgrading: `${APM_DOCS}server/master/upgrading.html`,
metaData: `${APM_DOCS}get-started/master/metadata.html`,
},
canvas: {
guide: `${KIBANA_DOCS}canvas.html`,
Expand Down
30 changes: 28 additions & 2 deletions src/core/server/deprecations/deprecations_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('DeprecationsService', () => {
const deprecationsRegistry = mockDeprecationsRegistry.create();
const getDeprecationsContext = mockDeprecationsRegistry.createGetDeprecationsContext();

it('registers config deprecations', () => {
it('registers config deprecations', async () => {
const deprecationsService = new DeprecationsService(coreContext);
coreContext.configService.getHandledDeprecatedConfigs.mockReturnValue([
[
Expand All @@ -93,7 +93,7 @@ describe('DeprecationsService', () => {
expect(deprecationsFactory.getRegistry).toBeCalledTimes(1);
expect(deprecationsFactory.getRegistry).toBeCalledWith('testDomain');
expect(deprecationsRegistry.registerDeprecations).toBeCalledTimes(1);
const configDeprecations = deprecationsRegistry.registerDeprecations.mock.calls[0][0].getDeprecations(
const configDeprecations = await deprecationsRegistry.registerDeprecations.mock.calls[0][0].getDeprecations(
getDeprecationsContext
);
expect(configDeprecations).toMatchInlineSnapshot(`
Expand All @@ -115,5 +115,31 @@ describe('DeprecationsService', () => {
]
`);
});

it('accepts `level` field overrides', async () => {
const deprecationsService = new DeprecationsService(coreContext);
coreContext.configService.getHandledDeprecatedConfigs.mockReturnValue([
[
'testDomain',
[
{
message: 'testMessage',
level: 'warning',
correctiveActions: {
manualSteps: ['step a'],
},
},
],
],
]);

deprecationsFactory.getRegistry.mockReturnValue(deprecationsRegistry);
deprecationsService['registerConfigDeprecationsInfo'](deprecationsFactory);

const configDeprecations = await deprecationsRegistry.registerDeprecations.mock.calls[0][0].getDeprecations(
getDeprecationsContext
);
expect(configDeprecations[0].level).toBe('warning');
});
});
});
26 changes: 15 additions & 11 deletions src/core/server/deprecations/deprecations_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,21 @@ export class DeprecationsService
deprecationsRegistry.registerDeprecations({
getDeprecations: () => {
return deprecationsContexts.map(
({ title, message, correctiveActions, documentationUrl }) => {
return {
title: title || `${domainId} has a deprecated setting`,
level: 'critical',
deprecationType: 'config',
message,
correctiveActions,
documentationUrl,
requireRestart: true,
};
}
({
title = `${domainId} has a deprecated setting`,
level = 'critical',
message,
correctiveActions,
documentationUrl,
}) => ({
title,
level,
message,
correctiveActions,
documentationUrl,
deprecationType: 'config',
requireRestart: true,
})
);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { memo, useCallback, useMemo } from 'react';
import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
import './index.scss';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
Expand All @@ -24,30 +24,61 @@ export interface DocTableEmbeddableProps extends DocTableProps {
const DocTableWrapperMemoized = memo(DocTableWrapper);

export const DocTableEmbeddable = (props: DocTableEmbeddableProps) => {
const pager = usePager({ totalItems: props.rows.length });
const tableWrapperRef = useRef<HTMLDivElement>(null);
const {
currentPage,
pageSize,
totalPages,
startIndex,
hasNextPage,
changePage,
changePageSize,
} = usePager({
totalItems: props.rows.length,
});
const showPagination = totalPages !== 0;

const pageOfItems = useMemo(
() => props.rows.slice(pager.startIndex, pager.pageSize + pager.startIndex),
[pager.pageSize, pager.startIndex, props.rows]
);
const scrollTop = useCallback(() => {
if (tableWrapperRef.current) {
tableWrapperRef.current.scrollTo(0, 0);
}
}, []);

const pageOfItems = useMemo(() => props.rows.slice(startIndex, pageSize + startIndex), [
pageSize,
startIndex,
props.rows,
]);

const shouldShowLimitedResultsWarning = () =>
!pager.hasNextPage && props.rows.length < props.totalHitCount;
const onPageChange = useCallback(
(page: number) => {
scrollTop();
changePage(page);
},
[changePage, scrollTop]
);

const scrollTop = () => {
const scrollDiv = document.querySelector('.kbnDocTableWrapper') as HTMLElement;
scrollDiv.scrollTo(0, 0);
};
const onPageSizeChange = useCallback(
(size: number) => {
scrollTop();
changePageSize(size);
},
[changePageSize, scrollTop]
);

const onPageChange = (page: number) => {
scrollTop();
pager.onPageChange(page);
};
/**
* Go to the first page if the current is no longer available
*/
useEffect(() => {
if (totalPages < currentPage + 1) {
onPageChange(0);
}
}, [currentPage, totalPages, onPageChange]);

const onPageSizeChange = (size: number) => {
scrollTop();
pager.onPageSizeChange(size);
};
const shouldShowLimitedResultsWarning = useMemo(
() => !hasNextPage && props.rows.length < props.totalHitCount,
[hasNextPage, props.rows.length, props.totalHitCount]
);

const sampleSize = useMemo(() => {
return getServices().uiSettings.get(SAMPLE_SIZE_SETTING, 500);
Expand Down Expand Up @@ -77,7 +108,7 @@ export const DocTableEmbeddable = (props: DocTableEmbeddableProps) => {
responsive={false}
wrap={true}
>
{shouldShowLimitedResultsWarning() && (
{shouldShowLimitedResultsWarning && (
<EuiFlexItem grow={false}>
<EuiText grow={false} size="s" color="subdued">
<FormattedMessage
Expand All @@ -97,18 +128,20 @@ export const DocTableEmbeddable = (props: DocTableEmbeddableProps) => {
</EuiFlexItem>

<EuiFlexItem style={{ minHeight: 0 }}>
<DocTableWrapperMemoized {...props} render={renderDocTable} />
<DocTableWrapperMemoized ref={tableWrapperRef} {...props} render={renderDocTable} />
</EuiFlexItem>

<EuiFlexItem grow={false}>
<ToolBarPagination
pageSize={pager.pageSize}
pageCount={pager.totalPages}
activePage={pager.currentPage}
onPageClick={onPageChange}
onPageSizeChange={onPageSizeChange}
/>
</EuiFlexItem>
{showPagination && (
<EuiFlexItem grow={false}>
<ToolBarPagination
pageSize={pageSize}
pageCount={totalPages}
activePage={currentPage}
onPageClick={onPageChange}
onPageSizeChange={onPageSizeChange}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
);
};
Loading

0 comments on commit 7033024

Please sign in to comment.