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

Replace extension menu with ActionMenuShell.vue #13505

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions shell/components/ActionMenuShell.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<script setup lang="ts">
import { computed } from 'vue';
import { useStore } from 'vuex';
import { useRoute } from 'vue-router';

import { isAlternate } from '@shell/utils/platform';
import { RcDropdownMenu } from '@components/RcDropdown';
import { ButtonRoleProps, ButtonSizeProps } from '@components/RcButton/types';
import { DropdownOption } from '@components/RcDropdown/types';

const store = useStore();

const options = computed(() => store.getters['action-menu/optionsArray']);

type RcDropdownMenuComponentProps = {
buttonRole?: keyof ButtonRoleProps;
buttonSize?: keyof ButtonSizeProps;
buttonAriaLabel?: string;
dropdownAriaLabel?: string;
dataTestid?: string;
resource: Object;
customActions?: DropdownOption[];
}

const props = defineProps <RcDropdownMenuComponentProps>();
Expand All @@ -27,6 +28,9 @@ const openChanged = (event: boolean) => {
}
};

const emit = defineEmits<{(event: string, payload: any): void}>();
const route = useRoute();

const execute = (action: any, event: MouseEvent, args?: any) => {
if (action.disabled) {
return;
Expand All @@ -48,6 +52,23 @@ const execute = (action: any, event: MouseEvent, args?: any) => {
fn.apply(this, [opts, resources]);
}
}
} else if (props.customActions) {
// If the state of this component is controlled
// by props instead of Vuex, we assume you wouldn't want
// the mutation to have a dependency on Vuex either.
// So in that case we use events to execute actions instead.
// If an action list item is clicked, this
// component emits that event, then we assume the parent
// component will execute the action.
emit(
action.action,
{
action,
event,
...args,
route,
}
);
} else {
// If the state of this component is controlled
// by Vuex, mutate the store when an action is clicked.
Expand All @@ -58,6 +79,16 @@ const execute = (action: any, event: MouseEvent, args?: any) => {
});
}
};

const options = computed(() => store.getters['action-menu/optionsArray']);

const menuOptions = () => {
if (props.customActions && props.customActions.length > 0) {
return props.customActions;
}

return options.value;
};
</script>

<template>
Expand All @@ -66,7 +97,7 @@ const execute = (action: any, event: MouseEvent, args?: any) => {
:button-size="buttonSize || 'small'"
:button-aria-label="buttonAriaLabel"
:dropdown-aria-label="dropdownAriaLabel"
:options="options"
:options="menuOptions()"
:data-testid="dataTestid"
@update:open="openChanged"
@select="(e: MouseEvent, option: object) => execute(option, e)"
Expand Down
22 changes: 4 additions & 18 deletions shell/pages/c/_cluster/uiplugins/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { fetchOrCreateSetting } from '@shell/utils/settings';
import { getVersionData, isRancherPrime } from '@shell/config/version';
import { CATALOG as CATALOG_ANNOTATIONS } from '@shell/config/labels-annotations';
import { NAME as APP_PRODUCT } from '@shell/config/product/apps';
import ActionMenu from '@shell/components/ActionMenu';
import ActionMenu from '@shell/components/ActionMenuShell';
import Tabbed from '@shell/components/Tabbed/index.vue';
import Tab from '@shell/components/Tabbed/Tab.vue';
import IconMessage from '@shell/components/IconMessage.vue';
Expand Down Expand Up @@ -688,25 +688,11 @@ export default {
</div>
<!-- extensions menu -->
<div v-if="hasFeatureFlag && hasMenuActions">
<button
ref="actions"
aria-haspopup="true"
type="button"
class="btn role-multi-action actions"
data-testid="extensions-page-menu"
role="button"
:aria-label="t('plugins.labels.menu')"
@click="setMenu"
>
<i class="icon icon-actions" />
</button>
<ActionMenu
data-testid="extensions-page-menu"
button-role="tertiary"
:button-aria-label="t('plugins.labels.menu')"
:custom-actions="menuActions"
:open="menuOpen"
:use-custom-target-element="true"
:custom-target-element="menuTargetElement"
:custom-target-event="menuTargetEvent"
@close="setMenu(false)"
@devLoad="showDeveloperLoadDialog"
@manageRepos="manageRepos"
@addRancherRepos="showAddExtensionReposDialog"
Expand Down
2 changes: 1 addition & 1 deletion shell/store/action-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getters = {
const map = {};

for ( const node of selected ) {
if (node.availableActions) {
if (node?.availableActions) {
for ( const act of node.availableActions ) {
_add(map, act);
}
Expand Down
Loading