fix: fix the trove instance store

fix the trove instance store to get better extension

Change-Id: I20950d667bbdac621644e4f8def5384eff48e67c
This commit is contained in:
xusongfu 2022-07-25 11:10:28 +08:00
parent af67087953
commit 7fb3e6eb2c
3 changed files with 41 additions and 14 deletions

View File

@ -34,11 +34,11 @@ export class BaseDetail extends Base {
}, },
{ {
label: t('Datastore'), label: t('Datastore'),
dataIndex: 'datastore.type', dataIndex: 'type',
}, },
{ {
label: t('Datastore Version'), label: t('Datastore Version'),
dataIndex: 'datastore.version', dataIndex: 'version',
}, },
{ {
label: t('Status'), label: t('Status'),
@ -62,13 +62,13 @@ export class BaseDetail extends Base {
const options = [ const options = [
{ {
label: t('Flavor'), label: t('Flavor'),
dataIndex: 'flavor.id', dataIndex: 'flavor',
render: (value) => { render: (value) => {
return this.getLinkRender( return this.getLinkRender(
'flavorDetail', 'flavorDetail',
value, value.name,
{ {
id: value, id: value.id,
}, },
null null
); );
@ -76,7 +76,8 @@ export class BaseDetail extends Base {
}, },
{ {
label: t('Volume Size'), label: t('Volume Size'),
dataIndex: 'volume.size', dataIndex: 'size',
render: (value) => (value ? `${value}GiB` : '-'),
}, },
{ {
label: t('Created'), label: t('Created'),
@ -119,7 +120,7 @@ export class BaseDetail extends Base {
}, },
{ {
label: t('Database Port'), label: t('Database Port'),
dataIndex: 'datastore.type', dataIndex: 'type',
render: (value) => { render: (value) => {
switch (value) { switch (value) {
case 'mysql': case 'mysql':

View File

@ -17,7 +17,6 @@ import { observer, inject } from 'mobx-react';
import Base from 'containers/List'; import Base from 'containers/List';
import globalInstancesStore from 'stores/trove/instances'; import globalInstancesStore from 'stores/trove/instances';
import { InstanceStatus } from 'resources/trove/database'; import { InstanceStatus } from 'resources/trove/database';
import { get as _get } from 'lodash';
import actions from './actions'; import actions from './actions';
export class Instances extends Base { export class Instances extends Base {
@ -58,13 +57,11 @@ export class Instances extends Base {
}, },
{ {
title: t('Datastore'), title: t('Datastore'),
dataIndex: 'datastore', dataIndex: 'type',
render: (value) => _get(value, 'type', '-'),
}, },
{ {
title: t('Datastore Version'), title: t('Datastore Version'),
dataIndex: 'datastore', dataIndex: 'version',
render: (value) => _get(value, 'version', '-'),
isHideable: true, isHideable: true,
}, },
{ {
@ -85,9 +82,9 @@ export class Instances extends Base {
}, },
{ {
title: t('Volume Size'), title: t('Volume Size'),
dataIndex: 'volume', dataIndex: 'size',
isHideable: true, isHideable: true,
render: (value) => (value ? `${value.size}GiB` : '-'), render: (value) => (value ? `${value}GiB` : '-'),
}, },
{ {
title: t('Status'), title: t('Status'),

View File

@ -15,6 +15,8 @@
import Base from 'stores/base'; import Base from 'stores/base';
import client from 'client'; import client from 'client';
import { action, observable } from 'mobx'; import { action, observable } from 'mobx';
import globalFlavorStore from 'stores/nova/flavor';
import { get as _get } from 'lodash';
export class InstancesStore extends Base { export class InstancesStore extends Base {
@observable @observable
@ -36,6 +38,33 @@ export class InstancesStore extends Base {
return client.trove.instancesAdmin; return client.trove.instancesAdmin;
} }
get mapper() {
return (data) => ({
...data,
type: _get(data, 'datastore.type'),
version: _get(data, 'datastore.version'),
size: _get(data, 'volume.size'),
});
}
async detailDidFetch(item) {
const flavor = await globalFlavorStore.fetchDetail({
id: _get(item, 'flavor.id'),
});
return {
...item,
flavor: { ...item.flavor, ...flavor },
};
}
listDidFetch(items) {
if (items.length === 0) return items;
return items.map((it) => ({
...it,
project_id: it.tenant_id,
}));
}
@action @action
async create(newbody) { async create(newbody) {
return this.submitting(this.client.create(newbody)); return this.submitting(this.client.create(newbody));