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

Add optional component props to Roles component #51322

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Conversation

avatus
Copy link
Contributor

@avatus avatus commented Jan 22, 2025

This PR enables us to add an optional RoleDiff component to the props for our Roles feature so that we can create an "e wrapper" around the Roles feature for enterprise specifically. Then we can pass the Role Diff visualizer into the E route.

Adds support (for this stub) in https://github.com/gravitational/teleport.e/pull/5902

@avatus avatus added the no-changelog Indicates that a PR does not require a changelog entry label Jan 22, 2025
@avatus avatus requested review from ryanclark and bl-nero January 22, 2025 00:07
@github-actions github-actions bot requested a review from gzdunek January 22, 2025 00:07
@avatus avatus removed the request for review from gzdunek January 22, 2025 00:08
{roleDiffProps ? (
<roleDiffProps.RoleDiffComponent />
) : (
<Box maxWidth={promoImageWidth + 2 * 2} minWidth={300}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the diff is a bit wild on this one due to a lot of similar child components, but i didnt change anything with the structure of the Coming Soon box, just moved it into the tertiary

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this part a separate component that is passed in as RoleDiffComponent for the OSS version?

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 can make it a separate component, sure. I didn't make it OSS only since e clusters will still need this if TAG isn't enabled

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah fair enough. I think putting it in a separate component and importing it from e makes it a bit more obvious what's happening on both the e and OSS side

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Ill update it

type RoleDiffProps =
| { RoleDiffComponent?: undefined; updateRoleDiff?: undefined }
| {
RoleDiffComponent: React.FC;
Copy link
Contributor

Choose a reason for hiding this comment

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

ComponentType

{roleDiffProps ? (
<roleDiffProps.RoleDiffComponent />
) : (
<Box maxWidth={promoImageWidth + 2 * 2} minWidth={300}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this part a separate component that is passed in as RoleDiffComponent for the OSS version?

// RoleDiffProps are an optonal set of props to render the role diff visualizer.
// This type union will ensure that either all fields are undefined or all are supplied
type RoleDiffProps =
| { RoleDiffComponent?: undefined; updateRoleDiff?: undefined }
Copy link
Contributor

Choose a reason for hiding this comment

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

If roleDiffProps is optional, why would I pass rollDiffProps={{}} (which matches this type)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i think i might have overthought this one. updated to just make roleDiffProps optional and typed the RoleDiffProps normally

</Flex>
</Flex>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just moved from the adapter component, right?

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

@@ -48,15 +48,25 @@ import { RoleList } from './RoleList';
import templates from './templates';
import { State, useRoles } from './useRoles';

export function RolesContainer() {
// RoleDiffProps are an optonal set of props to render the role diff visualizer.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// RoleDiffProps are an optonal set of props to render the role diff visualizer.
// RoleDiffProps are an optional set of props to render the role diff visualizer.

// RoleDiffProps are an optonal set of props to render the role diff visualizer.
type RoleDiffProps = {
RoleDiffComponent: ComponentType;
updateRoleDiff: (role: Role) => Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a property that will be used in future, or something that you forgot to remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the updateRoleDiff method is what will be passed down to RoleEditorAdapter as a callback for when the standardModel updates (or yaml is previewed)

@@ -320,6 +320,11 @@ export class FeatureRoles implements TeleportFeature {
};

showInDashboard = true;
// getRoute allows child class extending this
// parent class to refer to this parent's route.
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that every feature class has this, but I'm still confused right now how the presence of this function makes the route field more accessible. What's wrong with super.route?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

honestly idk. super.route wasn't functioning so i just followed prior work and moved on without diving in too deep. i did try that first tho

Copy link
Contributor

@ryanclark ryanclark Jan 23, 2025

Choose a reason for hiding this comment

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

You can only access super's methods, not properties (unless the route was defined in the constructor, then this.route would work)

Copy link
Contributor Author

@avatus avatus Jan 23, 2025

Choose a reason for hiding this comment

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

TIL. any class stuff ive ever done has ALWAYS had the stuff defined in the constructor so i guess thats why i never noticed

@avatus avatus force-pushed the avatus/roles_e branch 2 times, most recently from 94d42c5 to 0cc8244 Compare January 23, 2025 14:48
@avatus avatus added this pull request to the merge queue Jan 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 23, 2025
@avatus avatus added this pull request to the merge queue Jan 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 23, 2025
This PR enables us to add an optional RoleDiff component to the props
for our Roles feature so that we can create an "e wrapper" around the
Roles feature for enterprise specifically. Then we can pass the Role
Diff visualizer into the E route.
@avatus avatus added this pull request to the merge queue Jan 23, 2025
Merged via the queue into master with commit 928bb89 Jan 23, 2025
41 checks passed
@avatus avatus deleted the avatus/roles_e branch January 23, 2025 16:34
@public-teleport-github-review-bot

@avatus See the table below for backport results.

Branch Result
branch/v17 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v17 backport-required no-changelog Indicates that a PR does not require a changelog entry size/md ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants