Base model refactor (#810)

* Big upgrades

* WIP: Stash

* Stash, 30 flow errors left

* Downgrade mobx

* WIP

* When I understand the difference between class and instance methods

* 💚

* Fixes: File import
Model saving edge cases
pinning and starring docs
Collection editing
Upgrade mobx devtools

* Notification settings saving works

* Disabled settings

* Document mailer

* Working notifications

* Colletion created notification
Ensure not notified for own actions

* Tidy up

* Document updated event only for document creation
Add indexes
Notification setting on user creation

* Commentary

* Fixed: Notification setting on signup

* Fix document move / duplicate stale data
Add BaseModel.refresh method

* Fixes: Title in sidebar not updated after editing document

* 💚

* Improve / restore error handling
Better handle offline errors

* 👕
This commit is contained in:
Tom Moor
2018-12-04 22:24:30 -08:00
committed by GitHub
parent 67cd250316
commit 8cbcb77486
222 changed files with 2273 additions and 2361 deletions

View File

@ -1,75 +0,0 @@
// @flow
import * as React from 'react';
import { Provider, observer, inject } from 'mobx-react';
import stores from 'stores';
import AuthStore from 'stores/AuthStore';
import ApiKeysStore from 'stores/ApiKeysStore';
import UsersStore from 'stores/UsersStore';
import CollectionsStore from 'stores/CollectionsStore';
import IntegrationsStore from 'stores/IntegrationsStore';
import LoadingIndicator from 'components/LoadingIndicator';
import { isCustomSubdomain } from 'shared/utils/domains';
type Props = {
auth: AuthStore,
children?: React.Node,
};
let authenticatedStores;
const Auth = observer(({ auth, children }: Props) => {
if (auth.authenticated) {
const { user, team } = auth;
const { hostname } = window.location;
if (!team || !user) {
return <LoadingIndicator />;
}
// If we're authenticated but viewing a subdomain that doesn't match the
// currently authenticated team then kick the user to the teams subdomain.
if (
process.env.SUBDOMAINS_ENABLED &&
team.subdomain &&
isCustomSubdomain(hostname) &&
!hostname.startsWith(`${team.subdomain}.`)
) {
window.location.href = `${team.url}${window.location.pathname}`;
return <LoadingIndicator />;
}
// Only initialize stores once. Kept in global scope because otherwise they
// will get overridden on route change
if (!authenticatedStores) {
authenticatedStores = {
integrations: new IntegrationsStore({
ui: stores.ui,
}),
apiKeys: new ApiKeysStore(),
users: new UsersStore(),
collections: new CollectionsStore({
ui: stores.ui,
teamId: team.id,
}),
};
if (window.Bugsnag) {
Bugsnag.user = {
id: user.id,
name: user.name,
teamId: team.id,
team: team.name,
};
}
authenticatedStores.collections.fetchPage({ limit: 100 });
}
return <Provider {...authenticatedStores}>{children}</Provider>;
}
auth.logout();
return null;
});
export default inject('auth')(Auth);

View File

@ -0,0 +1,41 @@
// @flow
import * as React from 'react';
import { observer, inject } from 'mobx-react';
import AuthStore from 'stores/AuthStore';
import LoadingIndicator from 'components/LoadingIndicator';
import { isCustomSubdomain } from 'shared/utils/domains';
type Props = {
auth: AuthStore,
children?: React.Node,
};
const Authenticated = observer(({ auth, children }: Props) => {
if (auth.authenticated) {
const { user, team } = auth;
const { hostname } = window.location;
if (!team || !user) {
return <LoadingIndicator />;
}
// If we're authenticated but viewing a subdomain that doesn't match the
// currently authenticated team then kick the user to the teams subdomain.
if (
process.env.SUBDOMAINS_ENABLED &&
team.subdomain &&
isCustomSubdomain(hostname) &&
!hostname.startsWith(`${team.subdomain}.`)
) {
window.location.href = `${team.url}${window.location.pathname}`;
return <LoadingIndicator />;
}
return children;
}
auth.logout();
return null;
});
export default inject('auth')(Authenticated);

View File

@ -7,7 +7,7 @@ import styled from 'styled-components';
import Waypoint from 'react-waypoint';
import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
import { DEFAULT_PAGINATION_LIMIT } from 'stores/DocumentsStore';
import { DEFAULT_PAGINATION_LIMIT } from 'stores/BaseStore';
import Document from 'models/Document';
import RevisionsStore from 'stores/RevisionsStore';

View File

@ -1,42 +0,0 @@
// @flow
import { observable, action } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { User } from 'types';
type View = {
user: User,
count: number,
};
class DocumentViewersStore {
documentId: string;
@observable viewers: Array<View>;
@observable isFetching: boolean;
@action
fetchViewers = async () => {
this.isFetching = true;
try {
const res = await client.post(
'/views.list',
{
id: this.documentId,
},
{ cache: true }
);
invariant(res && res.data, 'Data should be available');
this.viewers = res.data.users;
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
constructor(documentId: string) {
this.documentId = documentId;
}
}
export default DocumentViewersStore;

View File

@ -1,71 +0,0 @@
// @flow
import * as React from 'react';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import Popover from 'components/Popover';
import styled from 'styled-components';
import DocumentViewers from './components/DocumentViewers';
import DocumentViewersStore from './DocumentViewersStore';
import Flex from 'shared/components/Flex';
const Container = styled(Flex)`
font-size: 13px;
user-select: none;
a {
color: #ccc;
&:hover {
color: #aaa;
}
}
`;
type Props = {
documentId: string,
count: number,
};
@observer
class DocumentViews extends React.Component<Props> {
@observable opened: boolean = false;
anchor: ?HTMLElement;
store: DocumentViewersStore;
constructor(props: Props) {
super(props);
this.store = new DocumentViewersStore(props.documentId);
}
openPopover = () => {
this.opened = true;
};
closePopover = () => {
this.opened = false;
};
setRef = (ref: ?HTMLElement) => {
this.anchor = ref;
};
render() {
return (
<Container align="center">
<a ref={this.setRef} onClick={this.openPopover}>
Viewed {this.props.count} {this.props.count === 1 ? 'time' : 'times'}
</a>
{this.opened && (
<Popover anchor={this.anchor} onClose={this.closePopover}>
<DocumentViewers
onMount={this.store.fetchViewers}
viewers={this.store.viewers}
/>
</Popover>
)}
</Container>
);
}
}
export default DocumentViews;

View File

@ -1,52 +0,0 @@
// @flow
import * as React from 'react';
import Flex from 'shared/components/Flex';
import styled from 'styled-components';
import map from 'lodash/map';
import Avatar from 'components/Avatar';
import Scrollable from 'components/Scrollable';
type Props = {
viewers: Array<Object>,
onMount: Function,
};
const List = styled.ul`
list-style: none;
font-size: 13px;
margin: -4px 0;
padding: 0;
li {
padding: 4px 0;
}
`;
const UserName = styled.span`
padding-left: 8px;
`;
class DocumentViewers extends React.Component<Props> {
componentDidMount() {
this.props.onMount();
}
render() {
return (
<Scrollable>
<List>
{map(this.props.viewers, view => (
<li key={view.user.id}>
<Flex align="center">
<Avatar src={view.user.avatarUrl} />{' '}
<UserName>{view.user.name}</UserName>
</Flex>
</li>
))}
</List>
</Scrollable>
);
}
}
export default DocumentViewers;

View File

@ -1,3 +0,0 @@
// @flow
import DocumentViewers from './DocumentViewers';
export default DocumentViewers;

View File

@ -1,3 +0,0 @@
// @flow
import DocumentViews from './DocumentViews';
export default DocumentViews;

View File

@ -3,15 +3,15 @@ import * as React from 'react';
import { observable } from 'mobx';
import { observer, inject } from 'mobx-react';
import { createGlobalStyle } from 'styled-components';
import importFile from 'utils/importFile';
import { omit } from 'lodash';
import invariant from 'invariant';
import _ from 'lodash';
import importFile from 'utils/importFile';
import Dropzone from 'react-dropzone';
import DocumentsStore from 'stores/DocumentsStore';
import LoadingIndicator from 'components/LoadingIndicator';
type Props = {
children?: React.Node,
children: React.Node,
collectionId: string,
documentId?: string,
activeClassName?: string,
@ -62,15 +62,13 @@ class DropToImport extends React.Component<Props> {
this.props.history.push(doc.url);
}
}
} catch (err) {
// TODO: show error alert.
} finally {
this.isImporting = false;
}
};
render() {
const props = _.omit(
const props = omit(
this.props,
'history',
'documentId',

View File

@ -124,4 +124,4 @@ const Content = styled(Flex)`
`};
`;
export default withRouter(inject('user', 'auth', 'ui', 'documents')(Layout));
export default withRouter(inject('auth', 'ui', 'documents')(Layout));

View File

@ -4,7 +4,7 @@ import { observable, action } from 'mobx';
import { observer } from 'mobx-react';
import Waypoint from 'react-waypoint';
import { DEFAULT_PAGINATION_LIMIT } from 'stores/DocumentsStore';
import { DEFAULT_PAGINATION_LIMIT } from 'stores/BaseStore';
import Document from 'models/Document';
import DocumentList from 'components/DocumentList';
import { ListPlaceholder } from 'components/LoadingPlaceholder';

View File

@ -1,12 +1,14 @@
// @flow
import * as React from 'react';
import { observer } from 'mobx-react';
import invariant from 'invariant';
import styled from 'styled-components';
import { GoToIcon } from 'outline-icons';
import Flex from 'shared/components/Flex';
import Document from 'models/Document';
import type { DocumentPath } from 'stores/CollectionsStore';
const StyledGoToIcon = styled(GoToIcon)``;
const ResultWrapper = styled.div`
display: flex;
@ -16,8 +18,6 @@ const ResultWrapper = styled.div`
cursor: default;
`;
const StyledGoToIcon = styled(GoToIcon)``;
const ResultWrapperLink = styled(ResultWrapper.withComponent('a'))`
height: 32px;
padding-top: 3px;
@ -40,10 +40,10 @@ const ResultWrapperLink = styled(ResultWrapper.withComponent('a'))`
`;
type Props = {
result: Object,
result: DocumentPath,
document?: Document,
onSuccess?: Function,
ref?: Function,
onSuccess?: *,
ref?: *,
};
@observer
@ -51,8 +51,7 @@ class PathToDocument extends React.Component<Props> {
handleClick = async (ev: SyntheticEvent<*>) => {
ev.preventDefault();
const { document, result, onSuccess } = this.props;
invariant(onSuccess && document, 'onSuccess unavailable');
if (!document) return;
if (result.type === 'document') {
await document.move(result.id);
@ -64,7 +63,8 @@ class PathToDocument extends React.Component<Props> {
} else {
throw new Error('Not implemented yet');
}
onSuccess();
if (onSuccess) onSuccess();
};
render() {
@ -74,7 +74,7 @@ class PathToDocument extends React.Component<Props> {
if (!result) return <div />;
return (
<Component ref={ref} onClick={this.handleClick} selectable href>
<Component ref={ref} onClick={this.handleClick} href="" selectable>
{result.path
.map(doc => <span key={doc.id}>{doc.title}</span>)
.reduce((prev, curr) => [prev, <StyledGoToIcon />, curr])}

View File

@ -39,7 +39,7 @@ class MainSidebar extends React.Component<Props> {
render() {
const { auth, documents } = this.props;
const { user, team } = auth;
if (!user || !team) return;
if (!user || !team) return null;
return (
<Sidebar>
@ -89,6 +89,4 @@ class MainSidebar extends React.Component<Props> {
}
}
export default withRouter(
inject('user', 'documents', 'auth', 'ui')(MainSidebar)
);
export default withRouter(inject('documents', 'auth', 'ui')(MainSidebar));

View File

@ -3,6 +3,7 @@ import * as React from 'react';
import { observer, inject } from 'mobx-react';
import {
DocumentIcon,
EmailIcon,
ProfileIcon,
PadlockIcon,
CodeIcon,
@ -34,7 +35,7 @@ class SettingsSidebar extends React.Component<Props> {
render() {
const { team, user } = this.props.auth;
if (!team || !user) return;
if (!team || !user) return null;
return (
<Sidebar>
@ -52,6 +53,9 @@ class SettingsSidebar extends React.Component<Props> {
<SidebarLink to="/settings" icon={<ProfileIcon />}>
Profile
</SidebarLink>
<SidebarLink to="/settings/notifications" icon={<EmailIcon />}>
Notifications
</SidebarLink>
<SidebarLink to="/settings/tokens" icon={<CodeIcon />}>
API Tokens
</SidebarLink>

View File

@ -18,7 +18,7 @@ type Props = {
collection: Collection,
ui: UiStore,
activeDocument: ?Document,
prefetchDocument: (id: string) => Promise<void>,
prefetchDocument: (id: string) => *,
};
@observer

View File

@ -24,6 +24,10 @@ type Props = {
@observer
class Collections extends React.Component<Props> {
componentDidMount() {
this.props.collections.fetchPage({ limit: 100 });
}
render() {
const { history, location, collections, ui, documents } = this.props;

View File

@ -14,7 +14,7 @@ import {
} from '../../shared/utils/routeHelpers';
type Props = {
label?: React.Node,
label: React.Node,
history: Object,
ui: UiStore,
auth: AuthStore,

View File

@ -40,13 +40,17 @@ class CollectionMenu extends React.Component<Props> {
onFilePicked = async (ev: SyntheticEvent<*>) => {
const files = getDataTransferFiles(ev);
const document = await importFile({
file: files[0],
documents: this.props.documents,
collectionId: this.props.collection.id,
});
this.props.history.push(document.url);
try {
const document = await importFile({
file: files[0],
documents: this.props.documents,
collectionId: this.props.collection.id,
});
this.props.history.push(document.url);
} catch (err) {
this.props.ui.showToast(err.message);
}
};
onEdit = (ev: SyntheticEvent<*>) => {

View File

@ -7,7 +7,7 @@ import { MoreIcon } from 'outline-icons';
import CopyToClipboard from 'components/CopyToClipboard';
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
import { documentHistoryUrl } from 'utils/routeHelpers';
import type { Revision } from 'types';
import Revision from 'models/Revision';
import Document from 'models/Document';
import UiStore from 'stores/UiStore';

View File

@ -4,11 +4,12 @@ import { withRouter } from 'react-router-dom';
import { inject } from 'mobx-react';
import { MoreIcon } from 'outline-icons';
import type { Share } from 'types';
import CopyToClipboard from 'components/CopyToClipboard';
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
import SharesStore from 'stores/SharesStore';
import UiStore from 'stores/UiStore';
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
import Share from 'models/Share';
type Props = {
label?: React.Node,

View File

@ -3,9 +3,9 @@ import * as React from 'react';
import { inject, observer } from 'mobx-react';
import { MoreIcon } from 'outline-icons';
import UsersStore from 'stores/UsersStore';
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
import type { User } from 'types';
import UsersStore from 'stores/UsersStore';
import User from 'models/User';
type Props = {
user: User,

10
app/models/ApiKey.js Normal file
View File

@ -0,0 +1,10 @@
// @flow
import BaseModel from './BaseModel';
class ApiKey extends BaseModel {
id: string;
name: string;
secret: string;
}
export default ApiKey;

View File

@ -1,3 +1,50 @@
// @flow
import BaseStore from 'stores/BaseStore';
export default BaseStore;
import { set, observable } from 'mobx';
export default class BaseModel {
@observable id: string;
@observable isSaving: boolean;
store: *;
constructor(fields: Object, store: *) {
set(this, fields);
this.store = store;
}
save = async params => {
this.isSaving = true;
try {
// ensure that the id is passed if the document has one
if (params) params = { ...params, id: this.id };
await this.store.save(params || this.toJS());
// if saving is successful set the new values on the model itself
if (params) set(this, params);
return this;
} finally {
this.isSaving = false;
}
};
fetch = (options: *) => {
return this.store.fetch(this.id, options);
};
refresh = () => {
return this.fetch({ force: true });
};
delete = async () => {
this.isSaving = true;
try {
return await this.store.delete(this);
} finally {
this.isSaving = false;
}
};
toJS = () => {
return { ...this };
};
}

View File

@ -1,26 +1,22 @@
// @flow
import { extendObservable, action, computed, runInAction } from 'mobx';
import invariant from 'invariant';
import { pick } from 'lodash';
import { action, computed } from 'mobx';
import BaseModel from 'models/BaseModel';
import Document from 'models/Document';
import { client } from 'utils/ApiClient';
import stores from 'stores';
import UiStore from 'stores/UiStore';
import type { NavigationNode } from 'types';
class Collection extends BaseModel {
isSaving: boolean = false;
ui: UiStore;
export default class Collection extends BaseModel {
isSaving: boolean;
createdAt: string;
description: string;
id: string;
name: string;
description: string;
color: string;
type: 'atlas' | 'journal';
documents: NavigationNode[];
updatedAt: string;
createdAt: ?string;
updatedAt: ?string;
url: string;
@computed
@ -56,103 +52,11 @@ class Collection extends BaseModel {
travelDocuments(this.documents);
}
@action
fetch = async () => {
try {
const res = await client.post('/collections.info', { id: this.id });
invariant(res && res.data, 'API response should be available');
const { data } = res;
runInAction('Collection#fetch', () => {
this.updateData(data);
});
} catch (e) {
this.ui.showToast('Collection failed loading');
}
return this;
toJS = () => {
return pick(this, ['name', 'color', 'description']);
};
@action
save = async () => {
if (this.isSaving) return this;
this.isSaving = true;
const params = {
name: this.name,
color: this.color,
description: this.description,
};
try {
let res;
if (this.id) {
res = await client.post('/collections.update', {
id: this.id,
...params,
});
} else {
res = await client.post('/collections.create', params);
}
runInAction('Collection#save', () => {
invariant(res && res.data, 'Data should be available');
this.updateData(res.data);
});
} catch (e) {
this.ui.showToast('Collection failed saving');
return false;
} finally {
this.isSaving = false;
}
return true;
export = () => {
return client.post('/collections.export', { id: this.id });
};
@action
delete = async () => {
try {
await client.post('/collections.delete', { id: this.id });
this.emit('collections.delete', { id: this.id });
return true;
} catch (e) {
this.ui.showToast('Collection failed to delete');
}
return false;
};
@action
export = async () => {
await client.post('/collections.export', { id: this.id });
};
@action
updateData(data: Object = {}) {
extendObservable(this, data);
}
constructor(collection: $Shape<Collection>) {
super();
this.updateData(collection);
this.ui = stores.ui;
this.on('documents.delete', (data: { collectionId: string }) => {
if (data.collectionId === this.id) this.fetch();
});
this.on(
'documents.update',
(data: { collectionId: string, document: Document }) => {
if (data.collectionId === this.id) {
this.updateDocument(data.document);
}
}
);
this.on('documents.publish', (data: { collectionId: string }) => {
if (data.collectionId === this.id) this.fetch();
});
this.on('documents.move', (data: { collectionId: string }) => {
if (data.collectionId === this.id) this.fetch();
});
}
}
export default Collection;

View File

@ -1,32 +1,12 @@
/* eslint-disable */
import Collection from './Collection';
const { client } = require('utils/ApiClient');
import stores from '../stores';
describe('Collection model', () => {
test('should initialize with data', () => {
const collection = new Collection({
const collection = stores.collections.add({
id: 123,
name: 'Engineering',
});
expect(collection.name).toBe('Engineering');
});
describe('#fetch', () => {
test('should update data', async () => {
client.post = jest.fn(() => ({
data: {
name: 'New collection',
},
}))
const collection = new Collection({
id: 123,
name: 'Engineering',
});
await collection.fetch();
expect(client.post).toHaveBeenCalledWith('/collections.info', { id: 123 });
expect(collection.name).toBe('New collection');
});
});
});

View File

@ -1,49 +1,57 @@
// @flow
import { extendObservable, action, runInAction, computed } from 'mobx';
import { action, set, computed } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import stores from 'stores';
import parseTitle from '../../shared/utils/parseTitle';
import unescape from '../../shared/utils/unescape';
import parseTitle from 'shared/utils/parseTitle';
import unescape from 'shared/utils/unescape';
import type { NavigationNode, Revision, User } from 'types';
import BaseModel from './BaseModel';
import Collection from './Collection';
import type { NavigationNode } from 'types';
import BaseModel from 'models/BaseModel';
import Revision from 'models/Revision';
import User from 'models/User';
import Collection from 'models/Collection';
type SaveOptions = { publish?: boolean, done?: boolean, autosave?: boolean };
class Document extends BaseModel {
isSaving: boolean = false;
export default class Document extends BaseModel {
isSaving: boolean;
ui: *;
store: *;
collaborators: User[];
collection: $Shape<Collection>;
collection: Collection;
collectionId: string;
firstViewedAt: ?string;
lastViewedAt: ?string;
modifiedSinceViewed: ?boolean;
createdAt: string;
createdBy: User;
updatedAt: string;
updatedBy: User;
html: string;
id: string;
team: string;
starred: boolean;
pinned: boolean;
text: string;
title: string;
emoji: string;
starred: boolean = false;
pinned: boolean = false;
text: string = '';
title: string = '';
parentDocument: ?string;
publishedAt: ?string;
url: string;
urlId: string;
shareUrl: ?string;
views: number;
revision: number;
/* Computed */
constructor(data?: Object = {}, store: *) {
super(data, store);
this.updateTitle();
}
@action
updateTitle() {
set(this, parseTitle(this.text));
}
@computed
get modifiedSinceViewed(): boolean {
@ -59,9 +67,8 @@ class Document extends BaseModel {
if (childNode.id === this.id) {
path = newPath;
return;
} else {
return traveler(childNode.children, newPath);
}
return traveler(childNode.children, newPath);
});
};
@ -96,44 +103,32 @@ class Document extends BaseModel {
: null;
}
/* Actions */
@action
share = async () => {
try {
const res = await client.post('/shares.create', { documentId: this.id });
invariant(res && res.data, 'Document API response should be available');
this.shareUrl = res.data.url;
} catch (e) {
this.ui.showToast('Document failed to share');
}
const res = await client.post('/shares.create', { documentId: this.id });
invariant(res && res.data, 'Share data should be available');
this.shareUrl = res.data.url;
return this.shareUrl;
};
@action
restore = async (revision: Revision) => {
try {
const res = await client.post('/documents.restore', {
id: this.id,
revisionId: revision.id,
});
runInAction('Document#save', () => {
invariant(res && res.data, 'Data should be available');
this.updateData(res.data);
});
} catch (e) {
this.ui.showToast('Document failed to restore');
}
updateFromJson = data => {
set(this, data);
this.updateTitle();
};
restore = (revision: Revision) => {
return this.store.restore(this, revision);
};
@action
pin = async () => {
this.pinned = true;
try {
await client.post('/documents.pin', { id: this.id });
} catch (e) {
await this.store.pin(this);
} catch (err) {
this.pinned = false;
this.ui.showToast('Document failed to pin');
throw err;
}
};
@ -141,10 +136,10 @@ class Document extends BaseModel {
unpin = async () => {
this.pinned = false;
try {
await client.post('/documents.unpin', { id: this.id });
} catch (e) {
await this.store.unpin(this);
} catch (err) {
this.pinned = true;
this.ui.showToast('Document failed to unpin');
throw err;
}
};
@ -152,10 +147,10 @@ class Document extends BaseModel {
star = async () => {
this.starred = true;
try {
await client.post('/documents.star', { id: this.id });
} catch (e) {
await this.store.star(this);
} catch (err) {
this.starred = false;
this.ui.showToast('Document failed star');
throw err;
}
};
@ -163,10 +158,10 @@ class Document extends BaseModel {
unstar = async () => {
this.starred = false;
try {
await client.post('/documents.unstar', { id: this.id });
} catch (e) {
this.starred = false;
this.ui.showToast('Document failed unstar');
await this.store.unstar(this);
} catch (err) {
this.starred = true;
throw err;
}
};
@ -178,28 +173,21 @@ class Document extends BaseModel {
@action
fetch = async () => {
try {
const res = await client.post('/documents.info', { id: this.id });
invariant(res && res.data, 'Document API response should be available');
const { data } = res;
runInAction('Document#update', () => {
this.updateData(data);
});
} catch (e) {
this.ui.showToast('Document failed loading');
}
const res = await client.post('/documents.info', { id: this.id });
invariant(res && res.data, 'Data should be available');
this.updateFromJson(res.data);
};
@action
save = async (options: SaveOptions) => {
if (this.isSaving) return this;
const wasDraft = !this.publishedAt;
const isCreating = !this.id;
const wasDraft = !this.publishedAt;
this.isSaving = true;
this.updateTitle();
try {
let res;
if (isCreating) {
const data = {
parentDocument: undefined,
@ -211,77 +199,30 @@ class Document extends BaseModel {
if (this.parentDocument) {
data.parentDocument = this.parentDocument;
}
res = await client.post('/documents.create', data);
const document = await this.store.create(data);
return document;
} else {
res = await client.post('/documents.update', {
const document = await this.store.update({
id: this.id,
title: this.title,
text: this.text,
lastRevision: this.revision,
...options,
});
return document;
}
runInAction('Document#save', () => {
invariant(res && res.data, 'Data should be available');
this.updateData(res.data);
if (isCreating) {
this.emit('documents.create', this);
}
this.emit('documents.update', {
document: this,
collectionId: this.collection.id,
});
if (wasDraft && this.publishedAt) {
this.emit('documents.publish', {
id: this.id,
collectionId: this.collection.id,
});
}
});
} catch (e) {
this.ui.showToast('Document failed to save');
} finally {
if (wasDraft && options.publish) {
this.store.rootStore.collections.fetch(this.collection.id, {
force: true,
});
}
this.isSaving = false;
}
return this;
};
@action
move = async (parentDocumentId: ?string) => {
try {
const res = await client.post('/documents.move', {
id: this.id,
parentDocument: parentDocumentId,
});
invariant(res && res.data, 'Data not available');
this.updateData(res.data);
this.emit('documents.move', {
id: this.id,
collectionId: this.collection.id,
});
} catch (e) {
this.ui.showToast('Error while moving the document');
}
return;
};
@action
delete = async () => {
try {
await client.post('/documents.delete', { id: this.id });
this.emit('documents.delete', {
id: this.id,
collectionId: this.collection.id,
});
return true;
} catch (e) {
this.ui.showToast('Error while deleting the document');
}
return false;
move = (parentDocumentId: ?string) => {
return this.store.move(this, parentDocumentId);
};
duplicate = () => {
@ -289,6 +230,7 @@ class Document extends BaseModel {
};
download = async () => {
// Ensure the document is upto date with latest server contents
await this.fetch();
const blob = new Blob([unescape(this.text)], { type: 'text/markdown' });
@ -301,23 +243,4 @@ class Document extends BaseModel {
a.download = `${this.title}.md`;
a.click();
};
updateData(data: Object = {}) {
if (data.text) {
const { title, emoji } = parseTitle(data.text);
data.title = title;
data.emoji = emoji;
}
extendObservable(this, data);
}
constructor(data?: Object = {}) {
super();
this.updateData(data);
this.ui = stores.ui;
this.store = stores.documents;
}
}
export default Document;

View File

@ -1,9 +1,9 @@
/* eslint-disable */
import Document from './Document';
import stores from '../stores';
describe('Document model', () => {
test('should initialize with data', () => {
const document = new Document({
const document = stores.documents.add({
id: 123,
text: '# Onboarding\nSome body text',
});

View File

@ -3,8 +3,6 @@ import { extendObservable, action } from 'mobx';
import BaseModel from 'models/BaseModel';
import { client } from 'utils/ApiClient';
import stores from 'stores';
import UiStore from 'stores/UiStore';
type Settings = {
url: string,
@ -15,8 +13,6 @@ type Settings = {
type Events = 'documents.create' | 'collections.create';
class Integration extends BaseModel {
ui: UiStore;
id: string;
service: string;
collectionId: string;
@ -25,33 +21,15 @@ class Integration extends BaseModel {
@action
update = async (data: Object) => {
try {
await client.post('/integrations.update', { id: this.id, ...data });
extendObservable(this, data);
} catch (e) {
this.ui.showToast('Integration failed to update');
}
return false;
await client.post('/integrations.update', { id: this.id, ...data });
extendObservable(this, data);
return true;
};
@action
delete = async () => {
try {
await client.post('/integrations.delete', { id: this.id });
this.emit('integrations.delete', { id: this.id });
return true;
} catch (e) {
this.ui.showToast('Integration failed to delete');
}
return false;
delete = () => {
return this.store.delete(this);
};
constructor(data?: Object = {}) {
super();
extendObservable(this, data);
this.ui = stores.ui;
}
}
export default Integration;

View File

@ -0,0 +1,9 @@
// @flow
import BaseModel from './BaseModel';
class NotificationSetting extends BaseModel {
id: string;
event: string;
}
export default NotificationSetting;

14
app/models/Revision.js Normal file
View File

@ -0,0 +1,14 @@
// @flow
import BaseModel from './BaseModel';
import User from './User';
class Revision extends BaseModel {
id: string;
documentId: string;
title: string;
text: string;
createdAt: string;
createdBy: User;
}
export default Revision;

15
app/models/Share.js Normal file
View File

@ -0,0 +1,15 @@
// @flow
import BaseModel from './BaseModel';
import User from './User';
class Share extends BaseModel {
id: string;
url: string;
documentTitle: string;
documentUrl: string;
createdBy: User;
createdAt: string;
updatedAt: string;
}
export default Share;

15
app/models/Team.js Normal file
View File

@ -0,0 +1,15 @@
// @flow
import BaseModel from './BaseModel';
class Team extends BaseModel {
id: string;
name: string;
avatarUrl: string;
slackConnected: boolean;
googleConnected: boolean;
sharing: boolean;
subdomain: ?string;
url: string;
}
export default Team;

15
app/models/User.js Normal file
View File

@ -0,0 +1,15 @@
// @flow
import BaseModel from './BaseModel';
class User extends BaseModel {
avatarUrl: string;
id: string;
name: string;
email: string;
username: string;
isAdmin: boolean;
isSuspended: boolean;
createdAt: string;
}
export default User;

View File

@ -11,6 +11,7 @@ import Document from 'scenes/Document';
import Search from 'scenes/Search';
import Settings from 'scenes/Settings';
import Details from 'scenes/Settings/Details';
import Notifications from 'scenes/Settings/Notifications';
import Security from 'scenes/Settings/Security';
import People from 'scenes/Settings/People';
import Slack from 'scenes/Settings/Slack';
@ -21,7 +22,7 @@ import Export from 'scenes/Settings/Export';
import Error404 from 'scenes/Error404';
import Layout from 'components/Layout';
import Auth from 'components/Auth';
import Authenticated from 'components/Authenticated';
import RouteSidebarHidden from 'components/RouteSidebarHidden';
import { matchDocumentSlug as slug } from 'utils/routeHelpers';
@ -36,7 +37,7 @@ export default function Routes() {
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/share/:shareId" component={Document} />
<Auth>
<Authenticated>
<Layout>
<Switch>
<Route path="/dashboard/:tab" component={Dashboard} />
@ -51,6 +52,11 @@ export default function Routes() {
<Route exact path="/settings/people/:filter" component={People} />
<Route exact path="/settings/shares" component={Shares} />
<Route exact path="/settings/tokens" component={Tokens} />
<Route
exact
path="/settings/notifications"
component={Notifications}
/>
<Route
exact
path="/settings/integrations/slack"
@ -86,7 +92,7 @@ export default function Routes() {
<Route component={NotFound} />
</Switch>
</Layout>
</Auth>
</Authenticated>
</Switch>
);
}

View File

@ -54,8 +54,7 @@ class CollectionScene extends React.Component<Props> {
}
loadContent = async (id: string) => {
const { collections } = this.props;
const collection = collections.getById(id) || (await collections.fetch(id));
const collection = await this.props.collections.fetch(id);
if (collection) {
this.props.ui.setActiveCollection(collection);
@ -103,7 +102,7 @@ class CollectionScene extends React.Component<Props> {
}
renderEmptyCollection() {
if (!this.collection) return;
if (!this.collection) return null;
return (
<CenteredContent>

View File

@ -9,11 +9,13 @@ import Flex from 'shared/components/Flex';
import HelpText from 'components/HelpText';
import Collection from 'models/Collection';
import CollectionsStore from 'stores/CollectionsStore';
import UiStore from 'stores/UiStore';
type Props = {
history: Object,
collection: Collection,
collections: CollectionsStore,
ui: UiStore,
onSubmit: () => void,
};
@ -24,14 +26,16 @@ class CollectionDelete extends React.Component<Props> {
handleSubmit = async (ev: SyntheticEvent<*>) => {
ev.preventDefault();
this.isDeleting = true;
const success = await this.props.collection.delete();
if (success) {
try {
await this.props.collection.delete();
this.props.history.push(homeUrl());
this.props.onSubmit();
} catch (err) {
this.props.ui.showToast(err.message);
} finally {
this.isDeleting = false;
}
this.isDeleting = false;
};
render() {
@ -54,4 +58,4 @@ class CollectionDelete extends React.Component<Props> {
}
}
export default inject('collections')(withRouter(CollectionDelete));
export default inject('collections', 'ui')(withRouter(CollectionDelete));

View File

@ -10,10 +10,12 @@ import Flex from 'shared/components/Flex';
import HelpText from 'components/HelpText';
import ColorPicker from 'components/ColorPicker';
import Collection from 'models/Collection';
import UiStore from 'stores/UiStore';
type Props = {
history: Object,
collection: Collection,
ui: UiStore,
onSubmit: () => void,
};
@ -33,18 +35,18 @@ class CollectionEdit extends React.Component<Props> {
ev.preventDefault();
this.isSaving = true;
this.props.collection.updateData({
name: this.name,
description: this.description,
color: this.color,
});
const success = await this.props.collection.save();
if (success) {
try {
await this.props.collection.save({
name: this.name,
description: this.description,
color: this.color,
});
this.props.onSubmit();
} catch (err) {
this.props.ui.showToast(err.message);
} finally {
this.isSaving = false;
}
this.isSaving = false;
};
handleDescriptionChange = getValue => {
@ -99,4 +101,4 @@ class CollectionEdit extends React.Component<Props> {
}
}
export default inject('collections')(withRouter(CollectionEdit));
export default inject('ui')(withRouter(CollectionEdit));

View File

@ -33,7 +33,7 @@ class CollectionExport extends React.Component<Props> {
render() {
const { collection, auth } = this.props;
if (!auth.user) return;
if (!auth.user) return null;
return (
<Flex column>

View File

@ -11,43 +11,43 @@ import HelpText from 'components/HelpText';
import Collection from 'models/Collection';
import CollectionsStore from 'stores/CollectionsStore';
import UiStore from 'stores/UiStore';
type Props = {
history: Object,
ui: UiStore,
collections: CollectionsStore,
onSubmit: () => void,
};
@observer
class CollectionNew extends React.Component<Props> {
@observable collection: Collection;
@observable name: string = '';
@observable description: string = '';
@observable color: string = '';
@observable isSaving: boolean;
constructor(props: Props) {
super(props);
this.collection = new Collection();
}
handleSubmit = async (ev: SyntheticEvent<*>) => {
ev.preventDefault();
this.isSaving = true;
this.collection.updateData({
name: this.name,
description: this.description,
color: this.color,
});
const success = await this.collection.save();
const collection = new Collection(
{
name: this.name,
description: this.description,
color: this.color,
},
this.props.collections
);
if (success) {
this.props.collections.add(this.collection);
try {
await collection.save();
this.props.onSubmit();
this.props.history.push(this.collection.url);
this.props.history.push(collection.url);
} catch (err) {
this.props.ui.showToast(err.message);
} finally {
this.isSaving = false;
}
this.isSaving = false;
};
handleNameChange = (ev: SyntheticInputEvent<*>) => {
@ -95,4 +95,4 @@ class CollectionNew extends React.Component<Props> {
}
}
export default inject('collections')(withRouter(CollectionNew));
export default inject('collections', 'ui')(withRouter(CollectionNew));

View File

@ -23,7 +23,7 @@ type Props = {
class Dashboard extends React.Component<Props> {
render() {
const { documents, auth } = this.props;
if (!auth.user) return;
if (!auth.user) return null;
const user = auth.user.id;
return (

View File

@ -1,6 +1,6 @@
// @flow
import * as React from 'react';
import debounce from 'lodash/debounce';
import { debounce } from 'lodash';
import styled from 'styled-components';
import breakpoint from 'styled-components-breakpoint';
import { observable } from 'mobx';
@ -18,9 +18,7 @@ import {
matchDocumentEdit,
} from 'utils/routeHelpers';
import { emojiToUrl } from 'utils/emoji';
import type { Revision } from 'types';
import Document from 'models/Document';
import Header from './components/Header';
import DocumentMove from './components/DocumentMove';
import Branding from './components/Branding';
@ -38,6 +36,9 @@ import UiStore from 'stores/UiStore';
import AuthStore from 'stores/AuthStore';
import DocumentsStore from 'stores/DocumentsStore';
import RevisionsStore from 'stores/RevisionsStore';
import Document from 'models/Document';
import Revision from 'models/Revision';
import schema from './schema';
const AUTOSAVE_DELAY = 3000;
@ -101,6 +102,10 @@ class DocumentScene extends React.Component<Props> {
this.props.ui.clearActiveDocument();
}
goToDocumentCanonical = () => {
if (this.document) this.props.history.push(this.document.url);
};
@keydown('m')
goToMove(ev) {
ev.preventDefault();
@ -121,14 +126,17 @@ class DocumentScene extends React.Component<Props> {
loadDocument = async props => {
if (props.newDocument) {
this.document = new Document({
collection: { id: props.match.params.id },
parentDocument: new URLSearchParams(props.location.search).get(
'parentDocument'
),
title: '',
text: '',
});
this.document = new Document(
{
collection: { id: props.match.params.id },
parentDocument: new URLSearchParams(props.location.search).get(
'parentDocument'
),
title: '',
text: '',
},
this.props.documents
);
} else {
const { shareId, revisionId } = props.match.params;
@ -140,7 +148,7 @@ class DocumentScene extends React.Component<Props> {
if (revisionId) {
this.revision = await this.props.revisions.fetch(
props.match.params.documentSlug,
revisionId
{ revisionId }
);
} else {
this.revision = undefined;
@ -201,7 +209,7 @@ class DocumentScene extends React.Component<Props> {
// prevent autosave if nothing has changed
if (options.autosave && document.text.trim() === text.trim()) return;
document.updateData({ text });
document.text = text;
if (!document.allowSave) return;
// prevent autosave before anything has been written
@ -310,7 +318,12 @@ class DocumentScene extends React.Component<Props> {
>
<Route
path={`${match.url}/move`}
component={() => <DocumentMove document={document} />}
component={() => (
<DocumentMove
document={document}
onRequestClose={this.goToDocumentCanonical}
/>
)}
/>
<PageTitle
title={document.title.replace(document.emoji, '')}

View File

@ -21,7 +21,7 @@ const Breadcrumb = observer(({ document, collections }: Props) => {
if (!document.collection) return null;
const collection =
collections.getById(document.collection.id) || document.collection;
collections.data.get(document.collection.id) || document.collection;
return (
<Wrapper justify="flex-start" align="center">

View File

@ -3,10 +3,9 @@ import * as React from 'react';
import ReactDOM from 'react-dom';
import { observable, computed } from 'mobx';
import { observer, inject } from 'mobx-react';
import { withRouter } from 'react-router-dom';
import { Search } from 'js-search';
import { first, last } from 'lodash';
import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
import _ from 'lodash';
import styled from 'styled-components';
import Modal from 'components/Modal';
@ -20,11 +19,10 @@ import DocumentsStore from 'stores/DocumentsStore';
import CollectionsStore, { type DocumentPath } from 'stores/CollectionsStore';
type Props = {
match: Object,
history: Object,
document: Document,
documents: DocumentsStore,
collections: CollectionsStore,
onRequestClose: *,
};
@observer
@ -44,7 +42,7 @@ class DocumentMove extends React.Component<Props> {
const indexeableDocuments = [];
paths.forEach(path => {
// TMP: For now, exclude paths to other collections
if (_.first(path.path).id !== document.collection.id) return;
if (first(path.path).id !== document.collection.id) return;
indexeableDocuments.push(path);
});
@ -91,7 +89,7 @@ class DocumentMove extends React.Component<Props> {
results = results.filter(
result =>
!result.path.map(doc => doc.id).includes(document.id) &&
_.last(result.path.map(doc => doc.id)) !== document.parentDocumentId
last(result.path.map(doc => doc.id)) !== document.parentDocumentId
);
return results;
@ -108,12 +106,8 @@ class DocumentMove extends React.Component<Props> {
}
};
handleClose = () => {
this.props.history.push(this.props.document.url);
};
handleFilter = (e: SyntheticInputEvent<*>) => {
this.searchTerm = e.target.value;
handleFilter = (ev: SyntheticInputEvent<*>) => {
this.searchTerm = ev.target.value;
};
setFirstDocumentRef = ref => {
@ -123,16 +117,17 @@ class DocumentMove extends React.Component<Props> {
renderPathToCurrentDocument() {
const { collections, document } = this.props;
const result = collections.getPathForDocument(document.id);
if (result) {
return <PathToDocument result={result} />;
}
}
render() {
const { document, collections } = this.props;
const { document, collections, onRequestClose } = this.props;
return (
<Modal isOpen onRequestClose={this.handleClose} title="Move document">
<Modal isOpen onRequestClose={onRequestClose} title="Move document">
{document &&
collections.isLoaded && (
<Flex column>
@ -166,7 +161,7 @@ class DocumentMove extends React.Component<Props> {
ref={ref =>
index === 0 && this.setFirstDocumentRef(ref)
}
onSuccess={this.handleClose}
onSuccess={onRequestClose}
/>
))}
</StyledArrowKeyNavigation>
@ -189,4 +184,4 @@ const StyledArrowKeyNavigation = styled(ArrowKeyNavigation)`
flex: 1;
`;
export default withRouter(inject('documents', 'collections')(DocumentMove));
export default inject('documents', 'collections')(DocumentMove);

View File

@ -8,11 +8,13 @@ import Flex from 'shared/components/Flex';
import HelpText from 'components/HelpText';
import Document from 'models/Document';
import DocumentsStore from 'stores/DocumentsStore';
import UiStore from 'stores/UiStore';
type Props = {
history: Object,
document: Document,
documents: DocumentsStore,
ui: UiStore,
onSubmit: () => void,
};
@ -24,14 +26,16 @@ class DocumentDelete extends React.Component<Props> {
ev.preventDefault();
this.isDeleting = true;
const { collection } = this.props.document;
const success = await this.props.document.delete();
if (success) {
try {
await this.props.document.delete();
this.props.history.push(collection.url);
this.props.onSubmit();
} catch (err) {
this.props.ui.showToast(err.message);
} finally {
this.isDeleting = false;
}
this.isDeleting = false;
};
render() {
@ -53,4 +57,4 @@ class DocumentDelete extends React.Component<Props> {
}
}
export default inject('documents')(withRouter(DocumentDelete));
export default inject('documents', 'ui')(withRouter(DocumentDelete));

View File

@ -5,25 +5,23 @@ import keydown from 'react-keydown';
import Waypoint from 'react-waypoint';
import { observable, action } from 'mobx';
import { observer, inject } from 'mobx-react';
import type { SearchResult } from 'types';
import _ from 'lodash';
import DocumentsStore, {
DEFAULT_PAGINATION_LIMIT,
} from 'stores/DocumentsStore';
import { debounce } from 'lodash';
import { withRouter } from 'react-router-dom';
import { searchUrl } from 'utils/routeHelpers';
import styled from 'styled-components';
import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
import Empty from 'components/Empty';
import type { SearchResult } from 'types';
import { DEFAULT_PAGINATION_LIMIT } from 'stores/BaseStore';
import DocumentsStore from 'stores/DocumentsStore';
import { searchUrl } from 'utils/routeHelpers';
import Flex from 'shared/components/Flex';
import Empty from 'components/Empty';
import CenteredContent from 'components/CenteredContent';
import LoadingIndicator from 'components/LoadingIndicator';
import SearchField from './components/SearchField';
import DocumentPreview from 'components/DocumentPreview';
import PageTitle from 'components/PageTitle';
import SearchField from './components/SearchField';
type Props = {
history: Object,
@ -115,11 +113,6 @@ class Search extends React.Component<Props> {
this.fetchResultsDebounced();
};
fetchResultsDebounced = _.debounce(this.fetchResults, 350, {
leading: false,
trailing: true,
});
@action
loadMoreResults = async () => {
// Don't paginate if there aren't more results or were in the middle of fetching
@ -158,6 +151,11 @@ class Search extends React.Component<Props> {
this.isFetching = false;
};
fetchResultsDebounced = debounce(this.fetchResults, 350, {
leading: false,
trailing: true,
});
updateLocation = query => {
this.props.history.replace(searchUrl(query));
};
@ -201,7 +199,7 @@ class Search extends React.Component<Props> {
defaultActiveChildIndex={0}
>
{this.results.map((result, index) => {
const document = documents.getById(result.document.id);
const document = documents.data.get(result.document.id);
if (!document) return null;
return (

View File

@ -121,7 +121,7 @@ class Details extends React.Component<Props> {
name="subdomain"
value={this.subdomain || ''}
onChange={this.handleSubdomainChange}
autocomplete="off"
autoComplete="off"
minLength={4}
maxLength={32}
short

View File

@ -26,18 +26,18 @@ class Export extends React.Component<Props> {
ev.preventDefault();
this.isLoading = true;
const success = await this.props.collections.export();
if (success) {
try {
await this.props.collections.export();
this.isExporting = true;
this.props.ui.showToast('Export in progress…', 'success');
} finally {
this.isLoading = false;
}
this.isLoading = false;
};
render() {
const { auth } = this.props;
if (!auth.user) return;
if (!auth.user) return null;
return (
<CenteredContent>

View File

@ -0,0 +1,93 @@
// @flow
import * as React from 'react';
import { debounce } from 'lodash';
import { observer, inject } from 'mobx-react';
import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle';
import HelpText from 'components/HelpText';
import NotificationListItem from './components/NotificationListItem';
import UiStore from 'stores/UiStore';
import NotificationSettingsStore from 'stores/NotificationSettingsStore';
type Props = {
ui: UiStore,
notificationSettings: NotificationSettingsStore,
};
const options = [
{
event: 'documents.publish',
title: 'Document published',
description: 'Receive a notification whenever a new document is published',
},
{
event: 'documents.update',
title: 'Document updated',
description: 'Receive a notification when a document you created is edited',
},
{
event: 'collections.create',
title: 'Collection created',
description: 'Receive a notification whenever a new collection is created',
},
];
@observer
class Notifications extends React.Component<Props> {
componentDidMount() {
this.props.notificationSettings.fetchPage();
}
handleChange = async (ev: SyntheticInputEvent<*>) => {
const { notificationSettings } = this.props;
const setting = notificationSettings.getByEvent(ev.target.name);
if (ev.target.checked) {
await notificationSettings.save({
event: ev.target.name,
});
} else if (setting) {
await notificationSettings.delete(setting);
}
this.showSuccessMessage();
};
showSuccessMessage = debounce(() => {
this.props.ui.showToast('Notifications updated');
}, 500);
render() {
const { notificationSettings } = this.props;
return (
<CenteredContent>
<PageTitle title="Notifications" />
<h1>Notifications</h1>
<HelpText>
Manage when you receive email notifications from Outline.
</HelpText>
{options.map(option => {
const setting = notificationSettings.getByEvent(option.event);
return (
<NotificationListItem
key={option.event}
onChange={this.handleChange}
setting={setting}
disabled={
(setting && setting.isSaving) || notificationSettings.isFetching
}
{...option}
/>
);
})}
</CenteredContent>
);
}
}
export default inject('notificationSettings', 'ui')(Notifications);

View File

@ -33,7 +33,7 @@ class People extends React.Component<Props> {
let users = this.props.users.active;
if (filter === 'all') {
users = this.props.users.data;
users = this.props.users.orderedData;
} else if (filter === 'admins') {
users = this.props.users.admins;
}

View File

@ -126,6 +126,7 @@ class Profile extends React.Component<Props> {
}
const DangerZone = styled.div`
background: #fff;
position: absolute;
bottom: 16px;
`;

View File

@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import { inject, observer } from 'mobx-react';
import _ from 'lodash';
import { find } from 'lodash';
import styled from 'styled-components';
import Button from 'components/Button';
@ -29,7 +29,7 @@ class Slack extends React.Component<Props> {
}
get commandIntegration() {
return _.find(this.props.integrations.slackIntegrations, {
return find(this.props.integrations.slackIntegrations, {
type: 'command',
});
}
@ -73,7 +73,7 @@ class Slack extends React.Component<Props> {
<List>
{collections.orderedData.map(collection => {
const integration = _.find(integrations.slackIntegrations, {
const integration = find(integrations.slackIntegrations, {
collectionId: collection.id,
});

View File

@ -30,13 +30,13 @@ class Tokens extends React.Component<Props> {
handleSubmit = async (ev: SyntheticEvent<*>) => {
ev.preventDefault();
await this.props.apiKeys.createApiKey(this.name);
await this.props.apiKeys.create({ name: this.name });
this.name = '';
};
render() {
const { apiKeys } = this.props;
const hasApiKeys = apiKeys.data.length > 0;
const hasApiKeys = apiKeys.orderedData.length > 0;
return (
<CenteredContent>
@ -51,11 +51,11 @@ class Tokens extends React.Component<Props> {
{hasApiKeys && (
<List>
{apiKeys.data.map(token => (
{apiKeys.orderedData.map(token => (
<TokenListItem
key={token.id}
token={token}
onDelete={apiKeys.deleteApiKey}
onDelete={token.delete}
/>
))}
</List>

View File

@ -0,0 +1,36 @@
// @flow
import * as React from 'react';
import Checkbox from 'components/Checkbox';
import NotificationSetting from 'models/NotificationSetting';
type Props = {
setting?: NotificationSetting,
title: string,
event: string,
description: string,
disabled: boolean,
onChange: *,
};
const NotificationListItem = ({
setting,
title,
event,
enabled,
onChange,
disabled,
description,
}: Props) => {
return (
<Checkbox
label={title}
name={event}
checked={!!setting}
onChange={onChange}
note={description}
disabled={disabled}
/>
);
};
export default NotificationListItem;

View File

@ -3,7 +3,7 @@ import * as React from 'react';
import ShareMenu from 'menus/ShareMenu';
import ListItem from 'components/List/Item';
import Time from 'shared/components/Time';
import type { Share } from '../../../types';
import Share from 'models/Share';
type Props = {
share: Share,

View File

@ -2,7 +2,7 @@
import * as React from 'react';
import Button from 'components/Button';
import ListItem from 'components/List/Item';
import type { ApiKey } from '../../../types';
import ApiKey from 'models/ApiKey';
type Props = {
token: ApiKey,

View File

@ -6,7 +6,7 @@ import UserMenu from 'menus/UserMenu';
import Avatar from 'components/Avatar';
import ListItem from 'components/List/Item';
import Time from 'shared/components/Time';
import type { User } from '../../../types';
import User from 'models/User';
type Props = {
user: User,

View File

@ -22,11 +22,8 @@ class UserDelete extends React.Component<Props> {
this.isDeleting = true;
try {
const success = await this.props.auth.deleteUser();
if (success) {
this.props.auth.logout();
}
await this.props.auth.deleteUser();
this.props.auth.logout();
} finally {
this.isDeleting = false;
}

View File

@ -1,60 +1,12 @@
// @flow
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { ApiKey, PaginationParams } from 'types';
import BaseStore from './BaseStore';
import RootStore from './RootStore';
import ApiKey from 'models/ApiKey';
class ApiKeysStore {
@observable data: ApiKey[] = [];
@observable isFetching: boolean = false;
@observable isSaving: boolean = false;
export default class ApiKeysStore extends BaseStore<ApiKey> {
actions = ['list', 'create', 'delete'];
@action
fetchPage = async (options: ?PaginationParams): Promise<*> => {
this.isFetching = true;
try {
const res = await client.post('/apiKeys.list', options);
invariant(res && res.data, 'Data should be available');
const { data } = res;
runInAction('fetchApiKeys', () => {
this.data = data;
});
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
@action
createApiKey = async (name: string) => {
this.isSaving = true;
try {
const res = await client.post('/apiKeys.create', { name });
invariant(res && res.data, 'Data should be available');
const { data } = res;
runInAction('createApiKey', () => {
this.data.push(data);
});
} catch (e) {
console.error('Something went wrong');
}
this.isSaving = false;
};
@action
deleteApiKey = async (id: string) => {
try {
await client.post('/apiKeys.delete', { id });
runInAction('deleteApiKey', () => {
this.fetchPage();
});
} catch (e) {
console.error('Something went wrong');
}
};
constructor(rootStore: RootStore) {
super(rootStore, ApiKey);
}
}
export default ApiKeysStore;

View File

@ -4,20 +4,45 @@ import invariant from 'invariant';
import Cookie from 'js-cookie';
import { client } from 'utils/ApiClient';
import { stripSubdomain } from 'shared/utils/domains';
import type { User, Team } from 'types';
import RootStore from 'stores/RootStore';
import User from 'models/User';
import Team from 'models/Team';
const AUTH_STORE = 'AUTH_STORE';
class AuthStore {
export default class AuthStore {
@observable user: ?User;
@observable team: ?Team;
@observable token: ?string;
@observable isSaving: boolean = false;
@observable isLoading: boolean = false;
@observable isSuspended: boolean = false;
@observable suspendedContactEmail: ?string;
rootStore: RootStore;
/* Computed */
constructor(rootStore: RootStore) {
// Rehydrate
let data = {};
try {
data = JSON.parse(localStorage.getItem(AUTH_STORE) || '{}');
} catch (_) {
// no-op Safari private mode
}
this.rootStore = rootStore;
this.user = data.user;
this.team = data.team;
this.token = Cookie.get('accessToken');
if (this.token) setImmediate(() => this.fetch());
autorun(() => {
try {
localStorage.setItem(AUTH_STORE, this.asJson);
} catch (_) {
// no-op Safari private mode
}
});
}
@computed
get authenticated(): boolean {
@ -39,8 +64,18 @@ class AuthStore {
invariant(res && res.data, 'Auth not available');
runInAction('AuthStore#fetch', () => {
this.user = res.data.user;
this.team = res.data.team;
const { user, team } = res.data;
this.user = user;
this.team = team;
if (window.Bugsnag) {
Bugsnag.user = {
id: user.id,
name: user.name,
teamId: team.id,
team: team.name,
};
}
});
} catch (err) {
if (err.error.error === 'user_suspended') {
@ -52,7 +87,7 @@ class AuthStore {
@action
deleteUser = async () => {
await client.post(`/user.delete`, { confirmation: true });
await client.post(`/users.delete`, { confirmation: true });
runInAction('AuthStore#updateUser', () => {
this.user = null;
@ -66,7 +101,7 @@ class AuthStore {
this.isSaving = true;
try {
const res = await client.post(`/user.update`, params);
const res = await client.post(`/users.update`, params);
invariant(res && res.data, 'User response not available');
runInAction('AuthStore#updateUser', () => {
@ -120,29 +155,4 @@ class AuthStore {
// add a timestamp to force reload from server
window.location.href = `${BASE_URL}?done=${new Date().getTime()}`;
};
constructor() {
// Rehydrate
let data = {};
try {
data = JSON.parse(localStorage.getItem(AUTH_STORE) || '{}');
} catch (_) {
// no-op Safari private mode
}
this.user = data.user;
this.team = data.team;
this.token = Cookie.get('accessToken');
if (this.token) setImmediate(() => this.fetch());
autorun(() => {
try {
localStorage.setItem(AUTH_STORE, this.asJson);
} catch (_) {
// no-op Safari private mode
}
});
}
}
export default AuthStore;

View File

@ -1,19 +1,162 @@
// @flow
import { EventEmitter } from 'fbemitter';
import _ from 'lodash';
import invariant from 'invariant';
import { observable, set, action, computed, runInAction } from 'mobx';
import { orderBy } from 'lodash';
import { client } from 'utils/ApiClient';
import RootStore from 'stores/RootStore';
import BaseModel from '../models/BaseModel';
import type { PaginationParams } from 'types';
const emitter = new EventEmitter();
window.__emitter = emitter;
type Action = 'list' | 'info' | 'create' | 'update' | 'delete';
class BaseStore {
emitter: EventEmitter;
on: (eventName: string, callback: Function) => void;
emit: (eventName: string, data: any) => void;
constructor() {
_.extend(this, emitter);
this.on = emitter.addListener;
}
function modelNameFromClassName(string) {
return string.charAt(0).toLowerCase() + string.slice(1);
}
export default BaseStore;
export const DEFAULT_PAGINATION_LIMIT = 25;
export default class BaseStore<T: BaseModel> {
@observable data: Map<string, T> = new Map();
@observable isFetching: boolean = false;
@observable isSaving: boolean = false;
@observable isLoaded: boolean = false;
model: Class<T>;
modelName: string;
rootStore: RootStore;
actions: Action[] = ['list', 'info', 'create', 'update', 'delete'];
constructor(rootStore: RootStore, model: Class<T>) {
this.rootStore = rootStore;
this.model = model;
this.modelName = modelNameFromClassName(model.name);
}
@action
clear() {
this.data.clear();
}
@action
add = (item: Object): T => {
const Model = this.model;
if (!(item instanceof Model)) {
const existing: ?T = this.data.get(item.id);
if (existing) {
set(existing, item);
return existing;
} else {
item = new Model(item, this);
}
}
this.data.set(item.id, item);
return item;
};
@action
remove(id: string): void {
this.data.delete(id);
}
save(params: Object) {
if (params.id) return this.update(params);
return this.create(params);
}
@action
async create(params: Object) {
if (!this.actions.includes('create')) {
throw new Error(`Cannot create ${this.modelName}`);
}
this.isSaving = true;
try {
const res = await client.post(`/${this.modelName}s.create`, params);
invariant(res && res.data, 'Data should be available');
return this.add(res.data);
} finally {
this.isSaving = false;
}
}
@action
async update(params: Object): * {
if (!this.actions.includes('update')) {
throw new Error(`Cannot update ${this.modelName}`);
}
this.isSaving = true;
try {
const res = await client.post(`/${this.modelName}s.update`, params);
invariant(res && res.data, 'Data should be available');
return this.add(res.data);
} finally {
this.isSaving = false;
}
}
@action
async delete(item: T) {
if (!this.actions.includes('delete')) {
throw new Error(`Cannot delete ${this.modelName}`);
}
this.isSaving = true;
try {
await client.post(`/${this.modelName}s.delete`, { id: item.id });
return this.remove(item.id);
} finally {
this.isSaving = false;
}
}
@action
async fetch(id: string, options?: Object = {}): Promise<*> {
if (!this.actions.includes('info')) {
throw new Error(`Cannot fetch ${this.modelName}`);
}
let item = this.data.get(id);
if (item && !options.force) return item;
this.isFetching = true;
try {
const res = await client.post(`/${this.modelName}s.info`, { id });
invariant(res && res.data, 'Data should be available');
return this.add(res.data);
} finally {
this.isFetching = false;
}
}
@action
async fetchPage(params: ?PaginationParams): Promise<*> {
if (!this.actions.includes('list')) {
throw new Error(`Cannot list ${this.modelName}`);
}
this.isFetching = true;
try {
const res = await client.post(`/${this.modelName}s.list`, params);
invariant(res && res.data, 'Data not available');
runInAction(`list#${this.modelName}`, () => {
res.data.forEach(this.add);
this.isLoaded = true;
});
} finally {
this.isFetching = false;
}
}
@computed
get orderedData(): T[] {
// $FlowIssue
return orderBy(Array.from(this.data.values()), 'createdAt', 'desc');
}
}

View File

@ -1,20 +1,14 @@
// @flow
import { observable, computed, action, runInAction, ObservableMap } from 'mobx';
import { computed, runInAction } from 'mobx';
import { concat, last } from 'lodash';
import { client } from 'utils/ApiClient';
import _ from 'lodash';
import invariant from 'invariant';
import BaseStore from './BaseStore';
import UiStore from './UiStore';
import Collection from 'models/Collection';
import RootStore from './RootStore';
import Collection from '../models/Collection';
import naturalSort from 'shared/utils/naturalSort';
import type { PaginationParams } from 'types';
type Options = {
ui: UiStore,
};
type DocumentPathItem = {
export type DocumentPathItem = {
id: string,
title: string,
url: string,
@ -25,17 +19,15 @@ export type DocumentPath = DocumentPathItem & {
path: DocumentPathItem[],
};
class CollectionsStore extends BaseStore {
@observable data: Map<string, Collection> = new ObservableMap([]);
@observable isLoaded: boolean = false;
@observable isFetching: boolean = false;
ui: UiStore;
export default class CollectionsStore extends BaseStore<Collection> {
constructor(rootStore: RootStore) {
super(rootStore, Collection);
}
@computed
get active(): ?Collection {
return this.ui.activeCollectionId
? this.getById(this.ui.activeCollectionId)
return this.rootStore.ui.activeCollectionId
? this.data.get(this.rootStore.ui.activeCollectionId)
: undefined;
}
@ -48,14 +40,14 @@ class CollectionsStore extends BaseStore {
* List of paths to each of the documents, where paths are composed of id and title/name pairs
*/
@computed
get pathsToDocuments(): Array<DocumentPath> {
get pathsToDocuments(): DocumentPath[] {
let results = [];
const travelDocuments = (documentList, path) =>
documentList.forEach(document => {
const { id, title, url } = document;
const node = { id, title, url, type: 'document' };
results.push(_.concat(path, node));
travelDocuments(document.children, _.concat(path, [node]));
results.push(concat(path, node));
travelDocuments(document.children, concat(path, [node]));
});
if (this.isLoaded) {
@ -68,7 +60,7 @@ class CollectionsStore extends BaseStore {
}
return results.map(result => {
const tail = _.last(result);
const tail = last(result);
return {
...tail,
path: result,
@ -85,90 +77,16 @@ class CollectionsStore extends BaseStore {
if (path) return path.title;
}
/* Actions */
delete(collection: Collection) {
super.delete(collection);
@action
fetchPage = async (options: ?PaginationParams): Promise<*> => {
this.isFetching = true;
try {
const res = await client.post('/collections.list', options);
invariant(res && res.data, 'Collection list not available');
const { data } = res;
runInAction('CollectionsStore#fetchPage', () => {
data.forEach(collection => {
this.data.set(collection.id, new Collection(collection));
});
this.isLoaded = true;
});
return res;
} catch (e) {
this.ui.showToast('Failed to load collections');
} finally {
this.isFetching = false;
}
};
@action
fetch = async (id: string): Promise<?Collection> => {
let collection = this.getById(id);
if (collection) return collection;
this.isFetching = true;
try {
const res = await client.post('/collections.info', {
id,
});
invariant(res && res.data, 'Collection not available');
const { data } = res;
const collection = new Collection(data);
runInAction('CollectionsStore#fetch', () => {
this.data.set(data.id, collection);
this.isLoaded = true;
});
return collection;
} catch (e) {
this.ui.showToast('Something went wrong');
} finally {
this.isFetching = false;
}
};
@action
export = async () => {
try {
await client.post('/collections.exportAll');
return true;
} catch (err) {
throw err;
}
};
@action
add = (collection: Collection): void => {
this.data.set(collection.id, collection);
};
@action
remove = (id: string): void => {
this.data.delete(id);
};
getById = (id: string): ?Collection => {
return this.data.get(id);
};
constructor(options: Options) {
super();
this.ui = options.ui;
this.on('collections.delete', (data: { id: string }) => {
this.remove(data.id);
runInAction(() => {
this.rootStore.documents.fetchRecentlyUpdated();
this.rootStore.documents.fetchRecentlyViewed();
});
}
}
export default CollectionsStore;
export = () => {
return client.post('/collections.exportAll');
};
}

View File

@ -1,55 +1,48 @@
// @flow
import { observable, action, computed, ObservableMap, runInAction } from 'mobx';
import { observable, action, computed, runInAction } from 'mobx';
import { without, map, find, orderBy, filter, compact, uniq } from 'lodash';
import { client } from 'utils/ApiClient';
import { map, find, orderBy, filter, compact, uniq, sortBy } from 'lodash';
import naturalSort from 'shared/utils/naturalSort';
import invariant from 'invariant';
import BaseStore from 'stores/BaseStore';
import Document from 'models/Document';
import UiStore from 'stores/UiStore';
import type { PaginationParams, SearchResult } from 'types';
import RootStore from 'stores/RootStore';
import Document from '../models/Document';
import Revision from '../models/Revision';
import type { FetchOptions, PaginationParams, SearchResult } from 'types';
export const DEFAULT_PAGINATION_LIMIT = 25;
type Options = {
ui: UiStore,
};
type FetchOptions = {
prefetch?: boolean,
shareId?: string,
};
class DocumentsStore extends BaseStore {
export default class DocumentsStore extends BaseStore<Document> {
@observable recentlyViewedIds: string[] = [];
@observable recentlyUpdatedIds: string[] = [];
@observable data: Map<string, Document> = new ObservableMap([]);
@observable isLoaded: boolean = false;
@observable isFetching: boolean = false;
ui: UiStore;
constructor(rootStore: RootStore) {
super(rootStore, Document);
}
@computed
get recentlyViewed(): Document[] {
get recentlyViewed(): * {
return orderBy(
compact(this.recentlyViewedIds.map(id => this.getById(id))),
compact(this.recentlyViewedIds.map(id => this.data.get(id))),
'updatedAt',
'desc'
);
}
@computed
get recentlyUpdated(): Document[] {
get recentlyUpdated(): * {
return orderBy(
compact(this.recentlyUpdatedIds.map(id => this.getById(id))),
compact(this.recentlyUpdatedIds.map(id => this.data.get(id))),
'updatedAt',
'desc'
);
}
createdByUser(userId: string): Document[] {
createdByUser(userId: string): * {
return orderBy(
filter(this.data.values(), document => document.createdBy.id === userId),
filter(
Array.from(this.data.values()),
document => document.createdBy.id === userId
),
'updatedAt',
'desc'
);
@ -65,7 +58,7 @@ class DocumentsStore extends BaseStore {
recentlyUpdatedInCollection(collectionId: string): Document[] {
return orderBy(
filter(
this.data.values(),
Array.from(this.data.values()),
document =>
document.collectionId === collectionId && !!document.publishedAt
),
@ -76,33 +69,31 @@ class DocumentsStore extends BaseStore {
@computed
get starred(): Document[] {
return filter(this.data.values(), 'starred');
return filter(this.orderedData, d => d.starred);
}
@computed
get starredAlphabetical(): Document[] {
return sortBy(this.starred, doc => doc.title.toLowerCase());
return naturalSort(this.starred, 'title');
}
@computed
get drafts(): Document[] {
return filter(
orderBy(this.data.values(), 'updatedAt', 'desc'),
orderBy(Array.from(this.data.values()), 'updatedAt', 'desc'),
doc => !doc.publishedAt
);
}
@computed
get active(): ?Document {
return this.ui.activeDocumentId
? this.getById(this.ui.activeDocumentId)
return this.rootStore.ui.activeDocumentId
? this.data.get(this.rootStore.ui.activeDocumentId)
: undefined;
}
/* Actions */
@action
fetchPage = async (
fetchNamedPage = async (
request: string = 'list',
options: ?PaginationParams
): Promise<?(Document[])> => {
@ -112,15 +103,11 @@ class DocumentsStore extends BaseStore {
const res = await client.post(`/documents.${request}`, options);
invariant(res && res.data, 'Document list not available');
const { data } = res;
runInAction('DocumentsStore#fetchPage', () => {
data.forEach(document => {
this.data.set(document.id, new Document(document));
});
runInAction('DocumentsStore#fetchNamedPage', () => {
data.forEach(this.add);
this.isLoaded = true;
});
return data;
} catch (e) {
this.ui.showToast('Failed to load documents');
} finally {
this.isFetching = false;
}
@ -128,7 +115,7 @@ class DocumentsStore extends BaseStore {
@action
fetchRecentlyUpdated = async (options: ?PaginationParams): Promise<*> => {
const data = await this.fetchPage('list', options);
const data = await this.fetchNamedPage('list', options);
runInAction('DocumentsStore#fetchRecentlyUpdated', () => {
// $FlowFixMe
@ -141,7 +128,7 @@ class DocumentsStore extends BaseStore {
@action
fetchRecentlyViewed = async (options: ?PaginationParams): Promise<*> => {
const data = await this.fetchPage('viewed', options);
const data = await this.fetchNamedPage('viewed', options);
runInAction('DocumentsStore#fetchRecentlyViewed', () => {
// $FlowFixMe
@ -154,22 +141,22 @@ class DocumentsStore extends BaseStore {
@action
fetchStarred = (options: ?PaginationParams): Promise<*> => {
return this.fetchPage('starred', options);
return this.fetchNamedPage('starred', options);
};
@action
fetchDrafts = (options: ?PaginationParams): Promise<*> => {
return this.fetchPage('drafts', options);
return this.fetchNamedPage('drafts', options);
};
@action
fetchPinned = (options: ?PaginationParams): Promise<*> => {
return this.fetchPage('pinned', options);
return this.fetchNamedPage('pinned', options);
};
@action
fetchOwned = (options: ?PaginationParams): Promise<*> => {
return this.fetchPage('list', options);
return this.fetchNamedPage('list', options);
};
@action
@ -183,23 +170,26 @@ class DocumentsStore extends BaseStore {
});
invariant(res && res.data, 'Search API response should be available');
const { data } = res;
data.forEach(result => this.add(new Document(result.document)));
data.forEach(result => this.add(result.document));
return data;
};
@action
prefetchDocument = async (id: string) => {
if (!this.getById(id)) {
this.fetch(id, { prefetch: true });
prefetchDocument = (id: string) => {
if (!this.data.get(id)) {
return this.fetch(id, { prefetch: true });
}
};
@action
fetch = async (id: string, options?: FetchOptions = {}): Promise<*> => {
fetch = async (
id: string,
options?: FetchOptions = {}
): Promise<?Document> => {
if (!options.prefetch) this.isFetching = true;
try {
const doc = this.getById(id) || this.getByUrl(id);
const doc: ?Document = this.data.get(id) || this.getByUrl(id);
if (doc) return doc;
const res = await client.post('/documents.info', {
@ -207,24 +197,32 @@ class DocumentsStore extends BaseStore {
shareId: options.shareId,
});
invariant(res && res.data, 'Document not available');
const { data } = res;
const document = new Document(data);
this.add(res.data);
runInAction('DocumentsStore#fetch', () => {
this.data.set(data.id, document);
this.isLoaded = true;
});
return document;
} catch (_err) {
if (!options.prefetch && navigator.onLine) {
this.ui.showToast('Failed to load document');
}
return this.data.get(res.data.id);
} finally {
this.isFetching = false;
}
};
@action
move = async (document: Document, parentDocumentId: ?string) => {
const res = await client.post('/documents.move', {
id: document.id,
parentDocument: parentDocumentId,
});
invariant(res && res.data, 'Data not available');
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
return this.add(res.data);
};
@action
duplicate = async (document: Document): * => {
const res = await client.post('/documents.create', {
@ -234,61 +232,69 @@ class DocumentsStore extends BaseStore {
title: `${document.title} (duplicate)`,
text: document.text,
});
invariant(res && res.data, 'Data should be available');
if (res && res.data) {
const duped = res.data;
this.emit('documents.create', new Document(duped));
this.emit('documents.publish', {
id: duped.id,
collectionId: duped.collection.id,
});
return duped;
}
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
return this.add(res.data);
};
async update(params: *) {
const document = await super.update(params);
// Because the collection object contains the url and title
// we need to ensure they are updated there as well.
const collection = this.getCollectionForDocument(document);
if (collection) collection.updateDocument(document);
return document;
}
async delete(document: Document) {
await super.delete(document);
runInAction(() => {
this.recentlyViewedIds = without(this.recentlyViewedIds, document.id);
this.recentlyUpdatedIds = without(this.recentlyUpdatedIds, document.id);
});
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
}
@action
add = (document: Document): void => {
this.data.set(document.id, document);
restore = async (document: Document, revision: Revision) => {
const res = await client.post('/documents.restore', {
id: document.id,
revisionId: revision.id,
});
runInAction('Document#restore', () => {
invariant(res && res.data, 'Data should be available');
document.updateFromJson(res.data);
});
};
@action
remove = (id: string): void => {
this.data.delete(id);
pin = (document: Document) => {
return client.post('/documents.pin', { id: document.id });
};
getById = (id: string): ?Document => {
return this.data.get(id);
unpin = (document: Document) => {
return client.post('/documents.unpin', { id: document.id });
};
star = (document: Document) => {
return client.post('/documents.star', { id: document.id });
};
unstar = (document: Document) => {
return client.post('/documents.unstar', { id: document.id });
};
/**
* Match documents by the url ID as the title slug can change
*/
getByUrl = (url: string): ?Document => {
return find(this.data.values(), doc => url.endsWith(doc.urlId));
return find(Array.from(this.data.values()), doc => url.endsWith(doc.urlId));
};
constructor(options: Options) {
super();
this.ui = options.ui;
this.on('documents.delete', (data: { id: string }) => {
this.remove(data.id);
});
this.on('documents.create', (data: Document) => {
this.add(data);
});
// Re-fetch dashboard content so that we don't show deleted documents
this.on('collections.delete', () => {
this.fetchRecentlyUpdated();
this.fetchRecentlyViewed();
});
this.on('documents.delete', () => {
this.fetchRecentlyUpdated();
this.fetchRecentlyViewed();
});
getCollectionForDocument(document: Document) {
return this.rootStore.collections.data.get(document.collectionId);
}
}
export default DocumentsStore;

View File

@ -1,74 +1,25 @@
// @flow
import { observable, computed, action, runInAction, ObservableMap } from 'mobx';
import { client } from 'utils/ApiClient';
import _ from 'lodash';
import invariant from 'invariant';
import UiStore from './UiStore';
import BaseStore from './BaseStore';
import { computed } from 'mobx';
import { filter } from 'lodash';
import naturalSort from 'shared/utils/naturalSort';
import BaseStore from 'stores/BaseStore';
import RootStore from 'stores/RootStore';
import Integration from 'models/Integration';
import type { PaginationParams } from 'types';
class IntegrationsStore extends BaseStore {
@observable data: Map<string, Integration> = new ObservableMap([]);
@observable isLoaded: boolean = false;
@observable isFetching: boolean = false;
ui: UiStore;
class IntegrationsStore extends BaseStore<Integration> {
constructor(rootStore: RootStore) {
super(rootStore, Integration);
}
@computed
get orderedData(): Integration[] {
return _.sortBy(this.data.values(), 'name');
return naturalSort(Array.from(this.data.values()), 'name');
}
@computed
get slackIntegrations(): Integration[] {
return _.filter(this.orderedData, { service: 'slack' });
}
@action
fetchPage = async (options: ?PaginationParams): Promise<*> => {
this.isFetching = true;
try {
const res = await client.post('/integrations.list', options);
invariant(res && res.data, 'Integrations list not available');
const { data } = res;
runInAction('IntegrationsStore#fetchPage', () => {
data.forEach(integration => {
this.data.set(integration.id, new Integration(integration));
});
this.isLoaded = true;
});
return res;
} catch (e) {
this.ui.showToast('Failed to load integrations');
} finally {
this.isFetching = false;
}
};
@action
add = (data: Integration): void => {
this.data.set(data.id, data);
};
@action
remove = (id: string): void => {
this.data.delete(id);
};
getById = (id: string): ?Integration => {
return this.data.get(id);
};
constructor(options: { ui: UiStore }) {
super();
this.ui = options.ui;
this.on('integrations.delete', (data: { id: string }) => {
this.remove(data.id);
});
return filter(this.orderedData, { service: 'slack' });
}
}

View File

@ -0,0 +1,19 @@
// @flow
import { find } from 'lodash';
import NotificationSetting from 'models/NotificationSetting';
import BaseStore from './BaseStore';
import RootStore from './RootStore';
export default class NotificationSettingsStore extends BaseStore<
NotificationSetting
> {
actions = ['list', 'create', 'delete'];
constructor(rootStore: RootStore) {
super(rootStore, NotificationSetting);
}
getByEvent = (event: string) => {
return find(this.orderedData, { event });
};
}

View File

@ -1,22 +1,18 @@
// @flow
import { observable, computed, action, runInAction, ObservableMap } from 'mobx';
import { client } from 'utils/ApiClient';
import { orderBy, filter } from 'lodash';
import { action, runInAction } from 'mobx';
import { filter } from 'lodash';
import invariant from 'invariant';
import BaseStore from './BaseStore';
import UiStore from './UiStore';
import type { Revision, PaginationParams } from 'types';
import { client } from 'utils/ApiClient';
import BaseStore from 'stores/BaseStore';
import RootStore from 'stores/RootStore';
import Revision from 'models/Revision';
import type { FetchOptions, PaginationParams } from 'types';
class RevisionsStore extends BaseStore {
@observable data: Map<string, Revision> = new ObservableMap([]);
@observable isLoaded: boolean = false;
@observable isFetching: boolean = false;
export default class RevisionsStore extends BaseStore<Revision> {
actions = ['list'];
ui: UiStore;
@computed
get orderedData(): Revision[] {
return orderBy(this.data.values(), 'createdAt', 'desc');
constructor(rootStore: RootStore) {
super(rootStore, Revision);
}
getDocumentRevisions(documentId: string): Revision[] {
@ -24,11 +20,16 @@ class RevisionsStore extends BaseStore {
}
@action
fetch = async (documentId: string, id: string): Promise<*> => {
fetch = async (
documentId: string,
options?: FetchOptions
): Promise<?Revision> => {
this.isFetching = true;
const id = options && options.revisionId;
if (!id) throw new Error('revisionId is required');
try {
const rev = this.getById(id);
const rev = this.data.get(id);
if (rev) return rev;
const res = await client.post('/documents.revision', {
@ -44,8 +45,6 @@ class RevisionsStore extends BaseStore {
});
return data;
} catch (e) {
this.ui.showToast('Failed to load document revision');
} finally {
this.isFetching = false;
}
@ -58,39 +57,14 @@ class RevisionsStore extends BaseStore {
try {
const res = await client.post('/documents.revisions', options);
invariant(res && res.data, 'Document revisions not available');
const { data } = res;
runInAction('RevisionsStore#fetchPage', () => {
data.forEach(revision => {
res.data.forEach(revision => {
this.data.set(revision.id, revision);
});
this.isLoaded = true;
});
return data;
} catch (e) {
this.ui.showToast('Failed to load document revisions');
} finally {
this.isFetching = false;
}
};
@action
add = (data: Revision): void => {
this.data.set(data.id, data);
};
@action
remove = (id: string): void => {
this.data.delete(id);
};
getById = (id: string): ?Revision => {
return this.data.get(id);
};
constructor(options: { ui: UiStore }) {
super();
this.ui = options.ui;
}
}
export default RevisionsStore;

48
app/stores/RootStore.js Normal file
View File

@ -0,0 +1,48 @@
// @flow
import ApiKeysStore from './ApiKeysStore';
import AuthStore from './AuthStore';
import CollectionsStore from './CollectionsStore';
import DocumentsStore from './DocumentsStore';
import IntegrationsStore from './IntegrationsStore';
import NotificationSettingsStore from './NotificationSettingsStore';
import RevisionsStore from './RevisionsStore';
import SharesStore from './SharesStore';
import UiStore from './UiStore';
import UsersStore from './UsersStore';
export default class RootStore {
apiKeys: ApiKeysStore;
auth: AuthStore;
collections: CollectionsStore;
documents: DocumentsStore;
integrations: IntegrationsStore;
notificationSettings: NotificationSettingsStore;
revisions: RevisionsStore;
shares: SharesStore;
ui: UiStore;
users: UsersStore;
constructor() {
this.apiKeys = new ApiKeysStore(this);
this.auth = new AuthStore(this);
this.collections = new CollectionsStore(this);
this.documents = new DocumentsStore(this);
this.integrations = new IntegrationsStore(this);
this.notificationSettings = new NotificationSettingsStore(this);
this.revisions = new RevisionsStore(this);
this.shares = new SharesStore(this);
this.ui = new UiStore();
this.users = new UsersStore(this);
}
logout() {
this.apiKeys.clear();
this.collections.clear();
this.documents.clear();
this.integrations.clear();
this.notificationSettings.clear();
this.revisions.clear();
this.shares.clear();
this.users.clear();
}
}

View File

@ -1,51 +1,26 @@
// @flow
import _ from 'lodash';
import { observable, action, runInAction, ObservableMap, computed } from 'mobx';
import invariant from 'invariant';
import { sortBy } from 'lodash';
import { action, computed } from 'mobx';
import { client } from 'utils/ApiClient';
import type { Share, PaginationParams } from 'types';
import BaseStore from './BaseStore';
import RootStore from './RootStore';
import Share from 'models/Share';
class SharesStore {
@observable data: Map<string, Share> = new ObservableMap([]);
@observable isFetching: boolean = false;
@observable isSaving: boolean = false;
export default class SharesStore extends BaseStore<Share> {
actions = ['list', 'create'];
constructor(rootStore: RootStore) {
super(rootStore, Share);
}
@computed
get orderedData(): Share[] {
return _.sortBy(this.data.values(), 'createdAt').reverse();
return sortBy(Array.from(this.data.values()), 'createdAt').reverse();
}
@action
fetchPage = async (options: ?PaginationParams): Promise<*> => {
this.isFetching = true;
try {
const res = await client.post('/shares.list', options);
invariant(res && res.data, 'Data should be available');
const { data } = res;
runInAction('fetchShares', () => {
data.forEach(share => {
this.data.set(share.id, share);
});
});
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
@action
revoke = async (share: Share) => {
try {
await client.post('/shares.revoke', { id: share.id });
runInAction('revoke', () => {
this.data.delete(share.id);
});
} catch (e) {
console.error('Something went wrong');
}
await client.post('/shares.revoke', { id: share.id });
this.remove(share.id);
};
}
export default SharesStore;

View File

@ -12,9 +12,8 @@ class UiStore {
@observable progressBarVisible: boolean = false;
@observable editMode: boolean = false;
@observable mobileSidebarVisible: boolean = false;
@observable toasts: Toast[] = observable.array([]);
@observable toasts: Toast[] = [];
/* Actions */
@action
setActiveModal = (name: string, props: ?Object): void => {
this.activeModalName = name;
@ -85,7 +84,7 @@ class UiStore {
@action
showToast = (
message: string,
type?: 'warning' | 'error' | 'info' | 'success' = 'warning'
type?: 'warning' | 'error' | 'info' | 'success' = 'success'
): void => {
this.toasts.push({ message, type });
};

View File

@ -1,73 +1,56 @@
// @flow
import { observable, computed, action, runInAction } from 'mobx';
import { filter } from 'lodash';
import { computed, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { User, PaginationParams } from 'types';
import BaseStore from './BaseStore';
import RootStore from './RootStore';
import User from 'models/User';
class UsersStore {
@observable data: User[] = [];
@observable isSaving: boolean = false;
export default class UsersStore extends BaseStore<User> {
constructor(rootStore: RootStore) {
super(rootStore, User);
}
@computed
get active(): User[] {
return this.data.filter(user => !user.isSuspended);
return filter(this.orderedData, user => !user.isSuspended);
}
@computed
get admins(): User[] {
return this.data.filter(user => user.isAdmin);
return filter(this.orderedData, user => user.isAdmin);
}
@action
fetchPage = async (options: ?PaginationParams): Promise<*> => {
try {
const res = await client.post('/team.users', options);
invariant(res && res.data, 'Data should be available');
const { data } = res;
runInAction('fetchUsers', () => {
this.data = data.reverse();
});
} catch (e) {
console.error('Something went wrong');
}
};
@action
promote = async (user: User) => {
promote = (user: User) => {
return this.actionOnUser('promote', user);
};
@action
demote = async (user: User) => {
demote = (user: User) => {
return this.actionOnUser('demote', user);
};
@action
suspend = async (user: User) => {
suspend = (user: User) => {
return this.actionOnUser('suspend', user);
};
@action
activate = async (user: User) => {
activate = (user: User) => {
return this.actionOnUser('activate', user);
};
actionOnUser = async (action: string, user: User) => {
try {
const res = await client.post(`/user.${action}`, {
id: user.id,
});
invariant(res && res.data, 'Data should be available');
const { data } = res;
const res = await client.post(`/users.${action}`, {
id: user.id,
});
invariant(res && res.data, 'Data should be available');
const { data } = res;
runInAction(`UsersStore#${action}`, () => {
this.data = this.data.map(user => (user.id === data.id ? data : user));
});
} catch (e) {
console.error('Something went wrong');
}
runInAction(`UsersStore#${action}`, () => {
this.add(data);
});
};
}
export default UsersStore;

View File

@ -1,18 +1,6 @@
// @flow
import AuthStore from './AuthStore';
import UiStore from './UiStore';
import DocumentsStore from './DocumentsStore';
import RevisionsStore from './RevisionsStore';
import SharesStore from './SharesStore';
import RootStore from 'stores/RootStore';
const ui = new UiStore();
const stores = {
user: null, // Including for Layout
auth: new AuthStore(),
ui,
documents: new DocumentsStore({ ui }),
revisions: new RevisionsStore({ ui }),
shares: new SharesStore(),
};
const stores = new RootStore();
export default stores;

View File

@ -1,53 +1,16 @@
// @flow
export type User = {
avatarUrl: string,
id: string,
name: string,
email: string,
username: string,
isAdmin?: boolean,
isSuspended?: boolean,
createdAt: string,
};
export type Revision = {
id: string,
documentId: string,
title: string,
text: string,
createdAt: string,
createdBy: User,
diff: {
added: number,
removed: number,
},
};
import Document from 'models/Document';
export type Toast = {
message: string,
type: 'warning' | 'error' | 'info' | 'success',
};
export type Share = {
id: string,
url: string,
documentTitle: string,
documentUrl: string,
createdBy: User,
createdAt: string,
updatedAt: string,
};
export type Team = {
id: string,
name: string,
avatarUrl: string,
slackConnected: boolean,
googleConnected: boolean,
sharing: boolean,
subdomain?: string,
url: string,
export type FetchOptions = {
prefetch?: boolean,
revisionId?: string,
shareId?: string,
force?: boolean,
};
export type NavigationNode = {
@ -57,24 +20,6 @@ export type NavigationNode = {
children: NavigationNode[],
};
export type Document = {
collaborators: User[],
collection: Object,
createdAt: string,
createdBy: User,
html: string,
id: string,
starred: boolean,
views: number,
team: string,
text: string,
title: string,
updatedAt: string,
updatedBy: User,
url: string,
views: number,
};
// Pagination response in an API call
export type Pagination = {
limit: number,
@ -90,12 +35,6 @@ export type PaginationParams = {
direction?: 'ASC' | 'DESC',
};
export type ApiKey = {
id: string,
name: string,
secret: string,
};
export type SearchResult = {
ranking: number,
context: string,

View File

@ -47,15 +47,23 @@ class ApiClient {
headers.set('Authorization', `Bearer ${stores.auth.token}`);
}
// $FlowFixMe don't care much about this right now
const response = await fetch(this.baseUrl + (modifiedPath || path), {
method,
body,
headers,
redirect: 'follow',
credentials: 'omit',
cache: 'no-cache',
});
let response;
try {
response = await fetch(this.baseUrl + (modifiedPath || path), {
method,
body,
headers,
redirect: 'follow',
credentials: 'omit',
cache: 'no-cache',
});
} catch (err) {
if (window.navigator.onLine) {
throw new Error('A network error occurred, try again?');
} else {
throw new Error('No internet connection available');
}
}
if (response.status >= 200 && response.status < 300) {
return response.json();
@ -92,9 +100,10 @@ class ApiClient {
// Helpers
constructQueryString = (data: Object) => {
return map(data, (v, k) => {
return `${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
}).join('&');
return map(
data,
(v, k) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`
).join('&');
};
}

View File

@ -15,7 +15,7 @@ const importFile = async ({
documentId,
collectionId,
}: Options): Promise<Document> => {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = async ev => {
@ -28,10 +28,13 @@ const importFile = async ({
if (documentId) data.parentDocument = documentId;
let document = new Document(data);
document = await document.save({ publish: true });
documents.add(document);
resolve(document);
const document = new Document(data, documents);
try {
await document.save({ publish: true });
resolve(document);
} catch (err) {
reject(err);
}
};
reader.readAsText(file);
});

View File

@ -23,7 +23,7 @@ export function documentUrl(doc: Document): string {
}
export function documentNewUrl(doc: Document): string {
const newUrl = `${doc.collection.url}/new`;
const newUrl = `${doc.collection.url || ''}/new`;
if (doc.parentDocumentId) {
return `${newUrl}?parentDocument=${doc.parentDocumentId}`;
}
@ -59,7 +59,7 @@ export function updateDocumentUrl(oldUrl: string, newUrl: string): string {
}
export function newDocumentUrl(collection: Collection): string {
return `${collection.url}/new`;
return `${collection.url || ''}/new`;
}
export function searchUrl(query?: string): string {

View File

@ -11,7 +11,7 @@ export const uploadFile = async (
option?: Options = { name: '' }
) => {
const filename = file instanceof File ? file.name : option.name;
const response = await client.post('/user.s3Upload', {
const response = await client.post('/users.s3Upload', {
kind: file.type,
size: file.size,
filename,

View File

@ -1,5 +1,5 @@
// flow-typed signature: 34ca0e3549dbccf06b1bfc979378b478
// flow-typed version: <<STUB>>/@tommoor/remove-markdown_v0.3.1/flow_v0.71.0
// flow-typed signature: 21d5fe028258d1ffba50a6b0736291d5
// flow-typed version: <<STUB>>/@tommoor/remove-markdown_v0.3.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 1716f73356cbdf5450e8d7ab82dd2e1a
// flow-typed version: <<STUB>>/@tommoor/slate-drop-or-paste-images_v^0.8.1/flow_v0.71.0
// flow-typed signature: 331ec8f8b563f7cbdee203ec29d377df
// flow-typed version: <<STUB>>/@tommoor/slate-drop-or-paste-images_v^0.8.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 0cb55f2f1730c36c81fb4d6e5baedccf
// flow-typed version: <<STUB>>/autotrack_v^2.4.1/flow_v0.71.0
// flow-typed signature: 7cf9fa5af6f3abd4a1bff3cd0f6bfa67
// flow-typed version: <<STUB>>/autotrack_v^2.4.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 89d44f4cb92605ee21e7925d36b4d4f1
// flow-typed version: <<STUB>>/aws-sdk_v^2.135.0/flow_v0.71.0
// flow-typed signature: b94812bc40dc3ffa6ade48e2b6be6b75
// flow-typed version: <<STUB>>/aws-sdk_v^2.135.0/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: e24af6bf202d8e5fab4e87cde4d2bfa2
// flow-typed version: <<STUB>>/babel-core_v^6.24.1/flow_v0.71.0
// flow-typed signature: fcaf7a7816f60a19ea3a1f56e8d0aece
// flow-typed version: <<STUB>>/babel-core_v^6.24.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 533f9ec506a216e4d7a0f986dfe83e8b
// flow-typed version: <<STUB>>/babel-eslint_v^8.1.2/flow_v0.71.0
// flow-typed signature: 2a52dca523c85f00349a5f796ac57f98
// flow-typed version: <<STUB>>/babel-eslint_v^8.1.2/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 16a74ec1b3f30574b1d17af2e1aae17e
// flow-typed version: <<STUB>>/babel-jest_v22/flow_v0.71.0
// flow-typed signature: 79b7d190650deeee4eae5fe6e58effab
// flow-typed version: <<STUB>>/babel-jest_v22/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: a62195ffbfff5c6790934103be75a8ff
// flow-typed version: <<STUB>>/babel-loader_v^7.1.2/flow_v0.71.0
// flow-typed signature: 86c74e4861e92b022be2751b4e34c07f
// flow-typed version: <<STUB>>/babel-loader_v^7.1.2/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 47c9088583f2a3b1c3bb03b4055baece
// flow-typed version: <<STUB>>/babel-plugin-lodash_v^3.2.11/flow_v0.71.0
// flow-typed signature: caeb055267c108526a45dbe39a1cfcde
// flow-typed version: <<STUB>>/babel-plugin-lodash_v^3.2.11/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 9da92a15fa5848fd1ac62d37d77a6850
// flow-typed version: <<STUB>>/babel-plugin-styled-components_v^1.1.7/flow_v0.71.0
// flow-typed signature: c1c7db4e6f9c1bbafd00e07275660942
// flow-typed version: <<STUB>>/babel-plugin-styled-components_v^1.1.7/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 652608d2e8431a8c5274bad836ee0926
// flow-typed version: <<STUB>>/babel-plugin-syntax-dynamic-import_v^6.18.0/flow_v0.71.0
// flow-typed signature: 3f861346197ad057d0c793c36f953381
// flow-typed version: <<STUB>>/babel-plugin-syntax-dynamic-import_v^6.18.0/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: b26839abd705c305219fee62938d492b
// flow-typed version: <<STUB>>/babel-plugin-transform-class-properties_v^6.24.1/flow_v0.71.0
// flow-typed signature: b69261b9b5752022ba1f9f5bd7d71ad4
// flow-typed version: <<STUB>>/babel-plugin-transform-class-properties_v^6.24.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: c7f83286bf05aa71691f77b01cfe5ca8
// flow-typed version: <<STUB>>/babel-plugin-transform-decorators-legacy_v1.3.4/flow_v0.71.0
// flow-typed signature: f8bc955b803a9e7e65e580d016899f98
// flow-typed version: <<STUB>>/babel-plugin-transform-decorators-legacy_v1.3.4/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 9afa5c60629c28d30730ce2df5dcfcd7
// flow-typed version: <<STUB>>/babel-plugin-transform-es2015-destructuring_v^6.23.0/flow_v0.71.0
// flow-typed signature: 62fe854d6357f8fd870790d2a53beac3
// flow-typed version: <<STUB>>/babel-plugin-transform-es2015-destructuring_v^6.23.0/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: c96a996d8250423b12b2ed9faec13a86
// flow-typed version: <<STUB>>/babel-plugin-transform-es2015-modules-commonjs_v^6.24.1/flow_v0.71.0
// flow-typed signature: 7ae27a2d87e57295d80ed091aa9f747d
// flow-typed version: <<STUB>>/babel-plugin-transform-es2015-modules-commonjs_v^6.24.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 51b77fa264d9add521224f44df19df82
// flow-typed version: <<STUB>>/babel-plugin-transform-object-rest-spread_v^6.23.0/flow_v0.71.0
// flow-typed signature: 690f072b1098aac2a8f78eb97deb0a34
// flow-typed version: <<STUB>>/babel-plugin-transform-object-rest-spread_v^6.23.0/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 246c54ac874037a4d9cffcb766e3bc91
// flow-typed version: <<STUB>>/babel-plugin-transform-regenerator_v^6.24.1/flow_v0.71.0
// flow-typed signature: b483d64df647a2fadd23197c9430df40
// flow-typed version: <<STUB>>/babel-plugin-transform-regenerator_v^6.24.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: b27490fff2d5c4468766643659a3eb2b
// flow-typed version: <<STUB>>/babel-preset-env_v^1.4.0/flow_v0.71.0
// flow-typed signature: bde8620567de0b1d912548f88f0a26da
// flow-typed version: <<STUB>>/babel-preset-env_v^1.4.0/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: c846d354ff1571b99d50a1c57f08f6e6
// flow-typed version: <<STUB>>/babel-preset-react-hmre_v1.1.1/flow_v0.71.0
// flow-typed signature: 3abd654a395868c66a1c68d8267ff856
// flow-typed version: <<STUB>>/babel-preset-react-hmre_v1.1.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: ff1392fee98b43939eca4077f29d32a4
// flow-typed version: <<STUB>>/babel-preset-react_v6.11.1/flow_v0.71.0
// flow-typed signature: e6cb7a9810afe2bffa684e40d8fb20bd
// flow-typed version: <<STUB>>/babel-preset-react_v6.11.1/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 9feb616713e12a7d3ffecfc3f6a59af1
// flow-typed version: <<STUB>>/babel-regenerator-runtime_v6.5.0/flow_v0.71.0
// flow-typed signature: 42bc50941758f28027f0c9bc0069019b
// flow-typed version: <<STUB>>/babel-regenerator-runtime_v6.5.0/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 0b32c7cc183482efcdb782eeb3211877
// flow-typed version: <<STUB>>/boundless-arrow-key-navigation_v^1.0.4/flow_v0.71.0
// flow-typed signature: 59397ad69c376794e3d306a1bd552752
// flow-typed version: <<STUB>>/boundless-arrow-key-navigation_v^1.0.4/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 67e1ab65a05ed9fc881e4c87f68ed770
// flow-typed version: <<STUB>>/boundless-popover_v^1.0.4/flow_v0.71.0
// flow-typed signature: 89f743d454f76a3c86e4c6950cc455d4
// flow-typed version: <<STUB>>/boundless-popover_v^1.0.4/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: ea1970876efdaf55e4b2b4d8d011e47a
// flow-typed version: <<STUB>>/bugsnag_v^1.7.0/flow_v0.71.0
// flow-typed signature: fa2210251969d5a91003802cd9026d2d
// flow-typed version: <<STUB>>/bugsnag_v^1.7.0/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:

View File

@ -1,5 +1,5 @@
// flow-typed signature: 3a17bfa26cb5d7355c449859669d7139
// flow-typed version: <<STUB>>/bull_v^3.3.7/flow_v0.71.0
// flow-typed signature: e34fc9065fe78e43e54c3456364357b7
// flow-typed version: <<STUB>>/bull_v^3.5.2/flow_v0.86.0
/**
* This is an autogenerated libdef stub for:
@ -22,10 +22,6 @@ declare module 'bull' {
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'bull/cron-parse-bug' {
declare module.exports: any;
}
declare module 'bull/examples/cluster-queue' {
declare module.exports: any;
}
@ -38,6 +34,10 @@ declare module 'bull/examples/state' {
declare module.exports: any;
}
declare module 'bull/lib/backoffs' {
declare module.exports: any;
}
declare module 'bull/lib/commands/index' {
declare module.exports: any;
}
@ -94,6 +94,10 @@ declare module 'bull/test/cluster_worker' {
declare module.exports: any;
}
declare module 'bull/test/fixtures/fixture_processor_bar' {
declare module.exports: any;
}
declare module 'bull/test/fixtures/fixture_processor_callback_fail' {
declare module.exports: any;
}
@ -102,6 +106,10 @@ declare module 'bull/test/fixtures/fixture_processor_callback' {
declare module.exports: any;
}
declare module 'bull/test/fixtures/fixture_processor_crash' {
declare module.exports: any;
}
declare module 'bull/test/fixtures/fixture_processor_exit' {
declare module.exports: any;
}
@ -110,6 +118,10 @@ declare module 'bull/test/fixtures/fixture_processor_fail' {
declare module.exports: any;
}
declare module 'bull/test/fixtures/fixture_processor_foo' {
declare module.exports: any;
}
declare module 'bull/test/fixtures/fixture_processor_progress' {
declare module.exports: any;
}
@ -122,6 +134,10 @@ declare module 'bull/test/fixtures/fixture_processor' {
declare module.exports: any;
}
declare module 'bull/test/test_child-pool' {
declare module.exports: any;
}
declare module 'bull/test/test_cluster' {
declare module.exports: any;
}
@ -134,6 +150,10 @@ declare module 'bull/test/test_events' {
declare module.exports: any;
}
declare module 'bull/test/test_getters' {
declare module.exports: any;
}
declare module 'bull/test/test_job' {
declare module.exports: any;
}
@ -166,14 +186,7 @@ declare module 'bull/test/utils' {
declare module.exports: any;
}
declare module 'bull/Untitled-1' {
declare module.exports: any;
}
// Filename aliases
declare module 'bull/cron-parse-bug.js' {
declare module.exports: $Exports<'bull/cron-parse-bug'>;
}
declare module 'bull/examples/cluster-queue.js' {
declare module.exports: $Exports<'bull/examples/cluster-queue'>;
}
@ -189,6 +202,9 @@ declare module 'bull/index' {
declare module 'bull/index.js' {
declare module.exports: $Exports<'bull'>;
}
declare module 'bull/lib/backoffs.js' {
declare module.exports: $Exports<'bull/lib/backoffs'>;
}
declare module 'bull/lib/commands/index.js' {
declare module.exports: $Exports<'bull/lib/commands/index'>;
}
@ -231,18 +247,27 @@ declare module 'bull/lib/worker.js' {
declare module 'bull/test/cluster_worker.js' {
declare module.exports: $Exports<'bull/test/cluster_worker'>;
}
declare module 'bull/test/fixtures/fixture_processor_bar.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_bar'>;
}
declare module 'bull/test/fixtures/fixture_processor_callback_fail.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_callback_fail'>;
}
declare module 'bull/test/fixtures/fixture_processor_callback.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_callback'>;
}
declare module 'bull/test/fixtures/fixture_processor_crash.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_crash'>;
}
declare module 'bull/test/fixtures/fixture_processor_exit.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_exit'>;
}
declare module 'bull/test/fixtures/fixture_processor_fail.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_fail'>;
}
declare module 'bull/test/fixtures/fixture_processor_foo.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_foo'>;
}
declare module 'bull/test/fixtures/fixture_processor_progress.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor_progress'>;
}
@ -252,6 +277,9 @@ declare module 'bull/test/fixtures/fixture_processor_slow.js' {
declare module 'bull/test/fixtures/fixture_processor.js' {
declare module.exports: $Exports<'bull/test/fixtures/fixture_processor'>;
}
declare module 'bull/test/test_child-pool.js' {
declare module.exports: $Exports<'bull/test/test_child-pool'>;
}
declare module 'bull/test/test_cluster.js' {
declare module.exports: $Exports<'bull/test/test_cluster'>;
}
@ -261,6 +289,9 @@ declare module 'bull/test/test_connection.js' {
declare module 'bull/test/test_events.js' {
declare module.exports: $Exports<'bull/test/test_events'>;
}
declare module 'bull/test/test_getters.js' {
declare module.exports: $Exports<'bull/test/test_getters'>;
}
declare module 'bull/test/test_job.js' {
declare module.exports: $Exports<'bull/test/test_job'>;
}
@ -285,6 +316,3 @@ declare module 'bull/test/test_worker.js' {
declare module 'bull/test/utils.js' {
declare module.exports: $Exports<'bull/test/utils'>;
}
declare module 'bull/Untitled-1.js' {
declare module.exports: $Exports<'bull/Untitled-1'>;
}

Some files were not shown because too many files have changed in this diff Show More