|
| 1 | +import React from 'react'; |
| 2 | +import { Box, EditField, Paragraph } from '../../components'; |
| 3 | +import styles from './index.module.scss'; |
| 4 | +import { titleCase } from '../../../utils'; |
| 5 | +import { ToggleField } from '../common/FormElement'; |
| 6 | +import JSONPretty from 'react-json-pretty'; |
| 7 | + |
| 8 | +export const NonEditableRunConfig: React.FC<{ runConfiguration: any }> = ({ |
| 9 | + runConfiguration, |
| 10 | +}) => { |
| 11 | + const getFormElement: any = (elementName: any, elementSchema: any) => { |
| 12 | + if (typeof elementSchema === 'string') { |
| 13 | + return ( |
| 14 | + <Box marginVertical={'md'} style={{ width: '40%' }}> |
| 15 | + <EditField |
| 16 | + disabled |
| 17 | + // onKeyDown={(e: any) => onPressEnter(e, 'string', elementName)} |
| 18 | + // onChangeText={(e: any) => onPressEnter(e, 'string', elementName)} |
| 19 | + label={titleCase(elementName)} |
| 20 | + optional={false} |
| 21 | + defaultValue={elementSchema} |
| 22 | + placeholder="" |
| 23 | + hasError={false} |
| 24 | + className={styles.field} |
| 25 | + /> |
| 26 | + </Box> |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + if (typeof elementSchema === 'object' && elementSchema !== null) { |
| 31 | + return ( |
| 32 | + <Box style={{ width: '40%' }}> |
| 33 | + <Paragraph size="body" style={{ color: 'black' }}> |
| 34 | + <label htmlFor={elementName}>{titleCase(elementName)}</label> |
| 35 | + </Paragraph> |
| 36 | + <Box |
| 37 | + padding={'md'} |
| 38 | + marginVertical={'md'} |
| 39 | + className={styles.JSONPretty} |
| 40 | + > |
| 41 | + <JSONPretty |
| 42 | + style={{ fontSize: '16px', fontFamily: 'Rubik' }} |
| 43 | + id="json-pretty" |
| 44 | + data={elementSchema} |
| 45 | + ></JSONPretty> |
| 46 | + </Box> |
| 47 | + </Box> |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + if (typeof elementSchema === 'boolean' || elementSchema === null) { |
| 52 | + return ( |
| 53 | + <Box marginVertical={'md'} style={{ width: '40%' }}> |
| 54 | + <Box> |
| 55 | + {/* {console.log(elementSchema, elementName, 'asdasdasda2222sdasd')} |
| 56 | + <FlexBox.Row justifyContent="space-between"> |
| 57 | + <Paragraph>{titleCase(elementName)}</Paragraph> |
| 58 | + <label className={styles.switch}> |
| 59 | + <input |
| 60 | + disabled |
| 61 | + type="checkbox" |
| 62 | + defaultChecked={elementSchema} |
| 63 | + /> |
| 64 | + <span className={`${styles.slider} ${styles.round}`}></span> |
| 65 | + </label> |
| 66 | + </FlexBox.Row> */} |
| 67 | + <ToggleField |
| 68 | + value={elementSchema} |
| 69 | + onHandleChange={() => {}} |
| 70 | + label={titleCase(elementName)} |
| 71 | + disabled={true} |
| 72 | + /> |
| 73 | + </Box> |
| 74 | + </Box> |
| 75 | + ); |
| 76 | + } |
| 77 | + }; |
| 78 | + |
| 79 | + return ( |
| 80 | + <> |
| 81 | + {Object.keys(runConfiguration).map((key, ind) => ( |
| 82 | + // <Col xs={6} key={ind}> |
| 83 | + <>{getFormElement(key, runConfiguration[key])}</> |
| 84 | + // </Col> |
| 85 | + ))} |
| 86 | + </> |
| 87 | + ); |
| 88 | +}; |
0 commit comments