Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modify experimental features to app-level #6823

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/common/env/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const runtimeFlagsSchema = z.object({
enableEnhanceShareMode: z.boolean(),
enablePayment: z.boolean(),
enablePageHistory: z.boolean(),
enableExperimentalFeature: 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 @@ -26,7 +26,7 @@ const ExperimentalFeaturesPrompt = ({
}, []);

return (
<div className={styles.promptRoot}>
<div className={styles.promptRoot} data-testid="experimental-prompt">
<div className={styles.promptTitle}>
{t[
'com.affine.settings.workspace.experimental-features.prompt-header'
Expand All @@ -49,14 +49,23 @@ const ExperimentalFeaturesPrompt = ({
<div className={styles.spacer} />

<label className={styles.promptDisclaimer}>
<Checkbox checked={checked} onChange={onChange} />
<Checkbox
checked={checked}
onChange={onChange}
data-testid="experimental-prompt-disclaimer"
/>
{t[
'com.affine.settings.workspace.experimental-features.prompt-disclaimer'
]()}
</label>

<div className={styles.promptDisclaimerConfirm}>
<Button disabled={!checked} onClick={onConfirm} type="primary">
<Button
disabled={!checked}
onClick={onConfirm}
type="primary"
data-testid="experimental-confirm-button"
>
{t[
'com.affine.settings.workspace.experimental-features.get-started'
]()}
Expand Down Expand Up @@ -158,7 +167,10 @@ const ExperimentalFeaturesMain = () => {
'com.affine.settings.workspace.experimental-features.header.plugins'
]()}
/>
<div className={styles.settingsContainer}>
<div
className={styles.settingsContainer}
data-testid="experimental-settings"
>
<SplitViewSettingRow />
<BlocksuiteFeatureFlagSettings />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { UserFeatureService } from '@affine/core/modules/cloud/services/user-feature';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import {
AppearanceIcon,
ExperimentIcon,
InformationIcon,
KeyboardIcon,
} from '@blocksuite/icons';
import { useLiveData, useService } from '@toeverything/infra';
import { useLiveData, useServices } from '@toeverything/infra';
import type { ReactElement, SVGProps } from 'react';
import { useEffect } from 'react';

import { AuthService, ServerConfigService } from '../../../../modules/cloud';
import type { GeneralSettingKey } from '../types';
import { AboutAffine } from './about';
import { AppearanceSettings } from './appearance';
import { BillingSettings } from './billing';
import { ExperimentalFeatures } from './experimental-features';
import { PaymentIcon, UpgradeIcon } from './icons';
import { AFFiNEPricingPlans } from './plans';
import { Shortcuts } from './shortcuts';
Expand All @@ -27,11 +31,22 @@ export type GeneralSettingList = GeneralSettingListItem[];

export const useGeneralSettingList = (): GeneralSettingList => {
const t = useAFFiNEI18N();
const status = useLiveData(useService(AuthService).session.status$);
const serverConfig = useService(ServerConfigService).serverConfig;
const { authService, serverConfigService, userFeatureService } = useServices({
AuthService,
ServerConfigService,
UserFeatureService,
});
const status = useLiveData(authService.session.status$);
const hasPaymentFeature = useLiveData(
serverConfig.features$.map(f => f?.payment)
serverConfigService.serverConfig.features$.map(f => f?.payment)
);
const isEarlyAccess = useLiveData(
userFeatureService.userFeature.isEarlyAccess$
);

useEffect(() => {
userFeatureService.userFeature.revalidate();
}, [userFeatureService]);

const settings: GeneralSettingListItem[] = [
{
Expand Down Expand Up @@ -71,6 +86,15 @@ export const useGeneralSettingList = (): GeneralSettingList => {
}
}

if (isEarlyAccess || runtimeConfig.enableExperimentalFeature) {
settings.push({
key: 'experimental-features',
title: t['com.affine.settings.workspace.experimental-features'](),
icon: ExperimentIcon,
testId: 'experimental-features-trigger',
});
}

return settings;
};

Expand All @@ -90,6 +114,8 @@ export const GeneralSetting = ({ generalKey }: GeneralSettingProps) => {
return <AFFiNEPricingPlans />;
case 'billing':
return <BillingSettings />;
case 'experimental-features':
return <ExperimentalFeatures />;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ const subTabConfigs = [
key: 'preference',
title: 'com.affine.settings.workspace.preferences',
},
{
key: 'experimental-features',
title: 'com.affine.settings.workspace.experimental-features',
},
{
key: 'properties',
title: 'com.affine.settings.workspace.properties',
Expand Down Expand Up @@ -267,9 +263,6 @@ const WorkspaceListItem = ({
const currentWorkspace = workspaceService.workspace;
const isCurrent = currentWorkspace.id === meta.id;
const t = useAFFiNEI18N();
const isEarlyAccess = useLiveData(
userFeatureService.userFeature.isEarlyAccess$
);

useEffect(() => {
userFeatureService.userFeature.revalidate();
Expand All @@ -280,30 +273,23 @@ const WorkspaceListItem = ({
}, [onClick]);

const subTabs = useMemo(() => {
return subTabConfigs
.filter(({ key }) => {
if (key === 'experimental-features') {
return information?.isOwner && isEarlyAccess;
}
return true;
})
.map(({ key, title }) => {
return (
<div
data-testid={`workspace-list-item-${key}`}
onClick={() => {
onClick(key);
}}
className={clsx(style.sidebarSelectSubItem, {
active: activeSubTab === key,
})}
key={key}
>
{t[title]()}
</div>
);
});
}, [activeSubTab, information?.isOwner, isEarlyAccess, onClick, t]);
return subTabConfigs.map(({ key, title }) => {
return (
<div
data-testid={`workspace-list-item-${key}`}
onClick={() => {
onClick(key);
}}
className={clsx(style.sidebarSelectSubItem, {
active: activeSubTab === key,
})}
key={key}
>
{t[title]()}
</div>
);
});
}, [activeSubTab, onClick, t]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ export const GeneralSettingKeys = [
'about',
'plans',
'billing',
] as const;

export const WorkspaceSubTabs = [
'preference',
'experimental-features',
'properties',
] as const;

export const WorkspaceSubTabs = ['preference', 'properties'] as const;

export type GeneralSettingKey = (typeof GeneralSettingKeys)[number];

export type WorkspaceSubTab = (typeof WorkspaceSubTabs)[number];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { WorkspaceMetadata } from '@toeverything/infra';

import { ExperimentalFeatures } from './experimental-features';
import type { WorkspaceSubTab } from '../types';
import { WorkspaceSettingDetail } from './new-workspace-setting-detail';
import { WorkspaceSettingProperties } from './properties';

Expand All @@ -9,13 +9,11 @@ export const WorkspaceSetting = ({
subTab,
}: {
workspaceMetadata: WorkspaceMetadata;
subTab: 'preference' | 'experimental-features' | 'properties';
subTab: WorkspaceSubTab;
}) => {
switch (subTab) {
case 'preference':
return <WorkspaceSettingDetail workspaceMetadata={workspaceMetadata} />;
case 'experimental-features':
return <ExperimentalFeatures />;
case 'properties':
return (
<WorkspaceSettingProperties workspaceMetadata={workspaceMetadata} />
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/i18n/src/resources/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in packages/frontend/i18n/src/resources/en.json

View workflow job for this annotation

GitHub Actions / main

Inconsistent keys

com.affine.payment.ai.pricing-plan.caption-free, com.affine.payment.billing-setting.ai.free-desc

Check notice on line 1 in packages/frontend/i18n/src/resources/en.json

View workflow job for this annotation

GitHub Actions / main

New keys

Get in touch! Join our communities., It takes up little space on your device., It takes up more space on your device., com.affine.auth.open.affine.download-app, com.affine.auth.open.affine.prompt, com.affine.auth.open.affine.try-again, com.affine.auth.reset.password.message, com.affine.auth.reset.password.page.success, com.affine.auth.sent.change.email.hint, com.affine.auth.sent.reset.password.success.message, com.affine.auth.sent.set.password.hint, com.affine.auth.sent.set.password.success.message, com.affine.auth.set.password.save, com.affine.auth.sign.up.sent.email.subtitle, com.affine.auth.sign.up.success.title, com.affine.editCollection.rules.tips.highlight, com.affine.page-properties.add-property.menu.create, com.affine.page-properties.add-property.menu.header, com.affine.pageMode.all, com.affine.pageMode.edgeless, com.affine.pageMode.page, com.affine.setting.account.delete.message, com.affine.settings.appearance.border-style-description, com.affine.settings.appearance.start-week-description, com.affine.settings.email.action, com.affine.settings.password.action.change, com.affine.settings.password.action.set, com.affine.settings.password.message, com.affine.settings.profile.message, com.affine.settings.profile.placeholder, com.affine.settings.workspace.experimental-features, com.affine.settings.workspace.experimental-features.get-started, com.affine.settings.workspace.experimental-features.header.plugins, com.affine.settings.workspace.experimental-features.prompt-disclaimer, com.affine.settings.workspace.experimental-features.prompt-header, com.affine.settings.workspace.experimental-features.prompt-warning, com.affine.settings.workspace.experimental-features.prompt-warning-title, com.affine.settings.workspace.preferences, com.affine.settings.workspace.properties, com.affine.settings.workspace.properties.add_property, com.affine.settings.workspace.properties.all, com.affine.settings.workspace.properties.delete-property, com.affine.settings.workspace.properties.doc, com.affine.settings.workspace.properties.doc_others, com.affine.settings.workspace.properties.edit-property, com.affine.settings.workspace.properties.header.subtitle, com.affine.settings.workspace.properties.header.title, com.affine.settings.workspace.properties.in-use, com.affine.settings.workspace.properties.set-as-required, com.affine.settings.workspace.properties.unused, com.affine.settings.workspace.storage.tip, com.affine.storage.maximum-tips.pro, com.affine.workspace.cloud.description

Check warning on line 1 in packages/frontend/i18n/src/resources/en.json

View workflow job for this annotation

GitHub Actions / main

Inconsistent keys

com.affine.payment.ai.pricing-plan.caption-free, com.affine.payment.billing-setting.ai.free-desc

Check notice on line 1 in packages/frontend/i18n/src/resources/en.json

View workflow job for this annotation

GitHub Actions / main

New keys

Get in touch! Join our communities., It takes up little space on your device., It takes up more space on your device., com.affine.auth.open.affine.download-app, com.affine.auth.open.affine.prompt, com.affine.auth.open.affine.try-again, com.affine.auth.reset.password.message, com.affine.auth.reset.password.page.success, com.affine.auth.sent.change.email.hint, com.affine.auth.sent.reset.password.success.message, com.affine.auth.sent.set.password.hint, com.affine.auth.sent.set.password.success.message, com.affine.auth.set.password.save, com.affine.auth.sign.up.sent.email.subtitle, com.affine.auth.sign.up.success.title, com.affine.editCollection.rules.tips.highlight, com.affine.page-properties.add-property.menu.create, com.affine.page-properties.add-property.menu.header, com.affine.pageMode.all, com.affine.pageMode.edgeless, com.affine.pageMode.page, com.affine.setting.account.delete.message, com.affine.settings.appearance.border-style-description, com.affine.settings.appearance.start-week-description, com.affine.settings.email.action, com.affine.settings.password.action.change, com.affine.settings.password.action.set, com.affine.settings.password.message, com.affine.settings.profile.message, com.affine.settings.profile.placeholder, com.affine.settings.workspace.experimental-features, com.affine.settings.workspace.experimental-features.get-started, com.affine.settings.workspace.experimental-features.header.plugins, com.affine.settings.workspace.experimental-features.prompt-disclaimer, com.affine.settings.workspace.experimental-features.prompt-header, com.affine.settings.workspace.experimental-features.prompt-warning, com.affine.settings.workspace.experimental-features.prompt-warning-title, com.affine.settings.workspace.preferences, com.affine.settings.workspace.properties, com.affine.settings.workspace.properties.add_property, com.affine.settings.workspace.properties.all, com.affine.settings.workspace.properties.delete-property, com.affine.settings.workspace.properties.doc, com.affine.settings.workspace.properties.doc_others, com.affine.settings.workspace.properties.edit-property, com.affine.settings.workspace.properties.header.subtitle, com.affine.settings.workspace.properties.header.title, com.affine.settings.workspace.properties.in-use, com.affine.settings.workspace.properties.set-as-required, com.affine.settings.workspace.properties.unused, com.affine.settings.workspace.storage.tip, com.affine.storage.maximum-tips.pro, com.affine.workspace.cloud.description
"404 - Page Not Found": "404 - Page Not Found",
"404.back": "Back to My Content",
"404.hint": "Sorry, you do not have access or this content does not exist...",
Expand Down Expand Up @@ -1129,7 +1129,7 @@
"com.affine.settings.translucent-style-description": "Use transparency effect on the sidebar.",
"com.affine.settings.workspace": "Workspace",
"com.affine.settings.workspace.description": "You can view current workspace's information here.",
"com.affine.settings.workspace.experimental-features": "Plugins",
"com.affine.settings.workspace.experimental-features": "Experimental Features",
"com.affine.settings.workspace.experimental-features.get-started": "Get Started",
"com.affine.settings.workspace.experimental-features.header.plugins": "Experimental Features",
"com.affine.settings.workspace.experimental-features.prompt-disclaimer": "I am aware of the risks, and I am willing to continue to use it.",
Expand Down
14 changes: 14 additions & 0 deletions tests/affine-local/e2e/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import {
confirmExperimentalPrompt,
openAboutPanel,
openAppearancePanel,
openExperimentalFeaturesPanel,
openSettingModal,
openShortcutsPanel,
} from '@affine-test/kit/utils/setting';
Expand Down Expand Up @@ -87,6 +89,18 @@ test('Open about panel', async ({ page }) => {
await expect(title).toBeVisible();
});

test('Open experimental features panel', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await openSettingModal(page);
await openExperimentalFeaturesPanel(page);
const prompt = page.getByTestId('experimental-prompt');
await expect(prompt).toBeVisible();
await confirmExperimentalPrompt(page);
const settings = page.getByTestId('experimental-settings');
await expect(settings).toBeVisible();
});

test('Different workspace should have different name in the setting panel', async ({
page,
}) => {
Expand Down
9 changes: 9 additions & 0 deletions tests/kit/utils/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export async function openAboutPanel(page: Page) {
await page.getByTestId('about-panel-trigger').click();
}

export async function openExperimentalFeaturesPanel(page: Page) {
await page.getByTestId('experimental-features-trigger').click();
}

export async function confirmExperimentalPrompt(page: Page) {
await page.getByTestId('experimental-prompt-disclaimer').click();
await page.getByTestId('experimental-confirm-button').click();
}

export async function openWorkspaceSettingPanel(
page: Page,
workspaceName: string
Expand Down
2 changes: 2 additions & 0 deletions tools/cli/src/webpack/runtime-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
enableEnhanceShareMode: false,
enablePayment: true,
enablePageHistory: true,
enableExperimentalFeature: false,
allowLocalWorkspace: buildFlags.distribution === 'desktop' ? true : false,
serverUrlPrefix: 'https://app.affine.pro',
appVersion: packageJson.version,
Expand Down Expand Up @@ -61,6 +62,7 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
enableEnhanceShareMode: false,
enablePayment: true,
enablePageHistory: true,
enableExperimentalFeature: true,
allowLocalWorkspace: buildFlags.distribution === 'desktop' ? true : false,
serverUrlPrefix: 'https://affine.fail',
appVersion: packageJson.version,
Expand Down
Loading