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(channels): Rename channel in block view (#557)
dev-rb1893c87117c1
diff --git a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx b/js/app/packages/app/component/split-layout/components/SplitLabel.tsxindex 5fdec891e2..04cb6128c6 100644--- a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx+++ b/js/app/packages/app/component/split-layout/components/SplitLabel.tsx@@ -34,7 +34,7 @@ export function StaticSplitLabel(props: {panel.handle.setDisplayName(props.label);});return (- <div class="z-3 relative flex items-center gap-2 w-screen max-w-full h-full shrink">+ <div class="z-3 relative flex items-center gap-2 max-w-full h-full shrink"><Show when={props.iconType}><EntityIconclass="shrink-0"@@ -52,7 +52,7 @@ export function StaticSplitLabel(props: {);}-function SplitLabel(props: {+export function SplitLabel(props: {label: string;onNameChanged?: (newName: string) => void;lockRename?: boolean;diff --git a/js/app/packages/app/component/split-layout/components/SplitModalContext.tsx b/js/app/packages/app/component/split-layout/components/SplitModalContext.tsxindex a650c36ec4..a8488ac566 100644--- a/js/app/packages/app/component/split-layout/components/SplitModalContext.tsx+++ b/js/app/packages/app/component/split-layout/components/SplitModalContext.tsx@@ -103,6 +103,11 @@ export function SplitModalProvider(props: ParentProps) {type: 'project',parentId: undefined,} as EntityData;+ case 'channel':+ return {+ ...baseEntity,+ type: 'channel',+ } as EntityData;default:return {...baseEntity,diff --git a/js/app/packages/block-channel/component/Top.tsx b/js/app/packages/block-channel/component/Top.tsxindex 2fecd745cf..ec5a69a3a9 100644--- a/js/app/packages/block-channel/component/Top.tsx+++ b/js/app/packages/block-channel/component/Top.tsx@@ -3,7 +3,7 @@ import {SplitHeaderLeft,SplitHeaderRight,} from '@app/component/split-layout/components/SplitHeader';-import { StaticSplitLabel } from '@app/component/split-layout/components/SplitLabel';+import { SplitLabel } from '@app/component/split-layout/components/SplitLabel';import { SplitToolbarRight } from '@app/component/split-layout/components/SplitToolbar';import { channelStore } from '@block-channel/signal/channel';import { useBlockId } from '@core/block';@@ -76,15 +76,19 @@ export function Top() {return (<><SplitHeaderLeft>- <StaticSplitLabel- label={channelName() ?? 'New Channel'}- icon={+ <div class="h-full my-auto flex gap-2 justify-center items-center">+ <div class="z-3 relative flex items-center gap-2 max-w-full h-full shrink"><TopIconchannelType={channelType()}participants={participants()}/>- }- />+ <SplitLabel+ label={channelName() ?? 'New Channel'}+ id={channel.id}+ itemType="channel"+ />+ </div>+ </div></SplitHeaderLeft><SplitHeaderRight><BlockLiveIndicators />diff --git a/js/app/packages/macro-entity/src/queries/dss.ts b/js/app/packages/macro-entity/src/queries/dss.tsindex c09dc7b139..3b6d12c955 100644--- a/js/app/packages/macro-entity/src/queries/dss.ts+++ b/js/app/packages/macro-entity/src/queries/dss.ts@@ -5,6 +5,7 @@ import {renameItem,} from '@core/component/FileList/itemOperations';import { itemToSafeName } from '@core/constant/allBlocks';+import { type MutationCallbacks, withCallbacks } from '@queries/utils';import type { ItemType } from '@service-storage/client';import type {PostItemsSoupParams,@@ -461,81 +462,96 @@ export function createBulkDeleteDssItemsMutation() {}));}-export function createRenameDssEntityMutation() {+type RenameDssEntityMutationVariables = {+ entity: EntityData & { name: string };+ newName: string;+};++type RenameDssEntityMutationData = {+ success: boolean;+};++const isEntityRenameSupported = (entity: EntityData) => {+ const type = entity.type;+ if (entity.type === 'channel') {+ return entity.channelType !== 'direct_message';+ }+ return type !== 'email';+};++/**+ * Mutation to mark a thread as seen.+ */+export function createRenameDssEntityMutation(+ callbacks?: MutationCallbacks<+ RenameDssEntityMutationData,+ Error,+ RenameDssEntityMutationVariables+ >+) {return useMutation(() => ({- mutationFn: async ({- entity: { id, type },- newName,- }: {- entity: EntityData & { name: string };- newName: string;- }) => {+ mutationFn: async (params: RenameDssEntityMutationVariables) => {+ if (!isEntityRenameSupported(params.entity)) {+ throw new Error('Unsupported entity type provided');+ }+const success = await renameItem({- itemType: type as ItemType,- id,- newName,+ id: params.entity.id,+ itemType: params.entity.type,+ newName: params.newName,});return { success };},- onMutate: async ({- entity: { id },- newName,- }: {- entity: EntityData & { name: string };- newName: string;- }) => {- queryClient.cancelQueries({- queryKey: queryKeys.dss({ infinite: true }),- });- function updateEntityNameInQueryData(- prev: { pages: { items: EntityData[] }[] } | undefined,- id: string,- newName: string- ): { pages: { items: EntityData[] }[] } | undefined {- if (!prev) return prev;- const pages = prev.pages.map((page) => ({- ...page,- items: page.items.map((item) =>- item.id === id ? { ...item, name: newName } : item- ),- }));- return {- ...prev,- pages,- };- }-- queryClient.setQueriesData(- { queryKey: queryKeys.dss({ infinite: true }) },- (prev) =>- updateEntityNameInQueryData(- prev as { pages: { items: EntityData[] }[] } | undefined,- id,- newName- )- );- },- onSettled: (data, error, { entity: { id } }) => {- if (data?.success === false || error)- console.error(`Failed to rename dss item ${id}`, data, error);+ ...withCallbacks<+ RenameDssEntityMutationData,+ Error,+ RenameDssEntityMutationVariables+ >(+ {+ onMutate: async ({ entity: { id }, newName }) => {+ queryClient.cancelQueries({+ queryKey: queryKeys.dss({ infinite: true }),+ });+ function updateEntityNameInQueryData(+ prev: { pages: { items: EntityData[] }[] } | undefined,+ id: string,+ newName: string+ ) {+ if (!prev) return prev;+ const pages = prev.pages.map((page) => ({+ ...page,+ items: page.items.map((item) =>+ item.id === id ? { ...item, name: newName } : item+ ),+ }));+ return {+ ...prev,+ pages,+ };+ }- queryClient.invalidateQueries({- queryKey: queryKeys.dss({ infinite: true }),- });- },+ queryClient.setQueriesData(+ { queryKey: queryKeys.dss({ infinite: true }) },+ (prev: { pages: { items: EntityData[] }[] } | undefined) =>+ updateEntityNameInQueryData(prev, id, newName)+ );+ },+ onSettled: (data, error, { entity: { id } }) => {+ if (data?.success === false || error)+ console.error(`Failed to rename dss item ${id}`, data, error);++ queryClient.invalidateQueries({+ queryKey: queryKeys.dss({ infinite: true }),+ });+ },+ },+ callbacks+ ),}));}export function createBulkRenameDssEntityMutation() {- const isUnsupportedEntity = (entity: EntityData) => {- const type = entity.type;- if (entity.type === 'channel') {- return entity.channelType === 'direct_message';- }- return type === 'email';- };-return useMutation(() => ({mutationFn: async ({entities,@@ -544,7 +560,7 @@ export function createBulkRenameDssEntityMutation() {entities: (EntityData & { name: string })[];name: (oldName: string) => string | string;}) => {- if (entities.some(isUnsupportedEntity)) {+ if (entities.every(isEntityRenameSupported)) {throw new Error(`Unsupported entity type provided`);}return await Promise.all(