mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Fix "Copy Link" in UserManager when its opened from a DocMenu page.
Test Plan: Added a check to the test case verifying the copied link. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2673
This commit is contained in:
parent
5172cae1c2
commit
9a7a42bc59
@ -310,7 +310,8 @@ export function makeDocOptionsMenu(home: HomeModel, doc: Document, renaming: Obs
|
||||
permissionData: api.getDocAccess(doc.id),
|
||||
activeEmail: user ? user.email : null,
|
||||
resourceType: 'document',
|
||||
resourceId: doc.id
|
||||
resourceId: doc.id,
|
||||
linkToCopy: urlState().makeUrl(docUrl(doc)),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {loadUserManager} from 'app/client/lib/imports';
|
||||
import {AppModel, reportError} from 'app/client/models/AppModel';
|
||||
import {DocInfo, DocPageModel} from 'app/client/models/DocPageModel';
|
||||
import {urlState} from 'app/client/models/gristUrlState';
|
||||
import {docUrl, urlState} from 'app/client/models/gristUrlState';
|
||||
import {makeCopy, replaceTrunkWithFork} from 'app/client/ui/MakeCopyMenu';
|
||||
import {cssHoverCircle, cssTopBarBtn} from 'app/client/ui/TopBarCss';
|
||||
import {primaryButton} from 'app/client/ui2018/buttons';
|
||||
@ -224,6 +224,7 @@ async function manageUsers(doc: DocInfo, docPageModel: DocPageModel) {
|
||||
resourceType: 'document',
|
||||
resourceId: doc.id,
|
||||
docPageModel,
|
||||
linkToCopy: urlState().makeUrl(docUrl(doc)),
|
||||
// On save, re-fetch the document info, to toggle the "Public Access" icon if it changed.
|
||||
onSave: () => docPageModel.refreshCurrentDoc(doc),
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ import {copyToClipboard} from 'app/client/lib/copyToClipboard';
|
||||
import {setTestState} from 'app/client/lib/testState';
|
||||
import {DocPageModel} from 'app/client/models/DocPageModel';
|
||||
import {reportError} from 'app/client/models/errors';
|
||||
import {getCurrentDocUrl, urlState} from 'app/client/models/gristUrlState';
|
||||
import {urlState} from 'app/client/models/gristUrlState';
|
||||
import {IEditableMember, IMemberSelectOption, IOrgMemberSelectOption} from 'app/client/models/UserManagerModel';
|
||||
import {UserManagerModel, UserManagerModelImpl} from 'app/client/models/UserManagerModel';
|
||||
import {getResourceParent, ResourceType} from 'app/client/models/UserManagerModel';
|
||||
@ -37,6 +37,7 @@ export interface IUserManagerOptions {
|
||||
resourceType: ResourceType;
|
||||
resourceId: string|number;
|
||||
docPageModel?: DocPageModel;
|
||||
linkToCopy?: string;
|
||||
onSave?: () => Promise<unknown>;
|
||||
}
|
||||
|
||||
@ -74,7 +75,7 @@ export function showUserManagerModal(userApi: UserAPI, options: IUserManagerOpti
|
||||
['Access Rules'] :
|
||||
[
|
||||
`Invite people to ${renderType(options.resourceType)}`,
|
||||
(options.resourceType === 'document' ? makeCopyBtn(cssCopyBtn.cls('-header')) : null),
|
||||
(options.resourceType === 'document' ? makeCopyBtn(options.linkToCopy, cssCopyBtn.cls('-header')) : null),
|
||||
]
|
||||
),
|
||||
testId('um-header')
|
||||
@ -84,7 +85,7 @@ export function showUserManagerModal(userApi: UserAPI, options: IUserManagerOpti
|
||||
dom.autoDispose(accessRules),
|
||||
cssUserManagerBody(
|
||||
// TODO: Show a loading indicator before the model is loaded.
|
||||
dom.maybe(modelObs, model => new UserManager(model).buildDom()),
|
||||
dom.maybe(modelObs, model => new UserManager(model, options.linkToCopy).buildDom()),
|
||||
dom.hide(accessRulesOpen),
|
||||
),
|
||||
cssUserManagerBody(
|
||||
@ -146,7 +147,7 @@ export function showUserManagerModal(userApi: UserAPI, options: IUserManagerOpti
|
||||
* um.buildDom();
|
||||
*/
|
||||
export class UserManager extends Disposable {
|
||||
constructor(private _model: UserManagerModel) {
|
||||
constructor(private _model: UserManagerModel, private _linkToCopy: string|undefined) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -244,7 +245,7 @@ export class UserManager extends Disposable {
|
||||
cssPublicMemberIcon('PublicFilled'),
|
||||
cssMemberText(
|
||||
cssMemberPrimary('Public Access'),
|
||||
cssMemberSecondary('Anyone with link ', makeCopyBtn()),
|
||||
cssMemberSecondary('Anyone with link ', makeCopyBtn(this._linkToCopy)),
|
||||
),
|
||||
this._memberRoleSelector(publicMember.effectiveAccess, publicMember.inheritedAccess, false,
|
||||
// Only show the Editor and Viewer options for the role of the "Public Access" member.
|
||||
@ -418,9 +419,9 @@ function getFullUser(member: IEditableMember): FullUser {
|
||||
}
|
||||
|
||||
// Create a "Copy Link" button.
|
||||
function makeCopyBtn(...domArgs: DomElementArg[]) {
|
||||
return cssCopyBtn(cssCopyIcon('Copy'), 'Copy Link',
|
||||
dom.on('click', copyLink),
|
||||
function makeCopyBtn(linkToCopy: string|undefined, ...domArgs: DomElementArg[]) {
|
||||
return linkToCopy && cssCopyBtn(cssCopyIcon('Copy'), 'Copy Link',
|
||||
dom.on('click', (ev, elem) => copyLink(elem, linkToCopy)),
|
||||
testId('um-copy-link'),
|
||||
...domArgs,
|
||||
);
|
||||
@ -428,8 +429,7 @@ function makeCopyBtn(...domArgs: DomElementArg[]) {
|
||||
|
||||
// Copy the current document link to clipboard, and notify the user with a transient popup near
|
||||
// the given element.
|
||||
async function copyLink(ev: MouseEvent, elem: HTMLElement) {
|
||||
const link = getCurrentDocUrl();
|
||||
async function copyLink(elem: HTMLElement, link: string) {
|
||||
await copyToClipboard(link);
|
||||
setTestState({clipboard: link});
|
||||
showTransientTooltip(elem, 'Link copied to clipboard', {key: 'copy-doc-link'});
|
||||
|
Loading…
Reference in New Issue
Block a user