Skip to content

Commit

Permalink
fix: 优化服务列表选项的加载逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
tingfuyeh committed Jan 9, 2025
1 parent d940f91 commit aa7fba0
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 174 deletions.
4 changes: 2 additions & 2 deletions web/src/polaris/administration/accessLimiting/PageDuck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { deleteRateLimit, describeLimitRules, DescribeLimitRulesParams, enableRa
import getColumns from './getColumns'
import { getAllList } from '@src/polaris/common/util/apiRequest'
import { describeComplicatedNamespaces } from '@src/polaris/namespace/model'
import { describeServices } from '@src/polaris/service/model'
import { cacheFetchAllServices } from '@src/polaris/service/model'
import { RuleStatus, SwitchStatusAction } from './types'
import LimitRuleCreatePageDuck from './operations/CreateDuck'
import { ComposedId } from '@src/polaris/service/detail/types'
Expand Down Expand Up @@ -214,7 +214,7 @@ export default class AccessLimitingDuck extends GridPageDuck {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
getAllList(describeServices, {})({}),
cacheFetchAllServices(),
])

const namespaceOptions = namespaceList.list.map(item => ({
Expand Down
40 changes: 2 additions & 38 deletions web/src/polaris/administration/accessLimiting/detail/PageDuck.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { reduceFromPayload } from 'saga-duck'
import DetailPage from '@src/polaris/common/ducks/DetailPage'
import { getAllList } from '@src/polaris/common/util/apiRequest'
import { describeComplicatedNamespaces } from '@src/polaris/namespace/model'
import { describeServices } from '@src/polaris/service/model'
import { put } from 'redux-saga/effects'
import { takeLatest } from 'redux-saga-catch'
import { describeLimitRules, RateLimit } from '../model'
Expand All @@ -14,14 +11,9 @@ interface ComposedId {
service: string
}

interface Data {
namespaceList: { value: string; text: string }[]
serviceList: { value: string; text: string; namespace: string }[]
}

export default class AccessLimitingDetailPageDuck extends DetailPage {
ComposedId: ComposedId
Data: Data
Data: {}

get baseUrl() {
return `/#/accesslimit-detail`
Expand Down Expand Up @@ -79,13 +71,6 @@ export default class AccessLimitingDetailPageDuck extends DetailPage {
}
}

get creators() {
const { types } = this
return {
...super.creators,
}
}

get reducers() {
const { types } = this
return {
Expand Down Expand Up @@ -140,27 +125,6 @@ export default class AccessLimitingDetailPageDuck extends DetailPage {
}

async getData() {
const [namespaceOptions, serviceOptions] = await Promise.all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
getAllList(describeServices, {})({}),
])

const namespaceList = namespaceOptions.list.map(item => ({
text: item.name,
value: item.name,
}))

const serviceList = serviceOptions.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))
return {
namespaceList,
serviceList,
}
return {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import { generateDefaultValues, LimitArgumentsType } from '../types'
import { getAllList } from '@src/polaris/common/util/apiRequest'
import { describeComplicatedNamespaces } from '@src/polaris/namespace/model'
import { describeServices } from '@src/polaris/service/model'
import { select, put, call } from 'redux-saga/effects'
import { cacheFetchAllServices } from '@src/polaris/service/model'
import { select, put, call, all, fork } from 'redux-saga/effects'
import { takeLatest } from 'redux-saga-catch'
import { delay } from 'redux-saga'
import router from '@src/polaris/common/util/router'
Expand Down Expand Up @@ -202,6 +202,7 @@ export default class LimitRuleCreatePageDuck extends DetailPage {
*saga() {
yield* super.saga()
const { types, ducks, selectors } = this
yield fork([this, this.sagaOnFetchLists])

// 规则创建
yield takeLatest(types.SUBMIT, function*() {
Expand Down Expand Up @@ -296,32 +297,39 @@ export default class LimitRuleCreatePageDuck extends DetailPage {
}
})
}
*sagaOnFetchLists() {
const { types } = this
yield takeLatest(types.ROUTE_INITIALIZED, function*() {
const [namespaceList, serviceList] = yield all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
cacheFetchAllServices(),
])

async getData() {
const [namespaceOptions, serviceOptions] = await Promise.all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
getAllList(describeServices, {})({}),
])
const hasGlobalLimit = true

const namespaceList = namespaceOptions.list.map(item => ({
text: item.name,
value: item.name,
}))
const namespaceOptions = namespaceList.list.map(item => ({
text: item.name,
value: item.name,
}))

const serviceList = serviceOptions.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))
const serviceOptions = serviceList.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))

return {
namespaceList,
serviceList,
hasGlobalLimit,
}
yield put({
type: types.UPDATE,
payload: {
namespaceList: namespaceOptions,
serviceList: serviceOptions,
hasGlobalLimit: true,
},
})
})
}
async getData() {
return { namespaceList: [], serviceList: [] }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import DetailPage from '@src/polaris/common/ducks/DetailPage'
import Form from '@src/polaris/common/ducks/Form'
import { getAllList } from '@src/polaris/common/util/apiRequest'
import { describeComplicatedNamespaces } from '@src/polaris/namespace/model'
import { describeServices } from '@src/polaris/service/model'
import { select, put, call } from 'redux-saga/effects'
import { cacheFetchAllServices } from '@src/polaris/service/model'
import { select, put, call, fork } from 'redux-saga/effects'
import { takeLatest } from 'redux-saga-catch'
import { delay } from 'redux-saga'
import router from '@src/polaris/common/util/router'
Expand Down Expand Up @@ -107,6 +107,7 @@ export default class CircuitBreakerCreatePageDuck extends DetailPage {
*saga() {
yield* super.saga()
const { types, ducks, selectors } = this
yield fork([this, this.sagaOnFetchLists])

// 规则创建
yield takeLatest(types.SUBMIT, function*() {
Expand Down Expand Up @@ -161,29 +162,43 @@ export default class CircuitBreakerCreatePageDuck extends DetailPage {
}
})
}
*sagaOnFetchLists() {
const { types } = this
yield takeLatest(types.ROUTE_INITIALIZED, function*() {
yield delay(10000)
const [namespaceList, serviceList] = yield Promise.all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
cacheFetchAllServices(),
])

async getData() {
const [namespaceOptions, serviceOptions] = await Promise.all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
getAllList(describeServices, {})({}),
])
const namespaceOptions = namespaceList.list.map(item => ({
text: item.name,
value: item.name,
}))

const namespaceList = namespaceOptions.list.map(item => ({
text: item.name,
value: item.name,
}))
const serviceOptions = serviceList.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))

const serviceList = serviceOptions.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))
yield put({
type: types.UPDATE,
payload: {
namespaceList: namespaceOptions,
serviceList: serviceOptions,
hasGlobalLimit: true,
},
})
})
}
async getData() {
return {
namespaceList,
serviceList,
namespaceList: [],
serviceList: [],
}
}
}
Expand Down Expand Up @@ -286,7 +301,7 @@ export class BreakerRuleCreateDuck extends Form {
receive: [],
},
editable: true,
deleteable: true
deleteable: true,
}
}

Expand Down
58 changes: 37 additions & 21 deletions web/src/polaris/administration/breaker/operations/CreateDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import DetailPage from '@src/polaris/common/ducks/DetailPage'
import Form from '@src/polaris/common/ducks/Form'
import { getAllList } from '@src/polaris/common/util/apiRequest'
import { describeComplicatedNamespaces } from '@src/polaris/namespace/model'
import { describeServices } from '@src/polaris/service/model'
import { select, put, call } from 'redux-saga/effects'
import { cacheFetchAllServices } from '@src/polaris/service/model'
import { select, put, call, fork } from 'redux-saga/effects'
import { takeLatest } from 'redux-saga-catch'
import { delay } from 'redux-saga'
import router from '@src/polaris/common/util/router'
Expand Down Expand Up @@ -113,6 +113,8 @@ export default class CircuitBreakerCreatePageDuck extends DetailPage {
*saga() {
yield* super.saga()
const { types, ducks, selectors, selector } = this
yield fork([this, this.sagaOnFetchLists])

yield takeLatest(types.SET_TYPE, function*(action) {
if (action.payload === BreakerType.Interface) {
yield put(ducks.form.creators.setValue('level', BreakLevelType.Instance))
Expand Down Expand Up @@ -181,29 +183,43 @@ export default class CircuitBreakerCreatePageDuck extends DetailPage {
}
})
}
*sagaOnFetchLists() {
const { types } = this
yield takeLatest(types.ROUTE_INITIALIZED, function*() {
yield delay(10000)
const [namespaceList, serviceList] = yield Promise.all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
cacheFetchAllServices(),
])

async getData() {
const [namespaceOptions, serviceOptions] = await Promise.all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
getAllList(describeServices, {})({}),
])
const namespaceOptions = namespaceList.list.map(item => ({
text: item.name,
value: item.name,
}))

const namespaceList = namespaceOptions.list.map(item => ({
text: item.name,
value: item.name,
}))
const serviceOptions = serviceList.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))

const serviceList = serviceOptions.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))
yield put({
type: types.UPDATE,
payload: {
namespaceList: namespaceOptions,
serviceList: serviceOptions,
hasGlobalLimit: true,
},
})
})
}
async getData() {
return {
namespaceList,
serviceList,
namespaceList: [],
serviceList: [],
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { createToPayload, reduceFromPayload } from 'saga-duck'
import DetailPage from '@src/polaris/common/ducks/DetailPage'
import { getAllList } from '@src/polaris/common/util/apiRequest'
import { describeComplicatedNamespaces } from '@src/polaris/namespace/model'
import { describeServices } from '@src/polaris/service/model'
import { put } from 'redux-saga/effects'
import { takeLatest } from 'redux-saga-catch'
import { CustomRoute, describeCustomRoute } from '../model'
Expand All @@ -14,14 +11,9 @@ interface ComposedId {
service: string
}

interface Data {
namespaceList: { value: string; text: string }[]
serviceList: { value: string; text: string; namespace: string }[]
}

export default class RouteDetailPageDuck extends DetailPage {
ComposedId: ComposedId
Data: Data
Data: {}

get baseUrl() {
return `/#/custom-route-detail`
Expand Down Expand Up @@ -148,27 +140,6 @@ export default class RouteDetailPageDuck extends DetailPage {
}

async getData() {
const [namespaceOptions, serviceOptions] = await Promise.all([
getAllList(describeComplicatedNamespaces, {
listKey: 'namespaces',
totalKey: 'amount',
})({}),
getAllList(describeServices, {})({}),
])

const namespaceList = namespaceOptions.list.map(item => ({
text: item.name,
value: item.name,
}))

const serviceList = serviceOptions.list.map(item => ({
text: item.name,
value: item.name,
namespace: item.namespace,
}))
return {
namespaceList,
serviceList,
}
return {}
}
}
Loading

0 comments on commit aa7fba0

Please sign in to comment.