Открыть боковую панель
Teknokomo
universo-react
Коммиты
a687e7c0
Не подтверждена
Коммит
a687e7c0
создал
Янв 24, 2024
по автору
Peng Xiao
Просмотр файлов
fix(core): workspace feature should be workspace specific (#5677)
fix TOV-429
владелец
994ab966
Изменения
7
Скрыть пробелы
Построчно
Рядом
packages/frontend/core/src/components/affine/setting-modal/setting-sidebar/index.tsx
Просмотр файла @
a687e7c0
...
...
@@ -240,7 +240,7 @@ const WorkspaceListItem = ({
const
isCurrent
=
currentWorkspace
.
id
===
meta
.
id
;
const
t
=
useAFFiNEI18N
();
const
isOwner
=
useIsWorkspaceOwner
(
meta
);
const
availableFeatures
=
useWorkspaceAvailableFeatures
();
const
availableFeatures
=
useWorkspaceAvailableFeatures
(
meta
);
const
onClickPreference
=
useCallback
(()
=>
{
onClick
(
'
preference
'
);
...
...
packages/frontend/core/src/components/affine/setting-modal/workspace-setting/experimental-features/index.tsx
Просмотр файла @
a687e7c0
...
...
@@ -8,6 +8,7 @@ import {
}
from
'
@affine/core/hooks/use-workspace-features
'
;
import
{
FeatureType
}
from
'
@affine/graphql
'
;
import
{
useAFFiNEI18N
}
from
'
@affine/i18n/hooks
'
;
import
type
{
WorkspaceMetadata
}
from
'
@affine/workspace/metadata
'
;
import
{
useAtom
}
from
'
jotai
'
;
import
{
atomWithStorage
}
from
'
jotai/utils
'
;
import
{
Suspense
,
useCallback
,
useState
}
from
'
react
'
;
...
...
@@ -74,16 +75,18 @@ const ExperimentalFeaturesPrompt = ({
interface
ExperimentalFeaturesItemProps
{
feature
:
FeatureType
;
title
:
React
.
ReactNode
;
workspaceMetadata
:
WorkspaceMetadata
;
}
const
ExperimentalFeaturesItem
=
({
feature
,
title
,
workspaceMetadata
,
}:
ExperimentalFeaturesItemProps
)
=>
{
const
enabledFeatures
=
useWorkspaceEnabledFeatures
();
const
enabledFeatures
=
useWorkspaceEnabledFeatures
(
workspaceMetadata
);
const
enabled
=
enabledFeatures
.
includes
(
feature
);
const
[
localEnabled
,
setLocalEnabled
]
=
useState
(
enabled
);
const
{
trigger
,
isMutating
}
=
useSetWorkspaceFeature
();
const
{
trigger
,
isMutating
}
=
useSetWorkspaceFeature
(
workspaceMetadata
);
const
onChange
=
useCallback
(
(
checked
:
boolean
)
=>
{
setLocalEnabled
(
checked
);
...
...
@@ -104,9 +107,13 @@ const ExperimentalFeaturesItem = ({
);
};
const
ExperimentalFeaturesMain
=
()
=>
{
const
ExperimentalFeaturesMain
=
({
workspaceMetadata
,
}:
{
workspaceMetadata
:
WorkspaceMetadata
;
})
=>
{
const
t
=
useAFFiNEI18N
();
const
features
=
useWorkspaceAvailableFeatures
();
const
features
=
useWorkspaceAvailableFeatures
(
workspaceMetadata
);
return
(
<>
...
...
@@ -119,6 +126,7 @@ const ExperimentalFeaturesMain = () => {
{
features
.
includes
(
FeatureType
.
Copilot
)
?
(
<
ExperimentalFeaturesItem
title
=
"AI POC"
workspaceMetadata
=
{
workspaceMetadata
}
feature
=
{
FeatureType
.
Copilot
}
/>
)
:
null
}
...
...
@@ -132,7 +140,11 @@ const experimentalFeaturesDisclaimerAtom = atomWithStorage(
false
);
export
const
ExperimentalFeatures
=
()
=>
{
export
const
ExperimentalFeatures
=
({
workspaceMetadata
,
}:
{
workspaceMetadata
:
WorkspaceMetadata
;
})
=>
{
const
[
enabled
,
setEnabled
]
=
useAtom
(
experimentalFeaturesDisclaimerAtom
);
const
handleConfirm
=
useAsyncCallback
(
async
()
=>
{
setEnabled
(
true
);
...
...
@@ -142,7 +154,7 @@ export const ExperimentalFeatures = () => {
}
else
{
return
(
<
Suspense
fallback
=
{
<
Loading
/>
}
>
<
ExperimentalFeaturesMain
/>
<
ExperimentalFeaturesMain
workspaceMetadata
=
{
workspaceMetadata
}
/>
</
Suspense
>
);
}
...
...
packages/frontend/core/src/components/affine/setting-modal/workspace-setting/index.tsx
Просмотр файла @
a687e7c0
...
...
@@ -22,6 +22,6 @@ export const WorkspaceSetting = ({
/>
);
case
'
experimental-features
'
:
return
<
ExperimentalFeatures
/>;
return
<
ExperimentalFeatures
workspaceMetadata
=
{
workspaceMetadata
}
/>;
}
};
packages/frontend/core/src/hooks/use-workspace-features.ts
Просмотр файла @
a687e7c0
...
...
@@ -5,25 +5,25 @@ import {
enabledFeaturesQuery
,
setWorkspaceExperimentalFeatureMutation
,
}
from
'
@affine/graphql
'
;
import
{
useAtomValue
}
from
'
jotai
'
;
import
type
{
WorkspaceMetadata
}
from
'
@affine/workspace/metadata
'
;
import
{
waitForCurrentWorkspaceAtom
}
from
'
../modules/workspace
'
;
import
{
useAsyncCallback
}
from
'
./affine-async-hooks
'
;
import
{
useMutateQueryResource
,
useMutation
}
from
'
./use-mutation
'
;
import
{
useQueryImmutable
}
from
'
./use-query
'
;
const
emptyFeatures
:
FeatureType
[]
=
[];
export
const
useWorkspaceAvailableFeatures
=
()
=>
{
const
currentWorkspace
=
useAtomValue
(
waitForCurrentWorkspaceAtom
);
export
const
useWorkspaceAvailableFeatures
=
(
workspaceMetadata
:
WorkspaceMetadata
)
=>
{
const
isCloudWorkspace
=
currentWorkspace
.
flavour
===
WorkspaceFlavour
.
AFFINE_CLOUD
;
workspaceMetadata
.
flavour
===
WorkspaceFlavour
.
AFFINE_CLOUD
;
const
{
data
}
=
useQueryImmutable
(
isCloudWorkspace
?
{
query
:
availableFeaturesQuery
,
variables
:
{
id
:
currentWorkspace
.
id
,
id
:
workspaceMetadata
.
id
,
},
}
:
undefined
...
...
@@ -31,16 +31,17 @@ export const useWorkspaceAvailableFeatures = () => {
return
data
?.
workspace
.
availableFeatures
??
emptyFeatures
;
};
export
const
useWorkspaceEnabledFeatures
=
()
=>
{
const
currentWorkspace
=
useAtomValue
(
waitForCurrentWorkspaceAtom
);
export
const
useWorkspaceEnabledFeatures
=
(
workspaceMetadata
:
WorkspaceMetadata
)
=>
{
const
isCloudWorkspace
=
currentWorkspace
.
flavour
===
WorkspaceFlavour
.
AFFINE_CLOUD
;
workspaceMetadata
.
flavour
===
WorkspaceFlavour
.
AFFINE_CLOUD
;
const
{
data
}
=
useQueryImmutable
(
isCloudWorkspace
?
{
query
:
enabledFeaturesQuery
,
variables
:
{
id
:
currentWorkspace
.
id
,
id
:
workspaceMetadata
.
id
,
},
}
:
undefined
...
...
@@ -48,8 +49,9 @@ export const useWorkspaceEnabledFeatures = () => {
return
data
?.
workspace
.
features
??
emptyFeatures
;
};
export
const
useSetWorkspaceFeature
=
()
=>
{
const
currentWorkspace
=
useAtomValue
(
waitForCurrentWorkspaceAtom
);
export
const
useSetWorkspaceFeature
=
(
workspaceMetadata
:
WorkspaceMetadata
)
=>
{
const
{
trigger
,
isMutating
}
=
useMutation
({
mutation
:
setWorkspaceExperimentalFeatureMutation
,
});
...
...
@@ -59,15 +61,15 @@ export const useSetWorkspaceFeature = () => {
trigger
:
useAsyncCallback
(
async
(
feature
:
FeatureType
,
enable
:
boolean
)
=>
{
await
trigger
({
workspaceId
:
currentWorkspace
.
id
,
workspaceId
:
workspaceMetadata
.
id
,
feature
,
enable
,
});
await
revalidate
(
enabledFeaturesQuery
,
vars
=>
{
return
vars
.
id
===
currentWorkspace
.
id
;
return
vars
.
id
===
workspaceMetadata
.
id
;
});
},
[
currentWorkspace
.
id
,
revalidate
,
trigger
]
[
workspaceMetadata
.
id
,
revalidate
,
trigger
]
),
isMutating
,
};
...
...
packages/frontend/core/src/pages/workspace/detail-page/detail-page-header.tsx
Просмотр файла @
a687e7c0
...
...
@@ -11,7 +11,6 @@ import { JournalTodayButton } from '@affine/core/components/blocksuite/block-sui
import
{
PageHeaderMenuButton
}
from
'
@affine/core/components/blocksuite/block-suite-header/menu
'
;
import
{
EditorModeSwitch
}
from
'
@affine/core/components/blocksuite/block-suite-mode-switch
'
;
import
{
useJournalInfoHelper
}
from
'
@affine/core/hooks/use-journal
'
;
import
type
{
BlockSuiteWorkspace
}
from
'
@affine/core/shared
'
;
import
type
{
Workspace
}
from
'
@affine/workspace
'
;
import
{
RightSidebarIcon
}
from
'
@blocksuite/icons
'
;
import
type
{
Page
}
from
'
@blocksuite/store
'
;
...
...
@@ -189,7 +188,7 @@ export function DetailPageHeader(props: PageHeaderProps) {
}
interface
SidebarHeaderProps
{
workspace
:
BlockSuite
Workspace
;
workspace
:
Workspace
;
page
:
Page
;
}
function
WindowsSidebarHeader
(
props
:
SidebarHeaderProps
)
{
...
...
packages/frontend/core/src/pages/workspace/detail-page/detail-page.tsx
Просмотр файла @
a687e7c0
...
...
@@ -206,7 +206,7 @@ const DetailPageImpl = memo(function DetailPageImpl({ page }: { page: Page }) {
sidebar
=
{
!
isInTrash
?
(
<
div
className
=
{
styles
.
sidebarContainerInner
}
>
<
RightSidebarHeader
workspace
=
{
blockSuite
Workspace
}
page
=
{
page
}
/>
<
RightSidebarHeader
workspace
=
{
current
Workspace
}
page
=
{
page
}
/>
<
EditorSidebar
workspace
=
{
blockSuiteWorkspace
}
page
=
{
page
}
/>
</
div
>
)
:
null
...
...
packages/frontend/core/src/pages/workspace/detail-page/editor-sidebar/extensions/extensions.tsx
Просмотр файла @
a687e7c0
import
{
IconButton
}
from
'
@affine/component
'
;
import
{
useJournalInfoHelper
}
from
'
@affine/core/hooks/use-journal
'
;
import
{
useWorkspaceEnabledFeatures
}
from
'
@affine/core/hooks/use-workspace-features
'
;
import
type
{
BlockSuiteWorkspace
}
from
'
@affine/core/shared
'
;
import
{
FeatureType
}
from
'
@affine/graphql
'
;
import
type
{
Workspace
}
from
'
@affine/workspace/workspace
'
;
import
type
{
Page
}
from
'
@blocksuite/store
'
;
import
{
assignInlineVars
}
from
'
@vanilla-extract/dynamic
'
;
import
{
useAtom
,
useAtomValue
}
from
'
jotai
'
;
...
...
@@ -15,15 +15,15 @@ import {
import
*
as
styles
from
'
./extensions.css
'
;
export
interface
ExtensionTabsProps
{
workspace
:
BlockSuite
Workspace
;
workspace
:
Workspace
;
page
:
Page
;
}
// provide a switcher for active extensions
// will be used in global top header (MacOS) or sidebar (Windows)
export
const
ExtensionTabs
=
({
page
}:
ExtensionTabsProps
)
=>
{
export
const
ExtensionTabs
=
({
page
,
workspace
}:
ExtensionTabsProps
)
=>
{
// todo: filter in editorExtensionsAtom instead?
const
copilotEnabled
=
useWorkspaceEnabledFeatures
().
includes
(
const
copilotEnabled
=
useWorkspaceEnabledFeatures
(
workspace
.
meta
).
includes
(
FeatureType
.
Copilot
);
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать