-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tyler Ohlsen <[email protected]>
- Loading branch information
Showing
5 changed files
with
155 additions
and
8 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
82 changes: 82 additions & 0 deletions
82
public/pages/workflow_detail/workflow_inputs/export_options/export_options.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,82 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import yaml from 'js-yaml'; | ||
import { | ||
EuiCodeBlock, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiRadioGroup, | ||
} from '@elastic/eui'; | ||
import { Workflow } from '../../../../../common'; | ||
import { reduceToTemplate } from '../../../../utils'; | ||
|
||
interface SearchInputsProps { | ||
workflow?: Workflow; | ||
} | ||
|
||
enum EXPORT_OPTION { | ||
JSON = 'json', | ||
YAML = 'yaml', | ||
} | ||
|
||
const exportOptions = [ | ||
{ | ||
id: EXPORT_OPTION.JSON, | ||
label: 'JSON', | ||
}, | ||
{ | ||
id: EXPORT_OPTION.YAML, | ||
label: 'YAML', | ||
}, | ||
]; | ||
|
||
/** | ||
* The base component containing all of the export options | ||
*/ | ||
export function ExportOptions(props: SearchInputsProps) { | ||
// format type state | ||
const [selectedOption, setSelectedOption] = useState<EXPORT_OPTION>( | ||
EXPORT_OPTION.JSON | ||
); | ||
|
||
// formatted string state | ||
const [formattedConfig, setFormattedConfig] = useState<string>(''); | ||
useEffect(() => { | ||
if (props.workflow) { | ||
const workflowTemplate = reduceToTemplate(props.workflow); | ||
if (selectedOption === EXPORT_OPTION.JSON) { | ||
setFormattedConfig(JSON.stringify(workflowTemplate, undefined, 2)); | ||
} else if (selectedOption === EXPORT_OPTION.YAML) { | ||
setFormattedConfig(yaml.dump(workflowTemplate)); | ||
} | ||
} | ||
}, [props.workflow, selectedOption]); | ||
|
||
return ( | ||
<EuiFlexGroup direction="column"> | ||
<EuiFlexItem grow={false}> | ||
<EuiRadioGroup | ||
options={exportOptions} | ||
idSelected={selectedOption} | ||
onChange={(option) => { | ||
setSelectedOption(option as EXPORT_OPTION); | ||
}} | ||
/> | ||
</EuiFlexItem> | ||
{props.workflow !== undefined && ( | ||
<EuiFlexItem grow={false}> | ||
<EuiCodeBlock | ||
language={selectedOption === EXPORT_OPTION.JSON ? 'json' : 'yaml'} | ||
fontSize="m" | ||
> | ||
{formattedConfig} | ||
</EuiCodeBlock> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
} |
6 changes: 6 additions & 0 deletions
6
public/pages/workflow_detail/workflow_inputs/export_options/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,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './export_options'; |
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