feat(core): remove ai from experimental features (#6529)
This commit is contained in:
@@ -2,14 +2,7 @@ import { Button, Checkbox, Loading, Switch } from '@affine/component';
|
|||||||
import { SettingHeader } from '@affine/component/setting-components';
|
import { SettingHeader } from '@affine/component/setting-components';
|
||||||
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
|
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
|
||||||
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
||||||
import {
|
|
||||||
useSetWorkspaceFeature,
|
|
||||||
useWorkspaceAvailableFeatures,
|
|
||||||
useWorkspaceEnabledFeatures,
|
|
||||||
} from '@affine/core/hooks/use-workspace-features';
|
|
||||||
import { FeatureType } from '@affine/graphql';
|
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import type { WorkspaceMetadata } from '@toeverything/infra';
|
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { atomWithStorage } from 'jotai/utils';
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
import { Suspense, useCallback, useState } from 'react';
|
import { Suspense, useCallback, useState } from 'react';
|
||||||
@@ -73,12 +66,6 @@ const ExperimentalFeaturesPrompt = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface ExperimentalFeaturesItemProps {
|
|
||||||
feature: FeatureType;
|
|
||||||
title: React.ReactNode;
|
|
||||||
workspaceMetadata: WorkspaceMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ExperimentalFeaturesItem = ({
|
const ExperimentalFeaturesItem = ({
|
||||||
title,
|
title,
|
||||||
isMutating,
|
isMutating,
|
||||||
@@ -102,49 +89,6 @@ const ExperimentalFeaturesItem = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const WorkspaceFeaturesSettingItem = ({
|
|
||||||
feature,
|
|
||||||
title,
|
|
||||||
workspaceMetadata,
|
|
||||||
}: ExperimentalFeaturesItemProps) => {
|
|
||||||
const enabledFeatures = useWorkspaceEnabledFeatures(workspaceMetadata);
|
|
||||||
const enabled = enabledFeatures.includes(feature);
|
|
||||||
const [localEnabled, setLocalEnabled] = useState(enabled);
|
|
||||||
const { trigger, isMutating } = useSetWorkspaceFeature(workspaceMetadata);
|
|
||||||
const onChange = useCallback(
|
|
||||||
(checked: boolean) => {
|
|
||||||
setLocalEnabled(checked);
|
|
||||||
trigger(feature, checked);
|
|
||||||
},
|
|
||||||
[trigger, feature]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ExperimentalFeaturesItem
|
|
||||||
title={title}
|
|
||||||
isMutating={isMutating}
|
|
||||||
checked={localEnabled}
|
|
||||||
onChange={onChange}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const CopilotSettingRow = ({
|
|
||||||
workspaceMetadata,
|
|
||||||
}: {
|
|
||||||
workspaceMetadata: WorkspaceMetadata;
|
|
||||||
}) => {
|
|
||||||
const features = useWorkspaceAvailableFeatures(workspaceMetadata);
|
|
||||||
|
|
||||||
return features.includes(FeatureType.Copilot) ? (
|
|
||||||
<WorkspaceFeaturesSettingItem
|
|
||||||
title="AI POC"
|
|
||||||
workspaceMetadata={workspaceMetadata}
|
|
||||||
feature={FeatureType.Copilot}
|
|
||||||
/>
|
|
||||||
) : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const SplitViewSettingRow = () => {
|
const SplitViewSettingRow = () => {
|
||||||
const { appSettings, updateSettings } = useAppSettingHelper();
|
const { appSettings, updateSettings } = useAppSettingHelper();
|
||||||
|
|
||||||
@@ -204,11 +148,7 @@ const BlocksuiteFeatureFlagSettings = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ExperimentalFeaturesMain = ({
|
const ExperimentalFeaturesMain = () => {
|
||||||
workspaceMetadata,
|
|
||||||
}: {
|
|
||||||
workspaceMetadata: WorkspaceMetadata;
|
|
||||||
}) => {
|
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -219,7 +159,6 @@ const ExperimentalFeaturesMain = ({
|
|||||||
]()}
|
]()}
|
||||||
/>
|
/>
|
||||||
<div className={styles.settingsContainer}>
|
<div className={styles.settingsContainer}>
|
||||||
<CopilotSettingRow workspaceMetadata={workspaceMetadata} />
|
|
||||||
<SplitViewSettingRow />
|
<SplitViewSettingRow />
|
||||||
<BlocksuiteFeatureFlagSettings />
|
<BlocksuiteFeatureFlagSettings />
|
||||||
</div>
|
</div>
|
||||||
@@ -233,11 +172,7 @@ const experimentalFeaturesDisclaimerAtom = atomWithStorage(
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
export const ExperimentalFeatures = ({
|
export const ExperimentalFeatures = () => {
|
||||||
workspaceMetadata,
|
|
||||||
}: {
|
|
||||||
workspaceMetadata: WorkspaceMetadata;
|
|
||||||
}) => {
|
|
||||||
const [enabled, setEnabled] = useAtom(experimentalFeaturesDisclaimerAtom);
|
const [enabled, setEnabled] = useAtom(experimentalFeaturesDisclaimerAtom);
|
||||||
const handleConfirm = useAsyncCallback(async () => {
|
const handleConfirm = useAsyncCallback(async () => {
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
@@ -247,7 +182,7 @@ export const ExperimentalFeatures = ({
|
|||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<Loading />}>
|
<Suspense fallback={<Loading />}>
|
||||||
<ExperimentalFeaturesMain workspaceMetadata={workspaceMetadata} />
|
<ExperimentalFeaturesMain />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const WorkspaceSetting = ({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'experimental-features':
|
case 'experimental-features':
|
||||||
return <ExperimentalFeatures workspaceMetadata={workspaceMetadata} />;
|
return <ExperimentalFeatures />;
|
||||||
case 'properties':
|
case 'properties':
|
||||||
return (
|
return (
|
||||||
<WorkspaceSettingProperties workspaceMetadata={workspaceMetadata} />
|
<WorkspaceSettingProperties workspaceMetadata={workspaceMetadata} />
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { useWorkspaceEnabledFeatures } from '@affine/core/hooks/use-workspace-features';
|
|
||||||
import { FeatureType } from '@affine/graphql';
|
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
import { AiIcon } from '@blocksuite/icons';
|
import { AiIcon } from '@blocksuite/icons';
|
||||||
import { ChatPanel } from '@blocksuite/presets';
|
import { ChatPanel } from '@blocksuite/presets';
|
||||||
import { useService, Workspace } from '@toeverything/infra';
|
|
||||||
import { useCallback, useRef } from 'react';
|
import { useCallback, useRef } from 'react';
|
||||||
|
|
||||||
import type { SidebarTab, SidebarTabProps } from '../sidebar-tab';
|
import type { SidebarTab, SidebarTabProps } from '../sidebar-tab';
|
||||||
@@ -11,21 +8,14 @@ import * as styles from './chat.css';
|
|||||||
|
|
||||||
// A wrapper for CopilotPanel
|
// A wrapper for CopilotPanel
|
||||||
const EditorChatPanel = ({ editor }: SidebarTabProps) => {
|
const EditorChatPanel = ({ editor }: SidebarTabProps) => {
|
||||||
const workspace = useService(Workspace);
|
|
||||||
const copilotEnabled = useWorkspaceEnabledFeatures(workspace.meta).includes(
|
|
||||||
FeatureType.Copilot
|
|
||||||
);
|
|
||||||
const chatPanelRef = useRef<ChatPanel | null>(null);
|
const chatPanelRef = useRef<ChatPanel | null>(null);
|
||||||
|
|
||||||
const onRefChange = useCallback(
|
const onRefChange = useCallback((container: HTMLDivElement | null) => {
|
||||||
(container: HTMLDivElement | null) => {
|
if (container) {
|
||||||
if (container && copilotEnabled) {
|
assertExists(chatPanelRef.current, 'chat panel should be initialized');
|
||||||
assertExists(chatPanelRef.current, 'chat panel should be initialized');
|
container.append(chatPanelRef.current);
|
||||||
container.append(chatPanelRef.current);
|
}
|
||||||
}
|
}, []);
|
||||||
},
|
|
||||||
[copilotEnabled]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { IconButton } from '@affine/component';
|
import { IconButton } from '@affine/component';
|
||||||
import { useJournalInfoHelper } from '@affine/core/hooks/use-journal';
|
import { useJournalInfoHelper } from '@affine/core/hooks/use-journal';
|
||||||
import { useWorkspaceEnabledFeatures } from '@affine/core/hooks/use-workspace-features';
|
|
||||||
import { FeatureType } from '@affine/graphql';
|
|
||||||
import { Doc, useService, Workspace } from '@toeverything/infra';
|
import { Doc, useService, Workspace } from '@toeverything/infra';
|
||||||
import { assignInlineVars } from '@vanilla-extract/dynamic';
|
import { assignInlineVars } from '@vanilla-extract/dynamic';
|
||||||
import { useEffect, useMemo } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import type { SidebarTab, SidebarTabName } from '../entities/sidebar-tab';
|
import type { SidebarTab, SidebarTabName } from '../entities/sidebar-tab';
|
||||||
import * as styles from './header-switcher.css';
|
import * as styles from './header-switcher.css';
|
||||||
@@ -24,22 +22,10 @@ export const MultiTabSidebarHeaderSwitcher = ({
|
|||||||
}: MultiTabSidebarHeaderSwitcherProps) => {
|
}: MultiTabSidebarHeaderSwitcherProps) => {
|
||||||
const workspace = useService(Workspace);
|
const workspace = useService(Workspace);
|
||||||
const doc = useService(Doc);
|
const doc = useService(Doc);
|
||||||
const copilotEnabled = useWorkspaceEnabledFeatures(workspace.meta).includes(
|
|
||||||
FeatureType.Copilot
|
|
||||||
);
|
|
||||||
|
|
||||||
const { isJournal } = useJournalInfoHelper(workspace.docCollection, doc.id);
|
const { isJournal } = useJournalInfoHelper(workspace.docCollection, doc.id);
|
||||||
|
|
||||||
const exts = useMemo(
|
const activeExtension = tabs.find(ext => ext.name === activeTabName);
|
||||||
() =>
|
|
||||||
tabs.filter(ext => {
|
|
||||||
if (ext.name === 'chat' && !copilotEnabled) return false;
|
|
||||||
return true;
|
|
||||||
}),
|
|
||||||
[copilotEnabled, tabs]
|
|
||||||
);
|
|
||||||
|
|
||||||
const activeExtension = exts.find(ext => ext.name === activeTabName);
|
|
||||||
|
|
||||||
// if journal is active, set selected to journal
|
// if journal is active, set selected to journal
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -50,14 +36,14 @@ export const MultiTabSidebarHeaderSwitcher = ({
|
|||||||
|
|
||||||
const vars = assignInlineVars({
|
const vars = assignInlineVars({
|
||||||
[styles.activeIdx]: String(
|
[styles.activeIdx]: String(
|
||||||
exts.findIndex(ext => ext.name === activeExtension?.name) ?? 0
|
tabs.findIndex(ext => ext.name === activeExtension?.name) ?? 0
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.switchRootWrapper}>
|
<div className={styles.switchRootWrapper}>
|
||||||
<div className={styles.switchRoot} style={vars}>
|
<div className={styles.switchRoot} style={vars}>
|
||||||
{exts.map(extension => {
|
{tabs.map(extension => {
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() => setActiveTabName(extension.name)}
|
onClick={() => setActiveTabName(extension.name)}
|
||||||
|
|||||||
Reference in New Issue
Block a user