-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add basic-auth UI Form #1718
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dd807d3
feat: add basic-auth UI Form
LiteSun 62619d7
feat: update
LiteSun 7e92854
fix: pluginTemplate CI
LiteSun d56d310
feat: update route ci
LiteSun 5c2f081
feat: update service ci
LiteSun 132dcf4
fix: plugin ci
LiteSun 59dba3e
fix: fe ci
LiteSun 0eacc8b
feat: update
LiteSun 9295fbc
chore: format codes
LiteSun ee2dfb7
feat: show empty when no configuration is required
LiteSun 23fb278
feat: update ci
LiteSun 0755b95
feat: update
LiteSun b94ac34
feat: update
LiteSun f502816
fix: lint
LiteSun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -38,6 +38,7 @@ import addFormats from 'ajv-formats'; | |||||
|
||||||
import { fetchSchema } from './service'; | ||||||
import { json2yaml, yaml2json } from '../../helpers'; | ||||||
import { PluginForm, PLUGIN_UI_LIST } from './UI'; | ||||||
|
||||||
type Props = { | ||||||
name: string; | ||||||
|
@@ -94,8 +95,10 @@ const PluginDetail: React.FC<Props> = ({ | |||||
enum codeMirrorModeList { | ||||||
JSON = 'JSON', | ||||||
YAML = 'YAML', | ||||||
UIForm = 'Form' | ||||||
} | ||||||
const [form] = Form.useForm(); | ||||||
const [UIForm] = Form.useForm(); | ||||||
const ref = useRef<any>(null); | ||||||
const data = initialData[name] || {}; | ||||||
const pluginType = pluginList.find((item) => item.name === name)?.type; | ||||||
|
@@ -107,11 +110,19 @@ const PluginDetail: React.FC<Props> = ({ | |||||
{ label: codeMirrorModeList.YAML, value: codeMirrorModeList.YAML }, | ||||||
]; | ||||||
|
||||||
if (PLUGIN_UI_LIST.includes(name)) { | ||||||
modeOptions.push({ label: codeMirrorModeList.UIForm, value: codeMirrorModeList.UIForm }); | ||||||
} | ||||||
|
||||||
useEffect(() => { | ||||||
form.setFieldsValue({ | ||||||
disable: initialData[name] && !initialData[name].disable, | ||||||
scope: 'global', | ||||||
}); | ||||||
if (PLUGIN_UI_LIST.includes(name)) { | ||||||
setCodeMirrorMode(codeMirrorModeList.UIForm); | ||||||
UIForm.setFieldsValue(initialData[name]); | ||||||
}; | ||||||
}, []); | ||||||
|
||||||
const validateData = (pluginName: string, value: PluginComponent.Data) => { | ||||||
|
@@ -161,23 +172,30 @@ const PluginDetail: React.FC<Props> = ({ | |||||
const handleModeChange = (value: PluginComponent.CodeMirrorMode) => { | ||||||
switch (value) { | ||||||
case codeMirrorModeList.JSON: { | ||||||
const { data: yamlData, error } = yaml2json(ref.current.editor.getValue(), true); | ||||||
|
||||||
if (error) { | ||||||
notification.error({ | ||||||
message: 'Invalid Yaml data', | ||||||
}); | ||||||
return; | ||||||
if (codeMirrorMode === codeMirrorModeList.YAML) { | ||||||
const { data: yamlData, error } = yaml2json(ref.current.editor.getValue(), true); | ||||||
if (error) { | ||||||
notification.error({ | ||||||
message: 'Invalid Yaml data', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
return; | ||||||
} | ||||||
ref.current.editor.setValue( | ||||||
js_beautify(yamlData, { | ||||||
indent_size: 2, | ||||||
}), | ||||||
); | ||||||
} else { | ||||||
ref.current.editor.setValue( | ||||||
js_beautify(JSON.stringify(UIForm.getFieldsValue()), { | ||||||
indent_size: 2, | ||||||
}), | ||||||
); | ||||||
} | ||||||
ref.current.editor.setValue( | ||||||
js_beautify(yamlData, { | ||||||
indent_size: 2, | ||||||
}), | ||||||
); | ||||||
break; | ||||||
} | ||||||
case codeMirrorModeList.YAML: { | ||||||
const { data: jsonData, error } = json2yaml(ref.current.editor.getValue()); | ||||||
const { data: jsonData, error } = json2yaml(codeMirrorMode === codeMirrorModeList.JSON ? ref.current.editor.getValue() : JSON.stringify(UIForm.getFieldsValue())); | ||||||
|
||||||
if (error) { | ||||||
notification.error({ | ||||||
|
@@ -188,11 +206,28 @@ const PluginDetail: React.FC<Props> = ({ | |||||
ref.current.editor.setValue(jsonData); | ||||||
break; | ||||||
} | ||||||
|
||||||
case codeMirrorModeList.UIForm: { | ||||||
if (codeMirrorMode === codeMirrorModeList.JSON) { | ||||||
UIForm.setFieldsValue(JSON.parse(ref.current.editor.getValue())); | ||||||
} else { | ||||||
const { data: yamlData, error } = yaml2json(ref.current.editor.getValue(), true); | ||||||
if (error) { | ||||||
notification.error({ | ||||||
message: 'Invalid Yaml data', | ||||||
}); | ||||||
return; | ||||||
} | ||||||
UIForm.setFieldsValue(JSON.parse(yamlData)); | ||||||
} | ||||||
break; | ||||||
} | ||||||
default: | ||||||
break; | ||||||
} | ||||||
setCodeMirrorMode(value); | ||||||
}; | ||||||
|
||||||
const formatCodes = () => { | ||||||
try { | ||||||
if (ref.current) { | ||||||
|
@@ -249,10 +284,15 @@ const PluginDetail: React.FC<Props> = ({ | |||||
type="primary" | ||||||
onClick={() => { | ||||||
try { | ||||||
const editorData = | ||||||
codeMirrorMode === codeMirrorModeList.JSON | ||||||
? JSON.parse(ref.current?.editor.getValue()) | ||||||
: yaml2json(ref.current?.editor.getValue(), false).data; | ||||||
let editorData; | ||||||
if (codeMirrorMode === codeMirrorModeList.JSON) { | ||||||
editorData = JSON.parse(ref.current?.editor.getValue()); | ||||||
} else if (codeMirrorMode === codeMirrorModeList.YAML) { | ||||||
editorData = yaml2json(ref.current?.editor.getValue(), false).data; | ||||||
} else { | ||||||
editorData = UIForm.getFieldsValue(); | ||||||
} | ||||||
|
||||||
validateData(name, editorData).then((value) => { | ||||||
onChange({ formData: form.getFieldsValue(), codemirrorData: value }); | ||||||
}); | ||||||
|
@@ -297,11 +337,9 @@ const PluginDetail: React.FC<Props> = ({ | |||||
<PageHeader | ||||||
title="" | ||||||
subTitle={ | ||||||
pluginType === 'auth' && schemaType !== 'consumer' ? ( | ||||||
<Alert message={`${name} does not require configuration`} type="warning" /> | ||||||
) : ( | ||||||
<>Current plugin: {name}</> | ||||||
) | ||||||
pluginType === 'auth' && schemaType !== 'consumer' && (codeMirrorMode !== codeMirrorModeList.UIForm) ? ( | ||||||
<Alert message={formatMessage({ id: 'component.global.noConfigurationRequired' })} type="warning" /> | ||||||
) : null | ||||||
} | ||||||
ghost={false} | ||||||
extra={[ | ||||||
|
@@ -328,12 +366,13 @@ const PluginDetail: React.FC<Props> = ({ | |||||
}} | ||||||
data-cy='code-mirror-mode' | ||||||
></Select>, | ||||||
<Button type="primary" onClick={formatCodes} key={3}> | ||||||
<Button type="primary" onClick={formatCodes} key={3} disabled={codeMirrorMode === codeMirrorModeList.UIForm}> | ||||||
{formatMessage({ id: 'component.global.format' })} | ||||||
</Button>, | ||||||
</Button> | ||||||
]} | ||||||
/> | ||||||
<CodeMirror | ||||||
{Boolean(codeMirrorMode === codeMirrorModeList.UIForm) && <PluginForm name={name} form={UIForm} renderForm={!(pluginType === 'auth' && schemaType !== 'consumer')} />} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be
Suggested change
|
||||||
<div style={{ display: codeMirrorMode === codeMirrorModeList.UIForm ? 'none' : 'unset' }}><CodeMirror | ||||||
ref={(codemirror) => { | ||||||
ref.current = codemirror; | ||||||
if (codemirror) { | ||||||
|
@@ -350,8 +389,8 @@ const PluginDetail: React.FC<Props> = ({ | |||||
lineNumbers: true, | ||||||
showCursorWhenSelecting: true, | ||||||
autofocus: true, | ||||||
}} | ||||||
/> | ||||||
}} /> | ||||||
</div> | ||||||
</Drawer> | ||||||
</> | ||||||
); | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will be adjusted in another PR.