Skip to content

Commit da8589f

Browse files
momesginMo Mesgin
andauthored
Hide "View YAML" when "Show configuration" is present (#17663)
* only display view yaml when show configuration is not enabled * fix e2e test --------- Co-authored-by: Mo Mesgin <mmesgin@Mos-M2-MacBook-Pro.local>
1 parent 2b7d450 commit da8589f

3 files changed

Lines changed: 94 additions & 3 deletions

File tree

cypress/e2e/tests/pages/users-and-auth/roles.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ describe('Roles Templates', { tags: ['@usersAndAuths', '@adminUser'] }, () => {
295295

296296
const actionMenu = detailPage.detail().openMastheadActionMenu();
297297

298-
actionMenu.clickMenuItem(5);
298+
actionMenu.clickMenuItem(4);
299299

300300
const promptRemove = new PromptRemove();
301301

shell/plugins/dashboard-store/__tests__/resource-class.test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import Resource from '@shell/plugins/dashboard-store/resource-class.js';
33
import { resourceClassJunkObject } from '@shell/plugins/dashboard-store/__tests__/utils/store-mocks';
44
import { EVENT } from '@shell/config/types';
55

6+
jest.mock('@shell/config/version', () => ({ getVersionData: () => ({ Version: 'v2.13.0' }) }));
7+
jest.mock('@shell/config/uiplugins', () => ({ parseRancherVersion: (v: string) => v }));
8+
jest.mock('@shell/core/plugin-helpers', () => ({ getApplicableExtensionEnhancements: () => [] }));
9+
610
describe('class: Resource', () => {
711
describe('given custom resource keys', () => {
812
const customResource = resourceClassJunkObject;
@@ -497,4 +501,88 @@ describe('class: Resource', () => {
497501
expect(actions[1].variant).toBe('primary');
498502
});
499503
});
504+
505+
describe('getter: _availableActions', () => {
506+
function createResource(links: Record<string, string>, overrides: Record<string, any> = {}) {
507+
const resource = new Resource({
508+
type: 'test-type',
509+
links,
510+
...overrides,
511+
}, {
512+
getters: {
513+
schemaFor: () => ({
514+
linkFor: jest.fn(),
515+
resourceMethods: [],
516+
collectionMethods: [],
517+
}),
518+
},
519+
dispatch: jest.fn(),
520+
rootState: { $extension: { getPlugins: () => ({}) } },
521+
rootGetters: {
522+
'i18n/t': (key: string) => key,
523+
'type-map/hasCustomEdit': () => false,
524+
'type-map/optionsFor': () => ({
525+
isEditable: false, isRemovable: true, isCreatable: false
526+
}),
527+
'prefs/get': () => false,
528+
currentCluster: undefined,
529+
currentProduct: undefined,
530+
...overrides.rootGetters,
531+
},
532+
});
533+
534+
jest.spyOn(resource, 'currentRouter').mockReturnValue({ currentRoute: { value: {} } } as any);
535+
536+
return resource;
537+
}
538+
539+
function findAction(actions: any[], actionName: string) {
540+
return actions.find((a: any) => a.action === actionName);
541+
}
542+
543+
it('should hide "View YAML" when "Show Configuration" is enabled and resource cannot edit YAML', () => {
544+
const resource = createResource({ view: '/api/v1/test' });
545+
546+
const actions = resource._availableActions;
547+
const viewYaml = findAction(actions, 'goToViewYaml');
548+
const showConfig = findAction(actions, 'showConfiguration');
549+
550+
expect(showConfig.enabled).toBe(true);
551+
expect(viewYaml.enabled).toBe(false);
552+
});
553+
554+
it('should show "Edit YAML" even when "Show Configuration" is enabled', () => {
555+
const resource = createResource(
556+
{ view: '/api/v1/test', update: '/api/v1/test' },
557+
{
558+
rootGetters: {
559+
'type-map/optionsFor': () => ({
560+
isEditable: true, isRemovable: true, isCreatable: false
561+
})
562+
}
563+
},
564+
);
565+
566+
const actions = resource._availableActions;
567+
const editYaml = findAction(actions, 'goToEditYaml');
568+
const showConfig = findAction(actions, 'showConfiguration');
569+
570+
expect(showConfig.enabled).toBe(true);
571+
expect(editYaml.enabled).toBe(true);
572+
});
573+
574+
it('should show "View YAML" when "Show Configuration" is not enabled', () => {
575+
const resource = createResource(
576+
{ view: '/api/v1/test' },
577+
{ disableResourceDetailDrawer: true },
578+
);
579+
580+
const actions = resource._availableActions;
581+
const viewYaml = findAction(actions, 'goToViewYaml');
582+
const showConfig = findAction(actions, 'showConfiguration');
583+
584+
expect(showConfig.enabled).toBe(false);
585+
expect(viewYaml.enabled).toBe(true);
586+
});
587+
});
500588
});

shell/plugins/dashboard-store/resource-class.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,15 @@ export default class Resource {
946946
// where mostly likely extension CRD model is extending from resource-class
947947
const isResourceDetailDrawerCompatibleWithRancherSystem = semver.satisfies(parsedRancherVersion, '>= 2.13.0');
948948

949+
// If the resource can't show an edit or a yaml we don't want to show the configuration drawer
950+
const showConfigEnabled = isResourceDetailDrawerCompatibleWithRancherSystem && this.disableResourceDetailDrawer !== true && (this.canCustomEdit || this.canYaml);
951+
949952
const all = [
950953
{
951954
action: 'showConfiguration',
952955
label: this.t('action.showConfiguration'),
953956
icon: 'icon icon-document',
954-
enabled: isResourceDetailDrawerCompatibleWithRancherSystem && this.disableResourceDetailDrawer !== true && (this.canCustomEdit || this.canYaml), // If the resource can't show an edit or a yaml we don't want to show the configuration drawer
957+
enabled: showConfigEnabled,
955958
},
956959
{ divider: true },
957960
{
@@ -964,7 +967,7 @@ export default class Resource {
964967
action: this.canEditYaml ? 'goToEditYaml' : 'goToViewYaml',
965968
label: this.t(this.canEditYaml ? 'action.editYaml' : 'action.viewYaml'),
966969
icon: 'icon icon-file',
967-
enabled: this.canYaml,
970+
enabled: this.canYaml && (this.canEditYaml || !showConfigEnabled), // Hide "View YAML" when "Show Configuration" is available since it already includes YAML viewing
968971
},
969972
{
970973
action: (this.canCustomEdit ? 'goToClone' : 'cloneYaml'),

0 commit comments

Comments
 (0)