kibana/examples
Kurt 323b0477e3
Changing where CodeEditor fields get useDarkMode value (#159638)
## Summary

Closes https://github.com/elastic/kibana/issues/157203
Closes https://github.com/elastic/kibana/issues/158051
Closes https://github.com/elastic/kibana/issues/158049

With the addition of Per User Dark Mode, components can no longer rely
on `uiSettings` as the source of truth for theme.

CodeEditor fields used to call `uiSettings` to determine if Dark Mode
was enabled, which had been provided in each callers Kibana React
Context.

The new source of truth for theme is the `CoreStart >
ThemeServiceStart`.

Currently, not all callers of CodeEditor provide the `theme` service in
their Kibana Context in a similar way and some callers don't provide it
at all.

This PR updates CodeEditor to get theme values from the Kibana Context
using a new `useKibanaTheme` react hook.

It also attempts audit the callers of CodeEditor to see if their Kibana
Context contains the theme service at the top level (Where I could add
theme to a caller's Context without major changes, I did. Some cases
will require CodeOwner guidance).

The new `useKibanaTheme` react hook will throw a TypeError if theme
isn't found in the top level of the Kibana Context, this will help with
testing as the component will not render. I will remove this after
testing so as not to introduce breaking changes.

## Testing

Please review files for which you are CODEOWNER.

I've attempted to tag all usages of `CodeEditor`/`CodeEditorFIeld` with
a TODO comment with one of the following scenarios:

1) a note where theme was provided already/where I made changes to
provide it in the appropriate context
2) I've asked for CODEOWNER guidance

For scenario 1, please pull and test that CodeEditor locally:

1. Enable Dark Mode from Edit User Profiles by clicking on the Profile
Icon on the top right, and updating your profile.
2. Navigate to the CodeEditors in the plugins you own. If they render
and display in Dark Mode - add a green check to the table below - and
you're done!
3. If it is not rendering, please help me figure out where the theme
service should be provided in the context.

For scenario 2, we will need to figure out where to make changes so your
context is providing theme. Some of the more complex usages may need to
addressed in separate issues.


## Tracking
| Team | Plugin | Theme in Context ? | Verified Working |
| - | - | - | - |
| apm-ui | apm | APM Storybook broken | ? |
| kibana-presentation | presentation_util | Yes. | Yes |
| response-ops | trigger_actions_ui | Yes | Yes |
| response-ops | stack_alerts | Yes | Yes |
| kibana-security | security  | Yes | Yes |
| security-defend-workflows | osquery | Yes | Yes |
| kibana-app-services | examples/expression_explorer | Yes | Yes |
| ml-ui | transform | Yes | Yes |
| ml-ui | ml | Yes | Yes |
| uptime | synthetics | Yes | Yes |
| kibana-gis | maps | Yes | Yes |
| kibana-gis | file_upload | Yes | Yes |
| platform-deployment-management | watcher | Yes | [AG] Yes |
| platform-deployment-management | snapshot_restore | Yes | [AG] Yes |
| platform-deployment-management | runtime_fields | Yes | [AG] Yes |
| platform-deployment-management | painless_lab | Yes | [AG] Yes |
| platform-deployment-management | ingest_pipelines | Yes | [AG] Yes |
| platform-deployment-management | index_management | Yes | [AG] Yes |
| platform-deployment-management | grokdebugger | Yes | [AG] Yes |
| platform-deployment-management | es_ui_shared | Yes | [AG] Yes |
| fleet | fleet | Yes | Yes |
| enterprise-search-frontend | enterprise_search | Yes | [AG] Yes |
| kibana-cloud-security-posture | cloud-security-posture | Yes | yes |
| sec-cloudnative-integrations | cloud_defend | Yes | Yes |
| kibana-visualizations/kibana-data-discovery | data | Yes | Yes |
| kibana-visualizations | examples/testing_embedded_lens | Yes | Yes |
| kibana-visualizations | vis_types | Yes | Yes |
| kibana-visualizations | vis_default_editor | Yes | Yes |
| kibana-visualizations | unified_search | Yes | Yes |
| kibana-visualizations | packages/kbn-text-based-editor | Yes | Yes |
| kibana-visualizatons | lens | Yes | Yes|
| kibana-core | saved_objects_management | Yes | Yes |
| kibana-presentation | inspector | Yes | Yes |
| kibana-presentation | canvas | Yes | Yes |
| kibana-data-discovery | discover | Yes | Yes |
| kibana-data-discovery | data_view_management | Yes | Yes |
| kibana-data-discovery | data_view_field_editor | Yes | Yes |
| appex-sharedux | advanced_settings | Yes | Yes |
| enterprise-search-frontend | serverless_search | Yes | [AG] Yes |
| - | - | - | - |

## Unit tests

Currently, many tests are failing since they are probably not providing
`theme` in the context. Once CODEOWNERs have weighed in on CodeEditors
usages that require discussion, I will update the accompanying tests.

## Release note
- Fixes theming of CodeEditors

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
Co-authored-by: Dima Arnautov <dmitrii.arnautov@elastic.co>
Co-authored-by: Dima Arnautov <arnautov.dima@gmail.com>
2023-07-11 14:02:42 -04:00
..
bfetch_explorer [shared-ux-router] Add Router and Routes components (#159834) 2023-06-23 10:02:06 -05:00
content_management_examples [TableListView] Fix dark mode for content editor (#161570) 2023-07-11 03:37:15 -07:00
controls_example [Tech Debt] Remove deprecated EuiLoadingContent (#156316) 2023-05-03 08:01:37 -06:00
data_view_field_editor_example [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
developer_examples [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
discover_customization_examples [Discover] Implement Discover customization framework (#158603) 2023-06-14 15:09:13 -03:00
embeddable_examples [Portable Dashboards] Add portable dashboard example plugin (#148997) 2023-02-10 13:21:53 -07:00
embeddable_explorer [Presentation] Migrate all usages of EuiPage*_Deprecated (#161496) 2023-07-10 12:28:30 -06:00
expressions_explorer Changing where CodeEditor fields get useDarkMode value (#159638) 2023-07-11 14:02:42 -04:00
field_formats_example [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
files_example Upgraded EUI to v76.0.0 (#152506) 2023-03-14 14:27:40 -05:00
guided_onboarding_example [Guided onboarding] Migrate all usages of EuiPage*_Deprecated (#161457) 2023-07-10 16:00:27 +01:00
hello_world [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
locator_examples [shared-ux-router] Add Router and Routes components (#159834) 2023-06-23 10:02:06 -05:00
locator_explorer [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
partial_results_example [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
portable_dashboards_example [shared-ux-router] Add Router and Routes components (#159834) 2023-06-23 10:02:06 -05:00
preboot_example [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
response_stream [shared-ux-router] Add Router and Routes components (#159834) 2023-06-23 10:02:06 -05:00
routing_example Upgraded EUI to v76.0.0 (#152506) 2023-03-14 14:27:40 -05:00
screenshot_mode_example [shared-ux-router] Add Router and Routes components (#159834) 2023-06-23 10:02:06 -05:00
search_examples [shared-ux-router] Add Router and Routes components (#159834) 2023-06-23 10:02:06 -05:00
share_examples [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
state_containers_examples [shared-ux-router] Add Router and Routes components (#159834) 2023-06-23 10:02:06 -05:00
ui_action_examples [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
ui_actions_explorer [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
unified_field_list_examples [Lens] Refactor drag and drop (#161257) 2023-07-11 13:05:03 +02:00
user_profile_examples [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
v8_profiler_examples [examples] add routes to access v8 profiling (#155956) 2023-06-30 08:42:38 -04:00
README.asciidoc Add a few asciidoc readmes (#72082) 2020-07-17 11:08:57 -04:00

[[example-plugins]]
== Example plugins

This folder contains example plugins.  To run the plugins in this folder, use the `--run-examples` flag, via

[source,bash]
----
yarn start --run-examples
----