Skip to content

Commit

Permalink
Merge pull request #6085 from gitbutlerapp/e-branch-12
Browse files Browse the repository at this point in the history
Display the users that commented on a review
  • Loading branch information
estib-vega authored Jan 27, 2025
2 parents 2c179bb + eb3d503 commit addf1e4
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 6 deletions.
30 changes: 28 additions & 2 deletions apps/web/src/lib/components/review/ReviewInfo.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
<script lang="ts">
import ChangeStatus from '../changes/ChangeStatus.svelte';
import {
getCommentersWithAvatars,
getPatchContributorsWithAvatars,
getPatchReviewersWithAvatars,
type Patch
} from '@gitbutler/shared/branches/types';
import { getChatChannelParticipants } from '@gitbutler/shared/chat/chatChannelsPreview.svelte';
import { ChatChannelsService } from '@gitbutler/shared/chat/chatChannelsService';
import { getContext } from '@gitbutler/shared/context';
import { AppState } from '@gitbutler/shared/redux/store.svelte';
import AvatarGroup from '@gitbutler/ui/avatar/AvatarGroup.svelte';
const NO_REVIEWERS = 'Not reviewed yet';
const NO_CONTRIBUTORS = 'No contributors';
const NO_COMMENTS = 'No comments yet';
interface Props {
projectId: string;
patch: Patch;
}
const { patch }: Props = $props();
const { patch, projectId }: Props = $props();
const appState = getContext(AppState);
const chatChannelService = getContext(ChatChannelsService);
const chatParticipants = getChatChannelParticipants(
appState,
chatChannelService,
projectId,
patch.changeId
);
const commenters = $derived(
chatParticipants.current === undefined
? Promise.resolve([])
: getCommentersWithAvatars(chatParticipants.current)
);
const contributors = $derived(getPatchContributorsWithAvatars(patch));
const reviewers = $derived(getPatchReviewersWithAvatars(patch));
</script>
Expand All @@ -42,7 +62,13 @@

<div class="review-main-content-info__entry">
<p class="review-main-content-info__header">Commented by:</p>
<p class="review-main-content-info__value">{NO_COMMENTS}</p>
{#await commenters then commentors}
{#if commentors.length === 0}
<p class="review-main-content-info__value">{NO_COMMENTS}</p>
{:else}
<AvatarGroup avatars={commentors}></AvatarGroup>
{/if}
{/await}
</div>

<div class="review-main-content-info__entry">
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/lib/diffParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function lineType(line: string): SectionType {

export function parsePatch(patch: string) {
const lines = patch.trim().split('\n');
console.log(lines);

const hunks = [];
let currentHunk: Hunk | undefined;
Expand Down Expand Up @@ -104,6 +103,5 @@ export function parsePatch(patch: string) {
}
}

console.log(hunks);
return hunks;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<Markdown content={patch.description?.trim() || DESCRIPTION_PLACE_HOLDER} />
</p>

<ReviewInfo {patch} />
<ReviewInfo projectId={repositoryId} {patch} />
<ReviewSections {patch} patchSections={patchSections?.current} />
</div>

Expand Down
17 changes: 17 additions & 0 deletions packages/shared/src/lib/branches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ async function getUsersWithAvatars(userEmails: string[]) {
);
}

export type Commenter = {
avatarUrl: string | undefined;
name: string | undefined;
};

export async function getCommentersWithAvatars(commenters: Commenter[]) {
return await Promise.all(
commenters.map(async (commenter) => {
const name = commenter.name ?? 'unknown';
return {
srcUrl: commenter.avatarUrl ?? (await gravatarUrlFromEmail(name)),
name
};
})
);
}

export async function getPatchContributorsWithAvatars(patch: Patch) {
return await getUsersWithAvatars(patch.contributors);
}
Expand Down
32 changes: 31 additions & 1 deletion packages/shared/src/lib/chat/chatChannelsPreview.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { chatChannelsSelectors } from './chatChannelsSlice';
import { createChannelKey, type LoadableChatChannel } from '$lib/chat/types';
import { createChannelKey, type ChatMessageUser, type LoadableChatChannel } from '$lib/chat/types';
import { registerInterest, type InView } from '$lib/interest/registerInterestFunction.svelte';
import { map } from '$lib/network/loadable';
import { deduplicateBy } from '$lib/utils/array';
import type { ChatChannelsService } from '$lib/chat/chatChannelsService';
import type { AppChatChannelsState } from '$lib/redux/store.svelte';
import type { Reactive } from '$lib/storeUtils';
Expand All @@ -26,3 +28,31 @@ export function getChatChannel(
}
};
}

export function getChatChannelParticipants(
appState: AppChatChannelsState,
chatMessagesService: ChatChannelsService,
projectId: string,
changeId: string,
inView?: InView
): Reactive<ChatMessageUser[] | undefined> {
const chatMessagesInterest = chatMessagesService.getChatChannelInterest(projectId, changeId);
registerInterest(chatMessagesInterest, inView);

const chatChannelKey = createChannelKey(projectId, changeId);
const chatChannelParticipants = $derived.by(() => {
const channel = chatChannelsSelectors.selectById(appState.chatChannels, chatChannelKey);
return map(channel, (channel) =>
deduplicateBy(
channel.messages.map((message) => message.user),
'id'
)
);
});

return {
get current() {
return chatChannelParticipants;
}
};
}
15 changes: 15 additions & 0 deletions packages/shared/src/lib/utils/array.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
export function deduplicate<T>(array: T[]): T[] {
return Array.from(new Set(array));
}

export function deduplicateBy<T, K extends keyof T>(array: T[], key: K): T[] {
const seen = new Set();
const result: T[] = [];

for (const item of array) {
const value = item[key];
if (!seen.has(value)) {
seen.add(value);
result.push(item);
}
}

return result;
}

0 comments on commit addf1e4

Please sign in to comment.