chore: Upgrade flow (#1854)
* wip: upgrade flow * chore: More sealed props improvements * Final fixes
This commit is contained in:
@@ -4,6 +4,7 @@ import invariant from "invariant";
|
||||
import { observable, action, computed, autorun, runInAction } from "mobx";
|
||||
import { getCookie, setCookie, removeCookie } from "tiny-cookie";
|
||||
import RootStore from "stores/RootStore";
|
||||
import Policy from "models/Policy";
|
||||
import Team from "models/Team";
|
||||
import User from "models/User";
|
||||
import env from "env";
|
||||
@@ -13,17 +14,17 @@ import { getCookieDomain } from "utils/domains";
|
||||
const AUTH_STORE = "AUTH_STORE";
|
||||
const NO_REDIRECT_PATHS = ["/", "/create", "/home"];
|
||||
|
||||
type Service = {
|
||||
type Service = {|
|
||||
id: string,
|
||||
name: string,
|
||||
authUrl: string,
|
||||
};
|
||||
|};
|
||||
|
||||
type Config = {
|
||||
type Config = {|
|
||||
name?: string,
|
||||
hostname?: string,
|
||||
services: Service[],
|
||||
};
|
||||
|};
|
||||
|
||||
export default class AuthStore {
|
||||
@observable user: ?User;
|
||||
@@ -88,7 +89,7 @@ export default class AuthStore {
|
||||
}
|
||||
}
|
||||
|
||||
addPolicies = (policies) => {
|
||||
addPolicies = (policies: Policy[]) => {
|
||||
if (policies) {
|
||||
policies.forEach((policy) => this.rootStore.policies.add(policy));
|
||||
}
|
||||
|
||||
@@ -174,7 +174,13 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
return this.drafts().length;
|
||||
}
|
||||
|
||||
drafts = (options = {}): Document[] => {
|
||||
drafts = (
|
||||
options: {
|
||||
...PaginationParams,
|
||||
dateFilter?: "day" | "week" | "month" | "year",
|
||||
collectionId?: string,
|
||||
} = {}
|
||||
): Document[] => {
|
||||
let drafts = filter(
|
||||
orderBy(this.all, "updatedAt", "desc"),
|
||||
(doc) => !doc.publishedAt
|
||||
@@ -185,7 +191,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
drafts,
|
||||
(draft) =>
|
||||
new Date(draft.updatedAt) >=
|
||||
subtractDate(new Date(), options.dateFilter)
|
||||
subtractDate(new Date(), options.dateFilter || "year")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -245,7 +251,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
@action
|
||||
fetchNamedPage = async (
|
||||
request: string = "list",
|
||||
options: ?PaginationParams
|
||||
options: ?Object
|
||||
): Promise<?(Document[])> => {
|
||||
this.isFetching = true;
|
||||
|
||||
@@ -338,10 +344,9 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
};
|
||||
|
||||
@action
|
||||
searchTitles = async (query: string, options: PaginationParams = {}) => {
|
||||
searchTitles = async (query: string) => {
|
||||
const res = await client.get("/documents.search_titles", {
|
||||
query,
|
||||
...options,
|
||||
});
|
||||
invariant(res && res.data, "Search response should be available");
|
||||
|
||||
@@ -354,7 +359,15 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
@action
|
||||
search = async (
|
||||
query: string,
|
||||
options: PaginationParams = {}
|
||||
options: {
|
||||
offset?: number,
|
||||
limit?: number,
|
||||
dateFilter?: "day" | "week" | "month" | "year",
|
||||
includeArchived?: boolean,
|
||||
includeDrafts?: boolean,
|
||||
collectionId?: string,
|
||||
userId?: string,
|
||||
}
|
||||
): Promise<SearchResult[]> => {
|
||||
const compactedOptions = omitBy(options, (o) => !o);
|
||||
const res = await client.get("/documents.search", {
|
||||
@@ -601,10 +614,14 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
};
|
||||
|
||||
@action
|
||||
restore = async (document: Document, options = {}) => {
|
||||
restore = async (
|
||||
document: Document,
|
||||
options: { revisionId?: string, collectionId?: string } = {}
|
||||
) => {
|
||||
const res = await client.post("/documents.restore", {
|
||||
id: document.id,
|
||||
...options,
|
||||
revisionId: options.revisionId,
|
||||
collectionId: options.collectionId,
|
||||
});
|
||||
runInAction("Document#restore", () => {
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
@@ -182,13 +182,15 @@ class UiStore {
|
||||
@action
|
||||
showToast = (
|
||||
message: string,
|
||||
options?: {
|
||||
type?: "warning" | "error" | "info" | "success",
|
||||
options: {
|
||||
type: "warning" | "error" | "info" | "success",
|
||||
timeout?: number,
|
||||
action?: {
|
||||
text: string,
|
||||
onClick: () => void,
|
||||
},
|
||||
} = {
|
||||
type: "info",
|
||||
}
|
||||
) => {
|
||||
if (!message) return;
|
||||
@@ -204,7 +206,14 @@ class UiStore {
|
||||
|
||||
const id = v4();
|
||||
const createdAt = new Date().toISOString();
|
||||
this.toasts.set(id, { message, createdAt, id, ...options });
|
||||
this.toasts.set(id, {
|
||||
id,
|
||||
message,
|
||||
createdAt,
|
||||
type: options.type,
|
||||
timeout: options.timeout,
|
||||
action: options.action,
|
||||
});
|
||||
this.lastToastId = id;
|
||||
return id;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user