Skip to content

Commit

Permalink
Toggle app scaling from table view
Browse files Browse the repository at this point in the history
  • Loading branch information
thgh committed Oct 3, 2023
1 parent d220295 commit ef53ba5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
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))
return
if (!row.appName) return alert('no row.appName')
this.props.onAppScaled(
row.appName,
instanceCount ? 0 : 1
)
}}
>
{instanceCount}
</Button>
)
},
},
{
title: 'Tags',
Expand Down

0 comments on commit ef53ba5

Please sign in to comment.