Skip to content

Commit 3c29b97

Browse files
luannmoreiragustavosbarreto
authored andcommitted
feat(ui): add SSH connection options to Connect button
Refactored TerminalConnectButton to include a button group with a dropdown menu for selecting connection methods. Added support for SSH ID prop and a TerminalHelper component to assist users. Updated DeviceTable and DetailsDevice to pass sshid prop. Adjusted tests and snapshots accordingly.
1 parent ca80f3e commit 3c29b97

20 files changed

+1556
-993
lines changed

ui/src/components/QuickConnection/QuickConnectionList.vue

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<v-card :key="i" data-test="device-card">
2121
<v-list-item
2222
@click="openDialog(item.uid)"
23+
@keydown="openTerminalMacro(item)"
2324
:key="i"
2425
class="ma-0 pa-0 card"
2526
data-test="device-list-item"
@@ -39,22 +40,22 @@
3940
<CopyWarning
4041
ref="copyRef"
4142
:copied-item="'Device SSHID'"
43+
:bypass="shouldOpenTerminalHelper()"
4244
:macro="sshidAddress(item)"
4345
>
4446
<template #default="{ copyText }">
4547
<span
4648
v-bind="props"
4749
tabindex="0"
4850
class="hover-text"
49-
@click.stop="copyText(sshidAddress(item))"
50-
@keydown.enter.stop="copyText(sshidAddress(item))"
51+
@click.stop="handleSshidClick(item, copyText)"
52+
@keypress.enter.stop="handleSshidClick(item, copyText)"
5153
data-test="copy-id-button"
5254
>
5355
{{ sshidAddress(item) }}
5456
</span>
5557
</template>
5658
</CopyWarning>
57-
5859
</template>
5960
<span>Copy ID</span>
6061
</v-tooltip>
@@ -85,7 +86,13 @@
8586
</v-card>
8687
</v-col>
8788
</v-list>
88-
89+
<TerminalHelper
90+
v-if="showTerminalHelper"
91+
v-model="showTerminalHelper"
92+
:sshid="selectedSshid"
93+
:user-id="userId"
94+
:show-checkbox="true"
95+
/>
8996
<TerminalDialog
9097
v-model="showDialog"
9198
:deviceUid="selectedDeviceUid"
@@ -96,29 +103,33 @@
96103
<script setup lang="ts">
97104
import { ref, onMounted, computed, watch } from "vue";
98105
import { VList } from "vuetify/components";
106+
import { useMagicKeys } from "@vueuse/core";
99107
import TerminalDialog from "../Terminal/TerminalDialog.vue";
108+
import TerminalHelper from "../Terminal/TerminalHelper.vue";
109+
import CopyWarning from "@/components/User/CopyWarning.vue";
100110
import { useStore } from "@/store";
101111
import { displayOnlyTenCharacters } from "@/utils/string";
102112
import showTag from "@/utils/tag";
103113
import DeviceIcon from "../Devices/DeviceIcon.vue";
104114
import handleError from "@/utils/handleError";
105115
import { IDevice } from "@/interfaces/IDevice";
106116
import useSnackbar from "@/helpers/snackbar";
107-
import CopyWarning from "@/components/User/CopyWarning.vue";
108117
109118
interface Device {
110119
online: boolean
111120
}
112121
113122
const store = useStore();
114123
const snackbar = useSnackbar();
115-
const copyRef = ref<InstanceType<typeof CopyWarning> | null>(null);
116124
const loading = ref(false);
117125
const itemsPerPage = ref(10);
118126
const page = ref();
119127
const rootEl = ref<VList>();
120128
const selectedDeviceUid = ref("");
121129
const showDialog = ref(false);
130+
const showTerminalHelper = ref(false);
131+
const selectedSshid = ref("");
132+
const userId = computed(() => store.getters["auth/id"]);
122133
123134
defineExpose({ rootEl });
124135
@@ -187,6 +198,43 @@ watch(itemsPerPage, async () => {
187198
});
188199
189200
const sshidAddress = (item: IDevice) => `${item.namespace}.${item.name}@${window.location.hostname}`;
201+
202+
const openTerminalHelper = (item: IDevice) => {
203+
selectedSshid.value = sshidAddress(item);
204+
showTerminalHelper.value = true;
205+
};
206+
207+
const shouldOpenTerminalHelper = () => {
208+
try {
209+
const dispensedUsers = JSON.parse(localStorage.getItem("dispenseTerminalHelper") || "[]");
210+
return !dispensedUsers.includes(userId.value);
211+
} catch {
212+
return true;
213+
}
214+
};
215+
216+
const handleSshidClick = (item: IDevice, copyFn: (text: string) => void) => {
217+
if (shouldOpenTerminalHelper()) {
218+
openTerminalHelper(item);
219+
return;
220+
}
221+
copyFn(sshidAddress(item));
222+
};
223+
224+
const openTerminalMacro = (value: IDevice) => {
225+
let executed = false;
226+
227+
return useMagicKeys({
228+
passive: false,
229+
onEventFired(e) {
230+
if (!executed && value && e.ctrlKey && e.key === "c" && e.type === "keydown") {
231+
executed = true;
232+
openTerminalHelper(value);
233+
e.preventDefault();
234+
}
235+
},
236+
});
237+
};
190238
</script>
191239

192240
<style scoped>

0 commit comments

Comments
 (0)