Skip to content

Commit

Permalink
apm migration to emotion
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamAparicio committed Dec 16, 2024
1 parent 4d26785 commit 145d376
Show file tree
Hide file tree
Showing 38 changed files with 250 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import { EuiButtonIcon, EuiToolTip, useEuiTheme } from '@elastic/eui';
import React, { useCallback, useMemo, useState } from 'react';
import { i18n } from '@kbn/i18n';
import {
Expand Down Expand Up @@ -40,7 +40,6 @@ import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plug
import { useFetchParams } from '../use_fetch_params';
import type { ApmPluginStartDeps } from '../../../../plugin';
import { useAdHocApmDataView } from '../../../../hooks/use_adhoc_apm_data_view';
import { useTheme } from '../../../../hooks/use_theme';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';

const HIGHLIGHTED_BUCKET_PROPS = {
Expand Down Expand Up @@ -205,7 +204,7 @@ export function FieldStatsPopover({
const field = dataView?.getFieldByName(fieldName);

const closePopover = useCallback(() => setInfoOpen(false), []);
const theme = useTheme();
const { euiTheme } = useEuiTheme();

const params = useFetchParams();

Expand Down Expand Up @@ -280,7 +279,7 @@ export function FieldStatsPopover({
}
)}
data-test-subj={'apmCorrelationsContextPopoverButton'}
style={{ marginLeft: theme.eui.euiSizeXS }}
style={{ marginLeft: euiTheme.size.xs }}
/>
</EuiToolTip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import React, { useCallback, useMemo, useState } from 'react';
import { debounce } from 'lodash';
import { EuiBasicTable, EuiBasicTableColumn } from '@elastic/eui';
import { EuiBasicTable, EuiBasicTableColumn, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type { EuiTableSortingType } from '@elastic/eui/src/components/basic_table/table_types';
import type { Criteria } from '@elastic/eui/src/components/basic_table/basic_table';
import { useUiTracker } from '@kbn/observability-shared-plugin/public';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { useTheme } from '../../../hooks/use_theme';
import type { FieldValuePair } from '../../../../common/correlations/types';

const PAGINATION_SIZE_OPTIONS = [5, 10, 20, 50];
Expand Down Expand Up @@ -43,7 +42,7 @@ export function CorrelationsTable<T extends FieldValuePair>({
sorting,
rowHeader,
}: CorrelationsTableProps<T>) {
const euiTheme = useTheme();
const { euiTheme } = useEuiTheme();
const trackApmEvent = useUiTracker({ app: 'apm' });
const trackSelectSignificantCorrelationTerm = useCallback(
() => debounce(() => trackApmEvent({ metric: 'select_significant_term' }), 1000),
Expand Down Expand Up @@ -105,7 +104,7 @@ export function CorrelationsTable<T extends FieldValuePair>({
selectedTerm.fieldValue === term.fieldValue &&
selectedTerm.fieldName === term.fieldName
? {
backgroundColor: euiTheme.eui.euiColorLightestShade,
backgroundColor: euiTheme.colors.lightestShade,
}
: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
* 2.0.
*/

import { EuiButtonEmpty, EuiEmptyPrompt, EuiImage, EuiLink, EuiLoadingSpinner } from '@elastic/eui';
import {
EuiButtonEmpty,
EuiEmptyPrompt,
EuiImage,
EuiLink,
EuiLoadingSpinner,
useEuiTheme,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
Expand All @@ -18,7 +25,6 @@ import { useApmParams } from '../../../../hooks/use_apm_params';
import { useApmRouter } from '../../../../hooks/use_apm_router';
import { useEntityCentricExperienceSetting } from '../../../../hooks/use_entity_centric_experience_setting';
import { FETCH_STATUS, isPending, useFetcher } from '../../../../hooks/use_fetcher';
import { useTheme } from '../../../../hooks/use_theme';
import { ApmPluginStartDeps } from '../../../../plugin';

const pageHeader = {
Expand All @@ -27,7 +33,7 @@ const pageHeader = {

export function EntityLink() {
const router = useApmRouter({ prependBasePath: false });
const theme = useTheme();
const { colorMode } = useEuiTheme();
const { services } = useKibana<ApmPluginStartDeps>();
const { observabilityShared, data } = services;
const timeRange = data.query.timefilter.timefilter.getTime();
Expand Down Expand Up @@ -65,7 +71,7 @@ export function EntityLink() {
icon={
<EuiImage
size="fullWidth"
src={theme.darkMode ? dashboardsDark : dashboardsLight}
src={colorMode === 'DARK' ? dashboardsDark : dashboardsLight}
alt=""
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ import {
DARK_THEME,
LegendValue,
} from '@elastic/charts';
import { EuiTitle } from '@elastic/eui';
import { EuiTitle, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
import { useLegacyUrlParams } from '../../../../context/url_params_context/use_url_params';
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
import { usePreviousPeriodLabel } from '../../../../hooks/use_previous_period_text';
import { useTheme } from '../../../../hooks/use_theme';
import { APIReturnType } from '../../../../services/rest/create_call_apm_api';
import { ChartContainer } from '../../../shared/charts/chart_container';
import { ChartType, getTimeSeriesColor } from '../../../shared/charts/helper/get_timeseries_color';
Expand All @@ -42,7 +41,7 @@ interface Props {

export function ErrorDistribution({ distribution, title, fetchStatus }: Props) {
const { core } = useApmPluginContext();
const theme = useTheme();
const { colorMode } = useEuiTheme();

const { urlParams } = useLegacyUrlParams();
const { comparisonEnabled } = urlParams;
Expand Down Expand Up @@ -97,7 +96,7 @@ export function ErrorDistribution({ distribution, title, fetchStatus }: Props) {
showLegend
legendValues={[LegendValue.CurrentAndLastValue]}
legendPosition={Position.Bottom}
theme={theme.darkMode ? DARK_THEME : LIGHT_THEME}
theme={colorMode === 'DARK' ? DARK_THEME : LIGHT_THEME}
locale={i18n.getLocale()}
/>
<Axis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
EuiDescriptionListTitle,
EuiEmptyPrompt,
EuiImage,
useEuiTheme,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import noResultsIllustrationDark from '../../../../assets/no_results_dark.svg';
import noResultsIllustrationLight from '../../../../assets/no_results_light.svg';
import { useTheme } from '../../../../hooks/use_theme';

export function EmptyPrompt() {
return (
Expand Down Expand Up @@ -52,9 +52,10 @@ export function EmptyPrompt() {
}

function NoResultsIllustration() {
const theme = useTheme();
const { colorMode } = useEuiTheme();

const illustration = theme.darkMode ? noResultsIllustrationDark : noResultsIllustrationLight;
const illustration =
colorMode === 'DARK' ? noResultsIllustrationDark : noResultsIllustrationLight;

return (
<EuiImage alt={noResultsIllustrationAlternativeText} size="fullWidth" src={illustration} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/
import { MetricDatum, MetricTrendShape } from '@elastic/charts';
import { i18n } from '@kbn/i18n';
import { EuiIcon, EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner } from '@elastic/eui';
import { EuiIcon, EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner, useEuiTheme } from '@elastic/eui';
import React, { useCallback } from 'react';
import { useTheme } from '@kbn/observability-shared-plugin/public';
import { useFetcher, isPending, FETCH_STATUS } from '../../../../../hooks/use_fetcher';
import { CLIENT_GEO_COUNTRY_NAME } from '../../../../../../common/es_fields/apm';
import { NOT_AVAILABLE_LABEL } from '../../../../../../common/i18n';
Expand Down Expand Up @@ -45,7 +44,7 @@ export function MobileLocationStats({
environment: string;
comparisonEnabled: boolean;
}) {
const euiTheme = useTheme();
const { euiTheme } = useEuiTheme();

const previousPeriodLabel = usePreviousPeriodLabel();

Expand Down Expand Up @@ -107,7 +106,7 @@ export function MobileLocationStats({

const metrics: MetricDatum[] = [
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.location.metrics.http.requests.title', {
defaultMessage: 'Most used in',
}),
Expand All @@ -121,7 +120,7 @@ export function MobileLocationStats({
trendShape: MetricTrendShape.Area,
},
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.location.metrics.mostCrashes', {
defaultMessage: 'Most crashes',
}),
Expand All @@ -135,7 +134,7 @@ export function MobileLocationStats({
trendShape: MetricTrendShape.Area,
},
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.location.metrics.sessions', {
defaultMessage: 'Most sessions',
}),
Expand All @@ -149,7 +148,7 @@ export function MobileLocationStats({
trendShape: MetricTrendShape.Area,
},
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.location.metrics.launches', {
defaultMessage: 'Most launches',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/
import { MetricDatum, MetricTrendShape } from '@elastic/charts';
import { i18n } from '@kbn/i18n';
import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiLoadingSpinner } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiLoadingSpinner, useEuiTheme } from '@elastic/eui';
import React, { useCallback } from 'react';
import { useTheme } from '@kbn/observability-shared-plugin/public';
import { NOT_AVAILABLE_LABEL } from '../../../../../../common/i18n';
import { useAnyOfApmParams } from '../../../../../hooks/use_apm_params';
import { FETCH_STATUS, isPending, useFetcher } from '../../../../../hooks/use_fetcher';
Expand All @@ -20,7 +19,7 @@ const valueFormatter = (value: number, suffix = '') => {
};

export function MobileStats({ start, end, kuery }: { start: string; end: string; kuery: string }) {
const euiTheme = useTheme();
const { euiTheme } = useEuiTheme();

const {
path: { serviceName },
Expand Down Expand Up @@ -77,7 +76,7 @@ export function MobileStats({ start, end, kuery }: { start: string; end: string;

const metrics: MetricDatum[] = [
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.metrics.crash.rate', {
defaultMessage: 'Crash rate',
}),
Expand All @@ -92,7 +91,7 @@ export function MobileStats({ start, end, kuery }: { start: string; end: string;
trendShape: MetricTrendShape.Area,
},
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.metrics.load.time', {
defaultMessage: 'Average app load time',
}),
Expand All @@ -105,7 +104,7 @@ export function MobileStats({ start, end, kuery }: { start: string; end: string;
trendShape: MetricTrendShape.Area,
},
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.metrics.sessions', {
defaultMessage: 'Sessions',
}),
Expand All @@ -118,7 +117,7 @@ export function MobileStats({ start, end, kuery }: { start: string; end: string;
trendShape: MetricTrendShape.Area,
},
{
color: euiTheme.eui.euiColorLightestShade,
color: euiTheme.colors.lightestShade,
title: i18n.translate('xpack.apm.mobile.metrics.http.requests', {
defaultMessage: 'HTTP requests',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
* 2.0.
*/
import React from 'react';
import { EuiEmptyPrompt, EuiImage } from '@elastic/eui';
import { EuiEmptyPrompt, EuiImage, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { dashboardsDark, dashboardsLight } from '@kbn/shared-svg';
import { useTheme } from '../../../hooks/use_theme';

interface Props {
actions: React.ReactNode;
}

export function EmptyDashboards({ actions }: Props) {
const theme = useTheme();
const { colorMode } = useEuiTheme();

return (
<>
Expand All @@ -25,7 +24,7 @@ export function EmptyDashboards({ actions }: Props) {
icon={
<EuiImage
size="fullWidth"
src={theme.darkMode ? dashboardsDark : dashboardsLight}
src={colorMode === 'DARK' ? dashboardsDark : dashboardsLight}
alt=""
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
*/

import React from 'react';
import { EuiBadge } from '@elastic/eui';
import { EuiBadge, useEuiTheme } from '@elastic/eui';
import {
getServiceHealthStatusBadgeColor,
getServiceHealthStatusLabel,
ServiceHealthStatus,
} from '../../../../../common/service_health_status';
import { useTheme } from '../../../../hooks/use_theme';

export function HealthBadge({ healthStatus }: { healthStatus: ServiceHealthStatus }) {
const theme = useTheme();
const { euiTheme } = useEuiTheme();

return (
<EuiBadge color={getServiceHealthStatusBadgeColor(theme, healthStatus)}>
<EuiBadge color={getServiceHealthStatusBadgeColor(euiTheme, healthStatus)}>
{getServiceHealthStatusLabel(healthStatus)}
</EuiBadge>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
* 2.0.
*/

import { EuiButtonIcon, EuiPanel, EuiToolTip } from '@elastic/eui';
import { EuiButtonIcon, EuiPanel, EuiToolTip, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useContext, useEffect, useState } from 'react';
import styled from '@emotion/styled';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { useTheme } from '../../../hooks/use_theme';
import { getLegacyApmHref } from '../../shared/links/apm/apm_link';
import { useLegacyUrlParams } from '../../../context/url_params_context/use_url_params';
import { APMQueryParams } from '../../shared/links/url_helpers';
Expand Down Expand Up @@ -97,7 +96,7 @@ function useDebugDownloadUrl(cy?: cytoscape.Core) {
export function Controls() {
const { core } = useApmPluginContext();
const { basePath } = core.http;
const theme = useTheme();
const { euiTheme } = useEuiTheme();
const cy = useContext(CytoscapeContext);
const { urlParams } = useLegacyUrlParams();

Expand All @@ -110,7 +109,8 @@ export function Controls() {
);

const [zoom, setZoom] = useState((cy && cy.zoom()) || 1);
const duration = parseInt(theme.eui.euiAnimSpeedFast, 10);
// @ts-expect-error
const duration = parseInt(euiTheme.animation.fast, 10);
const downloadUrl = useDebugDownloadUrl(cy);
const viewFullMapUrl = getLegacyApmHref({
basePath,
Expand Down Expand Up @@ -140,9 +140,9 @@ export function Controls() {
if (cy) {
const eles = cy.nodes();
cy.animate({
...getAnimationOptions(theme),
...getAnimationOptions(euiTheme),
center: { eles },
fit: { eles, padding: getNodeHeight(theme) },
fit: { eles, padding: getNodeHeight(euiTheme) },
});
}
}
Expand Down
Loading

0 comments on commit 145d376

Please sign in to comment.