forked from microsoft/BotFramework-Composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: break down the design page(the first step) (microsoft#5623)
* perf: split the design page * fix confilcts * fix some comments * fix lint * fix e2e test * refine the four parts * remove unused import * fix dialogid is empty * fix e2e test Co-authored-by: Srinaath Ravichandran <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,094 additions
and
801 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
190 changes: 190 additions & 0 deletions
190
Composer/packages/client/src/pages/design/CommandBar.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,190 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** @jsx jsx */ | ||
import { jsx } from '@emotion/core'; | ||
import React, { useMemo, useCallback, useEffect } from 'react'; | ||
import formatMessage from 'format-message'; | ||
import get from 'lodash/get'; | ||
import { getEditorAPI, registerEditorAPI } from '@bfc/shared'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { Toolbar, IToolbarItem } from '../../components/Toolbar'; | ||
import { createDiagnosticsPageUrl, navigateTo } from '../../utils/navigation'; | ||
import { | ||
visualEditorSelectionState, | ||
dispatcherState, | ||
rootBotProjectIdSelector, | ||
currentDialogState, | ||
} from '../../recoilModel'; | ||
import { undoFunctionState } from '../../recoilModel/undo/history'; | ||
import { undoStatusSelectorFamily } from '../../recoilModel/selectors/undo'; | ||
import { DiagnosticsHeader } from '../../components/DiagnosticsHeader'; | ||
import TelemetryClient from '../../telemetry/TelemetryClient'; | ||
|
||
type CommandBarProps = { dialogId?: string; projectId: string }; | ||
|
||
const CommandBar: React.FC<CommandBarProps> = ({ dialogId, projectId }) => { | ||
const currentDialog = useRecoilValue(currentDialogState({ dialogId, projectId })); | ||
const { undo, redo, clearUndo } = useRecoilValue(undoFunctionState(projectId)); | ||
const rootProjectId = useRecoilValue(rootBotProjectIdSelector) ?? projectId; | ||
const visualEditorSelection = useRecoilValue(visualEditorSelectionState); | ||
const [canUndo, canRedo] = useRecoilValue(undoStatusSelectorFamily(projectId)); | ||
|
||
const { onboardingAddCoachMarkRef } = useRecoilValue(dispatcherState); | ||
|
||
useEffect(() => { | ||
registerEditorAPI('Editing', { | ||
Undo: () => undo(), | ||
Redo: () => redo(), | ||
}); | ||
//leave design page should clear the history | ||
return clearUndo; | ||
}, []); | ||
|
||
const { actionSelected, showDisableBtn, showEnableBtn } = useMemo(() => { | ||
const actionSelected = Array.isArray(visualEditorSelection) && visualEditorSelection.length > 0; | ||
if (!actionSelected) { | ||
return { actionSelected: false, showDisableBtn: false, showEnableBtn: false }; | ||
} | ||
const selectedActions = visualEditorSelection.map((id) => get(currentDialog?.content, id)); | ||
const showDisableBtn = selectedActions.some((x) => get(x, 'disabled') !== true); | ||
const showEnableBtn = selectedActions.some((x) => get(x, 'disabled') === true); | ||
|
||
return { actionSelected, showDisableBtn, showEnableBtn }; | ||
}, [visualEditorSelection, currentDialog?.content]); | ||
|
||
const EditorAPI = getEditorAPI(); | ||
|
||
const toolbarItems: IToolbarItem[] = useMemo( | ||
() => [ | ||
{ | ||
type: 'element', | ||
element: <DiagnosticsHeader onClick={() => navigateTo(createDiagnosticsPageUrl(rootProjectId))} />, | ||
align: 'right', | ||
}, | ||
{ | ||
type: 'dropdown', | ||
text: formatMessage('Edit'), | ||
align: 'left', | ||
dataTestid: 'EditFlyout', | ||
buttonProps: { | ||
iconProps: { iconName: 'Edit' }, | ||
}, | ||
menuProps: { | ||
onMenuOpened: () => { | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'edit' }); | ||
}, | ||
items: [ | ||
{ | ||
key: 'edit.undo', | ||
text: formatMessage('Undo'), | ||
disabled: !canUndo, | ||
onClick: () => { | ||
undo(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'undo' }); | ||
}, | ||
}, | ||
{ | ||
key: 'edit.redo', | ||
text: formatMessage('Redo'), | ||
disabled: !canRedo, | ||
onClick: () => { | ||
redo(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'redo' }); | ||
}, | ||
}, | ||
{ | ||
key: 'edit.cut', | ||
text: formatMessage('Cut'), | ||
disabled: !actionSelected, | ||
onClick: () => { | ||
EditorAPI.Actions.CutSelection(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'cut' }); | ||
}, | ||
}, | ||
{ | ||
key: 'edit.copy', | ||
text: formatMessage('Copy'), | ||
disabled: !actionSelected, | ||
onClick: () => { | ||
EditorAPI.Actions.CopySelection(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'copy' }); | ||
}, | ||
}, | ||
{ | ||
key: 'edit.move', | ||
text: formatMessage('Move'), | ||
disabled: !actionSelected, | ||
onClick: () => { | ||
EditorAPI.Actions.MoveSelection(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'move' }); | ||
}, | ||
}, | ||
{ | ||
key: 'edit.delete', | ||
text: formatMessage('Delete'), | ||
disabled: !actionSelected, | ||
onClick: () => { | ||
EditorAPI.Actions.DeleteSelection(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'delete' }); | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
type: 'dropdown', | ||
text: formatMessage('Disable'), | ||
align: 'left', | ||
disabled: !actionSelected, | ||
buttonProps: { | ||
iconProps: { iconName: 'RemoveOccurrence' }, | ||
}, | ||
menuProps: { | ||
onMenuOpened: () => { | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'disableDropdown' }); | ||
}, | ||
items: [ | ||
{ | ||
key: 'disable', | ||
text: formatMessage('Disable'), | ||
disabled: !showDisableBtn, | ||
onClick: () => { | ||
EditorAPI.Actions.DisableSelection(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'disable' }); | ||
}, | ||
}, | ||
{ | ||
key: 'enable', | ||
text: formatMessage('Enable'), | ||
disabled: !showEnableBtn, | ||
onClick: () => { | ||
EditorAPI.Actions.EnableSelection(); | ||
TelemetryClient.track('ToolbarButtonClicked', { name: 'enable' }); | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
[showDisableBtn, showEnableBtn, actionSelected, canUndo, canRedo] | ||
); | ||
|
||
const addNewBtnRef = useCallback((addNew) => { | ||
onboardingAddCoachMarkRef({ addNew }); | ||
}, []); | ||
|
||
return ( | ||
<div css={{ position: 'relative' }} data-testid="DesignPage-ToolBar"> | ||
<span | ||
ref={addNewBtnRef} | ||
css={{ width: 120, height: '100%', position: 'absolute', left: 0, visibility: 'hidden' }} | ||
data-testid="CoachmarkRef-AddNew" | ||
/> | ||
<Toolbar toolbarItems={toolbarItems} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CommandBar; |
Oops, something went wrong.