-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): support creating cloud workspaces to different servers (#…
- Loading branch information
Showing
24 changed files
with
621 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/frontend/core/src/components/server-selector/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Menu, MenuItem, type MenuProps, MenuTrigger } from '@affine/component'; | ||
import type { Server } from '@affine/core/modules/cloud'; | ||
import { useMemo } from 'react'; | ||
|
||
import { triggerStyle } from './style.css'; | ||
|
||
export const ServerSelector = ({ | ||
servers, | ||
selectedSeverName, | ||
onSelect, | ||
contentOptions, | ||
}: { | ||
servers: Server[]; | ||
selectedSeverName: string; | ||
onSelect: (server: Server) => void; | ||
contentOptions?: MenuProps['contentOptions']; | ||
}) => { | ||
const menuItems = useMemo(() => { | ||
return servers.map(server => ( | ||
<MenuItem key={server.id} onSelect={() => onSelect(server)}> | ||
{server.config$.value.serverName} ({server.baseUrl}) | ||
</MenuItem> | ||
)); | ||
}, [servers, onSelect]); | ||
|
||
return ( | ||
<Menu | ||
items={menuItems} | ||
contentOptions={{ | ||
...contentOptions, | ||
style: { | ||
...contentOptions?.style, | ||
width: 'var(--radix-dropdown-menu-trigger-width)', | ||
}, | ||
}} | ||
> | ||
<MenuTrigger className={triggerStyle}>{selectedSeverName}</MenuTrigger> | ||
</Menu> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/frontend/core/src/components/server-selector/style.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const triggerStyle = style({ | ||
width: '100%', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/frontend/core/src/components/workspace-selector/enable-cloud/enable-cloud.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { cssVar } from '@toeverything/theme'; | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const root = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
width: '100%', | ||
gap: '20px', | ||
}); | ||
|
||
export const textContainer = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
textAlign: 'center', | ||
}); | ||
|
||
export const title = style({ | ||
fontSize: cssVar('fontH6'), | ||
fontWeight: 600, | ||
lineHeight: '26px', | ||
}); | ||
|
||
export const description = style({ | ||
fontSize: cssVar('fontBase'), | ||
fontWeight: 400, | ||
lineHeight: '24px', | ||
color: cssVar('textSecondaryColor'), | ||
}); | ||
|
||
export const serverSelector = style({ | ||
width: '100%', | ||
}); | ||
|
||
export const button = style({ | ||
width: '100%', | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/frontend/core/src/components/workspace-selector/enable-cloud/enable-cloud.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Server } from '@affine/core/modules/cloud'; | ||
import { CloudWorkspaceIcon } from '@blocksuite/icons/rc'; | ||
|
||
import { ServerSelector } from '../../server-selector'; | ||
import * as styles from './enable-cloud.css'; | ||
|
||
export const CustomServerEnableCloud = ({ | ||
serverList, | ||
selectedServer, | ||
setSelectedServer, | ||
title, | ||
description, | ||
}: { | ||
serverList: Server[]; | ||
selectedServer: Server; | ||
title?: string; | ||
description?: string; | ||
setSelectedServer: (server: Server) => void; | ||
}) => { | ||
return ( | ||
<div className={styles.root}> | ||
<CloudWorkspaceIcon width={'36px'} height={'36px'} /> | ||
<div className={styles.textContainer}> | ||
{title ? <div className={styles.title}>{title}</div> : null} | ||
{description ? ( | ||
<div className={styles.description}>{description}</div> | ||
) : null} | ||
</div> | ||
<div className={styles.serverSelector}> | ||
<ServerSelector | ||
servers={serverList} | ||
selectedSeverName={`${selectedServer.config$.value.serverName} (${selectedServer.baseUrl})`} | ||
onSelect={setSelectedServer} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/frontend/core/src/components/workspace-selector/enable-cloud/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './enable-cloud'; |
23 changes: 23 additions & 0 deletions
23
...d/core/src/components/workspace-selector/user-with-workspace-list/add-server/index.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { cssVar } from '@toeverything/theme'; | ||
import { style } from '@vanilla-extract/css'; | ||
export const ItemContainer = style({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'flex-start', | ||
padding: '8px 14px', | ||
gap: '14px', | ||
cursor: 'pointer', | ||
borderRadius: '8px', | ||
transition: 'background-color 0.2s', | ||
fontSize: '24px', | ||
color: cssVar('iconSecondary'), | ||
}); | ||
export const ItemText = style({ | ||
fontSize: cssVar('fontSm'), | ||
lineHeight: '22px', | ||
color: cssVar('textSecondaryColor'), | ||
fontWeight: 400, | ||
whiteSpace: 'nowrap', | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis', | ||
}); |
37 changes: 37 additions & 0 deletions
37
...tend/core/src/components/workspace-selector/user-with-workspace-list/add-server/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { MenuItem } from '@affine/component/ui/menu'; | ||
import { useI18n } from '@affine/i18n'; | ||
import { PlusIcon } from '@blocksuite/icons/rc'; | ||
import { | ||
FeatureFlagService, | ||
useLiveData, | ||
useService, | ||
} from '@toeverything/infra'; | ||
|
||
import * as styles from './index.css'; | ||
|
||
export const AddServer = ({ onAddServer }: { onAddServer?: () => void }) => { | ||
const t = useI18n(); | ||
const featureFlagService = useService(FeatureFlagService); | ||
const enableMultipleServer = useLiveData( | ||
featureFlagService.flags.enable_multiple_cloud_servers.$ | ||
); | ||
|
||
if (!enableMultipleServer) { | ||
return null; | ||
} | ||
return ( | ||
<div> | ||
<MenuItem | ||
block={true} | ||
prefixIcon={<PlusIcon />} | ||
onClick={onAddServer} | ||
data-testid="new-server" | ||
className={styles.ItemContainer} | ||
> | ||
<div className={styles.ItemText}> | ||
{t['com.affine.workspaceList.addServer']()} | ||
</div> | ||
</MenuItem> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.