-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a component details side panel (#57)
Signed-off-by: Tyler Ohlsen <[email protected]>
- Loading branch information
Showing
14 changed files
with
234 additions
and
44 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
99 changes: 99 additions & 0 deletions
99
public/pages/workflow_detail/workspace/component_details.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,99 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState, useContext } from 'react'; | ||
import { useOnSelectionChange } from 'reactflow'; | ||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSpacer, | ||
EuiPanel, | ||
EuiTitle, | ||
EuiEmptyPrompt, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { ReactFlowComponent } from '../../../../common'; | ||
import { rfContext } from '../../../store'; | ||
import { InputFieldList } from '../workspace_component/input_field_list'; | ||
|
||
// styling | ||
import './workspace-styles.scss'; | ||
|
||
interface ComponentDetailsProps { | ||
onToggleChange: () => void; | ||
isOpen: boolean; | ||
} | ||
|
||
/** | ||
* A panel that will be nested in a resizable container to dynamically show | ||
* the details and user-required inputs based on the selected component | ||
* in the flow workspace. | ||
*/ | ||
export function ComponentDetails(props: ComponentDetailsProps) { | ||
// TODO: use this instance to update the internal node state. ex: update field data in the selected node based | ||
// on user input | ||
const { reactFlowInstance } = useContext(rfContext); | ||
|
||
const [selectedComponent, setSelectedComponent] = useState< | ||
ReactFlowComponent | ||
>(); | ||
|
||
/** | ||
* Hook provided by reactflow to listen on when nodes are selected / de-selected. | ||
* - populate panel content appropriately | ||
* - open the panel if a node is selected and the panel is closed | ||
* - it is assumed that only one node can be selected at once | ||
*/ | ||
useOnSelectionChange({ | ||
onChange: ({ nodes, edges }) => { | ||
if (nodes && nodes.length > 0) { | ||
setSelectedComponent(nodes[0]); | ||
if (!props.isOpen) { | ||
props.onToggleChange(); | ||
} | ||
} else { | ||
setSelectedComponent(undefined); | ||
} | ||
}, | ||
}); | ||
|
||
return ( | ||
<EuiFlexGroup | ||
direction="column" | ||
gutterSize="none" | ||
className="workspace-panel" | ||
> | ||
<EuiFlexItem className="resizable-panel-border"> | ||
<EuiPanel paddingSize="m"> | ||
{selectedComponent ? ( | ||
<> | ||
<EuiTitle size="m"> | ||
<h2>{selectedComponent?.data.label || ''}</h2> | ||
</EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<InputFieldList | ||
inputFields={selectedComponent?.data.fields || []} | ||
/> | ||
</> | ||
) : ( | ||
<EuiEmptyPrompt | ||
iconType={'cross'} | ||
title={<h2>No component selected</h2>} | ||
titleSize="s" | ||
body={ | ||
<> | ||
<EuiText> | ||
Add a component, or select a component to view or edit its | ||
configuration. | ||
</EuiText> | ||
</> | ||
} | ||
/> | ||
)} | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
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
68 changes: 68 additions & 0 deletions
68
public/pages/workflow_detail/workspace/resizable_workspace.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,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useRef, useState } from 'react'; | ||
import { ReactFlowProvider } from 'reactflow'; | ||
import { EuiResizableContainer } from '@elastic/eui'; | ||
import { Workflow } from '../../../../common'; | ||
import { Workspace } from './workspace'; | ||
import { ComponentDetails } from './component_details'; | ||
|
||
interface ResizableWorkspaceProps { | ||
workflow?: Workflow; | ||
} | ||
|
||
const COMPONENT_DETAILS_PANEL_ID = 'component_details_panel_id'; | ||
|
||
/** | ||
* The overall workspace component that maintains state related to the 2 resizable | ||
* panels - the ReactFlow workspace panel and the selected component details panel. | ||
*/ | ||
export function ResizableWorkspace(props: ResizableWorkspaceProps) { | ||
const [isOpen, setIsOpen] = useState<boolean>(true); | ||
const collapseFn = useRef( | ||
(id: string, options: { direction: 'left' | 'right' }) => {} | ||
); | ||
|
||
const onToggleChange = () => { | ||
collapseFn.current(COMPONENT_DETAILS_PANEL_ID, { direction: 'left' }); | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return ( | ||
<EuiResizableContainer | ||
direction="horizontal" | ||
style={{ marginLeft: '-14px' }} | ||
> | ||
{(EuiResizablePanel, EuiResizableButton, { togglePanel }) => { | ||
if (togglePanel) { | ||
collapseFn.current = (panelId: string, { direction }) => | ||
togglePanel(panelId, { direction }); | ||
} | ||
|
||
return ( | ||
<ReactFlowProvider> | ||
<EuiResizablePanel mode="main" initialSize={75} minSize="50%"> | ||
<Workspace workflow={props.workflow} /> | ||
</EuiResizablePanel> | ||
<EuiResizableButton /> | ||
<EuiResizablePanel | ||
id={COMPONENT_DETAILS_PANEL_ID} | ||
mode="collapsible" | ||
initialSize={25} | ||
minSize="10%" | ||
onToggleCollapsedInternal={() => onToggleChange()} | ||
> | ||
<ComponentDetails | ||
onToggleChange={onToggleChange} | ||
isOpen={isOpen} | ||
/> | ||
</EuiResizablePanel> | ||
</ReactFlowProvider> | ||
); | ||
}} | ||
</EuiResizableContainer> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
public/pages/workflow_detail/workspace/workspace-styles.scss
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,12 @@ | ||
.workspace-panel { | ||
// this ratio will allow the workspace to render on a standard | ||
// laptop (3024 x 1964) without introducing overflow/scrolling | ||
height: 60vh; | ||
padding: 0; | ||
} | ||
|
||
.resizable-panel-border { | ||
border-style: groove; | ||
border-color: gray; | ||
border-width: 1px; | ||
} |
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
Oops, something went wrong.