Summary: Adds a new tip for the doc menu's Add New button. The tip is shown only when the current user is an editor or owner, and the site is non-empty. The presence of welcome videos or popups will also cause the tip to not be shown; it will instead be shown the next time the doc menu is visited. Test Plan: Browser tests. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D3757pull/403/head
parent
b7f65ff408
commit
db64dfeef0
@ -0,0 +1,53 @@
|
|||||||
|
import {HomeModel} from 'app/client/models/HomeModel';
|
||||||
|
import {shouldShowWelcomeQuestions} from 'app/client/ui/WelcomeQuestions';
|
||||||
|
|
||||||
|
export function attachAddNewTip(home: HomeModel): (el: Element) => void {
|
||||||
|
return () => {
|
||||||
|
const {app: {userPrefsObs}} = home;
|
||||||
|
if (shouldShowWelcomeQuestions(userPrefsObs)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldShowAddNewTip(home)) {
|
||||||
|
showAddNewTip(home);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldShowAddNewTip(home: HomeModel): boolean {
|
||||||
|
return (
|
||||||
|
// Only show if the user is an owner or editor.
|
||||||
|
home.app.isOwnerOrEditor() &&
|
||||||
|
// And the tip hasn't been shown before.
|
||||||
|
home.shouldShowAddNewTip.get() &&
|
||||||
|
// And the intro isn't being shown.
|
||||||
|
!home.showIntro.get() &&
|
||||||
|
// And the workspace loaded correctly.
|
||||||
|
home.available.get() &&
|
||||||
|
// And the current page isn't /p/trash; the Add New button is limited there.
|
||||||
|
home.currentPage.get() !== 'trash'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAddNewTip(home: HomeModel): void {
|
||||||
|
const addNewButton = document.querySelector('.behavioral-prompt-add-new');
|
||||||
|
if (!addNewButton) {
|
||||||
|
console.warn('AddNewTip failed to find Add New button');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isVisible(addNewButton as HTMLElement)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
home.app.behavioralPromptsManager.showTip(addNewButton, 'addNew', {
|
||||||
|
popupOptions: {
|
||||||
|
placement: 'right-start',
|
||||||
|
},
|
||||||
|
onDispose: () => home.shouldShowAddNewTip.set(false),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isVisible(element: HTMLElement): boolean {
|
||||||
|
// From https://github.com/jquery/jquery/blob/c66d4700dcf98efccb04061d575e242d28741223/src/css/hiddenVisibleSelectors.js.
|
||||||
|
return Boolean(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
import {AppModel} from 'app/client/models/AppModel';
|
import {AppModel} from 'app/client/models/AppModel';
|
||||||
|
|
||||||
export function showWelcomeCoachingCall(_triggerElement: Element, _app: AppModel): boolean {
|
export function shouldShowWelcomeCoachingCall(_app: AppModel) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showWelcomeCoachingCall(_triggerElement: Element, _app: AppModel) {
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in new issue