-
Notifications
You must be signed in to change notification settings - Fork 524
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(FE): add service module #1089
Merged
Merged
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
3fd5b25
feat: init service
LiteSun 464a9dd
feat: add service list page
LiteSun 5c1aa61
feat: add service step header
LiteSun e52da90
feat: add basic information page
LiteSun b9e4f57
feat: add plugin page
LiteSun 1e50509
feat: update license
LiteSun 52fd0d9
feat: add create service
LiteSun d3439c0
feat: add list operation
LiteSun 6a91c20
feat: add edit mode
LiteSun 0cebe35
Merge branch 'master' into feat-service
juzhiyuan e4a88c7
feat: add service edit
LiteSun b614b9a
Merge branch 'feat-service' of https://github.com/LiteSun/incubator-a…
LiteSun 6bdfc10
feat: remove useless file
LiteSun 0159ac4
feat: clean code
LiteSun 4a81f61
feat: validate upstream form
LiteSun 48ac69e
Merge branch 'master' into feat-service
juzhiyuan d86e3b3
feat: update codes
LiteSun dab89a4
Merge branch 'feat-service' of https://github.com/LiteSun/incubator-a…
LiteSun 9d108b5
Merge branch 'master' into feat-service
juzhiyuan 5d3cf44
feat: update UpstreamForm
LiteSun e417c1b
Merge branch 'feat-service' of https://github.com/LiteSun/incubator-a…
LiteSun 63b3b14
Merge branch 'master' into feat-service
juzhiyuan a7d355d
feat: add service_id in route step1 page
LiteSun 978d382
feat: update code
LiteSun ba1a54e
feat: update comment
LiteSun 4745035
feat: update route transform
LiteSun 1d53577
Merge branch 'master' into feat-service
juzhiyuan 4cddac6
Merge branch 'master' into feat-service
juzhiyuan 4a506a2
fix: upstreamForm not update when upstream_id change
LiteSun caeb4e4
Merge branch 'feat-service' of https://github.com/LiteSun/incubator-a…
LiteSun 769258d
feat: add init upstreamFrom default value
LiteSun cc97cc9
Merge branch 'master' into feat-service
LiteSun 3e11605
Merge branch 'master' into feat-service
juzhiyuan 31e8bf9
Merge branch 'master' into feat-service
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
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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import React, { useState, useRef, useEffect } from 'react' | ||
import { useIntl, history } from 'umi'; | ||
import { Card, Steps, Form, notification } from 'antd'; | ||
import { PageHeaderWrapper } from '@ant-design/pro-layout'; | ||
import { omit } from 'lodash'; | ||
|
||
import ActionBar from '@/components/ActionBar'; | ||
import PluginPage from '@/components/Plugin'; | ||
import Preview from './components/Preview'; | ||
import Step1 from "./components/Step1"; | ||
import { create, update, fetchItem } from './service'; | ||
|
||
const { Step } = Steps; | ||
|
||
const Page: React.FC = (props) => { | ||
const { formatMessage } = useIntl(); | ||
const [form] = Form.useForm(); | ||
const [upstreamForm] = Form.useForm(); | ||
const upstreamRef = useRef<any>(); | ||
const [plugins, setPlugins] = useState<PluginComponent.Data>({}); | ||
|
||
const STEP_HEADER = [ | ||
formatMessage({ id: 'page.service.steps.stepTitle.basicInformation' }), | ||
formatMessage({ id: 'page.service.steps.stepTitle.pluginConfig' }), | ||
formatMessage({ id: 'component.global.steps.stepTitle.preview' }), | ||
] | ||
|
||
const [stepHeader] = useState(STEP_HEADER); | ||
const [step, setStep] = useState(1); | ||
|
||
useEffect(() => { | ||
const { serviceId } = (props as any).match.params; | ||
if (serviceId) { | ||
fetchItem(serviceId).then(({ data }) => { | ||
if (data.upstream_id && data.upstream_id !== '') { | ||
upstreamForm.setFieldsValue({ upstream_id: data.upstream_id }); | ||
} | ||
if (data.upstream) { | ||
upstreamForm.setFieldsValue(data.upstream); | ||
} | ||
form.setFieldsValue(omit(data, ['upstream_id', 'upstream', 'plugins'])); | ||
setPlugins(data.plugins || {}); | ||
}); | ||
} | ||
}, []); | ||
|
||
const onSubmit = () => { | ||
const data = { | ||
...form.getFieldsValue(), | ||
plugins, | ||
}; | ||
|
||
const upstreamFormData = upstreamForm.getFieldsValue(); | ||
if (upstreamFormData.upstream_id === '') { | ||
data.upstream = omit(upstreamFormData, ['upstream_id']); | ||
} else { | ||
data.upstream_id = upstreamFormData.upstream_id; | ||
} | ||
|
||
const { serviceId } = (props as any).match.params; | ||
(serviceId ? update(serviceId, data) : create(data)) | ||
.then(() => { | ||
notification.success({ | ||
message: `${serviceId | ||
? formatMessage({ id: 'component.global.edit' }) | ||
: formatMessage({ id: 'component.global.create' }) | ||
} ${formatMessage({ id: 'menu.service' })} ${formatMessage({ | ||
id: 'component.status.success', | ||
})}`, | ||
}); | ||
history.push('/service/list'); | ||
}) | ||
.catch(() => { | ||
setStep(3); | ||
}); | ||
}; | ||
|
||
const onStepChange = (nextStep: number) => { | ||
if (step === 1 && nextStep === 2) { | ||
form.validateFields().then(() => { | ||
upstreamForm.validateFields().then(() => { | ||
setStep(nextStep); | ||
}) | ||
}) | ||
return; | ||
} | ||
if (nextStep === 4) { | ||
onSubmit(); | ||
return; | ||
}; | ||
setStep(nextStep); | ||
} | ||
|
||
return (<> | ||
<PageHeaderWrapper | ||
title={`${(props as any).match.params.rid | ||
? formatMessage({ id: 'component.global.edit' }) | ||
: formatMessage({ id: 'component.global.create' }) | ||
} ${formatMessage({ id: 'menu.service' })}`} | ||
> | ||
<Card bordered={false}> | ||
<Steps current={step - 1} style={{ marginBottom: "25px" }}> | ||
{stepHeader.map((item) => ( | ||
<Step title={item} key={item} /> | ||
))} | ||
</Steps> | ||
{step === 1 && <Step1 | ||
form={form} | ||
upstreamForm={upstreamForm} | ||
upstreamRef={upstreamRef} | ||
/>} | ||
{step === 2 && ( | ||
<PluginPage initialData={plugins} onChange={setPlugins} schemaType="route" /> | ||
liuxiran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)} | ||
{step === 3 && <Preview upstreamForm={upstreamForm} form={form} plugins={plugins} />} | ||
</Card> | ||
</PageHeaderWrapper> | ||
<ActionBar step={step} lastStep={3} onChange={onStepChange} withResultView /> | ||
</>) | ||
} | ||
|
||
export default Page; |
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.
do we need to add a new icon for service?
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.
oh yes, please select an icon here[1], then I will help to generate a new icon file.
[1] https://www.iconfont.cn/
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.
how about https://www.iconfont.cn/search/index?q=service-list
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.
fine, if there doesn't have a more proper icon, we could use it. I will file a new PR to do this.