Skip to content

Commit

Permalink
some renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
scazan committed Nov 23, 2023
1 parent 67ef969 commit 2c57b11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
5 changes: 2 additions & 3 deletions integrations/slack/src/actions/queryLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../configuration';
import { acknowledgeQuery } from '../middlewares';
import { slackAPI } from '../slack';
import { PagesBlock, QueryDisplayBlock, ShareTools, decodeSlackEscapeChars, Spacer } from '../ui';
import { QueryDisplayBlock, ShareTools, decodeSlackEscapeChars, Spacer, SourcesBlock } from '../ui';
import { getInstallationApiClient, stripBotName, stripMarkdown } from '../utils';

// Recursively extracts all pages from a collection of RevisionPages
Expand Down Expand Up @@ -126,7 +126,6 @@ async function getRelatedPages(params: {
return accum;
}, [] as RelatedSource[]);

// { type: 'capture', captureId: '72', source: 'slack' }
// extract all related pages from the Revisions along with the related public URL
const relatedSources: Array<RelatedSource> = sourcePages.reduce((accum, source) => {
switch (source.type) {
Expand Down Expand Up @@ -254,7 +253,7 @@ export async function queryLens({
{
type: 'divider',
},
...PagesBlock({
...SourcesBlock({
title: 'Sources',
items: relatedPages,
}),
Expand Down
16 changes: 7 additions & 9 deletions integrations/slack/src/ui/blocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { RevisionPage, SearchAIAnswer } from '@gitbook/api';
import { RelatedSource } from '../../actions/queryLens';
import { RelatedSource } from '../../actions/';

// Slack only encodes these specific characters so we need to remove them in the output (specifically used for inputs to slack)
export function decodeSlackEscapeChars(text: string) {
Expand All @@ -12,21 +11,20 @@ export function decodeSlackEscapeChars(text: string) {
}, text);
}

export function PageBlock(page: { path: string; title: string }, sourceUrl: string) {
// TODO: note for review. is this the best way to do this?
const nonRevisionPublicUrl = sourceUrl.split('~/')[0];
const url = `${nonRevisionPublicUrl}${page.path}`;
export function SourceBlock(source: RelatedSource) {
const nonRevisionPublicUrl = source.sourceUrl.split('~/')[0];
const url = `${nonRevisionPublicUrl}${source.page.path || ''}`;
return {
type: 'mrkdwn',
text: `*<${url}|:spiral_note_pad: ${page.title}>*`,
text: `*<${url}|:spiral_note_pad: ${source.page.title}>*`,
};
}

export function PagesBlock(params: { title?: string; items: Array<RelatedSource> }) {
export function SourcesBlock(params: { title?: string; items: Array<RelatedSource> }) {
const { title, items } = params;

const blocks = items.reduce<Array<any>>((acc, pageData) => {
const pageResultBlock = PageBlock(pageData.page, pageData.sourceUrl);
const pageResultBlock = SourceBlock(pageData);
acc.push(pageResultBlock);

return acc;
Expand Down

0 comments on commit 2c57b11

Please sign in to comment.