2024-07-07 09:32:30 -06:00
|
|
|
<script lang="ts">
|
|
|
|
import {SvgIcon} from '../svg.ts';
|
|
|
|
import {GET} from '../modules/fetch.ts';
|
2021-07-13 12:09:19 -06:00
|
|
|
|
2021-12-28 06:28:27 -07:00
|
|
|
const {appSubUrl, i18n} = window.config;
|
2021-07-13 12:09:19 -06:00
|
|
|
|
|
|
|
export default {
|
2022-12-23 09:03:11 -07:00
|
|
|
components: {SvgIcon},
|
2021-07-13 12:09:19 -06:00
|
|
|
data: () => ({
|
|
|
|
loading: false,
|
2021-12-28 06:28:27 -07:00
|
|
|
issue: null,
|
2024-04-29 20:36:32 -06:00
|
|
|
renderedLabels: '',
|
2021-12-28 06:28:27 -07:00
|
|
|
i18nErrorOccurred: i18n.error_occurred,
|
|
|
|
i18nErrorMessage: null,
|
2021-07-13 12:09:19 -06:00
|
|
|
}),
|
|
|
|
computed: {
|
|
|
|
createdAt() {
|
|
|
|
return new Date(this.issue.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'});
|
|
|
|
},
|
|
|
|
|
|
|
|
body() {
|
|
|
|
const body = this.issue.body.replace(/\n+/g, ' ');
|
|
|
|
if (body.length > 85) {
|
|
|
|
return `${body.substring(0, 85)}…`;
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
},
|
|
|
|
|
|
|
|
icon() {
|
|
|
|
if (this.issue.pull_request !== null) {
|
|
|
|
if (this.issue.state === 'open') {
|
2024-02-04 15:37:45 -07:00
|
|
|
if (this.issue.pull_request.draft === true) {
|
|
|
|
return 'octicon-git-pull-request-draft'; // WIP PR
|
|
|
|
}
|
2021-07-13 12:09:19 -06:00
|
|
|
return 'octicon-git-pull-request'; // Open PR
|
|
|
|
} else if (this.issue.pull_request.merged === true) {
|
|
|
|
return 'octicon-git-merge'; // Merged PR
|
|
|
|
}
|
|
|
|
return 'octicon-git-pull-request'; // Closed PR
|
|
|
|
} else if (this.issue.state === 'open') {
|
|
|
|
return 'octicon-issue-opened'; // Open Issue
|
|
|
|
}
|
|
|
|
return 'octicon-issue-closed'; // Closed Issue
|
|
|
|
},
|
|
|
|
|
|
|
|
color() {
|
2024-02-04 15:37:45 -07:00
|
|
|
if (this.issue.pull_request !== null) {
|
|
|
|
if (this.issue.pull_request.draft === true) {
|
|
|
|
return 'grey'; // WIP PR
|
|
|
|
} else if (this.issue.pull_request.merged === true) {
|
|
|
|
return 'purple'; // Merged PR
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 12:09:19 -06:00
|
|
|
if (this.issue.state === 'open') {
|
2024-02-04 15:37:45 -07:00
|
|
|
return 'green'; // Open Issue
|
2021-07-13 12:09:19 -06:00
|
|
|
}
|
2024-02-04 15:37:45 -07:00
|
|
|
return 'red'; // Closed Issue
|
2021-07-13 12:09:19 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
2023-03-05 07:23:42 -07:00
|
|
|
this.$refs.root.addEventListener('ce-load-context-popup', (e) => {
|
2022-10-01 08:26:38 -06:00
|
|
|
const data = e.detail;
|
2021-07-13 12:09:19 -06:00
|
|
|
if (!this.loading && this.issue === null) {
|
2022-10-01 08:26:38 -06:00
|
|
|
this.load(data);
|
2021-07-13 12:09:19 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
2024-02-24 05:03:53 -07:00
|
|
|
async load(data) {
|
2021-07-13 12:09:19 -06:00
|
|
|
this.loading = true;
|
2021-12-28 06:28:27 -07:00
|
|
|
this.i18nErrorMessage = null;
|
2024-02-24 05:03:53 -07:00
|
|
|
|
|
|
|
try {
|
2024-04-29 20:36:32 -06:00
|
|
|
const response = await GET(`${appSubUrl}/${data.owner}/${data.repo}/issues/${data.index}/info`); // backend: GetIssueInfo
|
2024-02-24 05:03:53 -07:00
|
|
|
const respJson = await response.json();
|
|
|
|
if (!response.ok) {
|
|
|
|
this.i18nErrorMessage = respJson.message ?? i18n.network_error;
|
|
|
|
return;
|
2021-12-28 06:28:27 -07:00
|
|
|
}
|
2024-04-29 20:36:32 -06:00
|
|
|
this.issue = respJson.convertedIssue;
|
|
|
|
this.renderedLabels = respJson.renderedLabels;
|
2024-02-24 05:03:53 -07:00
|
|
|
} catch {
|
|
|
|
this.i18nErrorMessage = i18n.network_error;
|
|
|
|
} finally {
|
2021-07-13 12:09:19 -06:00
|
|
|
this.loading = false;
|
2024-02-24 05:03:53 -07:00
|
|
|
}
|
2024-03-22 08:06:53 -06:00
|
|
|
},
|
|
|
|
},
|
2021-07-13 12:09:19 -06:00
|
|
|
};
|
|
|
|
</script>
|
2023-09-02 08:59:07 -06:00
|
|
|
<template>
|
|
|
|
<div ref="root">
|
2024-03-27 14:18:04 -06:00
|
|
|
<div v-if="loading" class="tw-h-12 tw-w-12 is-loading"/>
|
2024-05-02 07:42:33 -06:00
|
|
|
<div v-if="!loading && issue !== null" class="tw-flex tw-flex-col tw-gap-2">
|
|
|
|
<div class="tw-text-12">{{ issue.repository.full_name }} on {{ createdAt }}</div>
|
|
|
|
<div class="flex-text-block">
|
|
|
|
<svg-icon :name="icon" :class="['text', color]"/>
|
|
|
|
<span class="issue-title tw-font-semibold tw-break-anywhere">
|
|
|
|
{{ issue.title }}
|
|
|
|
<span class="index">#{{ issue.number }}</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div v-if="body">{{ body }}</div>
|
2024-04-29 20:36:32 -06:00
|
|
|
<!-- eslint-disable-next-line vue/no-v-html -->
|
2024-05-02 07:42:33 -06:00
|
|
|
<div v-if="issue.labels.length" v-html="renderedLabels"/>
|
2023-09-02 08:59:07 -06:00
|
|
|
</div>
|
2024-05-02 07:42:33 -06:00
|
|
|
<div class="tw-flex tw-flex-col tw-gap-2" v-if="!loading && issue === null">
|
|
|
|
<div class="tw-text-12">{{ i18nErrorOccurred }}</div>
|
|
|
|
<div>{{ i18nErrorMessage }}</div>
|
2023-09-02 08:59:07 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|