Skip to content

Commit

Permalink
fix: Replace footer actions with confirm for sub forms in edit-template
Browse files Browse the repository at this point in the history
1. replace footer actions with confirm for sub forms in edit-template
2. add loading status to detail layout to prevent permission judgment errors
3. resize the loading icon
  • Loading branch information
leoliu committed Dec 27, 2019
1 parent 1f8ffdc commit 1afb85b
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/components/Base/Card/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class Card extends PureComponent {
>
{this.renderTitle()}
{loading ? (
<Loading className={styles.loading} size="medium" />
<Loading className={styles.loading} />
) : (
this.renderContent()
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Base/CodeEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CodeEditor extends PureComponent {
const { value } = this.state

return (
<Suspense fallback={<Loading className="ks-page-loading" size="large" />}>
<Suspense fallback={<Loading className="ks-page-loading" />}>
<AceEditor
{...options}
className={classnames(styles.editor, className)}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Forms/Base/Confirm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import styles from './index.scss'

export default class Confirm extends React.PureComponent {
render() {
const { className, onOk, onCancel } = this.props
const { className, onOk, okText, onCancel, cancelText } = this.props
return (
<div className={classNames(styles.wrapper, className)}>
<div
className={styles.button}
onClick={onCancel}
data-test="confirm-cancel"
>
<Icon name="close" type="light" />
{cancelText || <Icon name="close" type="light" />}
</div>
<div className={styles.button} onClick={onOk} data-test="confirm-ok">
<Icon name="check" type="light" />
{okText || <Icon name="check" type="light" />}
</div>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions src/components/Forms/Base/Confirm/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
margin-right: 12px;
transition: all $trans-speed ease-in-out;
cursor: pointer;
color: #fff;

&:hover {
background-color: $dark-color06;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Graph/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class Graph extends React.Component {
})}
>
<div className={styles.loading}>
<Loading spinning={loading} size="small" />
<Loading spinning={loading} />
</div>
<Dragger
className={styles.dragger}
Expand Down
57 changes: 37 additions & 20 deletions src/components/Modals/Edit/Form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { isEmpty, get } from 'lodash'

import { Icon } from '@pitrix/lego-ui'
import { Button } from 'components/Base'
import Confirm from 'components/Forms/Base/Confirm'

import EnhanceWrapper from './wrapper'

Expand Down Expand Up @@ -78,6 +79,14 @@ export default class FormsBox extends React.Component {
}
}

handleSubFormCancel = () => {
const { subRoute } = this.state
if (subRoute && subRoute.onCancel) {
subRoute.onCancel()
this.setState({ subRoute: {} })
}
}

handlePrev = () => {
this.setState(({ subRoute }) => {
if (subRoute && subRoute.onCancel) {
Expand Down Expand Up @@ -191,10 +200,27 @@ export default class FormsBox extends React.Component {
formData={formData}
onSaveChange={this.handleSaveForm}
/>
{this.renderSubRouteConfirm()}
</div>
)
}

renderSubRouteConfirm() {
const { subRoute } = this.state

if (isEmpty(subRoute)) {
return null
}

return (
<Confirm
className={styles.confirm}
onOk={this.handleSubFormSave}
onCancel={this.handleSubFormCancel}
/>
)
}

renderContent() {
return (
<div className={styles.content}>
Expand All @@ -207,30 +233,21 @@ export default class FormsBox extends React.Component {
}

renderFooter() {
const { updatedTabs, subRoute = {} } = this.state
const { onCancel, onSave } = subRoute
const { updatedTabs } = this.state

return (
<div className={styles.footer}>
{onCancel && <Button onClick={this.handlePrev}>{t('Previous')}</Button>}
{onSave && (
<Button type="control" onClick={this.handleSubFormSave}>
{t('Save')}
<div>
<Button onClick={this.props.onCancel}>{t('Cancel')}</Button>
<Button
type="control"
disabled={isEmpty(updatedTabs)}
loading={this.props.isSubmitting}
onClick={this.handleSubmit}
>
{t('Confirm')}
</Button>
)}
{isEmpty(subRoute) && (
<div>
<Button onClick={this.props.onCancel}>{t('Cancel')}</Button>
<Button
type="control"
disabled={isEmpty(updatedTabs)}
loading={this.props.isSubmitting}
onClick={this.handleSubmit}
>
{t('Confirm')}
</Button>
</div>
)}
</div>
</div>
)
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/Modals/Edit/Form/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
position: relative;
width: calc(100% - 184px);
padding: 12px;
padding-bottom: 38px;
border-radius: 4px;
background-color: $white;
border: 1px solid $light-color03;
Expand Down Expand Up @@ -112,3 +113,9 @@
background-color: $light;
border-radius: 0 0 $border-radius $border-radius;
}

.confirm {
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
2 changes: 2 additions & 0 deletions src/components/Modals/Edit/Form/wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ const EnhanceWrapper = function(Component) {
className={classnames(styles.formActions, {
[styles.active]: this.state.showFormActions,
})}
okText={t('Save')}
cancelText={t('Undo')}
onOk={this.handleSaveChange}
onCancel={this.handleCancelChange}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/core/containers/Base/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export default class DetailBase extends React.Component {
if (this.isLoading)
return (
<div className={styles.loading}>
<Loading size="large" />
<Loading />
</div>
)

Expand Down
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const history = syncHistoryWithStore(browserHistory, store.routing)
const render = component => {
ReactDOM.render(
<AppContainer>
<Suspense fallback={<Loading className="ks-page-loading" size="large" />}>
<Suspense fallback={<Loading className="ks-page-loading" />}>
<LocaleProvider locales={locales} localeKey="lang" ignoreWarnings>
{component}
</LocaleProvider>
Expand Down
29 changes: 21 additions & 8 deletions src/core/layouts/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import ProjectStore from 'stores/project'
import DevOpsStore from 'stores/devops'
import WorkspaceStore from 'stores/workspace'

import { Layout } from '@pitrix/lego-ui'
import { Layout, Loading } from '@pitrix/lego-ui'

import { Breadcrumb } from 'components/Base'

import styles from './index.scss'
Expand All @@ -48,29 +49,35 @@ class DetailLayout extends Component {
constructor(props) {
super(props)

this.state = { initializing: true }
this.checkGlobalStore(props.match.params)
this.init(props.match.params)

this.detailRef = React.createRef()
}

init(params = {}) {
componentDidMount() {
this.init(this.props.match.params)
}

async init(params = {}) {
const rootStore = this.props.rootStore

if (params.namespace && rootStore.project) {
const projectRule = get(globals.user, `rules[${params.namespace}]`)

await rootStore.project.fetchDetail(params)
if (projectRule === undefined) {
rootStore.project.fetchRules(params)
await rootStore.project.fetchRules({
namespace: params.namespace,
workspace: rootStore.project.data.workspace,
})
}
rootStore.project.fetchDetail(params)
}

if (params.project_id && rootStore.devops) {
const devopsRule = get(globals.user, `rules[${params.project_id}]`)

if (devopsRule === undefined) {
rootStore.devops.fetchRules(params)
await rootStore.devops.fetchRules(params)
}
}

Expand All @@ -81,9 +88,11 @@ class DetailLayout extends Component {
)

if (workspaceRule === undefined) {
rootStore.workspace.fetchRules(params)
await rootStore.workspace.fetchRules(params)
}
}

this.setState({ initializing: false })
}

checkGlobalStore(params = {}) {
Expand Down Expand Up @@ -126,6 +135,10 @@ class DetailLayout extends Component {
...rest,
}

if (this.state.initializing) {
return <Loading className="ks-page-loading" />
}

return (
<Layout className={styles.wrapper}>
<LayoutHeader className={styles.header}>
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default {
Previous: '上一步',
Next: '下一步',
Update: '更新',
Undo: '撤销',
Save: '保存',
Create: '创建',

Expand Down
2 changes: 1 addition & 1 deletion src/pages/apps/components/Lists/AuditRecord/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class AuditRecord extends React.Component {
return (
<div className={classnames(styles.main, className)}>
{isLoading ? (
<Loading className={styles.loading} size="medium" />
<Loading className={styles.loading} />
) : (
this.renderContent()
)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/clusters/containers/Workspaces/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Workspaces extends React.Component {
}

if (isLoading) {
return <Loading className={styles.loading} size="large" />
return <Loading className={styles.loading} />
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default class Pipeline extends React.Component {

if (isLoading) {
return (
<Loading spinning size="large">
<Loading spinning>
<div className={style.pipelineCard} />
</Loading>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class BranchSider extends Base {
if (this.store.isLoading || this.sonarqubeStore.isLoading)
return (
<div className={styles.loading}>
<Loading size="large" />
<Loading />
</div>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class PipelineDetail extends Base {
if (this.store.isLoading || this.sonarqubeStore.isLoading)
return (
<div className={styles.loading}>
<Loading size="large" />
<Loading />
</div>
)

Expand Down
2 changes: 1 addition & 1 deletion src/pages/devops/containers/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DevOpsLayout extends Component {
const { detail } = this.props.rootStore.workspace

if (initializing) {
return <Loading className={styles.loading} size="large" />
return <Loading className={styles.loading} />
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class ImageBuilderLastRun extends React.Component {
<Icon name="templet" />
<p>{imageName}</p>
</div>
<Button onClick={this.handleDownload} type="primary" size="large">
<Button onClick={this.handleDownload} type="primary">
{t('Download Artifact')}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class TrafficManangement extends React.Component {
}

if (isGraphLoading) {
return <Loading className={styles.loading} size="large" />
return <Loading className={styles.loading} />
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class RevisionControl extends React.Component {
[styles.checked]: isCur,
})}
>
{isCur && <Icon name="check" type="light" size="large" />}
{isCur && <Icon name="check" type="light" />}
</div>
<div>
<div className={styles.title}>#{revision}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/projects/containers/GrayRelease/Jobs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Jobs extends React.Component {
const { data, isLoading } = this.store.list

if (isLoading) {
return <Loading className={styles.loading} size="large" />
return <Loading className={styles.loading} />
}

if (isEmpty(data)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ImageBuilderDetail extends Base {
if (this.store.isLoading || this.s2iRunStore.isLoading)
return (
<div className={styles.loading}>
<Loading size="large" />
<Loading />
</div>
)

Expand Down
2 changes: 1 addition & 1 deletion src/pages/projects/containers/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ProjectLayout extends Component {
const { detail } = this.props.rootStore.workspace

if (initializing) {
return <Loading className="ks-page-loading" size="large" />
return <Loading className="ks-page-loading" />
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspaces/containers/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class WorkspaceLayout extends Component {
const { detail, initializing } = this.props.rootStore.workspace

if (initializing) {
return <Loading className={styles.loading} size="large" />
return <Loading className={styles.loading} />
}

return (
Expand Down

0 comments on commit 1afb85b

Please sign in to comment.