Skip to content

Commit

Permalink
Removes duplicated RedirectAppLinks component (#170304)
Browse files Browse the repository at this point in the history
## Summary

This PR removes the [duplicated RedirectAppLinks
component](https://github.com/elastic/kibana/blob/v8.10.4/src/plugins/kibana_react/public/app_links/redirect_app_link.tsx)
which has been marked as deprecated since
74a00fa.

All references to the previous import declaration from
`@kbn/kibana-react-plugin/public` have been replaced with
`@kbn/shared-ux-link-redirect-app`, this change ensures that the current
app behaviour is preserved, and changes to match the expectation of the
new component have been applied where necessary.

Changes relating to the new `RedirectAppLinks` component; 
- The component does not accept a `className` anymore as it is not a
presentational component despite it being used as one previously,
there's change to make accommodation for how it had been used.
- The component introduces a`data-test-subj` attribute with the value
`kbnRedirectAppLink` on the dom node that wraps it's children.


### Checklist

<!--
Delete any items that are not applicable to this PR.

~- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~
-->
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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

<!--
~- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard
accessibility](https://webaim.org/techniques/keyboard/))~
~- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~
~- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~
~- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~
~- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)~


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
-->

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
eokoneyo and kibanamachine authored Nov 13, 2023
1 parent 84e0da6 commit f27427b
Show file tree
Hide file tree
Showing 83 changed files with 661 additions and 1,094 deletions.
6 changes: 3 additions & 3 deletions dev_docs/key_concepts/navigation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: kibDevKeyConceptsNavigation
slug: /kibana-dev-docs/routing-and-navigation
title: Routing, Navigation and URL
description: Learn best practices about navigation inside Kibana
date: 2021-10-05
date: 2023-11-07
tags: ['kibana', 'dev', 'architecture', 'contributor']
---

Expand Down Expand Up @@ -116,11 +116,11 @@ const MySPALink = () =>
```

As it would be too much boilerplate to do this for each link in your app, there is a handy wrapper that helps with it:
[RedirectAppLinks](https://github.com/elastic/kibana/blob/main/src/plugins/kibana_react/public/app_links/redirect_app_link.tsx#L49).
[RedirectAppLinks](https://github.com/elastic/kibana/blob/main/packages/shared-ux/link/redirect_app/impl/src/redirect_app_links.tsx).

```jsx
const MyApp = () =>
<RedirectAppLinks application={core.application}>
<RedirectAppLinks coreStart={{application: core.application}}>
{/*...*/}
{/* navigations using this link will happen in SPA friendly way */}
<a href={urlToADashboard}>Go to Dashboard</a>
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/best-practices/navigation.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ const MySPALink = () =>
----

As it would be too much boilerplate to do this for each {kib} link in your app, there is a handy wrapper that helps with it:
{kib-repo}tree/{branch}/src/plugins/kibana_react/public/app_links/redirect_app_link.tsx#L49[RedirectAppLinks].
{kib-repo}tree/{branch}/packages/shared-ux/link/redirect_app/impl/src/redirect_app_links.tsx[RedirectAppLinks].

[source,typescript jsx]
----
const MyApp = () =>
<RedirectAppLinks application={core.application}>
<RedirectAppLinks coreStart={{application: core.application}}>
{/*...*/}
{/* navigations using this link will happen in SPA friendly way */}
<a href={urlToADashboard}>Go to Dashboard</a>
Expand Down
8 changes: 6 additions & 2 deletions examples/search_examples/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Redirect } from 'react-router-dom';
import { Router, Routes, Route } from '@kbn/shared-ux-router';
import { I18nProvider } from '@kbn/i18n-react';
import { AppMountParameters, CoreStart } from '@kbn/core/public';
import { RedirectAppLinks } from '@kbn/kibana-react-plugin/public';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { AppPluginStartDependencies } from './types';
import { SearchExamplePage, ExampleLink } from './common/example_page';
import { SearchExamplesApp } from './search/app';
Expand Down Expand Up @@ -45,7 +45,11 @@ export const renderApp = (
) => {
ReactDOM.render(
<I18nProvider>
<RedirectAppLinks application={application}>
<RedirectAppLinks
coreStart={{
application,
}}
>
<SearchExamplePage exampleLinks={LINKS} basePath={http.basePath}>
<Router history={history}>
<Routes>
Expand Down
1 change: 1 addition & 0 deletions examples/search_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"@kbn/config-schema",
"@kbn/shared-ux-router",
"@kbn/search-response-warnings",
"@kbn/shared-ux-link-redirect-app",
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export const RedirectAppLinks: FC<RedirectAppLinksComponentProps> = ({

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<div onClick={handleClick} ref={containerRef} css={redirectAppLinksStyles}>
<div
onClick={handleClick}
ref={containerRef}
css={redirectAppLinksStyles}
data-test-subj="kbnRedirectAppLink"
>
{children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,43 @@ const mock = new RedirectAppLinksStorybookMock();

export const RedirectAppLinks = () => {
return (
<>
<Component {...mock.getProps()}>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="storybookButton"
iconType="plusInCircle"
href="/some-test-url"
>
Button with URL
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="storybookButton"
iconType="plusInCircle"
onClick={action('onClick')}
>
Button without URL
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</Component>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiFlexGroup direction="column">
<EuiFlexItem>
<Component {...mock.getProps()}>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="storybookButton"
iconType="plusInCircle"
href="/some-test-url"
>
Button with URL
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="storybookButton"
iconType="plusInCircle"
onClick={action('onClick')}
>
Button without URL
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</Component>
</EuiFlexItem>
<EuiFlexItem>
<div>
<EuiButton
data-test-subj="storybookButton"
iconType="plusInCircle"
href="/?path=/story/redirect-app-links--component"
>
Button outside RedirectAppLinks
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</>
</div>
</EuiFlexItem>
</EuiFlexGroup>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import { css } from '@emotion/react';

export const redirectAppLinksStyles = css({
display: 'flex',
display: 'inherit',
flex: '1',
flexFlow: 'column nowrap',
height: '100%',
width: '100%',
});
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ test("shouldn't show indicator in case no active search session", async () => {
expect(container).toMatchInlineSnapshot(`
<div>
<div
class="kbnRedirectCrossAppLinks"
css="You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop)."
data-test-subj="kbnRedirectAppLink"
/>
</div>
`);
Expand Down Expand Up @@ -109,7 +110,8 @@ test("shouldn't show indicator in case app hasn't opt-in", async () => {
expect(container).toMatchInlineSnapshot(`
<div>
<div
class="kbnRedirectCrossAppLinks"
css="You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop)."
data-test-subj="kbnRedirectAppLink"
/>
</div>
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { debounce } from 'rxjs/operators';
import { timer } from 'rxjs';
import useObservable from 'react-use/lib/useObservable';
import { i18n } from '@kbn/i18n';
import { RedirectAppLinks } from '@kbn/kibana-react-plugin/public';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { ApplicationStart, IBasePath } from '@kbn/core/public';
import { SearchSessionIndicator, SearchSessionIndicatorRef } from '../search_session_indicator';
Expand Down Expand Up @@ -150,7 +150,11 @@ export const createConnectedSearchSessionIndicator = ({

if (!sessionService.isSessionStorageReady()) return null;
return (
<RedirectAppLinks application={application}>
<RedirectAppLinks
coreStart={{
application,
}}
>
<SearchSessionIndicator
ref={searchSessionIndicatorRef}
state={state}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { CoreStart } from '@kbn/core/public';
import { capitalize } from 'lodash';
import React from 'react';
import { RedirectAppLinks } from '@kbn/kibana-react-plugin/public';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { SearchSessionStatus } from '../../../../../common';
import { OnActionComplete, PopoverActionsMenu, TableText } from '../components';
import { StatusIndicator } from '../components/status';
Expand Down Expand Up @@ -140,7 +140,11 @@ export const getColumns = (
) : null;

return (
<RedirectAppLinks application={core.application}>
<RedirectAppLinks
coreStart={{
application: core.application,
}}
>
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiLink
href={href}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"@kbn/core-saved-objects-utils-server",
"@kbn/data-service",
"@kbn/react-kibana-context-render",
"@kbn/search-response-warnings"
"@kbn/search-response-warnings",
"@kbn/shared-ux-link-redirect-app"
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@elastic/eui';
import type { UrlService } from '@kbn/share-plugin/common/url_service';
import { ApplicationStart, APP_WRAPPER_CLASS } from '@kbn/core/public';
import { RedirectAppLinks } from '@kbn/kibana-react-plugin/public';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';

type FlyoutProps = Omit<EuiFlyoutProps, 'onClose'>;
interface ViewApiRequestFlyoutProps {
Expand Down Expand Up @@ -133,13 +133,15 @@ export const ApiRequestFlyout: React.FunctionComponent<ViewApiRequestFlyoutProps
export const ViewApiRequestFlyout = (props: ViewApiRequestFlyoutProps) => {
if (props.application) {
return (
<RedirectAppLinks
application={props.application}
className={APP_WRAPPER_CLASS}
data-test-subj="apiRequestFlyoutRedirectWrapper"
>
<ApiRequestFlyout {...props} />
</RedirectAppLinks>
<div className={APP_WRAPPER_CLASS} data-test-subj="apiRequestFlyoutRedirectWrapper">
<RedirectAppLinks
coreStart={{
application: props.application,
}}
>
<ApiRequestFlyout {...props} />
</RedirectAppLinks>
</div>
);
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/es_ui_shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@kbn/kibana-react-plugin",
"@kbn/safer-lodash-set",
"@kbn/storybook",
"@kbn/shared-ux-link-redirect-app",
],
"exclude": [
"target/**/*",
Expand Down
14 changes: 8 additions & 6 deletions src/plugins/home/public/application/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { ScopedHistory, CoreStart, CoreTheme } from '@kbn/core/public';
import { Observable } from 'rxjs';
import {
KibanaContextProvider,
KibanaThemeProvider,
RedirectAppLinks,
} from '@kbn/kibana-react-plugin/public';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';

import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';

import { SampleDataTabKibanaProvider } from '@kbn/home-sample-data-tab';

Expand Down Expand Up @@ -42,7 +40,11 @@ export const renderApp = async (
.filter(({ id }) => navLinks.find(({ category, hidden }) => !hidden && category?.id === id));

render(
<RedirectAppLinks application={coreStart.application}>
<RedirectAppLinks
coreStart={{
application: coreStart.application,
}}
>
<KibanaThemeProvider theme$={theme$}>
<KibanaContextProvider services={{ ...coreStart }}>
<SampleDataTabKibanaProvider {...{ coreStart, dataViews, trackUiMetric }}>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template';
import { FormattedMessage } from '@kbn/i18n-react';
import { METRIC_TYPE } from '@kbn/analytics';
import { ApplicationStart } from '@kbn/core/public';
import { RedirectAppLinks } from '@kbn/kibana-react-plugin/public';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { MoveData } from '../move_data';
import { createAppNavigationHandler } from '../app_navigation_handler';
import { getServices } from '../../kibana_services';
Expand Down Expand Up @@ -89,7 +89,11 @@ export const AddData: FC<Props> = ({ addBasePath, application, isDarkMode, isClo
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<RedirectAppLinks application={application}>
<RedirectAppLinks
coreStart={{
application,
}}
>
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButton
data-test-subj="homeAddData"
Expand Down
Loading

0 comments on commit f27427b

Please sign in to comment.