Skip to content

Commit

Permalink
[APM] Fix loading message missing or inconsistent in various list vie…
Browse files Browse the repository at this point in the history
…ws (#110772) (#111322)

* [APM] Fix loading message missing or inconsistent in various list views

* fix types and i18n

* fix comment

* PR review comments

* fix JVM loading message

Co-authored-by: Miriam <[email protected]>
  • Loading branch information
kibanamachine and MiriamAparicio authored Sep 7, 2021
1 parent ac9c7c1 commit 10153b7
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '../../../../common/utils/formatters';
import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context';
import { useApmParams } from '../../../hooks/use_apm_params';
import { useFetcher } from '../../../hooks/use_fetcher';
import { useFetcher, FETCH_STATUS } from '../../../hooks/use_fetcher';
import { useTimeRange } from '../../../hooks/use_time_range';
import { truncate, unit } from '../../../utils/style';
import { ServiceNodeMetricOverviewLink } from '../../shared/Links/apm/ServiceNodeMetricOverviewLink';
Expand All @@ -42,7 +42,7 @@ function ServiceNodeOverview() {

const { serviceName } = useApmServiceContext();

const { data } = useFetcher(
const { data, status } = useFetcher(
(callApmApi) => {
if (!start || !end) {
return undefined;
Expand Down Expand Up @@ -164,6 +164,7 @@ function ServiceNodeOverview() {

return (
<ManagedTable
isLoading={status === FETCH_STATUS.LOADING}
noItemsMessage={i18n.translate('xpack.apm.jvmsTable.noJvmsLabel', {
defaultMessage: 'No JVMs were found',
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
<TableFetchWrapper status={status}>
<OverviewTableContainer
fixedHeight={true}
isEmptyAndLoading={
totalItems === 0 && status === FETCH_STATUS.LOADING
isEmptyAndNotInitiated={
totalItems === 0 && status === FETCH_STATUS.NOT_INITIATED
}
>
<EuiBasicTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export function ServiceOverviewInstancesChartAndTable({
serviceName={serviceName}
tableOptions={tableOptions}
isLoading={mainStatsStatus === FETCH_STATUS.LOADING}
isNotInitiated={mainStatsStatus === FETCH_STATUS.NOT_INITIATED}
onChangeTableOptions={(newTableOptions) => {
setTableOptions({
pageIndex: newTableOptions.page?.index ?? 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface Props {
}) => void;
detailedStatsData?: ServiceInstanceDetailedStatistics;
isLoading: boolean;
isNotInitiated: boolean;
}
export function ServiceOverviewInstancesTable({
mainStatsItems = [],
Expand All @@ -62,6 +63,7 @@ export function ServiceOverviewInstancesTable({
onChangeTableOptions,
detailedStatsData: detailedStatsData,
isLoading,
isNotInitiated,
}: Props) {
const { agentName } = useApmServiceContext();

Expand Down Expand Up @@ -151,13 +153,13 @@ export function ServiceOverviewInstancesTable({
<TableFetchWrapper status={status}>
<OverviewTableContainer
fixedHeight={true}
isEmptyAndLoading={mainStatsItemCount === 0 && isLoading}
isEmptyAndNotInitiated={mainStatsItemCount === 0 && isNotInitiated}
>
<EuiBasicTable
noItemsMessage={
isLoading
? i18n.translate('xpack.apm.serviceOverview.loadingText', {
defaultMessage: 'No instances found',
defaultMessage: 'Loading…',
})
: i18n.translate('xpack.apm.serviceOverview.noResultsText', {
defaultMessage: 'No instances found',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { truncate, unit } from '../../../utils/style';
import { EmptyMessage } from '../../shared/EmptyMessage';
import { ImpactBar } from '../../shared/ImpactBar';
import { TransactionDetailLink } from '../../shared/Links/apm/transaction_detail_link';
import { LoadingStatePrompt } from '../../shared/LoadingStatePrompt';
import { ITableColumn, ManagedTable } from '../../shared/managed_table';

type TraceGroup = APIReturnType<'GET /api/apm/traces'>['items'][0];
Expand Down Expand Up @@ -127,14 +126,14 @@ const noItemsMessage = (
);

export function TraceList({ items = [], isLoading }: Props) {
const noItems = isLoading ? <LoadingStatePrompt /> : noItemsMessage;
return (
<ManagedTable
isLoading={isLoading}
columns={traceListColumns}
items={items}
initialSortField="impact"
initialSortDirection="desc"
noItemsMessage={noItems}
noItemsMessage={noItemsMessage}
initialPageSize={25}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
* 2.0.
*/

import {
EuiBasicTableColumn,
EuiFlexGroup,
EuiFlexItem,
EuiInMemoryTable,
EuiTitle,
} from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { ConnectionStatsItemWithComparisonData } from '../../../../common/connections';
Expand All @@ -24,8 +18,10 @@ import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { unit } from '../../../utils/style';
import { SparkPlot } from '../charts/spark_plot';
import { ImpactBar } from '../ImpactBar';
import { TableFetchWrapper } from '../table_fetch_wrapper';
import { TruncateWithTooltip } from '../truncate_with_tooltip';
import { ITableColumn, ManagedTable } from '../managed_table';
import { EmptyMessage } from '../EmptyMessage';
import { TableFetchWrapper } from '../table_fetch_wrapper';
import { OverviewTableContainer } from '../overview_table_container';

export type DependenciesItem = Omit<
Expand Down Expand Up @@ -57,15 +53,7 @@ export function DependenciesTable(props: Props) {
compact = true,
} = props;

const pagination = compact
? {
initialPageSize: 5,
pageSizeOptions: [5],
hidePerPageOptions: true,
}
: {};

const columns: Array<EuiBasicTableColumn<DependenciesItem>> = [
const columns: Array<ITableColumn<DependenciesItem>> = [
{
field: 'name',
name: nameColumnTitle,
Expand Down Expand Up @@ -170,6 +158,18 @@ export function DependenciesTable(props: Props) {
impactValue: item.currentStats.impact,
})) ?? [];

const noItemsMessage = !compact ? (
<EmptyMessage
heading={i18n.translate('xpack.apm.dependenciesTable.notFoundLabel', {
defaultMessage: 'No dependencies found',
})}
/>
) : (
i18n.translate('xpack.apm.dependenciesTable.notFoundLabel', {
defaultMessage: 'No dependencies found',
})
);

return (
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
Expand All @@ -186,22 +186,19 @@ export function DependenciesTable(props: Props) {
<TableFetchWrapper status={status}>
<OverviewTableContainer
fixedHeight={fixedHeight}
isEmptyAndLoading={
items.length === 0 && status === FETCH_STATUS.LOADING
isEmptyAndNotInitiated={
items.length === 0 && status === FETCH_STATUS.NOT_INITIATED
}
>
<EuiInMemoryTable
<ManagedTable
isLoading={status === FETCH_STATUS.LOADING}
columns={columns}
items={items}
allowNeutralSort={false}
loading={status === FETCH_STATUS.LOADING}
pagination={pagination}
sorting={{
sort: {
direction: 'desc',
field: 'impactValue',
},
}}
noItemsMessage={noItemsMessage}
initialSortField="impactValue"
initialSortDirection="desc"
initialPageSize={5}
pagination={true}
/>
</OverviewTableContainer>
</TableFetchWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,18 @@ function UnoptimizedManagedTable<T>(props: Props<T>) {
};
}, [hidePerPageOptions, items, page, pageSize, pagination]);

const showNoItemsMessage = useMemo(() => {
return isLoading
? i18n.translate('xpack.apm.managedTable.loadingDescription', {
defaultMessage: 'Loading…',
})
: noItemsMessage;
}, [isLoading, noItemsMessage]);

return (
<EuiBasicTable
loading={isLoading}
noItemsMessage={
isLoading
? i18n.translate('xpack.apm.managedTable.loading', {
defaultMessage: 'Loading...',
})
: noItemsMessage
}
noItemsMessage={showNoItemsMessage}
items={renderedItems}
columns={(columns as unknown) as Array<EuiBasicTableColumn<T>>} // EuiBasicTableColumn is stricter than ITableColumn
sorting={sort}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const tableHeight = 282;
*
* Only do this when we're at a non-mobile breakpoint.
*
* Hide the empty message when we don't yet have any items and are still loading.
* Hide the empty message when we don't yet have any items and are still not initiated.
*/
const OverviewTableContainerDiv = euiStyled.div<{
fixedHeight?: boolean;
isEmptyAndLoading: boolean;
isEmptyAndNotInitiated: boolean;
shouldUseMobileLayout: boolean;
}>`
${({ fixedHeight, shouldUseMobileLayout }) =>
Expand All @@ -48,26 +48,26 @@ const OverviewTableContainerDiv = euiStyled.div<{
`}
.euiTableRowCell {
visibility: ${({ isEmptyAndLoading }) =>
isEmptyAndLoading ? 'hidden' : 'visible'};
visibility: ${({ isEmptyAndNotInitiated }) =>
isEmptyAndNotInitiated ? 'hidden' : 'visible'};
}
`;

export function OverviewTableContainer({
children,
fixedHeight,
isEmptyAndLoading,
isEmptyAndNotInitiated,
}: {
children?: ReactNode;
fixedHeight?: boolean;
isEmptyAndLoading: boolean;
isEmptyAndNotInitiated: boolean;
}) {
const { isMedium } = useBreakPoints();

return (
<OverviewTableContainerDiv
fixedHeight={fixedHeight}
isEmptyAndLoading={isEmptyAndLoading}
isEmptyAndNotInitiated={isEmptyAndNotInitiated}
shouldUseMobileLayout={isMedium}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export function TransactionsTable({
});

const isLoading = status === FETCH_STATUS.LOADING;
const isNotInitiated = status === FETCH_STATUS.NOT_INITIATED;

const pagination = {
pageIndex,
Expand Down Expand Up @@ -296,7 +297,9 @@ export function TransactionsTable({
<TableFetchWrapper status={status}>
<OverviewTableContainer
fixedHeight={fixedHeight}
isEmptyAndLoading={transactionGroupsTotalItems === 0 && isLoading}
isEmptyAndNotInitiated={
transactionGroupsTotalItems === 0 && isNotInitiated
}
>
<EuiBasicTable
noItemsMessage={
Expand Down

0 comments on commit 10153b7

Please sign in to comment.