Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ Adds option to open workspace sidebar items in new tab

github-actions[bot]11366783b1e1
diff --git a/src/components/Workspace/SideBarItem.vue b/src/components/Workspace/SideBarItem.vue
index 4bfc7f6a..598a541b 100644
--- a/src/components/Workspace/SideBarItem.vue
+++ b/src/components/Workspace/SideBarItem.vue
@@ -1,14 +1,28 @@
<template>
- <div @click="itemClicked()"
- :class="`side-bar-item ${icon ? 'w-icon' : 'text-only'}`" v-tooltip="tooltip">
+ <div
+ @click="itemClicked($event)"
+ @auxclick="itemAuxClicked($event)"
+ :class="`side-bar-item ${icon ? 'w-icon' : 'text-only'}`"
+ v-tooltip="tooltip"
+ >
<Icon v-if="icon" :icon="icon" size="small" :url="url" />
<p class="small-title" v-else>{{ title }}</p>
+ <button
+ v-if="url"
+ class="popout-btn"
+ :title="$t ? $t('context-menus.item.newtab') : 'Open in new tab'"
+ :aria-label="$t ? $t('context-menus.item.newtab') : 'Open in new tab'"
+ @click.stop="openInNewTab($event)"
+ >
+ <NewTabOpenIcon />
+ </button>
</div>
</template>
<script>
import Icon from '@/components/LinkItems/ItemIcon.vue';
+import NewTabOpenIcon from '@/assets/interface-icons/open-new-tab.svg';
export default {
name: 'SideBarItem',
@@ -22,18 +36,31 @@ export default {
emits: ['launch-app'],
components: {
Icon,
+ NewTabOpenIcon,
},
methods: {
- itemClicked() {
+ itemClicked(e) {
+ if (e && (e.ctrlKey || e.metaKey)) {
+ this.openInNewTab(e);
+ return;
+ }
if (this.url) this.$emit('launch-app', { url: this.url, target: this.target });
},
+ itemAuxClicked(e) {
+ if (e && e.button === 1) {
+ this.openInNewTab(e);
+ }
+ },
+ openInNewTab(e) {
+ if (e && e.preventDefault) e.preventDefault();
+ if (this.url) window.open(this.url, '_blank');
+ },
},
data() {
return {
tooltip: {
disabled: !this.title,
content: this.title,
-
placement: 'bottom-end',
},
};
@@ -44,6 +71,7 @@ export default {
<style lang="scss" scoped>
div.side-bar-item {
+ position: relative;
color: var(--side-bar-item-color);
background: var(--side-bar-item-background);
text-align: center;
@@ -58,5 +86,35 @@ div.side-bar-item {
padding: 0.5rem 0;
}
}
+
+ .popout-btn {
+ display: none;
+ position: absolute;
+ top: 50%;
+ right: 4px;
+ transform: translateY(-50%);
+ background: none;
+ border: none;
+ cursor: pointer;
+ padding: 2px;
+ color: currentColor;
+ opacity: 0.7;
+ border-radius: var(--curve-factor, 4px);
+ transition: opacity 0.15s ease-in-out, background 0.15s ease-in-out;
+ &:hover {
+ opacity: 1;
+ background: rgba(255, 255, 255, 0.15);
+ }
+ svg {
+ width: 0.75rem;
+ height: 0.75rem;
+ }
+ }
+
+ &:hover .popout-btn {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ }
}
</style>
diff --git a/tests/components/sidebar-item.test.js b/tests/components/sidebar-item.test.js
new file mode 100644
index 00000000..ed98795b
--- /dev/null
+++ b/tests/components/sidebar-item.test.js
@@ -0,0 +1,95 @@
+import {
+ describe, it, expect, beforeEach, afterEach, vi,
+} from 'vitest';
+import { shallowMount } from '@vue/test-utils';
+import SideBarItem from '@/components/Workspace/SideBarItem.vue';
+
+function mountItem(props = {}) {
+ return shallowMount(SideBarItem, {
+ props,
+ global: {
+ directives: {
+ tooltip: {},
+ },
+ mocks: {
+ $t: (key) => key,
+ },
+ stubs: {
+ Icon: true,
+ NewTabOpenIcon: true,
+ },
+ },
+ });
+}
+
+describe('SideBarItem', () => {
+ let openSpy;
+
+ beforeEach(() => {
+ openSpy = vi.spyOn(window, 'open').mockImplementation(() => {});
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it('renders icon when icon prop is provided', () => {
+ const wrapper = mountItem({ icon: 'fas fa-server', title: 'Server' });
+ expect(wrapper.classes()).toContain('w-icon');
+ expect(wrapper.findComponent({ name: 'Icon' }).exists()).toBe(true);
+ expect(wrapper.find('p.small-title').exists()).toBe(false);
+ });
+
+ it('renders title as small-title when icon is empty', () => {
+ const wrapper = mountItem({ title: 'No Icon App' });
+ expect(wrapper.classes()).toContain('text-only');
+ expect(wrapper.find('p.small-title').exists()).toBe(true);
+ expect(wrapper.find('p.small-title').text()).toBe('No Icon App');
+ });
+
+ it('does not render popout button when url is not set', () => {
+ const wrapper = mountItem({ title: 'Section Header' });
+ expect(wrapper.find('.popout-btn').exists()).toBe(false);
+ });
+
+ it('renders popout button when url is provided', () => {
+ const wrapper = mountItem({ title: 'App', url: 'https://example.com' });
+ expect(wrapper.find('.popout-btn').exists()).toBe(true);
+ });
+
+ it('emits launch-app on normal click', async () => {
+ const wrapper = mountItem({ title: 'App', url: 'https://example.com', target: 'workspace' });
+ await wrapper.trigger('click');
+ expect(wrapper.emitted('launch-app')).toBeTruthy();
+ expect(wrapper.emitted('launch-app')[0]).toEqual([{ url: 'https://example.com', target: 'workspace' }]);
+ expect(openSpy).not.toHaveBeenCalled();
+ });
+
+ it('opens in new tab on popout button click without emitting launch-app', async () => {
+ const wrapper = mountItem({ title: 'App', url: 'https://example.com', target: 'workspace' });
+ const popoutBtn = wrapper.find('.popout-btn');
+ expect(popoutBtn.exists()).toBe(true);
+ await popoutBtn.trigger('click');
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ expect(wrapper.emitted('launch-app')).toBeFalsy();
+ });
+
+ it('opens in new tab when clicked with ctrlKey or metaKey', async () => {
+ const wrapper = mountItem({ title: 'App', url: 'https://example.com', target: 'workspace' });
+ await wrapper.trigger('click', { ctrlKey: true });
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ expect(wrapper.emitted('launch-app')).toBeFalsy();
+
+ openSpy.mockClear();
+
+ await wrapper.trigger('click', { metaKey: true });
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ expect(wrapper.emitted('launch-app')).toBeFalsy();
+ });
+
+ it('opens in new tab when middle clicked (auxclick button 1)', async () => {
+ const wrapper = mountItem({ title: 'App', url: 'https://example.com', target: 'workspace' });
+ await wrapper.trigger('auxclick', { button: 1 });
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ });
+});