From 271987ddc237d3f87886bb9b016952928c9bd690 Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Mon, 3 Jun 2024 12:21:53 -0700 Subject: [PATCH] Add NONE option to availability filter This commit will "invalidate" https://github.com/gravitational/teleport/pull/42200 as it now defaults to NONE instead of ALL. This will allow us to change the visual of the included resource filter. NONE and ALL still function the same from a backend perspective, and will return the same resources. But now, if NONE is selected, the filter shows nothing checked and if ALL is selected, all the options are checked and the filter indicator is present --- .../v1/unified_resource_preferences.pb.go | 22 ++++++++++++------- .../v1/unified_resource_preferences.proto | 1 + .../v1/unified_resource_preferences_pb.ts | 6 ++++- .../userpreferencesv1/service_test.go | 2 +- lib/services/local/userpreferences.go | 2 +- lib/services/local/userpreferences_test.go | 6 ++--- .../UnifiedResources/FilterPanel.tsx | 21 ++++++++++-------- .../UnifiedResources/UnifiedResources.tsx | 8 +++++++ .../components/UnifiedResources/types.ts | 6 ++++- .../teleport/src/generateResourcePath.ts | 8 +++++++ .../userPreferences/userPreferences.ts | 2 +- 11 files changed, 59 insertions(+), 25 deletions(-) diff --git a/api/gen/proto/go/userpreferences/v1/unified_resource_preferences.pb.go b/api/gen/proto/go/userpreferences/v1/unified_resource_preferences.pb.go index 5e9d9100caf94..259769458d5dc 100644 --- a/api/gen/proto/go/userpreferences/v1/unified_resource_preferences.pb.go +++ b/api/gen/proto/go/userpreferences/v1/unified_resource_preferences.pb.go @@ -198,6 +198,7 @@ const ( AvailableResourceMode_AVAILABLE_RESOURCE_MODE_ALL AvailableResourceMode = 1 AvailableResourceMode_AVAILABLE_RESOURCE_MODE_ACCESSIBLE AvailableResourceMode = 2 AvailableResourceMode_AVAILABLE_RESOURCE_MODE_REQUESTABLE AvailableResourceMode = 3 + AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE AvailableResourceMode = 4 ) // Enum value maps for AvailableResourceMode. @@ -207,12 +208,14 @@ var ( 1: "AVAILABLE_RESOURCE_MODE_ALL", 2: "AVAILABLE_RESOURCE_MODE_ACCESSIBLE", 3: "AVAILABLE_RESOURCE_MODE_REQUESTABLE", + 4: "AVAILABLE_RESOURCE_MODE_NONE", } AvailableResourceMode_value = map[string]int32{ "AVAILABLE_RESOURCE_MODE_UNSPECIFIED": 0, "AVAILABLE_RESOURCE_MODE_ALL": 1, "AVAILABLE_RESOURCE_MODE_ACCESSIBLE": 2, "AVAILABLE_RESOURCE_MODE_REQUESTABLE": 3, + "AVAILABLE_RESOURCE_MODE_NONE": 4, } ) @@ -368,7 +371,7 @@ var file_teleport_userpreferences_v1_unified_resource_preferences_proto_rawDesc 0x4c, 0x53, 0x5f, 0x56, 0x49, 0x45, 0x57, 0x5f, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x45, 0x58, 0x50, 0x41, 0x4e, 0x44, 0x45, 0x44, 0x10, 0x01, 0x12, 0x1e, 0x0a, 0x1a, 0x4c, 0x41, 0x42, 0x45, 0x4c, 0x53, 0x5f, 0x56, 0x49, 0x45, 0x57, 0x5f, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x43, 0x4f, 0x4c, 0x4c, - 0x41, 0x50, 0x53, 0x45, 0x44, 0x10, 0x02, 0x2a, 0xb2, 0x01, 0x0a, 0x15, 0x41, 0x76, 0x61, 0x69, + 0x41, 0x50, 0x53, 0x45, 0x44, 0x10, 0x02, 0x2a, 0xd4, 0x01, 0x0a, 0x15, 0x41, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x27, 0x0a, 0x23, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x52, 0x45, 0x53, 0x4f, 0x55, 0x52, 0x43, 0x45, 0x5f, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x4e, 0x53, @@ -379,13 +382,16 @@ var file_teleport_userpreferences_v1_unified_resource_preferences_proto_rawDesc 0x45, 0x5f, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x41, 0x43, 0x43, 0x45, 0x53, 0x53, 0x49, 0x42, 0x4c, 0x45, 0x10, 0x02, 0x12, 0x27, 0x0a, 0x23, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x52, 0x45, 0x53, 0x4f, 0x55, 0x52, 0x43, 0x45, 0x5f, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x52, - 0x45, 0x51, 0x55, 0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x10, 0x03, 0x42, 0x59, 0x5a, 0x57, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x76, 0x69, - 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x67, 0x6f, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, - 0x65, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x75, 0x73, 0x65, 0x72, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, - 0x65, 0x6e, 0x63, 0x65, 0x73, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x45, 0x51, 0x55, 0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x10, 0x03, 0x12, 0x20, 0x0a, 0x1c, + 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x52, 0x45, 0x53, 0x4f, 0x55, 0x52, + 0x43, 0x45, 0x5f, 0x4d, 0x4f, 0x44, 0x45, 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x04, 0x42, 0x59, + 0x5a, 0x57, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, + 0x76, 0x69, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x6c, 0x65, 0x70, + 0x6f, 0x72, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x67, 0x6f, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, + 0x6e, 0x63, 0x65, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x75, 0x73, 0x65, 0x72, 0x70, 0x72, 0x65, 0x66, + 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/api/proto/teleport/userpreferences/v1/unified_resource_preferences.proto b/api/proto/teleport/userpreferences/v1/unified_resource_preferences.proto index e751ac89ed020..076ee0857a9e1 100644 --- a/api/proto/teleport/userpreferences/v1/unified_resource_preferences.proto +++ b/api/proto/teleport/userpreferences/v1/unified_resource_preferences.proto @@ -63,4 +63,5 @@ enum AvailableResourceMode { AVAILABLE_RESOURCE_MODE_ALL = 1; AVAILABLE_RESOURCE_MODE_ACCESSIBLE = 2; AVAILABLE_RESOURCE_MODE_REQUESTABLE = 3; + AVAILABLE_RESOURCE_MODE_NONE = 4; } diff --git a/gen/proto/ts/teleport/userpreferences/v1/unified_resource_preferences_pb.ts b/gen/proto/ts/teleport/userpreferences/v1/unified_resource_preferences_pb.ts index 268e482589417..3e1a9723b1b9e 100644 --- a/gen/proto/ts/teleport/userpreferences/v1/unified_resource_preferences_pb.ts +++ b/gen/proto/ts/teleport/userpreferences/v1/unified_resource_preferences_pb.ts @@ -148,7 +148,11 @@ export enum AvailableResourceMode { /** * @generated from protobuf enum value: AVAILABLE_RESOURCE_MODE_REQUESTABLE = 3; */ - REQUESTABLE = 3 + REQUESTABLE = 3, + /** + * @generated from protobuf enum value: AVAILABLE_RESOURCE_MODE_NONE = 4; + */ + NONE = 4 } // @generated message type with reflection information, may provide speed optimized methods class UnifiedResourcePreferences$Type extends MessageType { diff --git a/lib/auth/userpreferences/userpreferencesv1/service_test.go b/lib/auth/userpreferences/userpreferencesv1/service_test.go index 5cd814b80de04..52d7f4253e315 100644 --- a/lib/auth/userpreferences/userpreferencesv1/service_test.go +++ b/lib/auth/userpreferences/userpreferencesv1/service_test.go @@ -64,7 +64,7 @@ func TestService_GetUserPreferences(t *testing.T) { DefaultTab: userpreferencesv1.DefaultTab_DEFAULT_TAB_ALL, ViewMode: userpreferencesv1.ViewMode_VIEW_MODE_CARD, LabelsViewMode: userpreferencesv1.LabelsViewMode_LABELS_VIEW_MODE_COLLAPSED, - AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_ALL, + AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE, }, Onboard: &userpreferencesv1.OnboardUserPreferences{ PreferredResources: []userpreferencesv1.Resource{}, diff --git a/lib/services/local/userpreferences.go b/lib/services/local/userpreferences.go index d556f41e261df..a491494865a45 100644 --- a/lib/services/local/userpreferences.go +++ b/lib/services/local/userpreferences.go @@ -45,7 +45,7 @@ func DefaultUserPreferences() *userpreferencesv1.UserPreferences { DefaultTab: userpreferencesv1.DefaultTab_DEFAULT_TAB_ALL, ViewMode: userpreferencesv1.ViewMode_VIEW_MODE_CARD, LabelsViewMode: userpreferencesv1.LabelsViewMode_LABELS_VIEW_MODE_COLLAPSED, - AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_ALL, + AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE, }, Onboard: &userpreferencesv1.OnboardUserPreferences{ PreferredResources: []userpreferencesv1.Resource{}, diff --git a/lib/services/local/userpreferences_test.go b/lib/services/local/userpreferences_test.go index b4e21ec7fb151..8d2323820db6f 100644 --- a/lib/services/local/userpreferences_test.go +++ b/lib/services/local/userpreferences_test.go @@ -147,7 +147,7 @@ func TestUserPreferencesCRUD(t *testing.T) { DefaultTab: userpreferencesv1.DefaultTab_DEFAULT_TAB_PINNED, ViewMode: userpreferencesv1.ViewMode_VIEW_MODE_CARD, LabelsViewMode: userpreferencesv1.LabelsViewMode_LABELS_VIEW_MODE_COLLAPSED, - AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_ALL, + AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE, }, ClusterPreferences: defaultPref.ClusterPreferences, }, @@ -259,7 +259,7 @@ func TestUserPreferencesCRUD(t *testing.T) { DefaultTab: userpreferencesv1.DefaultTab_DEFAULT_TAB_PINNED, ViewMode: userpreferencesv1.ViewMode_VIEW_MODE_LIST, LabelsViewMode: userpreferencesv1.LabelsViewMode_LABELS_VIEW_MODE_COLLAPSED, - AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_ALL, + AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE, }, Assist: &userpreferencesv1.AssistUserPreferences{ PreferredLogins: []string{"baz"}, @@ -287,7 +287,7 @@ func TestUserPreferencesCRUD(t *testing.T) { DefaultTab: userpreferencesv1.DefaultTab_DEFAULT_TAB_PINNED, ViewMode: userpreferencesv1.ViewMode_VIEW_MODE_LIST, LabelsViewMode: userpreferencesv1.LabelsViewMode_LABELS_VIEW_MODE_COLLAPSED, - AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_ALL, + AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE, }, Assist: &userpreferencesv1.AssistUserPreferences{ PreferredLogins: []string{"baz"}, diff --git a/web/packages/shared/components/UnifiedResources/FilterPanel.tsx b/web/packages/shared/components/UnifiedResources/FilterPanel.tsx index ec87bbe13024a..633b2930f1085 100644 --- a/web/packages/shared/components/UnifiedResources/FilterPanel.tsx +++ b/web/packages/shared/components/UnifiedResources/FilterPanel.tsx @@ -547,19 +547,22 @@ const IncludedResourcesSelector = ({ const formData = new FormData(e.currentTarget); const availabilityOptionsForm = formData.getAll('availabilityOptions'); - // We selected all or nothing. - if ( - availabilityOptionsForm.length === 0 || - availabilityOptionsForm.length === 2 - ) { + if (availabilityOptionsForm.length === 0) { + onChange('none'); + return; + } + if (availabilityOptionsForm.length === 2) { onChange('all'); - } else { - onChange(availabilityOptionsForm.at(0) as IncludedResourceMode); + return; } + + onChange(availabilityOptionsForm.at(0) as IncludedResourceMode); } function isCheckboxPreSelected(option: IncludedResourceMode): boolean { - return availabilityFilter.mode === option; + return ( + availabilityFilter.mode === option || availabilityFilter.mode === 'all' + ); } return ( @@ -577,7 +580,7 @@ const IncludedResourcesSelector = ({ Availability {availabilityFilter.canRequestAll === true && - availabilityFilter.mode !== 'all' && } + availabilityFilter.mode !== 'none' && } { let mode = AvailableResourceMode.UNSPECIFIED; switch (includedResourceMode) { + case 'none': + mode = AvailableResourceMode.NONE; + break; case 'accessible': mode = AvailableResourceMode.ACCESSIBLE; break; @@ -746,6 +749,11 @@ export function getResourceAvailabilityFilter( canRequestAllResources: boolean ): ResourceAvailabilityFilter { switch (availableResourceMode) { + case AvailableResourceMode.NONE: + if (!canRequestAllResources) { + return { mode: 'accessible', canRequestAll: false }; + } + return { mode: 'none', canRequestAll: true }; case AvailableResourceMode.ALL: if (!canRequestAllResources) { return { mode: 'accessible', canRequestAll: false }; diff --git a/web/packages/shared/components/UnifiedResources/types.ts b/web/packages/shared/components/UnifiedResources/types.ts index 5ba53e2e52841..22c0c52547181 100644 --- a/web/packages/shared/components/UnifiedResources/types.ts +++ b/web/packages/shared/components/UnifiedResources/types.ts @@ -141,7 +141,11 @@ export enum PinningSupport { Hidden = 'Hidden', } -export type IncludedResourceMode = 'all' | 'requestable' | 'accessible'; +export type IncludedResourceMode = + | 'none' + | 'all' + | 'requestable' + | 'accessible'; export type ResourceItemProps = { name: string; diff --git a/web/packages/teleport/src/generateResourcePath.ts b/web/packages/teleport/src/generateResourcePath.ts index 761ad8e3b51fa..3c0abd1747a13 100644 --- a/web/packages/teleport/src/generateResourcePath.ts +++ b/web/packages/teleport/src/generateResourcePath.ts @@ -40,6 +40,14 @@ export default function generateResourcePath( : ''; } + // as of now, "none" and "all" function the same. if both options are selected (requestable, accessible_only) + // then you will see the same results. The distinction comes from user preferences, which change the visual of + // the filter. If "none", there are no options selected. If "all", both options are selected and a filter indicator + // is shown. + if (processedParams.includedResourceMode === 'none') { + processedParams.includedResourceMode = 'all'; + } + const output = path .replace(':clusterId', params.clusterId) .replace(':limit?', params.limit) diff --git a/web/packages/teleport/src/services/userPreferences/userPreferences.ts b/web/packages/teleport/src/services/userPreferences/userPreferences.ts index 1e551f7c2cfb0..c62c4116de68e 100644 --- a/web/packages/teleport/src/services/userPreferences/userPreferences.ts +++ b/web/packages/teleport/src/services/userPreferences/userPreferences.ts @@ -144,7 +144,7 @@ export function convertBackendUserPreferences( preferences.clusterPreferences ), unifiedResourcePreferences: { - availableResourceMode: AvailableResourceMode.ALL, + availableResourceMode: AvailableResourceMode.NONE, ...preferences.unifiedResourcePreferences, }, };