Skip to content

Commit

Permalink
update the layout of the notification list
Browse files Browse the repository at this point in the history
  • Loading branch information
scazan committed Nov 24, 2023
1 parent 58eee59 commit c6d7d2d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions integrations/slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createIntegration, EventCallback } from '@gitbook/runtime';
import { SlackRuntimeContext } from './configuration';
import { handleFetchEvent } from './router';
import { slackAPI } from './slack';
import { Spacer } from './ui';

/*
* Handle content being updated: send a notification on Slack.
Expand Down Expand Up @@ -100,6 +101,10 @@ const handleSpaceContentUpdated: EventCallback<
space.title || 'Space'
}>* has been updated.`;

const renderList = (list: string[]) => {
return list.map((item) => `• ${item}\n`);
};

if (
createdPages.length > 0 ||
editedPages.length > 0 ||
Expand All @@ -109,32 +114,32 @@ const handleSpaceContentUpdated: EventCallback<
editedFiles.length > 0 ||
deletedFiles.length > 0
) {
notificationText += '\n\nSummary of changes:';
// notificationText += '\n\n*Summary of changes:*';

if (createdPages.length > 0) {
notificationText += `\nNew pages: ${createdPages.join(', ')}`;
notificationText += `\n*New pages:*\n${renderList(createdPages)}\n\n`;
}
if (editedPages.length > 0) {
notificationText += `\nModified pages: ${editedPages.join(', ')}`;
notificationText += `\n*Modified pages:*\n${renderList(editedPages)}\n\n`;
}
if (deletedPages.length > 0) {
notificationText += `\nDeleted pages: ${deletedPages.join(', ')}`;
notificationText += `\n*Deleted pages:*\n${renderList(deletedPages)}\n\n`;
}
if (movedPages.length > 0) {
notificationText += `\nMoved pages: ${movedPages.join(', ')}`;
notificationText += `\n*Moved pages:*\n${renderList(movedPages)}\n\n`;
}
if (createdFiles.length > 0) {
notificationText += `\nNew files: ${createdFiles.join(', ')}`;
notificationText += `\n*New files:*\n${renderList(createdFiles)}\n\n`;
}
if (editedFiles.length > 0) {
notificationText += `\nModified files: ${editedFiles.join(', ')}`;
notificationText += `\n*Modified files:*\n${renderList(editedFiles)}\n\n`;
}
if (deletedFiles.length > 0) {
notificationText += `\nDeleted files: ${deletedFiles.join(', ')}`;
notificationText += `\n*Deleted files:*\n${renderList(deletedFiles)}\n\n`;
}

if (semanticChanges.more > 0) {
notificationText += `\n\nAnd another ${semanticChanges.more} changes not listed here.`;
notificationText += `\n\nAnd another ${semanticChanges.more} changes not listed here.\n`;
}
}

Expand All @@ -144,13 +149,15 @@ const handleSpaceContentUpdated: EventCallback<
payload: {
channel,
blocks: [
Spacer,
{
type: 'section',
text: {
type: 'mrkdwn',
text: notificationText,
},
},
Spacer,
],
},
});
Expand Down

0 comments on commit c6d7d2d

Please sign in to comment.