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

Add copy to clipboard button in Diagnostics page. #2717

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Panel header="Configuration" v-if="configs" class="border-none max-w-7xl mx-auto">
<pre><div v-for="config in configs" class=" text-muted-color font-mono text-sm">{{ config }}</div>
<pre id="ConfigurationData"><div v-for="config in configs" class=" text-muted-color font-mono text-sm">{{ config }}</div>
</pre>
</Panel>
</template>
Expand All @@ -11,9 +11,14 @@ import DiagnosticsService from "@/services/diagnostics-service";

const configs = ref<string[] | undefined>(undefined);

const emits = defineEmits<{
loaded: [];
}>();

function load() {
DiagnosticsService.config().then((response) => {
configs.value = response.data;
emits("loaded");
});
}

Expand Down
7 changes: 6 additions & 1 deletion resources/js/components/diagnostics/ErrorsDiagnostics.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Panel header="Errors" class="border-none max-w-7xl mx-auto">
<Panel header="Errors" class="border-none max-w-7xl mx-auto" :pt:contentcontainer:id="'ErrorsData'">
<div v-if="!errors" class="text-sky-400 font-bold">Loading...</div>
<div v-else v-for="error in errors" class="flex">
<div class="w-24 capitalize" :class="getCss(error.type)">{{ error.type }}</div>
Expand All @@ -14,9 +14,14 @@ import DiagnosticsService from "@/services/diagnostics-service";

const errors = ref<App.Http.Resources.Diagnostics.ErrorLine[] | undefined>(undefined);

const emits = defineEmits<{
loaded: [];
}>();

function load() {
DiagnosticsService.errors().then((response) => {
errors.value = response.data;
emits("loaded");
});
}

Expand Down
6 changes: 5 additions & 1 deletion resources/js/components/diagnostics/InfoDiagnostics.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Panel header="Info" v-if="infos" class="border-none max-w-7xl mx-auto">
<pre><div v-for="info in infos" class=" text-muted-color font-mono text-sm">{{ info }}</div>
<pre id="InfoData"><div v-for="info in infos" class=" text-muted-color font-mono text-sm">{{ info }}</div>
</pre>
</Panel>
</template>
Expand All @@ -10,10 +10,14 @@ import Panel from "primevue/panel";
import DiagnosticsService from "@/services/diagnostics-service";

const infos = ref<string[] | undefined>(undefined);
const emits = defineEmits<{
loaded: [];
}>();

function load() {
DiagnosticsService.info().then((response) => {
infos.value = response.data;
emits("loaded");
});
}

Expand Down
40 changes: 33 additions & 7 deletions resources/js/views/Diagnostics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
<Toolbar class="w-full border-0 h-14">
<template #start>
<Button @click="togglableStore.toggleLeftMenu" icon="pi pi-bars" class="mr-2 border-none" severity="secondary" text />
<!-- <router-link :to="{ name: 'gallery' }">
<Button icon="pi pi-angle-left" class="mr-2" severity="secondary" text />
</router-link> -->
</template>

<template #center>
{{ $t("lychee.DIAGNOSTICS") }}
</template>

<template #end> </template>
<template #end>
<Button :disabled="!canCopy" text aria-label="Copy" icon="pi pi-copy" v-tooltip="'Copy diagnostics to clipboard'" @click="copy" />
</template>
</Toolbar>
<ErrorsDiagnotics />
<InfoDiagnostics v-if="user?.id" />
<ErrorsDiagnotics @loaded="errorLoaded = true" />
<InfoDiagnostics v-if="user?.id" @loaded="infoLoaded = true" />
<SpaceDiagnostics v-if="user?.id" />
<ConfigurationsDiagnostics v-if="user?.id" />
<ConfigurationsDiagnostics v-if="user?.id" @loaded="configurationLoaded = true" />
</template>
<script setup lang="ts">
import { ref, computed } from "vue";
import Toolbar from "primevue/toolbar";
import Button from "primevue/button";
import ConfigurationsDiagnostics from "@/components/diagnostics/ConfigurationsDiagnostics.vue";
Expand All @@ -28,9 +28,35 @@ import SpaceDiagnostics from "@/components/diagnostics/SpaceDiagnostics.vue";
import { useAuthStore } from "@/stores/Auth";
import { storeToRefs } from "pinia";
import { useTogglablesStateStore } from "@/stores/ModalsState";
import { useToast } from "primevue/usetoast";
const authStore = useAuthStore();
const { user } = storeToRefs(authStore);
authStore.getUser();
const togglableStore = useTogglablesStateStore();
const toast = useToast();
const errorLoaded = ref<boolean>(false);
const infoLoaded = ref<boolean>(false);
const configurationLoaded = ref<boolean>(false);
const canCopy = computed(() => errorLoaded.value && infoLoaded.value && configurationLoaded.value);
function copy() {
const errors = document.getElementById("ErrorsData");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, that's definitely not the way to do it! 💩

it is possible to transmit the data to the outside via the emit
https://vuejs.org/guide/typescript/composition-api#typing-component-emits

Copy link
Member Author

@ildyria ildyria Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but I didn't feel like it. 😆
And that was simpler to "copy" the content that way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's still not the way to do it. The other is more standardized 😄

const info = document.getElementById("InfoData");
const Configuration = document.getElementById("ConfigurationData");
const errorLines = errors?.innerText.split("\n") ?? [];
let errorText = "";
for (let i = 0; i < errorLines.length; i++) {
errorText += `${errorLines[i].padEnd(7)}: ${errorLines[i + 1]}\n`;
i += 1;
ildyria marked this conversation as resolved.
Show resolved Hide resolved
}
const toClipBoard = `Errors:\n${"-".repeat(20)}\n${errorText}\n\n\nInfo:\n${"-".repeat(20)}\n${info?.innerText}\n\n\nConfig:\n${"-".repeat(20)}\n${Configuration?.innerText}`;
navigator.clipboard
.writeText(toClipBoard)
.then(() => toast.add({ severity: "info", summary: "Info", detail: "Diagnostic copied to clipboard", life: 3000 }));
}
</script>
2 changes: 1 addition & 1 deletion resources/js/views/Error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</template>
</template>
<script setup lang="ts">
import { type Ref, ref } from "vue";
import { ref } from "vue";
import Divider from "primevue/divider";
import Message from "primevue/message";
import Panel from "primevue/panel";
Expand Down