-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist form state and validation in Workspace (#61)
Signed-off-by: Tyler Ohlsen <[email protected]>
- Loading branch information
Showing
26 changed files
with
650 additions
and
244 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
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
42 changes: 42 additions & 0 deletions
42
public/pages/workflow_detail/component_details/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,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiPanel } from '@elastic/eui'; | ||
import { ReactFlowComponent } from '../../../../common'; | ||
import { ComponentInputs } from './component_inputs'; | ||
import { EmptyComponentInputs } from './empty_component_inputs'; | ||
|
||
// styling | ||
import '../workspace/workspace-styles.scss'; | ||
|
||
interface ComponentDetailsProps { | ||
selectedComponent?: ReactFlowComponent; | ||
} | ||
|
||
/** | ||
* 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) { | ||
return ( | ||
<EuiFlexGroup | ||
direction="column" | ||
gutterSize="none" | ||
className="workspace-panel" | ||
> | ||
<EuiFlexItem> | ||
<EuiPanel paddingSize="m"> | ||
{props.selectedComponent ? ( | ||
<ComponentInputs selectedComponent={props.selectedComponent} /> | ||
) : ( | ||
<EmptyComponentInputs /> | ||
)} | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
public/pages/workflow_detail/component_details/component_inputs.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,25 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiSpacer, EuiTitle } from '@elastic/eui'; | ||
import { InputFieldList } from './input_field_list'; | ||
import { ReactFlowComponent } from '../../../../common'; | ||
|
||
interface ComponentInputsProps { | ||
selectedComponent: ReactFlowComponent; | ||
} | ||
|
||
export function ComponentInputs(props: ComponentInputsProps) { | ||
return ( | ||
<> | ||
<EuiTitle size="m"> | ||
<h2>{props.selectedComponent.data.label || ''}</h2> | ||
</EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<InputFieldList selectedComponent={props.selectedComponent} /> | ||
</> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
public/pages/workflow_detail/component_details/empty_component_inputs.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,25 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiEmptyPrompt, EuiText } from '@elastic/eui'; | ||
|
||
export function EmptyComponentInputs() { | ||
return ( | ||
<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> | ||
</> | ||
} | ||
/> | ||
); | ||
} |
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,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './component_details'; |
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
File renamed without changes.
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
74 changes: 74 additions & 0 deletions
74
public/pages/workflow_detail/component_details/input_fields/select_field.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,74 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { | ||
EuiFormRow, | ||
EuiSuperSelect, | ||
EuiSuperSelectOption, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { Field, FieldProps, useFormikContext } from 'formik'; | ||
import { | ||
IComponentField, | ||
WorkspaceFormValues, | ||
getInitialValue, | ||
isFieldInvalid, | ||
} from '../../../../../common'; | ||
|
||
// TODO: Should be fetched from global state. | ||
// Need to have a way to determine where to fetch this dynamic data. | ||
const existingIndices = [ | ||
{ | ||
value: 'index-1', | ||
inputDisplay: <EuiText>my-index-1</EuiText>, | ||
disabled: false, | ||
}, | ||
{ | ||
value: 'index-2', | ||
inputDisplay: <EuiText>my-index-2</EuiText>, | ||
disabled: false, | ||
}, | ||
] as Array<EuiSuperSelectOption<string>>; | ||
|
||
interface SelectFieldProps { | ||
field: IComponentField; | ||
componentId: string; | ||
} | ||
|
||
/** | ||
* An input field for a component where users select from a list of available | ||
* options. | ||
*/ | ||
export function SelectField(props: SelectFieldProps) { | ||
const options = existingIndices; | ||
const formField = `${props.componentId}.${props.field.name}`; | ||
const { errors, touched } = useFormikContext<WorkspaceFormValues>(); | ||
|
||
return ( | ||
<Field name={formField}> | ||
{({ field, form }: FieldProps) => { | ||
return ( | ||
<EuiFormRow label={props.field.label}> | ||
<EuiSuperSelect | ||
options={options} | ||
valueOfSelected={field.value || getInitialValue(props.field.type)} | ||
onChange={(option) => { | ||
field.onChange(option); | ||
form.setFieldValue(formField, option); | ||
}} | ||
isInvalid={isFieldInvalid( | ||
props.componentId, | ||
props.field.name, | ||
errors, | ||
touched | ||
)} | ||
/> | ||
</EuiFormRow> | ||
); | ||
}} | ||
</Field> | ||
); | ||
} |
Oops, something went wrong.