Skip to content

Commit

Permalink
Add NONE option to availability filter
Browse files Browse the repository at this point in the history
This commit will "invalidate"
#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
  • Loading branch information
avatus committed Jun 3, 2024
1 parent 98d171a commit 9e33013
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 25 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/auth/userpreferences/userpreferencesv1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 1 addition & 1 deletion lib/services/local/userpreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
6 changes: 3 additions & 3 deletions lib/services/local/userpreferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down
21 changes: 12 additions & 9 deletions web/packages/shared/components/UnifiedResources/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -577,7 +580,7 @@ const IncludedResourcesSelector = ({
Availability
<ChevronDown ml={2} size="small" color="text.slightlyMuted" />
{availabilityFilter.canRequestAll === true &&
availabilityFilter.mode !== 'all' && <FiltersExistIndicator />}
availabilityFilter.mode !== 'none' && <FiltersExistIndicator />}
</ButtonSecondary>
</HoverTooltip>
<Menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ export function UnifiedResources(props: UnifiedResourcesProps) {
) => {
let mode = AvailableResourceMode.UNSPECIFIED;
switch (includedResourceMode) {
case 'none':
mode = AvailableResourceMode.NONE;
break;
case 'accessible':
mode = AvailableResourceMode.ACCESSIBLE;
break;
Expand Down Expand Up @@ -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 };
Expand Down
6 changes: 5 additions & 1 deletion web/packages/shared/components/UnifiedResources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions web/packages/teleport/src/generateResourcePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function convertBackendUserPreferences(
preferences.clusterPreferences
),
unifiedResourcePreferences: {
availableResourceMode: AvailableResourceMode.ALL,
availableResourceMode: AvailableResourceMode.NONE,
...preferences.unifiedResourcePreferences,
},
};
Expand Down

0 comments on commit 9e33013

Please sign in to comment.