import { inject, observer } from 'mobx-react';
import { ModalAction } from 'containers/Action';
import globalFloatingIpsStore from 'stores/neutron/floatingIp';
import { getQoSPolicyTabs } from 'resources/neutron/qos-policy';
import { QoSPolicyStore } from 'stores/neutron/qos-policy';
import { qosEndpoint } from 'client/client/constants';
export class Edit extends ModalAction {
static id = 'edit-floating-ip';
static policy = 'update_floatingip';
static get modalSize() {
return qosEndpoint() ? 'large' : 'small';
}
getModalSize() {
return qosEndpoint() ? 'large' : 'small';
}
get qosEndpoint() {
return qosEndpoint();
}
init() {
this.qosPolicyStore = new QoSPolicyStore();
}
get defaultValue() {
const { item } = this.props;
return {
description: this.item.description,
...(this.qosEndpoint
? {
qos_policy_id: {
selectedRowKeys: item.qos_policy_id ? [item.qos_policy_id] : [],
selectedRows: item.qos_policy_id
? [
{
id: item.qos_policy_id,
name: item.qos_policy_id,
},
]
: [],
},
}
: {}),
};
}
get instanceName() {
return this.item.floating_ip_address;
}
static allowed = () => Promise.resolve(true);
onSubmit = (values) => {
const { description, qos_policy_id } = values;
const body = {
description,
};
if (this.qosEndpoint) {
body.qos_policy_id = qos_policy_id
? qos_policy_id.selectedRowKeys.length
? qos_policy_id.selectedRowKeys[0]
: null
: null;
}
return globalFloatingIpsStore.edit({ id: this.item.id }, body);
};
get formItems() {
return [
{
name: 'description',
label: t('Description'),
type: 'textarea',
},
{
name: 'qos_policy_id',
label: t('QoS Policy'),
type: 'tab-select-table',
tabs: getQoSPolicyTabs.call(this),
isMulti: false,
tip: t('Choosing a QoS policy can limit bandwidth and DSCP'),
display: !!this.qosEndpoint,
},
];
}
}
export default inject('rootStore')(observer(Edit));