Skip to content

Commit

Permalink
feat: add feature flag for peek view (#7122)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed May 31, 2024
1 parent c96fb46 commit 03be1d6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/common/env/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const runtimeFlagsSchema = z.object({
enablePayment: z.boolean(),
enablePageHistory: z.boolean(),
enableExperimentalFeature: z.boolean(),
enablePeekView: z.boolean(),
allowLocalWorkspace: z.boolean(),
// this is for the electron app
serverUrlPrefix: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const usePatchSpecs = (page: Doc, specs: BlockSpec[]) => {
patchReferenceRenderer(patched, reactToLit, referenceRenderer),
confirmModal
);
if (!page.readonly) {
if (!page.readonly && runtimeConfig.enablePeekView) {
patched = patchPeekViewService(patched, peekViewService);
}
return patched;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ export class PeekViewEntity extends Entity {
.map(show => show && this._active$.value !== null)
.distinctUntilChanged();

// return true if the peek view will be handled
open = (target: ActivePeekView['target']) => {
if (!runtimeConfig.enablePeekView) {
return false;
}
const resolvedInfo = resolvePeekInfoFromPeekTarget(target);
if (!resolvedInfo) {
return;
return false;
}
this._active$.next({ target, info: resolvedInfo });
this._show$.next(true);
return true;
};

close = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/core/src/providers/modal-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function CurrentWorkspaceModals() {
<CloudQuotaModal />
)}
<AiLoginRequiredModal />
<PeekViewManagerModal />
{runtimeConfig.enablePeekView && <PeekViewManagerModal />}
{environment.isDesktop && <FindInPageModal />}
</>
);
Expand Down
7 changes: 7 additions & 0 deletions tools/cli/src/webpack/runtime-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
enablePayment: true,
enablePageHistory: true,
enableExperimentalFeature: false,
enablePeekView: false,
allowLocalWorkspace: buildFlags.distribution === 'desktop' ? true : false,
serverUrlPrefix: 'https://app.affine.pro',
appVersion: packageJson.version,
Expand Down Expand Up @@ -63,6 +64,7 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
enablePayment: true,
enablePageHistory: true,
enableExperimentalFeature: true,
enablePeekView: true,
allowLocalWorkspace: buildFlags.distribution === 'desktop' ? true : false,
serverUrlPrefix: 'https://affine.fail',
appVersion: packageJson.version,
Expand Down Expand Up @@ -117,6 +119,11 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
: buildFlags.mode === 'development'
? true
: currentBuildPreset.enablePageHistory,
enablePeekView: process.env.ENABLE_PEEK_VIEW
? process.env.ENABLE_PEEK_VIEW === 'true'
: buildFlags.mode === 'development'
? true
: currentBuildPreset.enablePeekView,
allowLocalWorkspace: process.env.ALLOW_LOCAL_WORKSPACE
? process.env.ALLOW_LOCAL_WORKSPACE === 'true'
: buildFlags.mode === 'development'
Expand Down

0 comments on commit 03be1d6

Please sign in to comment.