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

Create new ButtonMultiAction.vue component #12045

Merged
merged 3 commits into from
Sep 27, 2024
Merged
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
41 changes: 41 additions & 0 deletions shell/components/ButtonMultiAction.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script setup lang="ts">
import { computed, defineEmits } from 'vue';

defineEmits(['click']);

type Props = {
borderless?: boolean;
invisible?: boolean;
}

const props = defineProps<Props>();

const buttonClass = computed(() => {
return {
borderless: props?.borderless,
invisible: props?.invisible,
};
});
cnotv marked this conversation as resolved.
Show resolved Hide resolved
</script>

<template>
<button
type="button"
class="btn btn-sm role-multi-action actions"
:class="buttonClass"
@click="(e: Event) => $emit('click', e)"
>
<i class="icon icon-actions" />
</button>
</template>

<style lang="scss" scoped>
.borderless {
background-color: transparent;
border: none;
&:hover, &:focus {
background-color: var(--accent-btn);
box-shadow: none;
}
}
</style>
19 changes: 11 additions & 8 deletions shell/components/ExplorerProjectsNamespaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ExtensionPanel from '@shell/components/ExtensionPanel';
import Masthead from '@shell/components/ResourceList/Masthead';
import { mapPref, GROUP_RESOURCES, ALL_NAMESPACES } from '@shell/store/prefs';
import MoveModal from '@shell/components/MoveModal';
import ButtonMultiAction from '@shell/components/ButtonMultiAction.vue';

import { NAMESPACE_FILTER_ALL_ORPHANS } from '@shell/utils/namespace-filter';
import ResourceFetch from '@shell/mixins/resource-fetch';
Expand All @@ -18,7 +19,11 @@ import DOMPurify from 'dompurify';
export default {
name: 'ListProjectNamespace',
components: {
ExtensionPanel, Masthead, MoveModal, ResourceTable
ExtensionPanel,
Masthead,
MoveModal,
ResourceTable,
ButtonMultiAction,
},
mixins: [ResourceFetch],

Expand Down Expand Up @@ -430,14 +435,12 @@ export default {
>
{{ t('projectNamespaces.createNamespace') }}
</router-link>
<button
type="button"
class="project-action btn btn-sm role-multi-action actions mr-10"
:class="{invisible: !showProjectActionButton(group.group)}"
<ButtonMultiAction
class="project-action mr-10"
:borderless="true"
:invisible="!showProjectActionButton(group.group)"
@click="showProjectAction($event, group.group)"
>
<i class="icon icon-actions" />
</button>
/>
</div>
</div>
</template>
Expand Down
29 changes: 11 additions & 18 deletions shell/components/SortableTable/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import AdvancedFiltering from './advanced-filtering';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import { getParent } from '@shell/utils/dom';
import { FORMATTERS } from '@shell/components/SortableTable/sortable-config';
import ButtonMultiAction from '@shell/components/ButtonMultiAction.vue';

// Uncomment for table performance debugging
// import tableDebug from './debug';
Expand All @@ -44,7 +45,12 @@ export default {
emits: ['clickedActionButton', 'pagination-changed', 'group-value-change', 'selection', 'rowClick'],

components: {
THead, Checkbox, AsyncButton, ActionDropdown, LabeledSelect
THead,
Checkbox,
AsyncButton,
ActionDropdown,
LabeledSelect,
ButtonMultiAction,
},
mixins: [
filtering,
Expand Down Expand Up @@ -1415,18 +1421,15 @@ export default {
name="row-actions"
:row="row.row"
>
<button
<ButtonMultiAction
:id="`actionButton+${i}+${(row.row && row.row.name) ? row.row.name : ''}`"
:ref="`actionButton${i}`"
:data-testid="componentTestid + '-' + i + '-action-button'"
aria-haspopup="true"
aria-expanded="false"
type="button"
class="btn btn-sm role-multi-action actions"
:data-testid="componentTestid + '-' + i + '-action-button'"
:borderless="true"
@click="handleActionButtonClick(i, $event)"
>
<i class="icon icon-actions" />
</button>
/>
</slot>
</td>
</tr>
Expand Down Expand Up @@ -1661,17 +1664,7 @@ export default {
}
}

// Remove colors from multi-action buttons in the table
td {
.actions.role-multi-action {
background-color: transparent;
border: none;
&:hover, &:focus {
background-color: var(--accent-btn);
box-shadow: none;
}
}

// Aligns with COLUMN_BREAKPOINTS
@media only screen and (max-width: map-get($breakpoints, '--viewport-4')) {
// HIDE column on sizes below 480px
Expand Down
31 changes: 31 additions & 0 deletions shell/components/__tests__/ButtonMultiAction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { shallowMount } from '@vue/test-utils';
import ButtonMultiAction from '@shell/components/ButtonMultiAction.vue';

describe('buttonMultiAction.vue', () => {
it('renders correct classes when props are provided', () => {
const wrapper = shallowMount(ButtonMultiAction, {
props: {
borderless: true,
invisible: true,
},
});

expect(wrapper.find('button').classes()).toContain('borderless');
expect(wrapper.find('button').classes()).toContain('invisible');
});

it('renders correct classes when props are absent', () => {
const wrapper = shallowMount(ButtonMultiAction);

expect(wrapper.find('button').classes()).not.toContain('borderless');
expect(wrapper.find('button').classes()).not.toContain('invisible');
});

it('emits click event when button is clicked', () => {
const wrapper = shallowMount(ButtonMultiAction);

wrapper.find('button').trigger('click');

expect(wrapper.emitted('click')).toBeTruthy();
});
});
Loading