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

Fix issue label rendering in the issue popup #30763

Merged
merged 5 commits into from
Apr 30, 2024
Merged
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
5 changes: 4 additions & 1 deletion routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,10 @@ func GetIssueInfo(ctx *context.Context) {
}
}

ctx.JSON(http.StatusOK, convert.ToIssue(ctx, ctx.Doer, issue))
ctx.JSON(http.StatusOK, map[string]any{
"convertedIssue": convert.ToIssue(ctx, ctx.Doer, issue),
"renderedLabels": templates.RenderLabels(ctx, ctx.Locale, issue.Labels, ctx.Repo.RepoLink, issue),
})
}

// UpdateIssueTitle change issue's title
Expand Down
27 changes: 6 additions & 21 deletions web_src/js/components/ContextPopup.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import {SvgIcon} from '../svg.js';
import {contrastColor} from '../utils/color.js';
import {GET} from '../modules/fetch.js';

const {appSubUrl, i18n} = window.config;
Expand All @@ -10,6 +9,7 @@ export default {
data: () => ({
loading: false,
issue: null,
renderedLabels: '',
i18nErrorOccurred: i18n.error_occurred,
i18nErrorMessage: null,
}),
Expand Down Expand Up @@ -56,14 +56,6 @@ export default {
}
return 'red'; // Closed Issue
},

labels() {
return this.issue.labels.map((label) => ({
name: label.name,
color: `#${label.color}`,
textColor: contrastColor(`#${label.color}`),
}));
},
},
mounted() {
this.$refs.root.addEventListener('ce-load-context-popup', (e) => {
Expand All @@ -79,13 +71,14 @@ export default {
this.i18nErrorMessage = null;

try {
const response = await GET(`${appSubUrl}/${data.owner}/${data.repo}/issues/${data.index}/info`);
const response = await GET(`${appSubUrl}/${data.owner}/${data.repo}/issues/${data.index}/info`); // backend: GetIssueInfo
const respJson = await response.json();
if (!response.ok) {
this.i18nErrorMessage = respJson.message ?? i18n.network_error;
return;
}
this.issue = respJson;
this.issue = respJson.convertedIssue;
this.renderedLabels = respJson.renderedLabels;
} catch {
this.i18nErrorMessage = i18n.network_error;
} finally {
Expand All @@ -102,16 +95,8 @@ export default {
<p><small>{{ issue.repository.full_name }} on {{ createdAt }}</small></p>
<p><svg-icon :name="icon" :class="['text', color]"/> <strong>{{ issue.title }}</strong> #{{ issue.number }}</p>
<p>{{ body }}</p>
<div class="labels-list">
<div
v-for="label in labels"
:key="label.name"
class="ui label"
:style="{ color: label.textColor, backgroundColor: label.color }"
>
{{ label.name }}
</div>
</div>
<!-- eslint-disable-next-line vue/no-v-html -->
<div v-html="renderedLabels" />
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div v-if="!loading && issue === null">
<p><small>{{ i18nErrorOccurred }}</small></p>
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/common-issue-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function initCommonIssueListQuickGoto() {
// try to check whether the parsed goto link is valid
let targetUrl = parseIssueListQuickGotoLink(repoLink, searchText);
if (targetUrl) {
const res = await GET(`${targetUrl}/info`);
const res = await GET(`${targetUrl}/info`); // backend: GetIssueInfo, it only checks whether the issue exists by status code
if (res.status !== 200) targetUrl = '';
}
// if the input value has changed, then ignore the result
Expand Down
Loading