feat(core): hide search locally button when battery save enabled (#13423)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Integrated a feature flag to control "battery save mode" within quick search for documentation. * **Behavior Changes** * Local search is now enabled by default for non-cloud workspaces. * The "search locally" option is hidden when battery save mode is active. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -14,6 +14,7 @@ import type { WorkspaceServerService } from '../../cloud';
|
|||||||
import type { DocRecord, DocsService } from '../../doc';
|
import type { DocRecord, DocsService } from '../../doc';
|
||||||
import type { DocDisplayMetaService } from '../../doc-display-meta';
|
import type { DocDisplayMetaService } from '../../doc-display-meta';
|
||||||
import type { DocsSearchService } from '../../docs-search';
|
import type { DocsSearchService } from '../../docs-search';
|
||||||
|
import type { FeatureFlagService } from '../../feature-flag';
|
||||||
import type { WorkspaceService } from '../../workspace';
|
import type { WorkspaceService } from '../../workspace';
|
||||||
import type { QuickSearchSession } from '../providers/quick-search-provider';
|
import type { QuickSearchSession } from '../providers/quick-search-provider';
|
||||||
import type { QuickSearchItem } from '../types/item';
|
import type { QuickSearchItem } from '../types/item';
|
||||||
@@ -34,7 +35,8 @@ export class DocsQuickSearchSession
|
|||||||
private readonly workspaceServerService: WorkspaceServerService,
|
private readonly workspaceServerService: WorkspaceServerService,
|
||||||
private readonly docsSearchService: DocsSearchService,
|
private readonly docsSearchService: DocsSearchService,
|
||||||
private readonly docsService: DocsService,
|
private readonly docsService: DocsService,
|
||||||
private readonly docDisplayMetaService: DocDisplayMetaService
|
private readonly docDisplayMetaService: DocDisplayMetaService,
|
||||||
|
private readonly featureFlagService: FeatureFlagService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -44,6 +46,9 @@ export class DocsQuickSearchSession
|
|||||||
ServerFeature.Indexer
|
ServerFeature.Indexer
|
||||||
) ?? false;
|
) ?? false;
|
||||||
|
|
||||||
|
private readonly isEnableBatterySaveMode = () =>
|
||||||
|
this.featureFlagService.flags.enable_battery_save_mode.value;
|
||||||
|
|
||||||
private readonly isIndexerLoading$ = this.docsSearchService.indexerState$.map(
|
private readonly isIndexerLoading$ = this.docsSearchService.indexerState$.map(
|
||||||
({ completed }) => {
|
({ completed }) => {
|
||||||
return !completed;
|
return !completed;
|
||||||
@@ -87,7 +92,7 @@ export class DocsQuickSearchSession
|
|||||||
|
|
||||||
items$ = new LiveData<QuickSearchItem<'docs', DocsPayload>[]>([]);
|
items$ = new LiveData<QuickSearchItem<'docs', DocsPayload>[]>([]);
|
||||||
|
|
||||||
searchLocally = false;
|
searchLocally = !this.isCloudWorkspace;
|
||||||
|
|
||||||
query = effect(
|
query = effect(
|
||||||
tap(query => {
|
tap(query => {
|
||||||
@@ -144,7 +149,9 @@ export class DocsQuickSearchSession
|
|||||||
return out.pipe(
|
return out.pipe(
|
||||||
tap((items: QuickSearchItem<'docs', DocsPayload>[]) => {
|
tap((items: QuickSearchItem<'docs', DocsPayload>[]) => {
|
||||||
this.items$.next(
|
this.items$.next(
|
||||||
this.isSupportServerIndexer() && !this.searchLocally
|
this.isSupportServerIndexer() &&
|
||||||
|
!this.searchLocally &&
|
||||||
|
!this.isEnableBatterySaveMode()
|
||||||
? [...items, this.searchLocallyItem]
|
? [...items, this.searchLocallyItem]
|
||||||
: items
|
: items
|
||||||
);
|
);
|
||||||
@@ -153,7 +160,9 @@ export class DocsQuickSearchSession
|
|||||||
onStart(() => {
|
onStart(() => {
|
||||||
this.error$.next(null);
|
this.error$.next(null);
|
||||||
this.items$.next(
|
this.items$.next(
|
||||||
this.isSupportServerIndexer() && !this.searchLocally
|
this.isSupportServerIndexer() &&
|
||||||
|
!this.searchLocally &&
|
||||||
|
!this.isEnableBatterySaveMode()
|
||||||
? [this.searchLocallyItem]
|
? [this.searchLocallyItem]
|
||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
@@ -162,7 +171,9 @@ export class DocsQuickSearchSession
|
|||||||
catchError(err => {
|
catchError(err => {
|
||||||
this.error$.next(err instanceof Error ? err.message : err);
|
this.error$.next(err instanceof Error ? err.message : err);
|
||||||
this.items$.next(
|
this.items$.next(
|
||||||
this.isSupportServerIndexer() && !this.searchLocally
|
this.isSupportServerIndexer() &&
|
||||||
|
!this.searchLocally &&
|
||||||
|
!this.isEnableBatterySaveMode()
|
||||||
? [this.searchLocallyItem]
|
? [this.searchLocallyItem]
|
||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { WorkspaceDialogService } from '../dialogs';
|
|||||||
import { DocsService } from '../doc';
|
import { DocsService } from '../doc';
|
||||||
import { DocDisplayMetaService } from '../doc-display-meta';
|
import { DocDisplayMetaService } from '../doc-display-meta';
|
||||||
import { DocsSearchService } from '../docs-search';
|
import { DocsSearchService } from '../docs-search';
|
||||||
|
import { FeatureFlagService } from '../feature-flag';
|
||||||
import { GlobalContextService } from '../global-context';
|
import { GlobalContextService } from '../global-context';
|
||||||
import { JournalService } from '../journal';
|
import { JournalService } from '../journal';
|
||||||
import { TagService } from '../tag';
|
import { TagService } from '../tag';
|
||||||
@@ -61,6 +62,7 @@ export function configureQuickSearchModule(framework: Framework) {
|
|||||||
DocsSearchService,
|
DocsSearchService,
|
||||||
DocsService,
|
DocsService,
|
||||||
DocDisplayMetaService,
|
DocDisplayMetaService,
|
||||||
|
FeatureFlagService,
|
||||||
])
|
])
|
||||||
.entity(LinksQuickSearchSession, [
|
.entity(LinksQuickSearchSession, [
|
||||||
WorkspaceService,
|
WorkspaceService,
|
||||||
|
|||||||
Reference in New Issue
Block a user