feat: Option for separate edit mode (#4203)

* stash

* wip

* cleanup

* Remove collaborativeEditing toggle, it will always be on in next release.
Flip separateEdit -> seamlessEdit

* Clarify language, hide toggle when collaborative editing is disabled

* Flip boolean to match, easier to reason about
This commit is contained in:
Tom Moor
2022-10-02 17:58:33 +02:00
committed by GitHub
parent b9bf2e58cb
commit 933fbb2578
20 changed files with 172 additions and 124 deletions

View File

@@ -1,4 +1,5 @@
import { computed, observable } from "mobx";
import { TeamPreference, TeamPreferences } from "@shared/types";
import BaseModel from "./BaseModel";
import Field from "./decorators/Field";
@@ -51,6 +52,10 @@ class Team extends BaseModel {
@observable
defaultUserRole: string;
@Field
@observable
preferences: TeamPreferences | null;
domain: string | null | undefined;
url: string;
@@ -63,6 +68,45 @@ class Team extends BaseModel {
get signinMethods(): string {
return "SSO";
}
/**
* Returns whether this team is using a separate editing mode behind an "Edit"
* button rather than seamless always-editing.
*
* @returns True if editing mode is seamless (no button)
*/
@computed
get seamlessEditing(): boolean {
return (
this.collaborativeEditing &&
this.getPreference(TeamPreference.SeamlessEdit, true)
);
}
/**
* Get the value for a specific preference key, or return the fallback if
* none is set.
*
* @param key The TeamPreference key to retrieve
* @param fallback An optional fallback value, defaults to false.
* @returns The value
*/
getPreference(key: TeamPreference, fallback = false): boolean {
return this.preferences?.[key] ?? fallback;
}
/**
* Set the value for a specific preference key.
*
* @param key The TeamPreference key to retrieve
* @param value The value to set
*/
setPreference(key: TeamPreference, value: boolean) {
this.preferences = {
...this.preferences,
[key]: value,
};
}
}
export default Team;