Merge branch 'main' into feat/mass-import

This commit is contained in:
Tom Moor
2021-02-09 20:46:57 -08:00
committed by GitHub
42 changed files with 663 additions and 295 deletions

View File

@@ -7,7 +7,7 @@ import BaseModel from "../models/BaseModel";
import type { PaginationParams } from "types";
import { client } from "utils/ApiClient";
type Action = "list" | "info" | "create" | "update" | "delete";
type Action = "list" | "info" | "create" | "update" | "delete" | "count";
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", "count"];
constructor(rootStore: RootStore, model: Class<T>) {
this.rootStore = rootStore;

View File

@@ -1,8 +1,7 @@
// @flow
import invariant from "invariant";
import { concat, filter, last } from "lodash";
import { action, computed } from "mobx";
import { computed, action } from "mobx";
import naturalSort from "shared/utils/naturalSort";
import Collection from "models/Collection";
import BaseStore from "./BaseStore";
@@ -104,6 +103,24 @@ export default class CollectionsStore extends BaseStore<Collection> {
return res.data;
};
async update(params: Object): Promise<Collection> {
const result = await super.update(params);
// If we're changing sharing permissions on the collection then we need to
// remove all locally cached policies for documents in the collection as they
// are now invalid
if (params.sharing !== undefined) {
const collection = this.get(params.id);
if (collection) {
collection.documentIds.forEach((id) => {
this.rootStore.policies.remove(id);
});
}
}
return result;
}
getPathForDocument(documentId: string): ?DocumentPath {
return this.pathsToDocuments.find((path) => path.id === documentId);
}

View File

@@ -22,6 +22,7 @@ export default class DocumentsStore extends BaseStore<Document> {
@observable movingDocumentId: ?string;
importFileTypes: string[] = [
".md",
"text/markdown",
"text/plain",
"text/html",

View File

@@ -21,7 +21,7 @@ class UiStore {
@observable activeDocumentId: ?string;
@observable activeCollectionId: ?string;
@observable progressBarVisible: boolean = false;
@observable editMode: boolean = false;
@observable isEditing: boolean = false;
@observable tocVisible: boolean = false;
@observable mobileSidebarVisible: boolean = false;
@observable sidebarWidth: number;
@@ -151,12 +151,12 @@ class UiStore {
@action
enableEditMode = () => {
this.editMode = true;
this.isEditing = true;
};
@action
disableEditMode = () => {
this.editMode = false;
this.isEditing = false;
};
@action

View File

@@ -1,13 +1,21 @@
// @flow
import invariant from "invariant";
import { filter, orderBy } from "lodash";
import { computed, action, runInAction } from "mobx";
import { observable, computed, action, runInAction } from "mobx";
import User from "models/User";
import BaseStore from "./BaseStore";
import RootStore from "./RootStore";
import { client } from "utils/ApiClient";
export default class UsersStore extends BaseStore<User> {
@observable counts: {
active: number,
admins: number,
all: number,
invited: number,
suspended: number,
} = {};
constructor(rootStore: RootStore) {
super(rootStore, User);
}
@@ -52,21 +60,25 @@ export default class UsersStore extends BaseStore<User> {
@action
promote = (user: User) => {
this.counts.admins += 1;
return this.actionOnUser("promote", user);
};
@action
demote = (user: User) => {
this.counts.admins -= 1;
return this.actionOnUser("demote", user);
};
@action
suspend = (user: User) => {
this.counts.suspended += 1;
return this.actionOnUser("suspend", user);
};
@action
activate = (user: User) => {
this.counts.suspended -= 1;
return this.actionOnUser("activate", user);
};
@@ -76,10 +88,39 @@ export default class UsersStore extends BaseStore<User> {
invariant(res && res.data, "Data should be available");
runInAction(`invite`, () => {
res.data.users.forEach(this.add);
this.counts.invited += res.data.sent.length;
this.counts.all += res.data.sent.length;
});
return res.data;
};
@action
fetchCounts = async (teamId: string): Promise<*> => {
const res = await client.post(`/users.count`, { teamId });
invariant(res && res.data, "Data should be available");
this.counts = res.data.counts;
return res.data;
};
@action
async delete(user: User, options: Object = {}) {
super.delete(user, options);
if (!user.isSuspended && user.lastActiveAt) {
this.counts.active -= 1;
}
if (user.isInvited) {
this.counts.invited -= 1;
}
if (user.isAdmin) {
this.counts.admins -= 1;
}
if (user.isSuspended) {
this.counts.suspended -= 1;
}
this.counts.all -= 1;
}
notInCollection = (collectionId: string, query: string = "") => {
const memberships = filter(
this.rootStore.memberships.orderedData,