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

ServiceAccount : use InteractiveTable #85203

Merged

Conversation

eledobleefe
Copy link
Contributor

What is this feature?

We modify the ServiceAccount to use the InteractiveTable

Why do we need this feature?
To be consistent as OrgUserTable or UserTablealready use it.

Who is this feature for?

[Add information on what kind of user the feature is for.]

Which issue(s) does this PR fix?:

Fixes #85000

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@eledobleefe eledobleefe added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes internal for issues made by grafanistas labels Mar 26, 2024
@eledobleefe eledobleefe self-assigned this Mar 26, 2024
@grafana-delivery-bot grafana-delivery-bot bot added this to the 11.1.x milestone Mar 26, 2024
Copy link
Contributor

@Clarity-89 Clarity-89 left a comment

Choose a reason for hiding this comment

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

Looks good! 🎉 Left a few minor comments. Also I think somebody from the Identity access team should give this a look.

) : (
<Stack alignItems="center">
<Icon name="key-skeleton-alt"></Icon>
<TextLink href={href} aria-label={ariaLabel} color="primary">
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this needs to be a link, the first three columns should be enough.

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 copied it from the original code. It is how it works on main. Maybe a question for the identity team?

Copy link
Contributor

@tskarhed tskarhed left a comment

Choose a reason for hiding this comment

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

Could you extract some of the cell rendering functionality into separate functions? I think that would increase readability.

@eledobleefe
Copy link
Contributor Author

Looks good! 🎉 Left a few minor comments. Also I think somebody from the Identity access team should give this a look.

Yes, they will be added automatically when the PR turn into a normal one, not a draft. But wanted to check if I was in the right direction 😅

@eledobleefe eledobleefe marked this pull request as ready for review April 1, 2024 10:35
@eledobleefe eledobleefe requested a review from a team as a code owner April 1, 2024 10:35
Copy link
Contributor

@tskarhed tskarhed left a comment

Choose a reason for hiding this comment

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

You still need to extract roles and actions columns. Since you need contextSrv stuff, it might be easier to create the cells in separate function (at least these two).

Comment on lines 60 to 100
const getCellContent = (
value: string,
original: ServiceAccountDTO,
isLoading: boolean,
columnName?: Column<ServiceAccountDTO>['id']
) => {
if (isLoading) {
return columnName === 'avatarUrl' ? <Skeleton circle width={24} height={24} /> : <Skeleton width={100} />;
}
const href = `/org/serviceaccounts/${original.id}`;
const ariaLabel = `Edit service account's ${name} details`;
switch (columnName) {
case 'avatarUrl':
return (
<a aria-label={ariaLabel} href={href}>
<Avatar src={value} alt={'User avatar'} />
</a>
);
case 'id':
return (
<TextLink href={href} aria-label={ariaLabel} color="secondary">
{original.login}
</TextLink>
);
case 'tokens':
return (
<Stack alignItems="center">
<Icon name="key-skeleton-alt"></Icon>
<TextLink href={href} aria-label={ariaLabel} color="primary">
{value || 'No tokens'}
</TextLink>
</Stack>
);
default:
return (
<TextLink href={href} aria-label={ariaLabel} color="primary">
{value}
</TextLink>
);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be inside the component body? I was initially thinking that each cell type would have a separate function, but I think this works from a readability point of view, especially with the loading state.

Co-authored-by: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com>
Copy link
Contributor

@tskarhed tskarhed left a comment

Choose a reason for hiding this comment

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

It crashes when I try to sort by ID.
TypeError: a.split is not a function

Screen.Recording.2024-04-02.at.15.01.29.mov

cell: ({ cell: { value }, row: { original } }: Cell<'role'>) => {
return getCellContent(value, original, isLoading, 'avatarUrl');
},
sortType: 'string',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you actually need sort type here? I don't think it makes sense to have sorting enabled for this column

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I took a look at the original table and it does not sort so I think we could keep just sorting by 'account'. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like an idea :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ;) LGTY?

Copy link
Contributor

@tskarhed tskarhed left a comment

Choose a reason for hiding this comment

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

Good job! 👍

@eledobleefe eledobleefe merged commit 4845b1e into main Apr 3, 2024
14 checks passed
@eledobleefe eledobleefe deleted the eledobleefe/service-accounts-interactive-table-85000 branch April 3, 2024 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend internal for issues made by grafanistas no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Service Account table to use InteractiveTable component
4 participants