Skip to content
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

Toggle app scaling from table view #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/containers/apps/Apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ export default class Apps extends ApiComponent<
})
}

async onAppScaled(appName: string, instanceCount: number) {
const self = this

const def = self.state.apiData?.appDefinitions.find(
(x) => x.appName === appName
)
if (!def) return alert('App not found: ' + appName)

const toggled = { ...def, instanceCount }

Promise.resolve() //
.then(function () {
self.setState({ isLoading: true })
return self.apiManager.updateConfigAndSave(appName, toggled)
})
.then(function () {
return self.reFetchData()
})
.catch(Toaster.createCatcher())
.then(function () {
self.setState({ isLoading: false })
})
}

render() {
const self = this

Expand Down Expand Up @@ -80,6 +104,9 @@ export default class Apps extends ApiComponent<
defaultNginxConfig={apiData.defaultNginxConfig}
apps={apiData.appDefinitions}
rootDomain={apiData.rootDomain}
onAppScaled={(appName: string, count: number) =>
self.onAppScaled(appName, count)
}
/>
) : (
<div />
Expand Down
23 changes: 22 additions & 1 deletion src/containers/apps/AppsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
LinkOutlined,
LoadingOutlined,
} from '@ant-design/icons'
import { Card, Col, Input, Row, Table, Tag, Tooltip } from 'antd'
import { Button, Card, Col, Input, Row, Table, Tag, Tooltip } from 'antd'
import { ColumnProps } from 'antd/lib/table'
import { History } from 'history'
import React, { Component, Fragment } from 'react'
Expand All @@ -26,6 +26,7 @@ class AppsTable extends Component<
rootDomain: string
defaultNginxConfig: string
isMobile: boolean
onAppScaled: (appName: string, instanceCount: number) => void
search: string | undefined
},
{ searchTerm: string }
Expand Down Expand Up @@ -80,6 +81,26 @@ class AppsTable extends Component<
dataIndex: 'instanceCount',
key: 'instanceCount',
align: ALIGN,
render: (instanceCount: number, row, index) => {
return (
<Button
style={{ margin: -5 }}
onClick={async () => {
const warning =
'Do you want to turn this app OFF?'
if (instanceCount && !window.confirm(warning))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1- I think we should also have a confirmation for turning on to avoid accidental clicks.

2- Suggest using modal.confirm from ant design to match the existing UI.

return
if (!row.appName) return alert('no row.appName')
this.props.onAppScaled(
row.appName,
instanceCount ? 0 : 1
)
}}
>
{instanceCount}
</Button>
)
},
},
{
title: 'Tags',
Expand Down
Loading