Skip to content

Commit 7fc8cde

Browse files
authored
fix: Fetch data entangle with cluster and runtime (#329)
Refactor promise-polyfill
1 parent acb0e25 commit 7fc8cde

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

lib/polyfills.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import 'lib/polyfills';
2-
1+
import 'promise-polyfill/src/polyfill';
32
import React from 'react';
43
import ReactDOM from 'react-dom';
54
import { Provider } from 'mobx-react';

src/pages/Admin/Clusters/index.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ import styles from './index.scss';
2727
export default class Clusters extends Component {
2828
static async onEnter({ clusterStore, appStore, runtimeStore }) {
2929
await clusterStore.fetchAll();
30-
await clusterStore.clusterStatistics();
30+
await clusterStore.fetchStatistics();
3131
await appStore.fetchApps({
3232
status: ['active', 'deleted']
3333
});
3434
await runtimeStore.fetchAll({
3535
status: ['active', 'deleted'],
36-
limit: 99
36+
noLimit: true,
37+
simpleQuery: true
3738
});
3839
}
3940

@@ -91,6 +92,7 @@ export default class Clusters extends Component {
9192
/>
9293
) : null;
9394
};
95+
9496
renderHandleMenu = item => {
9597
const { t } = this.props;
9698
const { showOperateCluster } = this.props.clusterStore;
@@ -198,7 +200,7 @@ export default class Clusters extends Component {
198200
const { clusterStore, t } = this.props;
199201
const { summaryInfo, clusters, isLoading } = clusterStore;
200202

201-
const { runtimes } = this.props.runtimeStore;
203+
const runtimes = this.props.runtimeStore.allRuntimes;
202204
const { apps } = this.props.appStore;
203205

204206
const columns = [

src/pages/Admin/Runtimes/index.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import styles from './index.scss';
2424
export default class Runtimes extends Component {
2525
static async onEnter({ runtimeStore, clusterStore }) {
2626
await runtimeStore.fetchAll();
27-
await runtimeStore.runtimeStatistics();
27+
await runtimeStore.fetchStatistics();
2828
await clusterStore.fetchAll({
2929
noLimit: true
3030
});
@@ -37,6 +37,11 @@ export default class Runtimes extends Component {
3737
clusterStore.loadPageInit();
3838
}
3939

40+
componentWillMount() {
41+
const { runtimeStore } = this.props;
42+
runtimeStore.runtimes = runtimeStore.runtimes.filter(rt => rt.status !== 'deleted');
43+
}
44+
4045
onChangeSort = (params = {}) => {
4146
const { runtimeStore } = this.props;
4247
const order = params.reverse ? 'asc' : 'desc';

src/stores/cluster/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class ClusterStore extends Store {
9696
};
9797

9898
@action
99-
clusterStatistics = async () => {
99+
fetchStatistics = async () => {
100100
//this.isLoading = true;
101101
const result = await this.request.get('clusters/statistics');
102102
this.summaryInfo = {

src/stores/runtime/index.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import Store from '../Store';
33
import { assign, get } from 'lodash';
44
import _ from 'lodash';
55

6+
const defaultStatus = ['active'];
7+
68
export default class RuntimeStore extends Store {
7-
@observable runtimes = [];
9+
@observable runtimes = []; // current runtimes
810
@observable runtimeDetail = {};
911
@observable summaryInfo = {}; // replace original statistic
1012
@observable statistics = {};
@@ -15,7 +17,6 @@ export default class RuntimeStore extends Store {
1517

1618
@observable currentPage = 1; //runtime table query params
1719
@observable searchWord = '';
18-
defaultStatus = ['active'];
1920
@observable selectStatus = '';
2021
@observable userId = '';
2122

@@ -29,6 +30,8 @@ export default class RuntimeStore extends Store {
2930
action: '' // delete
3031
};
3132

33+
@observable allRuntimes = [];
34+
3235
@action.bound
3336
showModal = () => {
3437
this.isModalOpen = true;
@@ -45,7 +48,7 @@ export default class RuntimeStore extends Store {
4548
sort_key: 'status_time',
4649
limit: this.pageSize,
4750
offset: (this.currentPage - 1) * this.pageSize,
48-
status: this.selectStatus ? this.selectStatus : this.defaultStatus
51+
status: this.selectStatus ? this.selectStatus : defaultStatus
4952
};
5053

5154
if (params.noLimit) {
@@ -62,14 +65,25 @@ export default class RuntimeStore extends Store {
6265
}
6366

6467
this.isLoading = true;
65-
const result = await this.request.get('runtimes', assign(defaultParams, params));
66-
this.runtimes = get(result, 'runtime_set', []);
67-
this.totalCount = get(result, 'total_count', 0);
68+
let finalParams = assign(defaultParams, params);
69+
70+
if (!params.simpleQuery) {
71+
let result = await this.request.get('runtimes', finalParams);
72+
this.runtimes = get(result, 'runtime_set', []);
73+
this.totalCount = get(result, 'total_count', 0);
74+
} else {
75+
// simple query: just fetch runtime data used in other pages
76+
// no need to set totalCount
77+
delete finalParams.simpleQuery;
78+
let result = await this.request.get('runtimes', finalParams);
79+
this.allRuntimes = get(result, 'runtime_set', []);
80+
}
81+
6882
this.isLoading = false;
6983
};
7084

7185
@action
72-
runtimeStatistics = async () => {
86+
fetchStatistics = async () => {
7387
//this.isLoading = true;
7488
const result = await this.request.get('runtimes/statistics');
7589
this.summaryInfo = {

0 commit comments

Comments
 (0)