Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shared UX] Migrate router from kibana react to shared ux #138544

Merged
merged 44 commits into from
Sep 9, 2022

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Aug 10, 2022

Summary

Building from discussion in #132629, this PR aims to refactor the kibana router and bring it into shared ux. #131805 refactored the router in kibana react and this PR will migrate it to shared ux.

Next Steps for Future PRs

  • Deprecate react-router-dom usage throughout kibana
  • Add deprecation message for the kibana_react_router

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@rshen91 rshen91 changed the title router migration [Shared UX] Migrate router from kibana react to shared ux Aug 10, 2022
@rshen91 rshen91 self-assigned this Aug 16, 2022
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": ".",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might help.

Suggested change
"rootDir": ".",
"rootDir": "src",

@clintandrewhall
Copy link
Contributor

@rshen91 I pushed a set of changes to this branch that should fix your issues:

  • While @kbn/shared-ux-router is the name of the package produced from the impl directory, Bazel still needs to refer to it by the directory path. So we needed to add /impl to your build statements on 274 and 526.
  • @kbn/shared-ux-router-types needed to be added to 275, but not to 527+ because it it a types package. I figure you removed this due to other errors.
  • You were likely getting the configured to produce no outputs error because your types package contained no source files. Adding a blank .d.ts file should fix that.

cc: @spalger @mistic for developer experience reference

@rshen91 rshen91 marked this pull request as ready for review September 6, 2022 13:49
@rshen91 rshen91 requested a review from a team September 6, 2022 13:49
@rshen91 rshen91 added the release_note:skip Skip the PR/issue when compiling release notes label Sep 6, 2022
@rshen91 rshen91 added the Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) label Sep 6, 2022
@rshen91 rshen91 requested a review from sebelga September 6, 2022 14:57
Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at the code, haven't checked package-related files nor did any verification that the package builds correctly. Some comments below.

children?: ((props: RouteChildrenProps<any>) => React.ReactNode) | React.ReactNode;
path?: string | string[];
exact?: boolean;
sensitive?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some explanation about what these props are?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Added in a31f7b1 🥳



```jsx
<Route basepath="/url" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what this example is. basepath doesn't seem to be in RouteProps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to path - good catch!
a31f7b1

<Route basepath="/url" />
```

This component removes the need for manual calls to `useExecutionContext` and should be removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*they should be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! a31f7b1

import { Route } from './router';

describe('Route', () => {
test('renders', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a more extensive test suite? Given that the render logic depends on a lot of props, would be nice to test some of those scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some of the react dom route props in the test suite - let me know what you think. I think for testing exact, sensitive and strict it might involve an integration test?

/>
);
}
if (typeof children === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this and previous "if" in one if statement, cause they seem to be doing exactly the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait I could use some clarification - the first if is checking for a render and then rendering props whereas the if on line 54 is checking for the typeof children to be a function and if it is then is using the function from children to render the props (vs render itself). Let me know what I'm missing thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the body of the if-statement is exactly the same in both cases. You can do something like:

if (typeof children === 'function' || render) {
  const renderFunc = (typeof children === 'function') ? children : render;
  return (
      <ReactRouterRoute
        {...rest}
        render={(props) => (
          <>
            <MatchPropagator />
            {renderFunc(props)}
          </>
        )}
      />
    );
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the help! - 0556d16

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! Code review only

expect(example).toMatchSnapshot();
});

test('render prop renders', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@rshen91 rshen91 enabled auto-merge (squash) September 9, 2022 14:15
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #11 / apis uptime uptime REST endpoints uptime CRUD routes [PUT] /internal/uptime/service/monitors handles private location errors and does not update the monitor if integration policy is unable to be updated

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/shared-ux-router - 1 +1
@kbn/shared-ux-router-mocks - 1 +1
total +2
Unknown metric groups

API count

id before after diff
@kbn/shared-ux-router - 2 +2
@kbn/shared-ux-router-mocks - 1 +1
total +3

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @rshen91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants