Skip to content

Commit

Permalink
feat(settings): support multi workspace for SettingsForm
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Aug 20, 2021
1 parent 18cc16f commit 0ab144f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions packages/react-settings-form/src/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ import { NodePath } from './components/NodePath'
import { Empty } from 'antd'
import cls from 'classnames'
import './styles.less'
import { useWorkbench } from 'packages/react/lib'

const GlobalState = {
idleRequest: null,
}

export const SettingsForm: React.FC<ISettingFormProps> = observer(
(props) => {
const operation = useOperation()
const node = useCurrentNode()
const selected = useSelected()
const workbench = useWorkbench()
const currentWorkspace =
workbench?.activeWorkspace || workbench?.currentWorkspace
const currentWorkspaceId = currentWorkspace?.id
const operation = useOperation(currentWorkspaceId)
const node = useCurrentNode(currentWorkspaceId)
const selected = useSelected(currentWorkspaceId)
const prefix = usePrefix('settings-form')
const schema = node?.designerProps?.propsSchema
const form = useMemo(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/hooks/useCurrentNode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useSelected } from './useSelected'
import { useTree } from './useTree'

export const useCurrentNode = () => {
const selected = useSelected()
const tree = useTree()
export const useCurrentNode = (workspaceId?: string) => {
const selected = useSelected(workspaceId)
const tree = useTree(workspaceId)
return tree?.findById?.(selected[0])
}
4 changes: 2 additions & 2 deletions packages/react/src/hooks/useSelected.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSelection } from './useSelection'

export const useSelected = () => {
const selection = useSelection()
export const useSelected = (workspaceId?: string) => {
const selection = useSelection(workspaceId)
return selection?.selected || []
}

0 comments on commit 0ab144f

Please sign in to comment.