|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { getInstancesByNamespace, findInstance } from "../services/api"; |
| 19 | + |
| 20 | +export default { |
| 21 | + namespace: "instance", |
| 22 | + |
| 23 | + state: { |
| 24 | + instanceList: [], |
| 25 | + total: 0, |
| 26 | + }, |
| 27 | + |
| 28 | + effects: { |
| 29 | + *fetch(params, { call, put }) { |
| 30 | + const { payload } = params; |
| 31 | + const json = yield call(getInstancesByNamespace, payload); |
| 32 | + if (json.code === 200) { |
| 33 | + let { page, dataList } = json.data; |
| 34 | + dataList = dataList.map((item) => { |
| 35 | + item.key = item.id; |
| 36 | + return item; |
| 37 | + }); |
| 38 | + yield put({ |
| 39 | + type: "saveInstances", |
| 40 | + payload: { |
| 41 | + total: page.totalCount, |
| 42 | + dataList, |
| 43 | + }, |
| 44 | + }); |
| 45 | + } |
| 46 | + }, |
| 47 | + *fetchItem(params, { call }) { |
| 48 | + const { payload, callback } = params; |
| 49 | + const json = yield call(findInstance, payload); |
| 50 | + if (json.code === 200) { |
| 51 | + const instance = json.data; |
| 52 | + callback(instance); |
| 53 | + } |
| 54 | + }, |
| 55 | + *reload(params, { put }) { |
| 56 | + const { fetchValue } = params; |
| 57 | + const { name, currentPage, instanceType, instanceIp, pageSize } = |
| 58 | + fetchValue; |
| 59 | + const payload = { |
| 60 | + name, |
| 61 | + instanceType, |
| 62 | + instanceIp, |
| 63 | + currentPage, |
| 64 | + pageSize, |
| 65 | + }; |
| 66 | + yield put({ type: "fetch", payload }); |
| 67 | + }, |
| 68 | + }, |
| 69 | + |
| 70 | + reducers: { |
| 71 | + saveInstances(state, { payload }) { |
| 72 | + return { |
| 73 | + ...state, |
| 74 | + instanceList: payload.dataList, |
| 75 | + total: payload.total, |
| 76 | + }; |
| 77 | + }, |
| 78 | + }, |
| 79 | +}; |
0 commit comments