提交 89b1fee3 编写于 作者: K Kev

fix: label notes dissapear after submitting a comment

上级 cd9315af
......@@ -482,8 +482,15 @@ export async function validateCIConfig(content: string) {
return validCIConfig;
}
export async function fetchLabelEvents(issuable: RestIssuable) {
let labelEvents: { body: string }[] = [];
interface LabelEvent {
label: unknown;
body: string;
// eslint-disable-next-line camelcase
created_at: string;
}
export async function fetchLabelEvents(issuable: RestIssuable): Promise<LabelEvent[]> {
let labelEvents: LabelEvent[] = [];
try {
const type = issuable.sha ? 'merge_requests' : 'issues';
......@@ -503,8 +510,15 @@ export async function fetchLabelEvents(issuable: RestIssuable) {
return labelEvents;
}
export async function fetchDiscussions(issuable: RestIssuable, page = 1) {
let discussions: unknown[] = [];
interface Discussion {
notes: {
// eslint-disable-next-line camelcase
created_at: string;
}[];
}
export async function fetchDiscussions(issuable: RestIssuable, page = 1): Promise<Discussion[]> {
let discussions: Discussion[] = [];
try {
const type = issuable.sha ? 'merge_requests' : 'issues';
......@@ -579,3 +593,25 @@ export async function saveNote(params: {
return { success: false };
}
type note = Discussion | LabelEvent;
function isLabelEvent(object: any): object is LabelEvent {
return Boolean(object.label);
}
export async function fetchDiscussionsAndLabelEvents(issuable: RestIssuable): Promise<note[]> {
const [discussions, labelEvents] = await Promise.all([
fetchDiscussions(issuable),
fetchLabelEvents(issuable),
]);
const combinedEvents: note[] = [...discussions, ...labelEvents];
combinedEvents.sort((a: note, b: note) => {
const aCreatedAt = isLabelEvent(a) ? a.created_at : a.notes[0].created_at;
const bCreatedAt = isLabelEvent(b) ? b.created_at : b.notes[0].created_at;
return aCreatedAt < bCreatedAt ? -1 : 1;
});
return combinedEvents;
}
......@@ -84,8 +84,8 @@ const createMessageHandler = (panel, issuable, workspaceFolder) => async message
});
if (response.success !== false) {
const newDiscussions = await gitLabService.fetchDiscussions(issuable);
panel.webview.postMessage({ type: 'issuableFetch', issuable, discussions: newDiscussions });
const discussions = await gitLabService.fetchDiscussionsAndLabelEvents(issuable);
panel.webview.postMessage({ type: 'issuableFetch', issuable, discussions });
panel.webview.postMessage({ type: 'noteSaved' });
} else {
panel.webview.postMessage({ type: 'noteSaved', status: false });
......@@ -105,19 +105,9 @@ async function handleChangeViewState(panel, issuable) {
});
});
const [discussions, labelEvents] = await Promise.all([
gitLabService.fetchDiscussions(issuable),
gitLabService.fetchLabelEvents(issuable),
]);
const combinedEvents = discussions.concat(labelEvents);
combinedEvents.sort((a, b) => {
const aCreatedAt = a.label ? a.created_at : a.notes[0].created_at;
const bCreatedAt = b.label ? b.created_at : b.notes[0].created_at;
return aCreatedAt < bCreatedAt ? -1 : 1;
});
const discussonsAndLabels = await gitLabService.fetchDiscussionsAndLabelEvents(issuable);
await appReadyPromise;
panel.webview.postMessage({ type: 'issuableFetch', issuable, discussions: combinedEvents });
panel.webview.postMessage({ type: 'issuableFetch', issuable, discussions: discussonsAndLabels });
}
const getIconPathForIssuable = issuable => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册