chore: Move to prettier standard double quotes (#1309)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
// @flow
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import ApiKey from 'models/ApiKey';
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import ApiKey from "models/ApiKey";
|
||||
|
||||
export default class ApiKeysStore extends BaseStore<ApiKey> {
|
||||
actions = ['list', 'create', 'delete'];
|
||||
actions = ["list", "create", "delete"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, ApiKey);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// @flow
|
||||
import { observable, action, computed, autorun, runInAction } from 'mobx';
|
||||
import invariant from 'invariant';
|
||||
import { getCookie, setCookie, removeCookie } from 'tiny-cookie';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import { getCookieDomain } from 'shared/utils/domains';
|
||||
import RootStore from 'stores/RootStore';
|
||||
import User from 'models/User';
|
||||
import Team from 'models/Team';
|
||||
import { observable, action, computed, autorun, runInAction } from "mobx";
|
||||
import invariant from "invariant";
|
||||
import { getCookie, setCookie, removeCookie } from "tiny-cookie";
|
||||
import { client } from "utils/ApiClient";
|
||||
import { getCookieDomain } from "shared/utils/domains";
|
||||
import RootStore from "stores/RootStore";
|
||||
import User from "models/User";
|
||||
import Team from "models/Team";
|
||||
|
||||
const AUTH_STORE = 'AUTH_STORE';
|
||||
const AUTH_STORE = "AUTH_STORE";
|
||||
|
||||
export default class AuthStore {
|
||||
@observable user: ?User;
|
||||
@@ -23,7 +23,7 @@ export default class AuthStore {
|
||||
// Rehydrate
|
||||
let data = {};
|
||||
try {
|
||||
data = JSON.parse(localStorage.getItem(AUTH_STORE) || '{}');
|
||||
data = JSON.parse(localStorage.getItem(AUTH_STORE) || "{}");
|
||||
} catch (_) {
|
||||
// no-op Safari private mode
|
||||
}
|
||||
@@ -31,7 +31,7 @@ export default class AuthStore {
|
||||
this.rootStore = rootStore;
|
||||
this.user = new User(data.user);
|
||||
this.team = new Team(data.team);
|
||||
this.token = getCookie('accessToken');
|
||||
this.token = getCookie("accessToken");
|
||||
|
||||
if (this.token) setImmediate(() => this.fetch());
|
||||
|
||||
@@ -66,10 +66,10 @@ export default class AuthStore {
|
||||
@action
|
||||
fetch = async () => {
|
||||
try {
|
||||
const res = await client.post('/auth.info');
|
||||
invariant(res && res.data, 'Auth not available');
|
||||
const res = await client.post("/auth.info");
|
||||
invariant(res && res.data, "Auth not available");
|
||||
|
||||
runInAction('AuthStore#fetch', () => {
|
||||
runInAction("AuthStore#fetch", () => {
|
||||
this.addPolicies(res.policies);
|
||||
const { user, team } = res.data;
|
||||
this.user = new User(user);
|
||||
@@ -78,20 +78,20 @@ export default class AuthStore {
|
||||
if (window.Sentry) {
|
||||
Sentry.configureScope(function(scope) {
|
||||
scope.setUser({ id: user.id });
|
||||
scope.setExtra('team', team.name);
|
||||
scope.setExtra('teamId', team.id);
|
||||
scope.setExtra("team", team.name);
|
||||
scope.setExtra("teamId", team.id);
|
||||
});
|
||||
}
|
||||
|
||||
// If we came from a redirect then send the user immediately there
|
||||
const postLoginRedirectPath = getCookie('postLoginRedirectPath');
|
||||
const postLoginRedirectPath = getCookie("postLoginRedirectPath");
|
||||
if (postLoginRedirectPath) {
|
||||
removeCookie('postLoginRedirectPath');
|
||||
removeCookie("postLoginRedirectPath");
|
||||
window.location.href = postLoginRedirectPath;
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.error === 'user_suspended') {
|
||||
if (err.error === "user_suspended") {
|
||||
this.isSuspended = true;
|
||||
this.suspendedContactEmail = err.data.adminEmail;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ export default class AuthStore {
|
||||
deleteUser = async () => {
|
||||
await client.post(`/users.delete`, { confirmation: true });
|
||||
|
||||
runInAction('AuthStore#updateUser', () => {
|
||||
runInAction("AuthStore#updateUser", () => {
|
||||
this.user = null;
|
||||
this.team = null;
|
||||
this.token = null;
|
||||
@@ -115,9 +115,9 @@ export default class AuthStore {
|
||||
|
||||
try {
|
||||
const res = await client.post(`/users.update`, params);
|
||||
invariant(res && res.data, 'User response not available');
|
||||
invariant(res && res.data, "User response not available");
|
||||
|
||||
runInAction('AuthStore#updateUser', () => {
|
||||
runInAction("AuthStore#updateUser", () => {
|
||||
this.addPolicies(res.policies);
|
||||
this.user = res.data;
|
||||
});
|
||||
@@ -136,9 +136,9 @@ export default class AuthStore {
|
||||
|
||||
try {
|
||||
const res = await client.post(`/team.update`, params);
|
||||
invariant(res && res.data, 'Team response not available');
|
||||
invariant(res && res.data, "Team response not available");
|
||||
|
||||
runInAction('AuthStore#updateTeam', () => {
|
||||
runInAction("AuthStore#updateTeam", () => {
|
||||
this.addPolicies(res.policies);
|
||||
this.team = new Team(res.data);
|
||||
});
|
||||
@@ -161,19 +161,19 @@ export default class AuthStore {
|
||||
// if this logout was forced from an authenticated route then
|
||||
// save the current path so we can go back there once signed in
|
||||
if (savePath) {
|
||||
setCookie('postLoginRedirectPath', window.location.pathname);
|
||||
setCookie("postLoginRedirectPath", window.location.pathname);
|
||||
}
|
||||
|
||||
// remove authentication token itself
|
||||
removeCookie('accessToken', { path: '/' });
|
||||
removeCookie("accessToken", { path: "/" });
|
||||
|
||||
// remove session record on apex cookie
|
||||
const team = this.team;
|
||||
if (team) {
|
||||
const sessions = JSON.parse(getCookie('sessions') || '{}');
|
||||
const sessions = JSON.parse(getCookie("sessions") || "{}");
|
||||
delete sessions[team.id];
|
||||
|
||||
setCookie('sessions', JSON.stringify(sessions), {
|
||||
setCookie("sessions", JSON.stringify(sessions), {
|
||||
domain: getCookieDomain(window.location.hostname),
|
||||
});
|
||||
this.team = null;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// @flow
|
||||
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';
|
||||
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";
|
||||
|
||||
type Action = 'list' | 'info' | 'create' | 'update' | 'delete';
|
||||
type Action = "list" | "info" | "create" | "update" | "delete";
|
||||
|
||||
function modelNameFromClassName(string) {
|
||||
return string.charAt(0).toLowerCase() + string.slice(1);
|
||||
@@ -24,7 +24,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
model: Class<T>;
|
||||
modelName: string;
|
||||
rootStore: RootStore;
|
||||
actions: Action[] = ['list', 'info', 'create', 'update', 'delete'];
|
||||
actions: Action[] = ["list", "info", "create", "update", "delete"];
|
||||
|
||||
constructor(rootStore: RootStore, model: Class<T>) {
|
||||
this.rootStore = rootStore;
|
||||
@@ -77,7 +77,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
|
||||
@action
|
||||
async create(params: Object) {
|
||||
if (!this.actions.includes('create')) {
|
||||
if (!this.actions.includes("create")) {
|
||||
throw new Error(`Cannot create ${this.modelName}`);
|
||||
}
|
||||
this.isSaving = true;
|
||||
@@ -85,7 +85,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
try {
|
||||
const res = await client.post(`/${this.modelName}s.create`, params);
|
||||
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
return this.add(res.data);
|
||||
@@ -96,7 +96,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
|
||||
@action
|
||||
async update(params: Object): * {
|
||||
if (!this.actions.includes('update')) {
|
||||
if (!this.actions.includes("update")) {
|
||||
throw new Error(`Cannot update ${this.modelName}`);
|
||||
}
|
||||
this.isSaving = true;
|
||||
@@ -104,7 +104,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
try {
|
||||
const res = await client.post(`/${this.modelName}s.update`, params);
|
||||
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
return this.add(res.data);
|
||||
@@ -115,7 +115,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
|
||||
@action
|
||||
async delete(item: T, options?: Object = {}) {
|
||||
if (!this.actions.includes('delete')) {
|
||||
if (!this.actions.includes("delete")) {
|
||||
throw new Error(`Cannot delete ${this.modelName}`);
|
||||
}
|
||||
this.isSaving = true;
|
||||
@@ -133,7 +133,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
|
||||
@action
|
||||
async fetch(id: string, options?: Object = {}): Promise<*> {
|
||||
if (!this.actions.includes('info')) {
|
||||
if (!this.actions.includes("info")) {
|
||||
throw new Error(`Cannot fetch ${this.modelName}`);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
|
||||
try {
|
||||
const res = await client.post(`/${this.modelName}s.info`, { id });
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
return this.add(res.data);
|
||||
@@ -160,7 +160,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
|
||||
@action
|
||||
fetchPage = async (params: ?PaginationParams): Promise<*> => {
|
||||
if (!this.actions.includes('list')) {
|
||||
if (!this.actions.includes("list")) {
|
||||
throw new Error(`Cannot list ${this.modelName}`);
|
||||
}
|
||||
this.isFetching = true;
|
||||
@@ -168,7 +168,7 @@ export default class BaseStore<T: BaseModel> {
|
||||
try {
|
||||
const res = await client.post(`/${this.modelName}s.list`, params);
|
||||
|
||||
invariant(res && res.data, 'Data not available');
|
||||
invariant(res && res.data, "Data not available");
|
||||
|
||||
runInAction(`list#${this.modelName}`, () => {
|
||||
this.addPolicies(res.policies);
|
||||
@@ -183,6 +183,6 @@ export default class BaseStore<T: BaseModel> {
|
||||
|
||||
@computed
|
||||
get orderedData(): T[] {
|
||||
return orderBy(Array.from(this.data.values()), 'createdAt', 'desc');
|
||||
return orderBy(Array.from(this.data.values()), "createdAt", "desc");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// @flow
|
||||
import invariant from 'invariant';
|
||||
import { action, runInAction } from 'mobx';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import CollectionGroupMembership from 'models/CollectionGroupMembership';
|
||||
import type { PaginationParams } from 'types';
|
||||
import invariant from "invariant";
|
||||
import { action, runInAction } from "mobx";
|
||||
import { client } from "utils/ApiClient";
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import CollectionGroupMembership from "models/CollectionGroupMembership";
|
||||
import type { PaginationParams } from "types";
|
||||
|
||||
export default class CollectionGroupMembershipsStore extends BaseStore<
|
||||
CollectionGroupMembership
|
||||
> {
|
||||
actions = ['create', 'delete'];
|
||||
actions = ["create", "delete"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, CollectionGroupMembership);
|
||||
@@ -23,7 +23,7 @@ export default class CollectionGroupMembershipsStore extends BaseStore<
|
||||
try {
|
||||
const res = await client.post(`/collections.group_memberships`, params);
|
||||
|
||||
invariant(res && res.data, 'Data not available');
|
||||
invariant(res && res.data, "Data not available");
|
||||
|
||||
runInAction(`CollectionGroupMembershipsStore#fetchPage`, () => {
|
||||
res.data.groups.forEach(this.rootStore.groups.add);
|
||||
@@ -46,12 +46,12 @@ export default class CollectionGroupMembershipsStore extends BaseStore<
|
||||
groupId: string,
|
||||
permission: string,
|
||||
}) {
|
||||
const res = await client.post('/collections.add_group', {
|
||||
const res = await client.post("/collections.add_group", {
|
||||
id: collectionId,
|
||||
groupId,
|
||||
permission,
|
||||
});
|
||||
invariant(res && res.data, 'Membership data should be available');
|
||||
invariant(res && res.data, "Membership data should be available");
|
||||
|
||||
res.data.collectionGroupMemberships.forEach(this.add);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export default class CollectionGroupMembershipsStore extends BaseStore<
|
||||
collectionId: string,
|
||||
groupId: string,
|
||||
}) {
|
||||
await client.post('/collections.remove_group', {
|
||||
await client.post("/collections.remove_group", {
|
||||
id: collectionId,
|
||||
groupId,
|
||||
});
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// @flow
|
||||
import { computed } from 'mobx';
|
||||
import { concat, filter, last } from 'lodash';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import { computed } from "mobx";
|
||||
import { concat, filter, last } from "lodash";
|
||||
import { client } from "utils/ApiClient";
|
||||
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import Collection from 'models/Collection';
|
||||
import naturalSort from 'shared/utils/naturalSort';
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import Collection from "models/Collection";
|
||||
import naturalSort from "shared/utils/naturalSort";
|
||||
|
||||
export type DocumentPathItem = {
|
||||
id: string,
|
||||
collectionId: string,
|
||||
title: string,
|
||||
url: string,
|
||||
type: 'collection' | 'document',
|
||||
type: "collection" | "document",
|
||||
};
|
||||
|
||||
export type DocumentPath = DocumentPathItem & {
|
||||
@@ -35,7 +35,7 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
@computed
|
||||
get orderedData(): Collection[] {
|
||||
return filter(
|
||||
naturalSort(Array.from(this.data.values()), 'name'),
|
||||
naturalSort(Array.from(this.data.values()), "name"),
|
||||
d => !d.deletedAt
|
||||
);
|
||||
}
|
||||
@@ -59,7 +59,7 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
const travelDocuments = (documentList, collectionId, path) =>
|
||||
documentList.forEach(document => {
|
||||
const { id, title, url } = document;
|
||||
const node = { id, collectionId, title, url, type: 'document' };
|
||||
const node = { id, collectionId, title, url, type: "document" };
|
||||
results.push(concat(path, node));
|
||||
travelDocuments(document.children, collectionId, concat(path, [node]));
|
||||
});
|
||||
@@ -72,7 +72,7 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
collectionId: id,
|
||||
title: name,
|
||||
url,
|
||||
type: 'collection',
|
||||
type: "collection",
|
||||
};
|
||||
results.push([node]);
|
||||
travelDocuments(collection.documents, id, [node]);
|
||||
@@ -105,6 +105,6 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
}
|
||||
|
||||
export = () => {
|
||||
return client.post('/collections.export_all');
|
||||
return client.post("/collections.export_all");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
import { observable, action } from 'mobx';
|
||||
import { USER_PRESENCE_INTERVAL } from 'shared/constants';
|
||||
import { observable, action } from "mobx";
|
||||
import { USER_PRESENCE_INTERVAL } from "shared/constants";
|
||||
|
||||
type DocumentPresence = Map<string, { isEditing: boolean, userId: string }>;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
import { observable, action, computed, runInAction } from 'mobx';
|
||||
import { observable, action, computed, runInAction } from "mobx";
|
||||
import {
|
||||
without,
|
||||
map,
|
||||
@@ -9,16 +9,16 @@ import {
|
||||
compact,
|
||||
omitBy,
|
||||
uniq,
|
||||
} from 'lodash';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import naturalSort from 'shared/utils/naturalSort';
|
||||
import invariant from 'invariant';
|
||||
} from "lodash";
|
||||
import { client } from "utils/ApiClient";
|
||||
import naturalSort from "shared/utils/naturalSort";
|
||||
import invariant from "invariant";
|
||||
|
||||
import BaseStore from 'stores/BaseStore';
|
||||
import RootStore from 'stores/RootStore';
|
||||
import Document from 'models/Document';
|
||||
import Revision from 'models/Revision';
|
||||
import type { FetchOptions, PaginationParams, SearchResult } from 'types';
|
||||
import BaseStore from "stores/BaseStore";
|
||||
import RootStore from "stores/RootStore";
|
||||
import Document from "models/Document";
|
||||
import Revision from "models/Revision";
|
||||
import type { FetchOptions, PaginationParams, SearchResult } from "types";
|
||||
|
||||
export default class DocumentsStore extends BaseStore<Document> {
|
||||
@observable recentlyViewedIds: string[] = [];
|
||||
@@ -39,21 +39,21 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
get recentlyViewed(): Document[] {
|
||||
return orderBy(
|
||||
compact(this.recentlyViewedIds.map(id => this.data.get(id))),
|
||||
'updatedAt',
|
||||
'desc'
|
||||
"updatedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
@computed
|
||||
get recentlyUpdated(): Document[] {
|
||||
return orderBy(this.all, 'updatedAt', 'desc');
|
||||
return orderBy(this.all, "updatedAt", "desc");
|
||||
}
|
||||
|
||||
createdByUser(userId: string): Document[] {
|
||||
return orderBy(
|
||||
filter(this.all, d => d.createdBy.id === userId),
|
||||
'updatedAt',
|
||||
'desc'
|
||||
"updatedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,23 +77,23 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
}
|
||||
|
||||
leastRecentlyUpdatedInCollection(collectionId: string): Document[] {
|
||||
return orderBy(this.inCollection(collectionId), 'updatedAt', 'asc');
|
||||
return orderBy(this.inCollection(collectionId), "updatedAt", "asc");
|
||||
}
|
||||
|
||||
recentlyUpdatedInCollection(collectionId: string): Document[] {
|
||||
return orderBy(this.inCollection(collectionId), 'updatedAt', 'desc');
|
||||
return orderBy(this.inCollection(collectionId), "updatedAt", "desc");
|
||||
}
|
||||
|
||||
recentlyPublishedInCollection(collectionId: string): Document[] {
|
||||
return orderBy(
|
||||
this.publishedInCollection(collectionId),
|
||||
'publishedAt',
|
||||
'desc'
|
||||
"publishedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
alphabeticalInCollection(collectionId: string): Document[] {
|
||||
return naturalSort(this.inCollection(collectionId), 'title');
|
||||
return naturalSort(this.inCollection(collectionId), "title");
|
||||
}
|
||||
|
||||
searchResults(query: string): SearchResult[] {
|
||||
@@ -108,7 +108,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
@computed
|
||||
get archived(): Document[] {
|
||||
return filter(
|
||||
orderBy(this.orderedData, 'archivedAt', 'desc'),
|
||||
orderBy(this.orderedData, "archivedAt", "desc"),
|
||||
d => d.archivedAt && !d.deletedAt
|
||||
);
|
||||
}
|
||||
@@ -116,20 +116,20 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
@computed
|
||||
get deleted(): Document[] {
|
||||
return filter(
|
||||
orderBy(this.orderedData, 'deletedAt', 'desc'),
|
||||
orderBy(this.orderedData, "deletedAt", "desc"),
|
||||
d => d.deletedAt
|
||||
);
|
||||
}
|
||||
|
||||
@computed
|
||||
get starredAlphabetical(): Document[] {
|
||||
return naturalSort(this.starred, 'title');
|
||||
return naturalSort(this.starred, "title");
|
||||
}
|
||||
|
||||
@computed
|
||||
get drafts(): Document[] {
|
||||
return filter(
|
||||
orderBy(this.all, 'updatedAt', 'desc'),
|
||||
orderBy(this.all, "updatedAt", "desc"),
|
||||
doc => !doc.publishedAt
|
||||
);
|
||||
}
|
||||
@@ -146,9 +146,9 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const res = await client.post(`/documents.list`, {
|
||||
backlinkDocumentId: documentId,
|
||||
});
|
||||
invariant(res && res.data, 'Document list not available');
|
||||
invariant(res && res.data, "Document list not available");
|
||||
const { data } = res;
|
||||
runInAction('DocumentsStore#fetchBacklinks', () => {
|
||||
runInAction("DocumentsStore#fetchBacklinks", () => {
|
||||
data.forEach(this.add);
|
||||
this.backlinks.set(documentId, data.map(doc => doc.id));
|
||||
});
|
||||
@@ -158,8 +158,8 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const documentIds = this.backlinks.get(documentId) || [];
|
||||
return orderBy(
|
||||
compact(documentIds.map(id => this.data.get(id))),
|
||||
'updatedAt',
|
||||
'desc'
|
||||
"updatedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -168,24 +168,24 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const res = await client.post(`/documents.list`, {
|
||||
parentDocumentId: documentId,
|
||||
});
|
||||
invariant(res && res.data, 'Document list not available');
|
||||
invariant(res && res.data, "Document list not available");
|
||||
const { data } = res;
|
||||
runInAction('DocumentsStore#fetchChildDocuments', () => {
|
||||
runInAction("DocumentsStore#fetchChildDocuments", () => {
|
||||
data.forEach(this.add);
|
||||
});
|
||||
};
|
||||
|
||||
@action
|
||||
fetchNamedPage = async (
|
||||
request: string = 'list',
|
||||
request: string = "list",
|
||||
options: ?PaginationParams
|
||||
): Promise<?(Document[])> => {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post(`/documents.${request}`, options);
|
||||
invariant(res && res.data, 'Document list not available');
|
||||
runInAction('DocumentsStore#fetchNamedPage', () => {
|
||||
invariant(res && res.data, "Document list not available");
|
||||
runInAction("DocumentsStore#fetchNamedPage", () => {
|
||||
res.data.forEach(this.add);
|
||||
this.addPolicies(res.policies);
|
||||
this.isLoaded = true;
|
||||
@@ -198,24 +198,24 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
fetchArchived = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('archived', options);
|
||||
return this.fetchNamedPage("archived", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchDeleted = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('deleted', options);
|
||||
return this.fetchNamedPage("deleted", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchRecentlyUpdated = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', options);
|
||||
return this.fetchNamedPage("list", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchAlphabetical = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', {
|
||||
sort: 'title',
|
||||
direction: 'ASC',
|
||||
return this.fetchNamedPage("list", {
|
||||
sort: "title",
|
||||
direction: "ASC",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
@@ -224,30 +224,30 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
fetchLeastRecentlyUpdated = async (
|
||||
options: ?PaginationParams
|
||||
): Promise<*> => {
|
||||
return this.fetchNamedPage('list', {
|
||||
sort: 'updatedAt',
|
||||
direction: 'ASC',
|
||||
return this.fetchNamedPage("list", {
|
||||
sort: "updatedAt",
|
||||
direction: "ASC",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@action
|
||||
fetchRecentlyPublished = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', {
|
||||
sort: 'publishedAt',
|
||||
direction: 'DESC',
|
||||
return this.fetchNamedPage("list", {
|
||||
sort: "publishedAt",
|
||||
direction: "DESC",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@action
|
||||
fetchRecentlyViewed = async (options: ?PaginationParams): Promise<*> => {
|
||||
const data = await this.fetchNamedPage('viewed', options);
|
||||
const data = await this.fetchNamedPage("viewed", options);
|
||||
|
||||
runInAction('DocumentsStore#fetchRecentlyViewed', () => {
|
||||
runInAction("DocumentsStore#fetchRecentlyViewed", () => {
|
||||
// $FlowFixMe
|
||||
this.recentlyViewedIds.replace(
|
||||
uniq(this.recentlyViewedIds.concat(map(data, 'id')))
|
||||
uniq(this.recentlyViewedIds.concat(map(data, "id")))
|
||||
);
|
||||
});
|
||||
return data;
|
||||
@@ -255,22 +255,22 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
fetchStarred = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('starred', options);
|
||||
return this.fetchNamedPage("starred", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchDrafts = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('drafts', options);
|
||||
return this.fetchNamedPage("drafts", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchPinned = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('pinned', options);
|
||||
return this.fetchNamedPage("pinned", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchOwned = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', options);
|
||||
return this.fetchNamedPage("list", options);
|
||||
};
|
||||
|
||||
@action
|
||||
@@ -280,11 +280,11 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
): Promise<SearchResult[]> => {
|
||||
// $FlowFixMe
|
||||
const compactedOptions = omitBy(options, o => !o);
|
||||
const res = await client.get('/documents.search', {
|
||||
const res = await client.get("/documents.search", {
|
||||
...compactedOptions,
|
||||
query,
|
||||
});
|
||||
invariant(res && res.data, 'Search response should be available');
|
||||
invariant(res && res.data, "Search response should be available");
|
||||
|
||||
// add the documents and associated policies to the store
|
||||
res.data.forEach(result => this.add(result.document));
|
||||
@@ -335,16 +335,16 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
return doc;
|
||||
}
|
||||
|
||||
const res = await client.post('/documents.info', {
|
||||
const res = await client.post("/documents.info", {
|
||||
id,
|
||||
shareId: options.shareId,
|
||||
});
|
||||
invariant(res && res.data, 'Document not available');
|
||||
invariant(res && res.data, "Document not available");
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
this.add(res.data);
|
||||
|
||||
runInAction('DocumentsStore#fetch', () => {
|
||||
runInAction("DocumentsStore#fetch", () => {
|
||||
this.isLoaded = true;
|
||||
});
|
||||
|
||||
@@ -360,12 +360,12 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
collectionId: string,
|
||||
parentDocumentId: ?string
|
||||
) => {
|
||||
const res = await client.post('/documents.move', {
|
||||
const res = await client.post("/documents.move", {
|
||||
id: document.id,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
});
|
||||
invariant(res && res.data, 'Data not available');
|
||||
invariant(res && res.data, "Data not available");
|
||||
|
||||
res.data.documents.forEach(this.add);
|
||||
res.data.collections.forEach(this.rootStore.collections.add);
|
||||
@@ -373,14 +373,14 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
duplicate = async (document: Document): * => {
|
||||
const res = await client.post('/documents.create', {
|
||||
const res = await client.post("/documents.create", {
|
||||
publish: !!document.publishedAt,
|
||||
parentDocumentId: document.parentDocumentId,
|
||||
collectionId: document.collectionId,
|
||||
title: `${document.title} (duplicate)`,
|
||||
text: document.text,
|
||||
});
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
if (collection) collection.refresh();
|
||||
@@ -439,11 +439,11 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
archive = async (document: Document) => {
|
||||
const res = await client.post('/documents.archive', {
|
||||
const res = await client.post("/documents.archive", {
|
||||
id: document.id,
|
||||
});
|
||||
runInAction('Document#archive', () => {
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
runInAction("Document#archive", () => {
|
||||
invariant(res && res.data, "Data should be available");
|
||||
document.updateFromJson(res.data);
|
||||
this.addPolicies(res.policies);
|
||||
});
|
||||
@@ -454,12 +454,12 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
restore = async (document: Document, revision?: Revision) => {
|
||||
const res = await client.post('/documents.restore', {
|
||||
const res = await client.post("/documents.restore", {
|
||||
id: document.id,
|
||||
revisionId: revision ? revision.id : undefined,
|
||||
});
|
||||
runInAction('Document#restore', () => {
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
runInAction("Document#restore", () => {
|
||||
invariant(res && res.data, "Data should be available");
|
||||
document.updateFromJson(res.data);
|
||||
this.addPolicies(res.policies);
|
||||
});
|
||||
@@ -469,18 +469,18 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
};
|
||||
|
||||
pin = (document: Document) => {
|
||||
return client.post('/documents.pin', { id: document.id });
|
||||
return client.post("/documents.pin", { id: document.id });
|
||||
};
|
||||
|
||||
unpin = (document: Document) => {
|
||||
return client.post('/documents.unpin', { id: document.id });
|
||||
return client.post("/documents.unpin", { id: document.id });
|
||||
};
|
||||
|
||||
star = async (document: Document) => {
|
||||
this.starredIds.set(document.id, true);
|
||||
|
||||
try {
|
||||
return client.post('/documents.star', { id: document.id });
|
||||
return client.post("/documents.star", { id: document.id });
|
||||
} catch (err) {
|
||||
this.starredIds.set(document.id, false);
|
||||
}
|
||||
@@ -490,13 +490,13 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
this.starredIds.set(document.id, false);
|
||||
|
||||
try {
|
||||
return client.post('/documents.unstar', { id: document.id });
|
||||
return client.post("/documents.unstar", { id: document.id });
|
||||
} catch (err) {
|
||||
this.starredIds.set(document.id, false);
|
||||
}
|
||||
};
|
||||
|
||||
getByUrl = (url: string = ''): ?Document => {
|
||||
getByUrl = (url: string = ""): ?Document => {
|
||||
return find(this.orderedData, doc => url.endsWith(doc.urlId));
|
||||
};
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// @flow
|
||||
import { sortBy } from 'lodash';
|
||||
import { computed } from 'mobx';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import Event from 'models/Event';
|
||||
import { sortBy } from "lodash";
|
||||
import { computed } from "mobx";
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import Event from "models/Event";
|
||||
|
||||
export default class EventsStore extends BaseStore<Event> {
|
||||
actions = ['list'];
|
||||
actions = ["list"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, Event);
|
||||
@@ -14,6 +14,6 @@ export default class EventsStore extends BaseStore<Event> {
|
||||
|
||||
@computed
|
||||
get orderedData(): Event[] {
|
||||
return sortBy(Array.from(this.data.values()), 'createdAt').reverse();
|
||||
return sortBy(Array.from(this.data.values()), "createdAt").reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// @flow
|
||||
import invariant from 'invariant';
|
||||
import { action, runInAction } from 'mobx';
|
||||
import { filter } from 'lodash';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import GroupMembership from 'models/GroupMembership';
|
||||
import type { PaginationParams } from 'types';
|
||||
import invariant from "invariant";
|
||||
import { action, runInAction } from "mobx";
|
||||
import { filter } from "lodash";
|
||||
import { client } from "utils/ApiClient";
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import GroupMembership from "models/GroupMembership";
|
||||
import type { PaginationParams } from "types";
|
||||
|
||||
export default class GroupMembershipsStore extends BaseStore<GroupMembership> {
|
||||
actions = ['create', 'delete'];
|
||||
actions = ["create", "delete"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, GroupMembership);
|
||||
@@ -22,7 +22,7 @@ export default class GroupMembershipsStore extends BaseStore<GroupMembership> {
|
||||
try {
|
||||
const res = await client.post(`/groups.memberships`, params);
|
||||
|
||||
invariant(res && res.data, 'Data not available');
|
||||
invariant(res && res.data, "Data not available");
|
||||
|
||||
runInAction(`GroupMembershipsStore#fetchPage`, () => {
|
||||
res.data.users.forEach(this.rootStore.users.add);
|
||||
@@ -37,11 +37,11 @@ export default class GroupMembershipsStore extends BaseStore<GroupMembership> {
|
||||
|
||||
@action
|
||||
async create({ groupId, userId }: { groupId: string, userId: string }) {
|
||||
const res = await client.post('/groups.add_user', {
|
||||
const res = await client.post("/groups.add_user", {
|
||||
id: groupId,
|
||||
userId,
|
||||
});
|
||||
invariant(res && res.data, 'Group Membership data should be available');
|
||||
invariant(res && res.data, "Group Membership data should be available");
|
||||
|
||||
res.data.users.forEach(this.rootStore.users.add);
|
||||
res.data.groups.forEach(this.rootStore.groups.add);
|
||||
@@ -50,11 +50,11 @@ export default class GroupMembershipsStore extends BaseStore<GroupMembership> {
|
||||
|
||||
@action
|
||||
async delete({ groupId, userId }: { groupId: string, userId: string }) {
|
||||
const res = await client.post('/groups.remove_user', {
|
||||
const res = await client.post("/groups.remove_user", {
|
||||
id: groupId,
|
||||
userId,
|
||||
});
|
||||
invariant(res && res.data, 'Group Membership data should be available');
|
||||
invariant(res && res.data, "Group Membership data should be available");
|
||||
|
||||
this.remove(`${userId}-${groupId}`);
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// @flow
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import naturalSort from 'shared/utils/naturalSort';
|
||||
import Group from 'models/Group';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import invariant from 'invariant';
|
||||
import { filter } from 'lodash';
|
||||
import { action, runInAction, computed } from 'mobx';
|
||||
import type { PaginationParams } from 'types';
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import naturalSort from "shared/utils/naturalSort";
|
||||
import Group from "models/Group";
|
||||
import { client } from "utils/ApiClient";
|
||||
import invariant from "invariant";
|
||||
import { filter } from "lodash";
|
||||
import { action, runInAction, computed } from "mobx";
|
||||
import type { PaginationParams } from "types";
|
||||
|
||||
export default class GroupsStore extends BaseStore<Group> {
|
||||
constructor(rootStore: RootStore) {
|
||||
@@ -16,7 +16,7 @@ export default class GroupsStore extends BaseStore<Group> {
|
||||
|
||||
@computed
|
||||
get orderedData(): Group[] {
|
||||
return naturalSort(Array.from(this.data.values()), 'name');
|
||||
return naturalSort(Array.from(this.data.values()), "name");
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -26,7 +26,7 @@ export default class GroupsStore extends BaseStore<Group> {
|
||||
try {
|
||||
const res = await client.post(`/groups.list`, params);
|
||||
|
||||
invariant(res && res.data, 'Data not available');
|
||||
invariant(res && res.data, "Data not available");
|
||||
|
||||
runInAction(`GroupsStore#fetchPage`, () => {
|
||||
this.addPolicies(res.policies);
|
||||
@@ -54,7 +54,7 @@ export default class GroupsStore extends BaseStore<Group> {
|
||||
return queriedGroups(groups, query);
|
||||
};
|
||||
|
||||
notInCollection = (collectionId: string, query: string = '') => {
|
||||
notInCollection = (collectionId: string, query: string = "") => {
|
||||
const memberships = filter(
|
||||
this.rootStore.collectionGroupMemberships.orderedData,
|
||||
member => member.collectionId === collectionId
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// @flow
|
||||
import { computed } from 'mobx';
|
||||
import { filter } from 'lodash';
|
||||
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 naturalSort from "shared/utils/naturalSort";
|
||||
import BaseStore from "stores/BaseStore";
|
||||
import RootStore from "stores/RootStore";
|
||||
import Integration from "models/Integration";
|
||||
|
||||
class IntegrationsStore extends BaseStore<Integration> {
|
||||
constructor(rootStore: RootStore) {
|
||||
@@ -14,12 +14,12 @@ class IntegrationsStore extends BaseStore<Integration> {
|
||||
|
||||
@computed
|
||||
get orderedData(): Integration[] {
|
||||
return naturalSort(Array.from(this.data.values()), 'name');
|
||||
return naturalSort(Array.from(this.data.values()), "name");
|
||||
}
|
||||
|
||||
@computed
|
||||
get slackIntegrations(): Integration[] {
|
||||
return filter(this.orderedData, { service: 'slack' });
|
||||
return filter(this.orderedData, { service: "slack" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// @flow
|
||||
import invariant from 'invariant';
|
||||
import { action, runInAction } from 'mobx';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import Membership from 'models/Membership';
|
||||
import type { PaginationParams } from 'types';
|
||||
import invariant from "invariant";
|
||||
import { action, runInAction } from "mobx";
|
||||
import { client } from "utils/ApiClient";
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import Membership from "models/Membership";
|
||||
import type { PaginationParams } from "types";
|
||||
|
||||
export default class MembershipsStore extends BaseStore<Membership> {
|
||||
actions = ['create', 'delete'];
|
||||
actions = ["create", "delete"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, Membership);
|
||||
@@ -21,7 +21,7 @@ export default class MembershipsStore extends BaseStore<Membership> {
|
||||
try {
|
||||
const res = await client.post(`/collections.memberships`, params);
|
||||
|
||||
invariant(res && res.data, 'Data not available');
|
||||
invariant(res && res.data, "Data not available");
|
||||
|
||||
runInAction(`/collections.memberships`, () => {
|
||||
res.data.users.forEach(this.rootStore.users.add);
|
||||
@@ -44,12 +44,12 @@ export default class MembershipsStore extends BaseStore<Membership> {
|
||||
userId: string,
|
||||
permission: string,
|
||||
}) {
|
||||
const res = await client.post('/collections.add_user', {
|
||||
const res = await client.post("/collections.add_user", {
|
||||
id: collectionId,
|
||||
userId,
|
||||
permission,
|
||||
});
|
||||
invariant(res && res.data, 'Membership data should be available');
|
||||
invariant(res && res.data, "Membership data should be available");
|
||||
|
||||
res.data.users.forEach(this.rootStore.users.add);
|
||||
res.data.memberships.forEach(this.add);
|
||||
@@ -63,7 +63,7 @@ export default class MembershipsStore extends BaseStore<Membership> {
|
||||
collectionId: string,
|
||||
userId: string,
|
||||
}) {
|
||||
await client.post('/collections.remove_user', {
|
||||
await client.post("/collections.remove_user", {
|
||||
id: collectionId,
|
||||
userId,
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// @flow
|
||||
import { find } from 'lodash';
|
||||
import NotificationSetting from 'models/NotificationSetting';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
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'];
|
||||
actions = ["list", "create", "delete"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, NotificationSetting);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import Policy from 'models/Policy';
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import Policy from "models/Policy";
|
||||
|
||||
export default class PoliciesStore extends BaseStore<Policy> {
|
||||
actions = [];
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// @flow
|
||||
import { action, runInAction } from 'mobx';
|
||||
import { filter } from 'lodash';
|
||||
import invariant from 'invariant';
|
||||
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';
|
||||
import { action, runInAction } from "mobx";
|
||||
import { filter } from "lodash";
|
||||
import invariant from "invariant";
|
||||
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";
|
||||
|
||||
export default class RevisionsStore extends BaseStore<Revision> {
|
||||
actions = ['list'];
|
||||
actions = ["list"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, Revision);
|
||||
@@ -22,19 +22,19 @@ export default class RevisionsStore extends BaseStore<Revision> {
|
||||
@action
|
||||
fetch = async (id: string, options?: FetchOptions): Promise<?Revision> => {
|
||||
this.isFetching = true;
|
||||
invariant(id, 'Id is required');
|
||||
invariant(id, "Id is required");
|
||||
|
||||
try {
|
||||
const rev = this.data.get(id);
|
||||
if (rev) return rev;
|
||||
|
||||
const res = await client.post('/revisions.info', {
|
||||
const res = await client.post("/revisions.info", {
|
||||
id,
|
||||
});
|
||||
invariant(res && res.data, 'Revision not available');
|
||||
invariant(res && res.data, "Revision not available");
|
||||
this.add(res.data);
|
||||
|
||||
runInAction('RevisionsStore#fetch', () => {
|
||||
runInAction("RevisionsStore#fetch", () => {
|
||||
this.isLoaded = true;
|
||||
});
|
||||
|
||||
@@ -49,9 +49,9 @@ export default class RevisionsStore extends BaseStore<Revision> {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post('/revisions.list', options);
|
||||
invariant(res && res.data, 'Document revisions not available');
|
||||
runInAction('RevisionsStore#fetchPage', () => {
|
||||
const res = await client.post("/revisions.list", options);
|
||||
invariant(res && res.data, "Document revisions not available");
|
||||
runInAction("RevisionsStore#fetchPage", () => {
|
||||
res.data.forEach(revision => this.add(revision));
|
||||
this.isLoaded = true;
|
||||
});
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
// @flow
|
||||
import ApiKeysStore from './ApiKeysStore';
|
||||
import AuthStore from './AuthStore';
|
||||
import CollectionsStore from './CollectionsStore';
|
||||
import DocumentsStore from './DocumentsStore';
|
||||
import EventsStore from './EventsStore';
|
||||
import GroupsStore from './GroupsStore';
|
||||
import GroupMembershipsStore from './GroupMembershipsStore';
|
||||
import IntegrationsStore from './IntegrationsStore';
|
||||
import MembershipsStore from './MembershipsStore';
|
||||
import NotificationSettingsStore from './NotificationSettingsStore';
|
||||
import DocumentPresenceStore from './DocumentPresenceStore';
|
||||
import PoliciesStore from './PoliciesStore';
|
||||
import RevisionsStore from './RevisionsStore';
|
||||
import SharesStore from './SharesStore';
|
||||
import UiStore from './UiStore';
|
||||
import UsersStore from './UsersStore';
|
||||
import ViewsStore from './ViewsStore';
|
||||
import CollectionGroupMembershipsStore from './CollectionGroupMembershipsStore';
|
||||
import ApiKeysStore from "./ApiKeysStore";
|
||||
import AuthStore from "./AuthStore";
|
||||
import CollectionsStore from "./CollectionsStore";
|
||||
import DocumentsStore from "./DocumentsStore";
|
||||
import EventsStore from "./EventsStore";
|
||||
import GroupsStore from "./GroupsStore";
|
||||
import GroupMembershipsStore from "./GroupMembershipsStore";
|
||||
import IntegrationsStore from "./IntegrationsStore";
|
||||
import MembershipsStore from "./MembershipsStore";
|
||||
import NotificationSettingsStore from "./NotificationSettingsStore";
|
||||
import DocumentPresenceStore from "./DocumentPresenceStore";
|
||||
import PoliciesStore from "./PoliciesStore";
|
||||
import RevisionsStore from "./RevisionsStore";
|
||||
import SharesStore from "./SharesStore";
|
||||
import UiStore from "./UiStore";
|
||||
import UsersStore from "./UsersStore";
|
||||
import ViewsStore from "./ViewsStore";
|
||||
import CollectionGroupMembershipsStore from "./CollectionGroupMembershipsStore";
|
||||
|
||||
export default class RootStore {
|
||||
apiKeys: ApiKeysStore;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// @flow
|
||||
import { sortBy } from 'lodash';
|
||||
import { action, computed } from 'mobx';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import Share from 'models/Share';
|
||||
import { sortBy } from "lodash";
|
||||
import { action, computed } from "mobx";
|
||||
import { client } from "utils/ApiClient";
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import Share from "models/Share";
|
||||
|
||||
export default class SharesStore extends BaseStore<Share> {
|
||||
actions = ['list', 'create'];
|
||||
actions = ["list", "create"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, Share);
|
||||
@@ -15,12 +15,12 @@ export default class SharesStore extends BaseStore<Share> {
|
||||
|
||||
@computed
|
||||
get orderedData(): Share[] {
|
||||
return sortBy(Array.from(this.data.values()), 'createdAt').reverse();
|
||||
return sortBy(Array.from(this.data.values()), "createdAt").reverse();
|
||||
}
|
||||
|
||||
@action
|
||||
revoke = async (share: Share) => {
|
||||
await client.post('/shares.revoke', { id: share.id });
|
||||
await client.post("/shares.revoke", { id: share.id });
|
||||
this.remove(share.id);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// @flow
|
||||
import { v4 } from 'uuid';
|
||||
import { orderBy } from 'lodash';
|
||||
import { observable, action, autorun, computed } from 'mobx';
|
||||
import Document from 'models/Document';
|
||||
import Collection from 'models/Collection';
|
||||
import type { Toast } from '../types';
|
||||
import { v4 } from "uuid";
|
||||
import { orderBy } from "lodash";
|
||||
import { observable, action, autorun, computed } from "mobx";
|
||||
import Document from "models/Document";
|
||||
import Collection from "models/Collection";
|
||||
import type { Toast } from "../types";
|
||||
|
||||
const UI_STORE = 'UI_STORE';
|
||||
const UI_STORE = "UI_STORE";
|
||||
|
||||
class UiStore {
|
||||
// theme represents the users UI preference (defaults to system)
|
||||
@observable theme: 'light' | 'dark' | 'system';
|
||||
@observable theme: "light" | "dark" | "system";
|
||||
|
||||
// systemTheme represents the system UI theme (Settings -> General in macOS)
|
||||
@observable systemTheme: 'light' | 'dark';
|
||||
@observable systemTheme: "light" | "dark";
|
||||
@observable activeModalName: ?string;
|
||||
@observable activeModalProps: ?Object;
|
||||
@observable activeDocumentId: ?string;
|
||||
@@ -28,18 +28,18 @@ class UiStore {
|
||||
// Rehydrate
|
||||
let data = {};
|
||||
try {
|
||||
data = JSON.parse(localStorage.getItem(UI_STORE) || '{}');
|
||||
data = JSON.parse(localStorage.getItem(UI_STORE) || "{}");
|
||||
} catch (_) {
|
||||
// no-op Safari private mode
|
||||
}
|
||||
|
||||
// system theme listeners
|
||||
const colorSchemeQueryList = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)'
|
||||
"(prefers-color-scheme: dark)"
|
||||
);
|
||||
|
||||
const setSystemTheme = event => {
|
||||
this.systemTheme = event.matches ? 'dark' : 'light';
|
||||
this.systemTheme = event.matches ? "dark" : "light";
|
||||
};
|
||||
setSystemTheme(colorSchemeQueryList);
|
||||
if (colorSchemeQueryList.addListener) {
|
||||
@@ -48,7 +48,7 @@ class UiStore {
|
||||
|
||||
// persisted keys
|
||||
this.tocVisible = data.tocVisible;
|
||||
this.theme = data.theme || 'system';
|
||||
this.theme = data.theme || "system";
|
||||
|
||||
autorun(() => {
|
||||
try {
|
||||
@@ -60,11 +60,11 @@ class UiStore {
|
||||
}
|
||||
|
||||
@action
|
||||
setTheme = (theme: 'light' | 'dark' | 'system') => {
|
||||
setTheme = (theme: "light" | "dark" | "system") => {
|
||||
this.theme = theme;
|
||||
|
||||
if (window.localStorage) {
|
||||
window.localStorage.setItem('theme', this.theme);
|
||||
window.localStorage.setItem("theme", this.theme);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -149,7 +149,7 @@ class UiStore {
|
||||
showToast = (
|
||||
message: string,
|
||||
options?: {
|
||||
type?: 'warning' | 'error' | 'info' | 'success',
|
||||
type?: "warning" | "error" | "info" | "success",
|
||||
timeout?: number,
|
||||
action?: {
|
||||
text: string,
|
||||
@@ -171,8 +171,8 @@ class UiStore {
|
||||
};
|
||||
|
||||
@computed
|
||||
get resolvedTheme(): 'dark' | 'light' {
|
||||
if (this.theme === 'system') {
|
||||
get resolvedTheme(): "dark" | "light" {
|
||||
if (this.theme === "system") {
|
||||
return this.systemTheme;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ class UiStore {
|
||||
|
||||
@computed
|
||||
get orderedToasts(): Toast[] {
|
||||
return orderBy(Array.from(this.toasts.values()), 'createdAt', 'desc');
|
||||
return orderBy(Array.from(this.toasts.values()), "createdAt", "desc");
|
||||
}
|
||||
|
||||
@computed
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// @flow
|
||||
import { filter, orderBy } from 'lodash';
|
||||
import { computed, action, runInAction } from 'mobx';
|
||||
import invariant from 'invariant';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import User from 'models/User';
|
||||
import { filter, orderBy } from "lodash";
|
||||
import { computed, action, runInAction } from "mobx";
|
||||
import invariant from "invariant";
|
||||
import { client } from "utils/ApiClient";
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import User from "models/User";
|
||||
|
||||
export default class UsersStore extends BaseStore<User> {
|
||||
constructor(rootStore: RootStore) {
|
||||
@@ -47,40 +47,40 @@ export default class UsersStore extends BaseStore<User> {
|
||||
|
||||
@computed
|
||||
get orderedData(): User[] {
|
||||
return orderBy(Array.from(this.data.values()), 'name', 'asc');
|
||||
return orderBy(Array.from(this.data.values()), "name", "asc");
|
||||
}
|
||||
|
||||
@action
|
||||
promote = (user: User) => {
|
||||
return this.actionOnUser('promote', user);
|
||||
return this.actionOnUser("promote", user);
|
||||
};
|
||||
|
||||
@action
|
||||
demote = (user: User) => {
|
||||
return this.actionOnUser('demote', user);
|
||||
return this.actionOnUser("demote", user);
|
||||
};
|
||||
|
||||
@action
|
||||
suspend = (user: User) => {
|
||||
return this.actionOnUser('suspend', user);
|
||||
return this.actionOnUser("suspend", user);
|
||||
};
|
||||
|
||||
@action
|
||||
activate = (user: User) => {
|
||||
return this.actionOnUser('activate', user);
|
||||
return this.actionOnUser("activate", user);
|
||||
};
|
||||
|
||||
@action
|
||||
invite = async (invites: { email: string, name: string }[]) => {
|
||||
const res = await client.post(`/users.invite`, { invites });
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
invariant(res && res.data, "Data should be available");
|
||||
runInAction(`invite`, () => {
|
||||
res.data.users.forEach(this.add);
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
notInCollection = (collectionId: string, query: string = '') => {
|
||||
notInCollection = (collectionId: string, query: string = "") => {
|
||||
const memberships = filter(
|
||||
this.rootStore.memberships.orderedData,
|
||||
member => member.collectionId === collectionId
|
||||
@@ -109,7 +109,7 @@ export default class UsersStore extends BaseStore<User> {
|
||||
return queriedUsers(users, query);
|
||||
};
|
||||
|
||||
notInGroup = (groupId: string, query: string = '') => {
|
||||
notInGroup = (groupId: string, query: string = "") => {
|
||||
const memberships = filter(
|
||||
this.rootStore.groupMemberships.orderedData,
|
||||
member => member.groupId === groupId
|
||||
@@ -142,7 +142,7 @@ export default class UsersStore extends BaseStore<User> {
|
||||
const res = await client.post(`/users.${action}`, {
|
||||
id: user.id,
|
||||
});
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
runInAction(`UsersStore#${action}`, () => {
|
||||
this.addPolicies(res.policies);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// @flow
|
||||
import { reduce, filter, find, orderBy } from 'lodash';
|
||||
import BaseStore from './BaseStore';
|
||||
import RootStore from './RootStore';
|
||||
import View from 'models/View';
|
||||
import { reduce, filter, find, orderBy } from "lodash";
|
||||
import BaseStore from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
import View from "models/View";
|
||||
|
||||
export default class ViewsStore extends BaseStore<View> {
|
||||
actions = ['list', 'create'];
|
||||
actions = ["list", "create"];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
super(rootStore, View);
|
||||
@@ -14,8 +14,8 @@ export default class ViewsStore extends BaseStore<View> {
|
||||
inDocument(documentId: string): View[] {
|
||||
return orderBy(
|
||||
filter(this.orderedData, view => view.documentId === documentId),
|
||||
'lastViewedAt',
|
||||
'desc'
|
||||
"lastViewedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
import RootStore from 'stores/RootStore';
|
||||
import RootStore from "stores/RootStore";
|
||||
|
||||
const stores = new RootStore();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user