Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(new-channels): participants tab (#2307)
teoe54fcb4e8342
diff --git a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsxindex d63bc045cf..541f4a8e34 100644--- a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx+++ b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx@@ -12,12 +12,14 @@ import { useBlockEntityCommands } from '@app/component/next-soup/actions';import { ChannelTopLeft } from './Top';import { useChannelName, useChannelType } from '@core/context/channels';import { useChannelParticipantsQuery } from '@queries/channel/channel-participants';+import { ChannelTypeEnum } from '@service-comms/client';import {CHANNEL_TABS,DEFAULT_CHANNEL_TAB,type ChannelTabId,} from '@channel/Channel/channel-tabs';import { ChannelAttachmentsTab } from '@channel/Attachments/ChannelAttachmentsTab';+import { ChannelParticipantsTab } from '@channel/Participants/ChannelParticipantsTab';function NewTop(props: {channelId: string;@@ -29,6 +31,10 @@ function NewTop(props: {const participantsQuery = useChannelParticipantsQuery(() => props.channelId);const participants = () =>participantsQuery.isLoading ? [] : participantsQuery.data;+ const tabs = () =>+ channelType() === ChannelTypeEnum.DirectMessage+ ? CHANNEL_TABS.filter((tab) => tab.value !== 'participants')+ : CHANNEL_TABS;return (<Suspense>@@ -37,7 +43,7 @@ function NewTop(props: {channelType={channelType()!}participants={participants() ?? []}channelName={channelName() ?? 'New Channel'}- tabs={CHANNEL_TABS}+ tabs={tabs()}activeTab={props.activeTab}onTabChange={props.onTabChange}/>@@ -82,6 +88,9 @@ export function NewChannelBlockAdapter() {<Match when={activeTab() === 'attachments'}><ChannelAttachmentsTab channelId={channelId} /></Match>+ <Match when={activeTab() === 'participants'}>+ <ChannelParticipantsTab channelId={channelId} />+ </Match></Switch><NewTopchannelId={channelId}diff --git a/js/app/packages/channel/Channel/channel-tabs.ts b/js/app/packages/channel/Channel/channel-tabs.tsindex 1412552e27..077f4cfd28 100644--- a/js/app/packages/channel/Channel/channel-tabs.ts+++ b/js/app/packages/channel/Channel/channel-tabs.ts@@ -1,6 +1,7 @@export const CHANNEL_TABS = [{ value: 'messages', label: 'Messages' },{ value: 'attachments', label: 'Attachments' },+ { value: 'participants', label: 'Participants' },] as const;export type ChannelTabId = (typeof CHANNEL_TABS)[number]['value'];diff --git a/js/app/packages/channel/Participants/ChannelParticipantsTab.tsx b/js/app/packages/channel/Participants/ChannelParticipantsTab.tsxnew file mode 100644index 0000000000..d11031ac96--- /dev/null+++ b/js/app/packages/channel/Participants/ChannelParticipantsTab.tsx@@ -0,0 +1,130 @@+import { useSplitLayout } from '@app/component/split-layout/layout';+import { useUserId } from '@core/context/user';+import { useChannelType } from '@core/context/channels';+import { isOk } from '@core/util/maybeResult';+import {+ useAddParticipantsMutation,+ useRemoveParticipantsMutation,+} from '@queries/channel/participants';+import { useChannelParticipantsQuery } from '@queries/channel/channel-participants';+import { commsServiceClient } from '@service-comms/client';+import { ChannelType } from '@service-comms/generated/models/channelType';+import { createSignal, Show } from 'solid-js';+import { idToEmail } from '@core/user';+import { ParticipantsAddPanel } from './ParticipantsAddPanel';+import { ParticipantsList } from './ParticipantsList';+import { ParticipantsSearchInput } from './ParticipantsSearchInput';++function ParticipantsSection(props: {+ title: string;+ children: import('solid-js').JSX.Element;+ class?: string;+ contentClass?: string;+}) {+ return (+ <div+ class={`rounded-sm border border-edge-muted bg-menu py-3 ${props.class ?? ''}`}+ >+ <div class="px-3 pb-3 text-sm font-medium text-ink">{props.title}</div>+ <div class="border-b border-edge-muted" />+ <div class={`px-3 pt-3 ${props.contentClass ?? ''}`}>+ {props.children}+ </div>+ </div>+ );+}++export function ChannelParticipantsTab(props: { channelId: string }) {+ const { replaceOrInsertSplit } = useSplitLayout();+ const userId = useUserId();+ const channelType = useChannelType(props.channelId);+ const participantsQuery = useChannelParticipantsQuery(() => props.channelId);+ const addParticipantsMutation = useAddParticipantsMutation();+ const removeParticipantsMutation = useRemoveParticipantsMutation();+ const [searchQuery, setSearchQuery] = createSignal('');++ const participants = () => participantsQuery.data ?? [];+ const canManageParticipants = () =>+ channelType() !== ChannelType.organization;+ const canAddParticipants = () =>+ canManageParticipants() && channelType() === ChannelType.private;++ const filteredParticipants = () => {+ const query = searchQuery().trim().toLowerCase();+ if (query.length === 0) return participants();++ return participants().filter((participant) => {+ const email = idToEmail(participant.user_id).toLowerCase();+ return (+ participant.user_id.toLowerCase().includes(query) ||+ email.includes(query) ||+ participant.role.toLowerCase().includes(query)+ );+ });+ };++ const addParticipants = (participantIds: string[]) => {+ if (participantIds.length === 0) return;++ addParticipantsMutation.mutate({+ channelId: props.channelId,+ participants: participantIds,+ });+ };++ const removeParticipant = (participantId: string) => {+ removeParticipantsMutation.mutate({+ channelId: props.channelId,+ participants: [participantId],+ });+ };++ const openDirectMessage = async (participantId: string) => {+ const result = await commsServiceClient.getOrCreateDirectMessage({+ recipient_id: participantId,+ });+ const channelId = isOk(result) && result[1]?.channel_id;++ if (channelId) {+ replaceOrInsertSplit({+ type: 'channel',+ id: channelId,+ });+ }+ };++ return (+ <div class="relative flex-1 min-h-0 overflow-hidden">+ <div class="macro-message-width macro-message-padding mx-auto flex h-full min-h-0 w-full flex-col gap-6 py-4">+ <Show when={canAddParticipants()}>+ <ParticipantsSection title="Add participants">+ <ParticipantsAddPanel+ participants={participants}+ onAddParticipants={addParticipants}+ />+ </ParticipantsSection>+ </Show>+ <ParticipantsSection+ title="Participants"+ class="flex flex-1 min-h-0 flex-col md:flex-none"+ contentClass="flex flex-1 min-h-0 flex-col"+ >+ <ParticipantsSearchInput+ value={searchQuery()}+ onInput={setSearchQuery}+ />+ <div class="min-h-0 flex-1 pt-2">+ <ParticipantsList+ participants={filteredParticipants}+ searchQuery={searchQuery}+ currentUserId={userId() ?? undefined}+ editable={canManageParticipants()}+ onParticipantClick={openDirectMessage}+ onRemoveParticipant={removeParticipant}+ />+ </div>+ </ParticipantsSection>+ </div>+ </div>+ );+}diff --git a/js/app/packages/channel/Participants/ParticipantsAddPanel.tsx b/js/app/packages/channel/Participants/ParticipantsAddPanel.tsxnew file mode 100644index 0000000000..9742ecb7dc--- /dev/null+++ b/js/app/packages/channel/Participants/ParticipantsAddPanel.tsx@@ -0,0 +1,61 @@+import { getDestinationFromOptions } from '@core/component/NewMessage';+import { RecipientSelector } from '@core/component/RecipientSelector';+import {+ recipientEntityMapper,+ useContacts,+ type WithCustomUserInput,+} from '@core/user';+import type { ChannelParticipant } from '@queries/channel/types';+import { createSignal, type Accessor } from 'solid-js';++export function ParticipantsAddPanel(props: {+ participants: Accessor<ChannelParticipant[]>;+ onAddParticipants: (participantIds: string[]) => void;+}) {+ const contacts = useContacts();+ const [selectedUsers, setSelectedUsers] = createSignal<+ WithCustomUserInput<'user'>[]+ >([]);++ const options = () => {+ const existingParticipantIds = new Set(+ props.participants().map((participant) => participant.user_id)+ );++ return (+ contacts()+ ?.filter((user) => !existingParticipantIds.has(user.id))+ .map(recipientEntityMapper('user')) ?? []+ );+ };++ const handleAddParticipants = () => {+ const destination = getDestinationFromOptions(selectedUsers());+ props.onAddParticipants(destination.users);+ setSelectedUsers([]);+ };++ return (+ <div class="flex flex-col gap-2 md:flex-row md:items-center">+ <div class="min-w-0 flex-1 rounded-xs border border-edge-muted bg-input px-3 py-2 text-sm text-ink outline-none focus-within:border-accent/50">+ <RecipientSelector<'user'>+ setSelectedOptions={setSelectedUsers}+ selectedOptions={selectedUsers()}+ placeholder="[email protected]"+ options={options}+ hideBorder+ noPadding+ noBrackets+ />+ </div>+ <button+ type="button"+ disabled={selectedUsers().length === 0}+ onClick={handleAddParticipants}+ class="w-full shrink-0 rounded-xs bg-accent px-3 py-1.5 text-sm font-medium text-menu transition-colors hover:bg-accent/90 disabled:opacity-50 md:w-auto"+ >+ {selectedUsers().length > 1 ? 'Add Participants' : 'Add Participant'}+ </button>+ </div>+ );+}diff --git a/js/app/packages/channel/Participants/ParticipantsEmptyState.tsx b/js/app/packages/channel/Participants/ParticipantsEmptyState.tsxnew file mode 100644index 0000000000..0a2e76239a--- /dev/null+++ b/js/app/packages/channel/Participants/ParticipantsEmptyState.tsx@@ -0,0 +1,9 @@+export function ParticipantsEmptyState(props: { searchQuery: string }) {+ return (+ <div class="flex min-h-[240px] items-center justify-center border-b border-edge-muted/50 px-4 text-center text-sm text-ink-muted">+ {props.searchQuery.trim().length > 0+ ? `No participants match "${props.searchQuery}".`+ : 'No participants found.'}+ </div>+ );+}diff --git a/js/app/packages/channel/Participants/ParticipantsList.tsx b/js/app/packages/channel/Participants/ParticipantsList.tsxnew file mode 100644index 0000000000..1a86aa0963--- /dev/null+++ b/js/app/packages/channel/Participants/ParticipantsList.tsx@@ -0,0 +1,43 @@+import type { ChannelParticipant } from '@queries/channel/types';+import { Show, type Accessor } from 'solid-js';+import { VList } from 'virtua/solid';+import { ParticipantsEmptyState } from './ParticipantsEmptyState';+import { ParticipantsListItem } from './ParticipantsListItem';++export function ParticipantsList(props: {+ participants: Accessor<ChannelParticipant[]>;+ searchQuery: Accessor<string>;+ currentUserId?: string;+ editable: boolean;+ onParticipantClick: (participantId: string) => void | Promise<void>;+ onRemoveParticipant: (participantId: string) => void;+}) {+ return (+ <Show+ when={props.participants().length > 0}+ fallback={<ParticipantsEmptyState searchQuery={props.searchQuery()} />}+ >+ <div class="min-h-0 h-full overflow-hidden md:h-[420px]">+ <VList+ data={props.participants()}+ class="h-full"+ style={{+ height: '100%',+ width: '100%',+ }}+ bufferSize={500}+ >+ {(participant) => (+ <ParticipantsListItem+ participant={participant}+ currentUserId={props.currentUserId}+ editable={props.editable}+ onClick={() => props.onParticipantClick(participant.user_id)}+ onRemove={() => props.onRemoveParticipant(participant.user_id)}+ />+ )}+ </VList>+ </div>+ </Show>+ );+}diff --git a/js/app/packages/channel/Participants/ParticipantsListItem.tsx b/js/app/packages/channel/Participants/ParticipantsListItem.tsxnew file mode 100644index 0000000000..9b42d66f52--- /dev/null+++ b/js/app/packages/channel/Participants/ParticipantsListItem.tsx@@ -0,0 +1,69 @@+import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';+import { UserIcon } from '@core/component/UserIcon';+import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';+import { idToEmail } from '@core/user';+import IconX from '@icon/regular/x.svg';+import type { ChannelParticipant } from '@queries/channel/types';++export function ParticipantsListItem(props: {+ participant: ChannelParticipant;+ currentUserId?: string;+ editable: boolean;+ onClick: () => void | Promise<void>;+ onRemove: () => void;+}) {+ const canRemove =+ props.editable && props.currentUserId !== props.participant.user_id;++ const navigationHandlers = useSplitNavigationHandler<HTMLButtonElement>(+ async (event) => {+ event.preventDefault();+ event.stopPropagation();+ await props.onClick();+ }+ );++ return (+ <div class="flex items-center gap-2 min-h-10 px-2 py-2 text-sm w-full border-b border-edge-muted/50 last:border-b-0 hover:bg-hover/30">+ <button+ {...navigationHandlers}+ type="button"+ class="flex min-w-0 flex-1 items-center gap-2 rounded-xs px-2 py-1 text-left cursor-pointer focus:outline-none"+ >+ <div class="shrink-0">+ <UserIcon+ id={props.participant.user_id}+ size="xs"+ isDeleted={false}+ />+ </div>+ <span class="ph-no-capture font-semibold truncate flex-1 text-ink">+ {idToEmail(props.participant.user_id)}+ </span>+ </button>+ <span class="text-xs font-mono text-ink-extra-muted uppercase font-light shrink-0">+ {props.participant.role}+ </span>+ <div class="shrink-0">+ <DeprecatedIconButton+ tooltip={{+ label: canRemove+ ? 'Remove participant'+ : 'Cannot remove participant',+ }}+ icon={IconX}+ iconSize={16}+ theme="clear"+ size="sm"+ disabled={!canRemove}+ onClick={(event) => {+ event.preventDefault();+ event.stopPropagation();+ if (!canRemove) return;+ props.onRemove();+ }}+ />+ </div>+ </div>+ );+}diff --git a/js/app/packages/channel/Participants/ParticipantsSearchInput.tsx b/js/app/packages/channel/Participants/ParticipantsSearchInput.tsxnew file mode 100644index 0000000000..520d4d1a7f--- /dev/null+++ b/js/app/packages/channel/Participants/ParticipantsSearchInput.tsx@@ -0,0 +1,13 @@+export function ParticipantsSearchInput(props: {+ value: string;+ onInput: (value: string) => void;+}) {+ return (+ <input+ value={props.value}+ onInput={(event) => props.onInput(event.currentTarget.value)}+ placeholder="Search participants"+ class="h-10 w-full rounded-sm border border-edge-muted bg-panel px-3 text-sm text-ink placeholder:text-ink-muted focus:outline-none"+ />+ );+}diff --git a/js/app/packages/queries/channel/participants.ts b/js/app/packages/queries/channel/participants.tsindex bebb83a923..61adca7c90 100644--- a/js/app/packages/queries/channel/participants.ts+++ b/js/app/packages/queries/channel/participants.ts@@ -5,10 +5,10 @@ import {commsServiceClient,type MessageResponse,} from '@service-comms/client';-import type { ChannelParticipant, GetChannelResponse } from './types';+import type { ChannelParticipant } from './types';import { useMutation } from '@tanstack/solid-query';import { queryClient } from '../client';-import { softInvalidateChannelWithID } from './channel';+import { softInvalidateChannelParticipants } from './channel-participants';import { channelKeys } from './keys';type WithChannelId<T> = T & { channelId: string };@@ -28,26 +28,28 @@ export type RemoveParticipantsContext = {export function optimisticAddParticipants(vars: WithChannelId<{ participants: string[] }>): AddParticipantsContext | undefined {- const queryKey = channelKeys.withID(vars.channelId).queryKey;- queryClient.cancelQueries({ queryKey });+ const participantsQueryKey = channelKeys.participants(+ vars.channelId+ ).queryKey;+ queryClient.cancelQueries({ queryKey: participantsQueryKey });let context: AddParticipantsContext | undefined;-- queryClient.setQueriesData(- { queryKey },- (prev: GetChannelResponse | undefined) => {+ queryClient.setQueryData(+ participantsQueryKey,+ (prev: ChannelParticipant[] | undefined) => {if (!prev) return prev;- const existingUserIds = new Set(prev.participants.map((p) => p.user_id));- const newUserIds = vars.participants.filter(- (id) => !existingUserIds.has(id)+ const existingUserIds = new Set(+ prev.map((participant) => participant.user_id)+ );+ const addedUserIds = vars.participants.filter(+ (userId) => !existingUserIds.has(userId));- if (newUserIds.length === 0) return prev;-- context = { addedUserIds: newUserIds };+ if (addedUserIds.length === 0) return prev;+ context = { addedUserIds };- const newParticipants: ChannelParticipant[] = newUserIds.map(+ const addedParticipants: ChannelParticipant[] = addedUserIds.map((userId) => ({user_id: userId,role: 'member',@@ -57,10 +59,7 @@ export function optimisticAddParticipants(}));- return {- ...prev,- participants: [...prev.participants, ...newParticipants],- };+ return [...prev, ...addedParticipants];});@@ -74,18 +73,15 @@ export function rollbackAddParticipants(channelId: string,context: AddParticipantsContext): void {- const queryKey = channelKeys.withID(channelId).queryKey;+ const participantsQueryKey = channelKeys.participants(channelId).queryKey;- queryClient.setQueriesData(- { queryKey },- (prev: GetChannelResponse | undefined) => {+ queryClient.setQueryData(+ participantsQueryKey,+ (prev: ChannelParticipant[] | undefined) => {if (!prev) return prev;const addedSet = new Set(context.addedUserIds);- return {- ...prev,- participants: prev.participants.filter((p) => !addedSet.has(p.user_id)),- };+ return prev.filter((participant) => !addedSet.has(participant.user_id));});}@@ -97,31 +93,31 @@ export function rollbackAddParticipants(export function optimisticRemoveParticipants(vars: WithChannelId<{ participants: string[] }>): RemoveParticipantsContext | undefined {- const queryKey = channelKeys.withID(vars.channelId).queryKey;- queryClient.cancelQueries({ queryKey });+ const participantsQueryKey = channelKeys.participants(+ vars.channelId+ ).queryKey;+ queryClient.cancelQueries({ queryKey: participantsQueryKey });let context: RemoveParticipantsContext | undefined;- queryClient.setQueriesData(- { queryKey },- (prev: GetChannelResponse | undefined) => {+ queryClient.setQueryData(+ participantsQueryKey,+ (prev: ChannelParticipant[] | undefined) => {if (!prev) return prev;const toRemoveSet = new Set(vars.participants);- const removedParticipants = prev.participants.filter((p) =>- toRemoveSet.has(p.user_id)+ const removedParticipants = prev.filter((participant) =>+ toRemoveSet.has(participant.user_id));if (removedParticipants.length === 0) return prev;+ if (!context) {+ context = { removedParticipants };+ }- context = { removedParticipants };-- return {- ...prev,- participants: prev.participants.filter(- (p) => !toRemoveSet.has(p.user_id)- ),- };+ return prev.filter(+ (participant) => !toRemoveSet.has(participant.user_id)+ );});@@ -135,17 +131,22 @@ export function rollbackRemoveParticipants(channelId: string,context: RemoveParticipantsContext): void {- const queryKey = channelKeys.withID(channelId).queryKey;+ const participantsQueryKey = channelKeys.participants(channelId).queryKey;- queryClient.setQueriesData(- { queryKey },- (prev: GetChannelResponse | undefined) => {+ queryClient.setQueryData(+ participantsQueryKey,+ (prev: ChannelParticipant[] | undefined) => {if (!prev) return prev;- return {- ...prev,- participants: [...prev.participants, ...context.removedParticipants],- };+ const existingUserIds = new Set(+ prev.map((participant) => participant.user_id)+ );+ const restoredParticipants = context.removedParticipants.filter(+ (participant) => !existingUserIds.has(participant.user_id)+ );++ if (restoredParticipants.length === 0) return prev;+ return [...prev, ...restoredParticipants];});}@@ -204,7 +205,8 @@ export function useAddParticipantsMutation(rollbackAddParticipants(vars.channelId, context);}},- onSettled: (_, __, vars) => softInvalidateChannelWithID(vars.channelId),+ onSettled: (_, __, vars) =>+ softInvalidateChannelParticipants(vars.channelId),},callbacks),@@ -252,7 +254,8 @@ export function useRemoveParticipantsMutation(rollbackRemoveParticipants(vars.channelId, context);}},- onSettled: (_, __, vars) => softInvalidateChannelWithID(vars.channelId),+ onSettled: (_, __, vars) =>+ softInvalidateChannelParticipants(vars.channelId),},callbacks),