(core) Don't override search on Code View and Access Rules pages.

Summary:
On some pages, Grist search doesn't work, so better to omit it and give
a chance to browser's native search.

Test Plan: Existing search tests should pass. Tested manually that shortcuts now open native browser search on Code View and Access Rules pages.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3703
This commit is contained in:
Dmitry S 2022-11-14 09:34:50 -05:00
parent 044d7a1e5c
commit ccbdeb71e5
2 changed files with 25 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import {makeT} from 'app/client/lib/localization';
import {GristDoc} from 'app/client/components/GristDoc';
import {loadSearch} from 'app/client/lib/imports';
import type * as searchModule from 'app/client/ui2018/search';
import {AppModel, reportError} from 'app/client/models/AppModel';
import {DocPageModel} from 'app/client/models/DocPageModel';
import {workspaceName} from 'app/client/models/WorkspaceInfo';
@ -16,7 +17,6 @@ import {cssHideForNarrowScreen, testId, theme} from 'app/client/ui2018/cssVars';
import {IconName} from 'app/client/ui2018/IconList';
import {menuAnnotate} from 'app/client/ui2018/menus';
import {COMMENTS} from 'app/client/models/features';
import {waitGrainObs} from 'app/common/gutil';
import * as roles from 'app/common/roles';
import {Computed, dom, DomElementArg, makeTestId, MultiHolder, Observable, styled} from 'grainjs';
@ -48,14 +48,25 @@ export function createTopBarDoc(owner: MultiHolder, appModel: AppModel, pageMode
const renameDoc = (val: string) => pageModel.renameDoc(val);
const displayNameWs = Computed.create(owner, pageModel.currentWorkspace,
(use, ws) => ws ? {...ws, name: workspaceName(appModel, ws)} : ws);
const searchBarContent = Observable.create<HTMLElement|null>(owner, null);
loadSearch()
.then(async module => {
const model = module.SearchModelImpl.create(owner, (await waitGrainObs(pageModel.gristDoc))!);
searchBarContent.set(module.searchBar(model, makeTestId('test-tb-search-')));
})
.catch(reportError);
const moduleObs = Observable.create<typeof searchModule|null>(owner, null);
loadSearch().then(module => moduleObs.set(module)).catch(reportError);
// Observable to decide whether to include the searchBar into this page. It doesn't work on
// 'code' and 'acl' pages, so it's better to omit it, and let the browser's native search work.
const enabledObs = Computed.create(owner, pageModel.gristDoc, (use, gristDoc) => {
const viewId = gristDoc ? use(gristDoc.activeViewId) : null;
return viewId !== null && viewId !== 'code' && viewId !== 'acl';
});
const searchModelObs = Computed.create(owner,
moduleObs, pageModel.gristDoc, enabledObs,
(use, module, gristDoc, enabled) => {
if (!module || !gristDoc || !enabled) {
return null;
}
return module.SearchModelImpl.create(use.owner, gristDoc);
});
return [
// TODO Before gristDoc is loaded, we could show doc-name without the page. For now, we delay
@ -96,7 +107,10 @@ export function createTopBarDoc(owner: MultiHolder, appModel: AppModel, pageMode
),
cssSpacer(),
]),
dom.domComputed(searchBarContent),
dom.domComputed((use) => {
const model = use(searchModelObs);
return model && use(moduleObs)?.searchBar(model, makeTestId('test-tb-search-'));
}),
buildShareMenuButton(pageModel),

View File

@ -171,6 +171,8 @@ export function searchBar(model: SearchModel, testId: TestId = noTestId) {
searchWrapper.cls('-expand', model.isOpen),
dom.autoDispose(commandGroup),
dom.autoDispose(lis),
// Make sure we don't attempt to call delayed callback after disposal.
dom.onDispose(() => toggleMenu.cancel()),
cssHoverCircle(
cssTopBarBtn('Search',
testId('icon'),