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

Bye tabs, hi URLs #389

Merged
merged 9 commits into from
May 1, 2024
Merged

Bye tabs, hi URLs #389

merged 9 commits into from
May 1, 2024

Conversation

gabalafou
Copy link
Contributor

@gabalafou gabalafou commented Apr 9, 2024

Closes #386

Testing

The automatic tests should give some confidence that this PR does not horribly break anything. That said, a manual run-through should be done before approving and merging.

Types of website actions affected by this PR that should be tested manually in various combinations:

  • Open an environment
  • Create a new environment
  • Go back
  • Go forward
  • Click edit
  • Click save
  • Click cancel
  • Click delete

@gabalafou gabalafou changed the title React router Bye tabs, hi URLs Apr 9, 2024
@trallard trallard added the type: enhancement 💅🏼 New feature or request label Apr 9, 2024
Copy link
Contributor Author

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

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

done self-reviewing

watch: false,
...getContext(__dirname),

output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js"
filename: "[name].js",
publicPath: "/"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to add this to get the dev server to work. Will need to check that this works for production server too. Full disclosure: webpack is black magic to me.

Copy link
Contributor

@peytondmurray peytondmurray Apr 25, 2024

Choose a reason for hiding this comment

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

😅 Really not sure why either. I guess this is telling webpack to insert / at the beginning of every path?

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 guess we'll just need to keep an eye on this when we release and deploy

test/playwright/test_ux.py Show resolved Hide resolved
test/environments/Environment.test.tsx Show resolved Hide resolved
Comment on lines 33 to 35
// const editButton = component.getByText("Edit");
// fireEvent.click(editButton);
// expect(store.getState().environmentDetails.mode).toEqual("edit");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO remove or fix

src/utils/helpers/namespaces.ts Show resolved Hide resolved

const onUpdateOrCreateEnv = ({ data }: IUpdateEnvironment) => {
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 decided to get rid of this callback function because:

  • Turning the child components into routed components means that the parent no longer imports the child components and so cannot pass properties directly to them (see line 47 on the right for how a route parent has to pass properties to route children)
  • It seemed that having a centralized place in the app state for notifications is a good idea. PageLayout probably shouldn't own these functions.
  • Keeping the setRefreshEnvironment behavior would be easy with the useEffect hook. However this will need to be changed in the future (I will add a TODO comment)

src/routes.tsx Show resolved Hide resolved
src/store/rootReducer.ts Show resolved Hide resolved
src/store/rootReducer.ts Show resolved Hide resolved
src/App.tsx Outdated Show resolved Hide resolved
src/features/environments/reducer.ts Outdated Show resolved Hide resolved
@@ -44,7 +43,8 @@ export const Environment = ({
/>
</ListItemIcon>
<Button
onClick={onClick}
component={Link}
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 wanted to change the Button component directly to a Link, but it was causing styling issues. The reason why is that the MUI button component renders with several classes attached to it and those same classes get applied whether the HTML element used is button or (now) a. This should probably be cleaned up at some point but it's low priority in my mind.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yah, this doesn't seem like a big deal unless I'm missing something accessibility related or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's just not very hygienic. Because you end up with an <a> tag that has button classes applied to it. (But yes, not a big deal.)

@trallard trallard added this to the challenges: Round 2 🚀 milestone Apr 16, 2024
Copy link
Contributor

@peytondmurray peytondmurray left a comment

Choose a reason for hiding this comment

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

Tested locally, seems like it's working. I'm a big fan of putting state into the URL, so this seems like a really nice change. Thank you! 🎉

Comment on lines +45 to +46
dispatch(modeChanged(EnvironmentDetailsModes.CREATE));
dispatch(openCreateNewEnvironmentTab(namespaceName));
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I'm not even sure how else you'd do it other than a useEffect hook unless you mean something really hacky with URLSearchParams or something. So this seems good 🤷

dispatch(modeChanged(EnvironmentDetailsModes.READ));
dispatch(toggleNewEnvironmentView(false));
}
}, [namespaceName, environmentName, foundNamespace, foundEnvironment]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, you're right that a comment here would help clear this up. I guess this means the UI will now have an "intermediate" state where this hook has run once but not twice, right?

@@ -44,7 +43,8 @@ export const Environment = ({
/>
</ListItemIcon>
<Button
onClick={onClick}
component={Link}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yah, this doesn't seem like a big deal unless I'm missing something accessibility related or something?

const { palette } = useTheme();

const onCreateNewEnvironmentTab = (
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Comment on lines +18 to +20
// This use of state to refetch the environment is an anti-pattern. We should
// leverage RTK's cache invalidation features instead.
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this comment, can you create an issue so we can track this work later on? That way we won't lose track of it after we merge this PR.

Copy link
Contributor Author

@gabalafou gabalafou Apr 30, 2024

Choose a reason for hiding this comment

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

src/routes.tsx Show resolved Hide resolved
test/environments/Environment.test.tsx Show resolved Hide resolved
test/playwright/test_ux.py Show resolved Hide resolved
watch: false,
...getContext(__dirname),

output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js"
filename: "[name].js",
publicPath: "/"
Copy link
Contributor

@peytondmurray peytondmurray Apr 25, 2024

Choose a reason for hiding this comment

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

😅 Really not sure why either. I guess this is telling webpack to insert / at the beginning of every path?

Copy link
Contributor Author

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

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

Thanks @peytondmurray for your review!

Comment on lines +45 to +46
dispatch(modeChanged(EnvironmentDetailsModes.CREATE));
dispatch(openCreateNewEnvironmentTab(namespaceName));
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 mean, I could put some bit of code that runs as soon as the the Redux-related functions are available, checks the URL, and dispatches these actions. Or I could probably figure out some way to leverage the React Router's loader function.

But so long as this seems good to you, I'll keep it for now. (Again, it's a question of effort versus reward, and I'm not sure more effort is worth the reward, not yet.)

@@ -44,7 +43,8 @@ export const Environment = ({
/>
</ListItemIcon>
<Button
onClick={onClick}
component={Link}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's just not very hygienic. Because you end up with an <a> tag that has button classes applied to it. (But yes, not a big deal.)

src/routes.tsx Show resolved Hide resolved
dispatch(modeChanged(EnvironmentDetailsModes.READ));
dispatch(toggleNewEnvironmentView(false));
}
}, [namespaceName, environmentName, foundNamespace, foundEnvironment]);
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 think I overcomplicated this. I'm going to push a commit that should simplify this.

Comment on lines +18 to +20
// This use of state to refetch the environment is an anti-pattern. We should
// leverage RTK's cache invalidation features instead.
useEffect(() => {
Copy link
Contributor Author

@gabalafou gabalafou Apr 30, 2024

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement 💅🏼 New feature or request
Projects
Status: Done 💪🏾
Development

Successfully merging this pull request may close these issues.

App URL routing
3 participants