From 8dbb57541190b4710c0ad270eda1a590994a7384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Bl=C3=A1zquez?= Date: Mon, 2 Dec 2024 14:16:23 +0100 Subject: [PATCH] Replace inline styles with `css` prop in `src/` folder (#201563) ## Summary Part of the resolution of this issue: - https://github.com/elastic/kibana/issues/149246 Removes the `style` prop in React components and elements to avoid using inline styles. Instead, it uses now the `emotion.css` prop to dynamically attach all styles to the native `class` attribute. ### Motivation Using inline styles at scale causes a performance penalty at rendering time. It's way more efficient to attach styles to a single or several classnames instead. ### How to review From [Emotion's official docs](https://emotion.sh/docs/css-prop#style-precedence): > [!NOTE] > Any component or element that accepts a `className` prop can also use the `css` prop. The styles supplied to the `css` prop are evaluated and the computed class name is applied to the `className` prop. Components that are safe to migrate from `style` to `css`: - React elements - React components exposed by EUI (they all support a `className` prop and the [Babel plugin](https://www.npmjs.com/package/@emotion/babel-preset-css-prop) is enabled throughout Kibana) Components where styling might break: - Custom component we wrote that currently don't accept a `className` prop. - Specific 3P components that pass in a `style` prop to our components i.e. `react-window` (it calculates the dynamic position of all virtualized elements and hides the ones outside the visible fold) - Specific 3P components that expect a `style` prop to be styled i.e. charts, etc. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Main risk is breaking the UI by not applying or incorrectly applying the styling. This was explained in the "How to review" section above. The risk has **low severity** though. The mitigation plan will simply be reverting the commit asap not to affect production and test locally until it's fixed./ --- .../with_auto_scale.test.tsx.snap | 1 - .../public/components/metric_value.tsx | 2 +- .../public/components/metric_vis.tsx | 2 +- .../public/utils/get_legend_actions.tsx | 2 +- .../components/legend_action_popover.tsx | 2 +- .../public/helpers/annotations.tsx | 6 ++-- .../public/static/components/warnings.tsx | 2 +- .../application/components/help_popover.tsx | 2 +- .../application/containers/editor/editor.tsx | 8 ++--- .../containers/history/history.tsx | 2 +- .../components/options_list_popover.tsx | 2 +- .../options_list_popover_footer.tsx | 2 +- .../search_session_name.tsx | 2 +- .../advanced_params_section.tsx | 2 +- .../components/form_fields/type_field.tsx | 4 +-- .../advanced_parameters_section.tsx | 2 +- .../__snapshots__/format_editor.test.tsx.snap | 4 +-- .../__snapshots__/static_lookup.test.tsx.snap | 20 ++++++------- .../editors/static_lookup/static_lookup.tsx | 2 +- .../field_format_editor/format_editor.tsx | 2 +- .../components/preview/field_preview.tsx | 2 +- .../preview/field_preview_empty_prompt.tsx | 2 +- .../public/components/add_data_prompt.tsx | 2 +- .../header/__snapshots__/header.test.tsx.snap | 2 +- .../components/header/header.tsx | 2 +- .../field_format_editor.test.tsx.snap | 4 +-- .../field_format_editor.tsx | 2 +- .../index_pattern_table.tsx | 2 +- src/plugins/dev_tools/public/application.tsx | 2 +- .../esql_dataview_transition_modal.tsx | 2 +- .../total_documents/total_documents.tsx | 2 +- .../__snapshots__/table_header.test.tsx.snap | 4 +-- .../components/table_header/table_header.tsx | 2 +- .../saved_search_embeddable_base.tsx | 2 +- .../forms/docs/examples/dynamic_fields.mdx | 10 +++---- .../docs/examples/fields_composition.mdx | 4 +-- .../examples/serializers_deserializers.mdx | 2 +- .../__stories__/use_array_complex.tsx | 28 ++++++++--------- .../__stories__/use_array_dynamic_data.tsx | 28 ++++++++--------- .../__stories__/use_array_reorder.tsx | 4 +-- .../__stories__/use_field_field_types.tsx | 6 ++-- .../esql_datagrid/public/create_datagrid.tsx | 2 +- .../public/components/error/error.tsx | 4 +-- .../components/error/show_debugging.tsx | 2 +- .../components/repeat_image_component.tsx | 2 +- .../react_expression_renderer.tsx | 2 +- .../components/guide_button_popover.tsx | 2 +- .../components/recently_accessed.js | 2 +- .../instruction_set.test.js.snap | 12 ++++---- .../components/tutorial/instruction_set.js | 2 +- .../image_editor/image_editor_flyout.tsx | 2 +- .../components/image_viewer/image_viewer.tsx | 2 +- .../input_control_vis.test.tsx.snap | 24 +++++++-------- .../components/vis/input_control_vis.tsx | 6 +--- .../__snapshots__/cluster_view.test.tsx.snap | 30 +++++++++---------- .../clusters_table/cluster_view.tsx | 2 +- .../public/cluster_configuration_form.tsx | 2 +- .../public/enrollment_token_form.tsx | 2 +- .../public/single_chars_field.tsx | 6 ++-- .../action_cards/action_cards.tsx | 2 +- .../elastic_agent_card.test.tsx.snap | 20 ++++++------- .../no_data_card/elastic_agent_card.tsx | 2 +- .../presentation_panel_hover_actions.tsx | 2 +- .../use_presentation_panel_header_actions.tsx | 2 +- .../components/labs/environment_switch.tsx | 6 ++-- .../components/labs/labs_beaker_button.tsx | 2 +- .../objects_table/components/flyout.tsx | 2 +- .../action_wizard/action_wizard.tsx | 2 +- .../components/action_wizard/test_data.tsx | 2 +- .../drilldown_table/drilldown_table.tsx | 2 +- .../drilldown_template_table.tsx | 4 +-- .../components/flyout_frame/flyout_frame.tsx | 2 +- .../text_with_icon/text_with_icon.tsx | 2 +- .../trigger_picker/trigger_picker.tsx | 2 +- .../url_drilldown_collect_config.tsx | 2 +- .../components/variable_popover/index.tsx | 2 +- .../components/doc_viewer_table/table.tsx | 2 +- .../filter_editor/filter_editor.tsx | 2 +- .../filter_bar/filter_item/filter_item.tsx | 2 +- .../query_string_input/add_filter_popover.tsx | 8 ++++- .../filter_editor_wrapper.tsx | 2 +- .../query_string_input/no_data_popover.tsx | 2 +- .../query_string_input/query_bar_top_row.tsx | 4 +-- .../query_string_input/query_string_input.tsx | 2 +- .../components/sidebar/sidebar_title.tsx | 2 +- .../public/default_editor_controller.tsx | 2 +- .../application/components/aggs/agg_row.tsx | 2 +- .../components/aggs/percentile_ui.js | 2 +- .../switch_mode_popover.tsx | 7 ++--- ...isualization_missed_saved_object_error.tsx | 2 +- .../embeddable/visualize_embeddable.tsx | 4 +-- 91 files changed, 196 insertions(+), 198 deletions(-) diff --git a/src/plugins/chart_expressions/expression_legacy_metric/public/components/__snapshots__/with_auto_scale.test.tsx.snap b/src/plugins/chart_expressions/expression_legacy_metric/public/components/__snapshots__/with_auto_scale.test.tsx.snap index 37b8587d6b6af..4acbab635ba47 100644 --- a/src/plugins/chart_expressions/expression_legacy_metric/public/components/__snapshots__/with_auto_scale.test.tsx.snap +++ b/src/plugins/chart_expressions/expression_legacy_metric/public/components/__snapshots__/with_auto_scale.test.tsx.snap @@ -29,4 +29,3 @@ exports[`AutoScale withAutoScale renders 1`] = ` `; - diff --git a/src/plugins/chart_expressions/expression_legacy_metric/public/components/metric_value.tsx b/src/plugins/chart_expressions/expression_legacy_metric/public/components/metric_value.tsx index e338d1779a10b..8199a2ec1f842 100644 --- a/src/plugins/chart_expressions/expression_legacy_metric/public/components/metric_value.tsx +++ b/src/plugins/chart_expressions/expression_legacy_metric/public/components/metric_value.tsx @@ -74,7 +74,7 @@ export const MetricVisValue = (props: MetricVisValueProps) => { if (onFilter) { return (