From 0038d0a4551ff5521c1dd0a23dd5d4a98c328e8e Mon Sep 17 00:00:00 2001 From: Maggie Brewster Date: Mon, 30 Mar 2020 14:42:44 -0600 Subject: [PATCH 01/13] use auto form --- .../lookup-edit-dialog.scss | 4 +- .../lookup-edit-dialog.spec.tsx | 2 +- .../lookup-edit-dialog/lookup-edit-dialog.tsx | 74 ++++++++++++------- .../src/views/lookups-view/lookups-view.tsx | 13 ++-- 4 files changed, 58 insertions(+), 35 deletions(-) diff --git a/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.scss b/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.scss index e2de177e3255..df604f25616a 100644 --- a/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.scss +++ b/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.scss @@ -23,8 +23,8 @@ width: 600px; } - .ace_editor { - margin: 0px 20px 10px; + .auto-form { + margin: 5px 20px 10px; } .lookup-label { diff --git a/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.spec.tsx b/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.spec.tsx index b243f145db11..06fa64968090 100644 --- a/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.spec.tsx +++ b/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.spec.tsx @@ -31,7 +31,7 @@ describe('lookup edit dialog', () => { lookupName={'test'} lookupTier={'test'} lookupVersion={'test'} - lookupSpec={'test'} + lookupSpec={{ type: 'test', map: {} }} isEdit={false} allLookupTiers={['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']} /> diff --git a/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.tsx b/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.tsx index 6c93ec82b0e7..18bdbf652024 100644 --- a/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.tsx +++ b/web-console/src/dialogs/lookup-edit-dialog/lookup-edit-dialog.tsx @@ -26,20 +26,27 @@ import { Intent, } from '@blueprintjs/core'; import React from 'react'; -import AceEditor from 'react-ace'; -import { validJson } from '../../utils'; +import { AutoForm } from '../../components'; +// import { validJson } from '../../utils'; import './lookup-edit-dialog.scss'; +// import AceEditor from 'react-ace'; +// import {SnitchDialog} from ".."; + +export interface LookupSpec { + type: string; + map?: {}; +} export interface LookupEditDialogProps { onClose: () => void; onSubmit: () => void; - onChange: (field: string, value: string) => void; + onChange: (field: string, value: string | LookupSpec) => void; lookupName: string; lookupTier: string; lookupVersion: string; - lookupSpec: string; + lookupSpec: LookupSpec; isEdit: boolean; allLookupTiers: string[]; } @@ -57,6 +64,20 @@ export const LookupEditDialog = React.memo(function LookupEditDialog(props: Look allLookupTiers, } = props; + function isValidMap(map: object) { + try { + if (typeof map !== 'object') return false; + const entries = Object.entries(map); + for (let i = 0; i < entries.length; i++) { + if (typeof entries[i][1] !== 'string') return false; + } + return true; + } catch { + return false; + } + return true; + } + function addISOVersion() { const currentDate = new Date(); const ISOString = currentDate.toISOString(); @@ -94,7 +115,13 @@ export const LookupEditDialog = React.memo(function LookupEditDialog(props: Look } const disableSubmit = - lookupName === '' || lookupVersion === '' || lookupTier === '' || !validJson(lookupSpec); + lookupName === '' || + lookupVersion === '' || + lookupTier === '' || + lookupSpec.type === '' || + lookupSpec.type === undefined || + lookupSpec.map === undefined || + !isValidMap(lookupSpec.map); return ( - {renderTierInput()} - - - - - onChange('lookupEditSpec', e)} - fontSize={12} - height="40vh" - width="auto" - showPrintMargin={false} - showGutter={false} - value={lookupSpec} - editorProps={{ $blockScrolling: Infinity }} - setOptions={{ - tabSize: 2, + { + onChange('lookupEditSpec', m); }} - style={{}} /> -
- -
-
-
-