Skip to content

Commit

Permalink
Add Notion import status
Browse files Browse the repository at this point in the history
  • Loading branch information
handotdev committed Jun 27, 2022
1 parent facb144 commit d4ee2f4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
3 changes: 2 additions & 1 deletion server/src/helpers/routes/docs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Doc from '../../models/Doc';
import { OrgType } from '../../models/Org';
import Org, { OrgType } from '../../models/Org';
import { ConfluencePage } from '../../routes/integrations/confluence';
import { GoogleDoc } from '../../routes/integrations/google';
import { NotionPage } from '../../routes/integrations/notion';
Expand Down Expand Up @@ -66,6 +66,7 @@ export const importDocsFromNotion = async (pages: NotionPage[], org: OrgType, us
}));

await Promise.all(addDocPromises);
await Org.findById(orgId, { 'importStatus.notion': false })
}

export const importDocsFromGoogleDocs = async (docs: GoogleDoc[], org: OrgType, userId: string) => {
Expand Down
12 changes: 12 additions & 0 deletions server/src/models/Org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export type OrgType = {
google?: GoogleDocsCredentials;
confluence?: ConfluenceCredentials;
};
importStatus?: {
notion?: boolean,
github?: boolean,
confluence?: boolean,
googledocs?: boolean,
},
users: string[];
invitedEmails?: string[];
notifications: {
Expand Down Expand Up @@ -106,6 +112,12 @@ const OrgSchema = new Schema({
}]
}
},
importStatus: {
notion: Boolean,
confluence: Boolean,
googledocs: Boolean,
github: Boolean,
},
notifications: {
monthlyDigest: { type: Boolean, default: true },
newsletter: { type: Boolean, default: true },
Expand Down
20 changes: 11 additions & 9 deletions server/src/routes/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ docsRouter.get('/', userMiddleware, async (req, res) => {
}
});

const groupNameMap: Record<ScrapingMethod, string> = {
'notion-private': 'Notion Workspace',
'confluence-private': 'Confluence Space',
'googledocs-private': 'Google Docs',
'github': 'GitHub Markdown',
'web': 'Web Pages',
const groupMap: Record<ScrapingMethod, { name: string, importStatusId: string }> = {
'notion-private': { name: 'Notion Workspace', importStatusId: 'notion' },
'confluence-private': { name: 'Confluence Space', importStatusId: 'confluence' },
'googledocs-private': { name: 'Google Docs', importStatusId: 'googledocs' },
'github': { name: 'GitHub Markdown', importStatusId: 'github' },
'web': { name: 'Web Pages', importStatusId: '' },
}

docsRouter.get('/groups', userMiddleware, async (_, res) => {
Expand Down Expand Up @@ -198,12 +198,14 @@ docsRouter.get('/groups', userMiddleware, async (_, res) => {
},
]);

const groupsWithNames = groups.map((group: { _id: ScrapingMethod }) => {
const groupsWithNames: any[] = groups.map((group: { _id: ScrapingMethod }) => {
const groupData = groupMap[group._id];
return {
...group,
name: groupNameMap[group._id],
name: groupData.name,
isLoading: Boolean(org.importStatus[groupData.importStatusId])
}
})
});

return res.send({ groups: groupsWithNames })
});
Expand Down
3 changes: 2 additions & 1 deletion server/src/routes/integrations/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ notionRouter.get('/authorization', async (req, res) => {
if (state == null) return res.status(403).send('No state provided');
const parsedState = JSON.parse(decodeURIComponent(state as string));
const { org: orgId, userId } = parsedState;
const org = await Org.findByIdAndUpdate(orgId, { 'integrations.notion': { ...response } });
const org = await Org.findByIdAndUpdate(orgId, { 'integrations.notion': { ...response }, 'importStatus.notion': true });

if (org == null) {
return res.status(403).send({ error: 'Invalid organization ID' });
Expand All @@ -113,6 +113,7 @@ notionRouter.get('/authorization', async (req, res) => {
}
return res.redirect(redirectUrl);
} catch {
await Org.findById(orgId, { 'importStatus.notion': false })
return res.redirect(redirectUrl);
}
});
Expand Down
9 changes: 8 additions & 1 deletion web/components/GroupItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Group = {
count: number;
lastUpdatedDoc: Doc;
tasksCount: number;
isLoading: boolean;
}

type GroupItemProps = {
Expand Down Expand Up @@ -65,7 +66,13 @@ export default function GroupItem({ group, setSelectedGroup }: GroupItemProps) {
<a className="relative group flex items-center space-x-2.5">
<span className="flex items-center space-x-2.5 text-sm text-gray-500 truncate">
<div>
{group.count} documents • Last updated {timeAgo.format(Date.parse(group.lastUpdatedDoc.lastUpdatedAt))}
{ group.isLoading
? <span className="flex items-center text-gran-400">
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 512 512" className="h-3 w-3 text-gray-500 animate-spin mr-2">
<path d="M449.9 39.96l-48.5 48.53C362.5 53.19 311.4 32 256 32C161.5 32 78.59 92.34 49.58 182.2c-5.438 16.81 3.797 34.88 20.61 40.28c16.97 5.5 34.86-3.812 40.3-20.59C130.9 138.5 189.4 96 256 96c37.96 0 73 14.18 100.2 37.8L311.1 178C295.1 194.8 306.8 223.4 330.4 224h146.9C487.7 223.7 496 215.3 496 204.9V59.04C496 34.99 466.9 22.95 449.9 39.96zM441.8 289.6c-16.94-5.438-34.88 3.812-40.3 20.59C381.1 373.5 322.6 416 256 416c-37.96 0-73-14.18-100.2-37.8L200 334C216.9 317.2 205.2 288.6 181.6 288H34.66C24.32 288.3 16 296.7 16 307.1v145.9c0 24.04 29.07 36.08 46.07 19.07l48.5-48.53C149.5 458.8 200.6 480 255.1 480c94.45 0 177.4-60.34 206.4-150.2C467.9 313 458.6 294.1 441.8 289.6z"/>
</svg>
Importing</span>
: <>{group.count} documents • Last updated {timeAgo.format(Date.parse(group.lastUpdatedDoc.lastUpdatedAt))}</> }
</div>
</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion web/components/commands/documentation/AddDocumentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const addDocumentationMap: Record<AddDocumentationType, AddDocumentationS
webpage: {
type: 'webpage',
title: 'Web Page',
description: 'Add public web page with URL',
description: 'Add web page with URL',
},
}

Expand Down

1 comment on commit d4ee2f4

@vercel
Copy link

@vercel vercel bot commented on d4ee2f4 Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

connect – ./

connect-mintlify.vercel.app
*.mintlify.com
connect-git-main-mintlify.vercel.app

Please sign in to comment.