import { inject, observer } from 'mobx-react';
import globalContainersStore from 'src/stores/zun/containers';
import { ModalAction } from 'containers/Action';
import { checkItemAction } from 'resources/zun/container';
export class AttachNetwork extends ModalAction {
static id = 'AttachNetwork';
static title = t('Attach Network');
init() {
this.store = globalContainersStore;
}
static get modalSize() {
return 'large';
}
getModalSize() {
return 'large';
}
get name() {
return t('Attach Network');
}
get defaultValue() {
const { name } = this.item;
const value = {
instance: name,
};
return value;
}
static policy = 'container:network_attach';
aliasPolicy = 'zun:container:network_attach';
static allowed = (item) => {
return checkItemAction(item, 'network_attach_detach');
};
disabledNetwork = (it) => {
const { networks } = this.item;
return networks.some((net) => net.id === it.id);
};
get formItems() {
return [
{
name: 'instance',
label: t('Instance'),
type: 'label',
iconType: 'instance',
},
{
name: 'networks',
label: t('Networks'),
type: 'network-select-table',
required: true,
disabledFunc: this.disabledNetwork,
},
];
}
onSubmit = (values) => {
const { networks } = values;
const network = networks.selectedRowKeys[0];
return this.store.attachNetwork(this.item.id, { network });
};
}
export default inject('rootStore')(observer(AttachNetwork));