Skip to content

Web: define discover resource guide ids and add discover user preference field#51672

Merged
kimlisa merged 6 commits intomasterfrom
lisa/discover-guide-ids
Feb 4, 2025
Merged

Web: define discover resource guide ids and add discover user preference field#51672
kimlisa merged 6 commits intomasterfrom
lisa/discover-guide-ids

Conversation

@kimlisa
Copy link
Copy Markdown
Contributor

@kimlisa kimlisa commented Jan 30, 2025

Part of improving the enroll resources page in the web UI, which is to allow user to pin favored resource guides. This PR just defines the user preference fields, the UI work to allow user to pin will be in another PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alternative is to define these as proto enums. This takes more lines of code, but advantage is probably that it's harder to modify it? And stricter typing (like you can't just store any strings, it has to be a type of enum).

I opted to go for the simpler approach and see what kind of review I get.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think enums client side like you have it is fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah looks good since there isn't extra processing done by the backend on these id values and are meant just for the UI. The downside are that we must make sure that the id names (mostly words, spells etc) are correct the first time we merge to master as changing them later risks backend data and id values going out of sync. That wont be case if we define this in backend first and then copy 1:1 to frontend.

@kimlisa kimlisa added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v17 labels Jan 30, 2025
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think enums client side like you have it is fine.

Comment thread web/packages/teleport/src/services/userPreferences/discoverPreference.ts Outdated
Comment thread web/packages/teleport/src/services/userPreferences/discoverPreference.ts Outdated
DatabaseAwsSqlServerAd = 'database-aws-sql-server-ad',
DatabaseAwsPostgresRedshift = 'database-aws-postgres-redshift',
DatabaseAwsRdsPostgresSql = 'database-aws-rds-postgres-sql',
DatabaseAwsRdsProxyPostgres = 'database-aws-rds-proxy-postgres',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i dont really know what the protocol is here if we should call it postgres or postgresql or whatever. i think weve been pretty inconsistent in the rest of the code base. feel free to skip if you want (but when using the full name, lets keep it one word postgresql)

Copy link
Copy Markdown
Contributor Author

@kimlisa kimlisa Feb 4, 2025

Choose a reason for hiding this comment

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

just realized i've been misspelling it (the extra s in postgressql), i decided to replace all postgressql with its shortened version postgres

Comment thread web/packages/teleport/src/services/userPreferences/discoverPreference.ts Outdated
DatabaseAzureSqlServerAd = 'database-azure-sql-server-ad',

DatabaseGcpMysqlCloudSql = 'database-gcp-mysql-cloud-sql',
DatabaseGcpPostgresCloudSql = 'database-gcp-postgres-cloud-sql',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
DatabaseGcpPostgresCloudSql = 'database-gcp-postgres-cloud-sql',
DatabaseGcpPostgresCloudSql = 'database-gcp-postgres-cloud-sql',

PostgresqlCloud?

Copy link
Copy Markdown
Contributor Author

@kimlisa kimlisa Feb 4, 2025

Choose a reason for hiding this comment

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

Comment thread web/packages/teleport/src/services/userPreferences/discoverPreference.ts Outdated
Copy link
Copy Markdown
Contributor

@flyinghermit flyinghermit 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

Comment on lines +22 to +25
message DiscoverGuidePreferences {
// pinned_guides is a list of ids of pinned guides.
repeated string pinned_guides = 1;
}

// DiscoverResourcePreferences holds preferences related to discovering resource.
message DiscoverResourcePreferences {
DiscoverGuidePreferences discover_guide_preferences = 1;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Curious, do we have plans to add more configuration to the guide preference?

Otherwise putting pinned guide directly in the discover resource preference seem like a better type to me.

message DiscoverResourcePreferences {
  // pinned_guides is a list of ids of pinned guides.
  repeated string pinned_guides = 1;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Glad you pointed it out b/c i wanted to double check.

Curious, do we have plans to add more configuration to the guide preference?

probably not, i was partly following the existing pattern for pinning here and mostly because i needed a way to tell from init value vs user intentionally setting it empty

  • i use the nil value to render default pinned items
  • pinned results will only be saved if a user ever updates any pinned items
  • a user can also unpin everything leading to a empty list

you could also say DiscoverResourcePreferences can also be nil? but we could add more settings later that may not affect the pinned results

let me know what you think

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i needed a way to tell from init value vs user intentionally setting it empty

Why do we want to check this?

Unless we know we need it 100% later on, I say lets settle for simple one like this. Any more settings you want to add can be added directly or wrapped in another message when necessary.

Copy link
Copy Markdown
Contributor Author

@kimlisa kimlisa Jan 31, 2025

Choose a reason for hiding this comment

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

Why do we want to check this?

we want to display default pinned guides like this (default == nil preference):

image

if a user wanted to just unpin all of them (empty list), i needed a way to tell if they did that, otherwise the default pins will always render which is unexpected behavior.

or, are you saying just always render default if empty list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

actually, i think i can do something like this

DiscoverPreference {
  repeated string pinned_guides   `...yada yada, omitempty`
}

if i remember correctly, the omitempty allows for js to distinguish between value undefined and a empty length array. i'll test it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah my thinking was to show out set of predefined defaults if the pinned_guides choice is empty. Any issue with that?

option go_package = "github.com/gravitational/teleport/api/gen/proto/go/userpreferences/v1;userpreferencesv1";

// DiscoverGuidePreferences holds preferences related to discover resource guides.
message DiscoverGuidePreferences {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: not sure if it will be confusing in practice but just looking at it, I think we can leave out Preferences suffix as this will ultimately be used as userpreferencesv1.DiscoverGuide. userpreferencesv1.DiscoverGuidePreferences reads redundant.

Suggested change
message DiscoverGuidePreferences {
message DiscoverGuide {

(same comment below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

keeping it as is, since it's the established pattern 😅

Comment thread lib/web/userpreferences.go Outdated
PinnedGuides []string `json:"pinnedGuides"`
}

type DiscoverResourcePreferencesResponse struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Godoc

Comment on lines +81 to +82
ClusterPreferences ClusterUserPreferencesResponse `json:"clusterPreferences,omitempty"`
DiscoverResourcePreferences DiscoverResourcePreferencesResponse `json:"discoverResourcePreferences"`
AccessGraph AccessGraphPreferencesResponse `json:"accessGraph,omitempty"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should DiscoverResourcePreferences also define omitempty or we are ok sending empty fields?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

recording slack discussion: DiscoverResourcePreferences should always be initialized since i am using the undefined value as a way to determine if response came from an older proxy

Comment thread lib/web/userpreferences.go Outdated
Comment on lines +266 to +260
// accessGraphPreferencesResponse creates a JSON response for the access graph preferences.
func discoverResourcePreferenceResponse(resp *userpreferencesv1.DiscoverResourcePreferences) DiscoverResourcePreferencesResponse {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: update comment

Comment thread lib/web/userpreferences.go Outdated

// accessGraphPreferencesResponse creates a JSON response for the access graph preferences.
func discoverResourcePreferenceResponse(resp *userpreferencesv1.DiscoverResourcePreferences) DiscoverResourcePreferencesResponse {
if resp == nil || resp.DiscoverGuidePreferences == nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: use GetX where possible as it adds safety from nil pointer

Suggested change
if resp == nil || resp.DiscoverGuidePreferences == nil {
if resp == nil || resp.GetDiscoverGuidePreferences == nil {

r.id === DiscoverGuideId.ApplicationSamlGeneric ||
r.id === DiscoverGuideId.ApplicationSamlGrafana
) {
return 'Teleport as IDP';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

where does this name show up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it shows up in the select a resource to enroll tile :

image

* An empty array or undefined means that the resource supports all auth types.
*/
supportedAuthTypes?: AuthType[];
id: DiscoverGuideId;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

curious, is is deliberate that this new field added as last item but another new field pinned?: boolean; added as first item?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not deliberate 😅 , i updated to put both fields at top since it's more fitting

*
* Existing enum values must not be modified.
*/
export enum DiscoverGuideId {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: In favor of shorter names (since this will be used to pin the resource internally and not exposed to users right?

  • Application can be App
  • ApplicationSaml can be Saml
  • Database can be `Db

Applied to both key and values.

Feel free to ignore if you think we gain by spelling out loud.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

keeping it as is

@kimlisa kimlisa force-pushed the lisa/discover-guide-ids branch from 7ae8dae to 26da534 Compare February 4, 2025 19:41
@kimlisa kimlisa force-pushed the lisa/discover-guide-ids branch from c4435e2 to 6b1c121 Compare February 4, 2025 21:52
@kimlisa kimlisa added this pull request to the merge queue Feb 4, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 4, 2025
@kimlisa kimlisa added this pull request to the merge queue Feb 4, 2025
Merged via the queue into master with commit 4312c5f Feb 4, 2025
@kimlisa kimlisa deleted the lisa/discover-guide-ids branch February 4, 2025 23:31
@public-teleport-github-review-bot
Copy link
Copy Markdown

@kimlisa See the table below for backport results.

Branch Result
branch/v17 Failed

kimlisa added a commit that referenced this pull request Feb 14, 2025
…nce field (#51672)

* Add discover resource preferences to user preferences

* Define hard coded guide id consts

* Set guide ids for resources

* Add test

* Address CRs

* Define a new type just for SelectResource.tsx which requires id field
carloscastrojumo pushed a commit to carloscastrojumo/teleport that referenced this pull request Feb 19, 2025
…nce field (gravitational#51672)

* Add discover resource preferences to user preferences

* Define hard coded guide id consts

* Set guide ids for resources

* Add test

* Address CRs

* Define a new type just for SelectResource.tsx which requires id field
github-merge-queue Bot pushed a commit that referenced this pull request Feb 20, 2025
…52176)

* Web: make SelectResource.tsx component leaner (#51698)

* Web: Move resource specs into resource directory

* Web: move code out into separate files

* Web: define discover resource guide ids and add discover user preference field (#51672)

* Add discover resource preferences to user preferences

* Define hard coded guide id consts

* Set guide ids for resources

* Add test

* Address CRs

* Define a new type just for SelectResource.tsx which requires id field

* Wrap discover guide preference "pinned" field inside a proto message (#52017)

This allows us to use "nil" value to mean no discover
guide preferences set (which is used to set default
values in the web UI).

* Web: Add filters and pinning support for Enroll Resources page (#51893)

* Minor changes

- Stop propagation and default behavior when clicking on pin button
- Add small or large icon option for discover icons

* Add pinning guide support

* Fix lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/branch/v17 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