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

frontend: add default actions to ResourceListView #2044

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

farodin91
Copy link
Contributor

No description provided.

@farodin91
Copy link
Contributor Author

@joaquimrocha What do you think of this idea? I could try to merge details and list actions.

Copy link
Collaborator

@joaquimrocha joaquimrocha left a comment

Choose a reason for hiding this comment

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

Incredible changes @farodin91 ! Thanks a lot.
I left some comments which I believe will improve the code. I also noticed that the menu options partially outside the view. Not sure if you can e.g. render the menu with the anchor being the top right to avoid this.
Menu partially hidden

Also. Once the review is approved, I think it would make sense to have the commits separated a bit. At least in 2: 1. Add actions capability to tables; 2. Add the view/edit/delete context actions to resource tables

import { ConfirmDialog } from '../Dialog';
import AuthVisible from './AuthVisible';

interface DeleteButtonProps {
item?: KubeObject;
options?: CallbackActionOptions;
menuAction?: Boolean;
afterConfirm?: () => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was confused with this one, as to why it's called afterConfirm and not onClick.
They I saw it's used effectively when the user confirms the dialog. But since this will be used mainly to close the menu, shouldn't we just use an onClick prop and close the menu right when the user clicks it?

It indeed looks a bit odd to me to see the menu open in the background of the dialog.

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 had the issue that delete didn't went through, if i close it with onclick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to work more dispatching that would be a major refactor in this PR of all actions.

import { ConfirmDialog } from '../Dialog';
import AuthVisible from './AuthVisible';

interface DeleteButtonProps {
item?: KubeObject;
options?: CallbackActionOptions;
menuAction?: Boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For booleans, usually it makes it easier for devs to guess that the property is a boolean when it is prefixed with is.
So isMenuItem would sound more intuitive.

A different way would be for the delete button to support a component which could take an enum OR a clickable component, so we could override whatever renders it. Using DeleteButtonRenderOptions.{Button|MenuItem} as built-in options.
But I do understand though that having this quick boolean property is convenient, so we can stick with isMenuItem if you prefer.

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 updated it a bit.

frontend/src/components/common/Resource/DeleteButton.tsx Outdated Show resolved Hide resolved
frontend/src/components/common/Resource/DeleteButton.tsx Outdated Show resolved Hide resolved
frontend/src/components/common/Resource/EditButton.tsx Outdated Show resolved Hide resolved
frontend/src/components/common/Resource/ResourceTable.tsx Outdated Show resolved Hide resolved
Comment on lines 381 to 408
{
id: DefaultHeaderAction.EDIT,
action: ({ item, closeMenu }) => (
<EditButton item={item} menuAction afterConfirm={closeMenu} />
),
},
{
id: DefaultHeaderAction.DELETE,
action: ({ item, closeMenu }) => (
<DeleteButton item={item} menuAction afterConfirm={closeMenu} />
),
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

For read-only roles, where users cannot delete nor edit resources, this will render the menu empty AFAIU.
One quick way to avoid this is to add a VIEW item. So at least we have an option in the menu. It's also something I have seen as an option sometimes, maybe it even improves a11y.

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 added VIEW.

frontend/src/components/common/Table/Table.tsx Outdated Show resolved Hide resolved
@illume illume marked this pull request as draft June 19, 2024 11:26
@farodin91 farodin91 force-pushed the frontend--idea-to-add-action-button-to-all-tables branch 2 times, most recently from 89b7e73 to 1808383 Compare July 1, 2024 20:01
@farodin91 farodin91 changed the title frontend: idea to add action button to all tables frontend: add default actions to ResourceListView Jul 1, 2024
@farodin91
Copy link
Contributor Author

I also noticed that the menu options partially outside the view. Not sure if you can e.g. render the menu with the anchor being the top right to avoid this.

i used the inhouse method to render the menu.

Signed-off-by: farodin91 <github@jan-jansen.net>
@farodin91 farodin91 force-pushed the frontend--idea-to-add-action-button-to-all-tables branch from 1808383 to 94c6cc6 Compare July 1, 2024 20:10
@farodin91
Copy link
Contributor Author

@joaquimrocha I updated a lot of thinks. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants