From 242b41ec5a04b453bc892e6ec987d2ad67ab953b Mon Sep 17 00:00:00 2001 From: tingfuyeh Date: Thu, 28 Nov 2024 17:09:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/polaris/auth/login/PageDuck.ts | 11 ++++++--- web/src/polaris/common/ducks/Page.ts | 18 +++++++++----- web/src/polaris/common/helpers/index.tsx | 19 +++++---------- web/src/polaris/common/util/apiRequest.ts | 24 +++++++++---------- web/src/polaris/common/util/router.ts | 4 +--- .../polaris/service/detail/instance/Page.tsx | 20 ++++++++++++++-- .../service/detail/instance/PageDuck.ts | 13 +++++++--- web/src/polaris/service/operation/Create.tsx | 1 + web/src/polaris/service/utils.tsx | 6 ++--- 9 files changed, 70 insertions(+), 46 deletions(-) diff --git a/web/src/polaris/auth/login/PageDuck.ts b/web/src/polaris/auth/login/PageDuck.ts index 4a0a0aee..7135a2c0 100644 --- a/web/src/polaris/auth/login/PageDuck.ts +++ b/web/src/polaris/auth/login/PageDuck.ts @@ -11,13 +11,18 @@ import { LoginUserOwnerIdKey, LoginUserNameKey, } from '@src/polaris/common/util/common' +import router from '@src/polaris/common/util/router' export default abstract class CreateDuck extends Page { get baseUrl() { return `/#/login` } get preEffects() { - return [call([this, this.ready], this), call([this, this.checkAdminUserExist]), call([this, this.checkUserLogin], this)] + return [ + call([this, this.ready], this), + call([this, this.checkAdminUserExist]), + call([this, this.checkUserLogin], this), + ] } get quickTypes() { enum Types { @@ -48,7 +53,7 @@ export default abstract class CreateDuck extends Page { yield* super.saga() const duck = this const { types, ducks } = duck - yield takeLatest(types.SUBMIT, function* () { + yield takeLatest(types.SUBMIT, function*() { try { yield* ducks.form.submit() } catch (e) { @@ -117,7 +122,7 @@ export class CreateFormDuck extends Form { window.localStorage.setItem(LoginRoleKey, loginResponse.role) window.localStorage.setItem(LoginUserIdKey, loginResponse.user_id) window.localStorage.setItem(LoginUserOwnerIdKey, loginResponse.owner_id) - window.location.hash = "/service" + router.navigate('/service') } else { throw new Error() } diff --git a/web/src/polaris/common/ducks/Page.ts b/web/src/polaris/common/ducks/Page.ts index 5c6b322b..12f9e629 100644 --- a/web/src/polaris/common/ducks/Page.ts +++ b/web/src/polaris/common/ducks/Page.ts @@ -9,7 +9,8 @@ import { PolarisTokenKey } from '../util/common' import router from '../util/router' import insertCSS from '../helpers/insertCSS' import React from 'react' -import { checkExistAdminUser, loginUser } from '@src/polaris/auth/model' +import { checkExistAdminUser } from '@src/polaris/auth/model' +import { resolvePromise } from 'saga-duck/build/helper' insertCSS( `license-notification`, @@ -294,7 +295,12 @@ get preSagas(){ * ``` */ get preEffects(): Effect[] { - return [call([this, this.ready], this), call([this, this.checkLicense], this), call([this, this.checkAdminUserExist]), call([this, this.checkUserLogin])] + return [ + call([this, this.ready], this), + call([this, this.checkLicense], this), + call([this, this.checkAdminUserExist], this), + call([this, this.checkUserLogin]), + ] } /** preEffects类型定义 */ get PreEffects(): Effect[] { @@ -347,14 +353,14 @@ get preSagas(){ * 判断是否初始化了主账户 */ *checkAdminUserExist() { - const ret = yield checkExistAdminUser() + const ret = yield* resolvePromise(checkExistAdminUser()) if (ret?.user) { - console.log("主账户已初始化") - return true + console.log('主账户已初始化') } else { - console.log("主账户没有初始化") + console.log('主账户没有初始化') router.navigate('/init') } + return true } *checkUserLogin() { diff --git a/web/src/polaris/common/helpers/index.tsx b/web/src/polaris/common/helpers/index.tsx index 5d16e8af..e23d932e 100644 --- a/web/src/polaris/common/helpers/index.tsx +++ b/web/src/polaris/common/helpers/index.tsx @@ -5,38 +5,31 @@ import { DuckRuntime, DuckCmpProps } from 'saga-duck' type OMIT_DUCK_CMP = Omit interface DuckClass { - new(...any: any[]): TDuck + new (...any: any[]): TDuck } export function connectWithDuck, TState, TDuck>( Component: React.ComponentClass, Duck: DuckClass, - extraMiddlewares?: any[] + extraMiddlewares?: any[], ): React.StatelessComponent> export function connectWithDuck( Component: React.StatelessComponent, Duck: DuckClass, - extraMiddlewares?: any[] + extraMiddlewares?: any[], ): React.StatelessComponent> export function connectWithDuck(Component, Duck, extraMiddlewares = []) { return function ConnectedWithDuck(props) { try { const { duckRuntime, ConnectedComponent } = React.useMemo(() => { - const middlewares = - process.env.NODE_ENV === 'development' - ? [createLogger({ collapsed: true })] - : [] + const middlewares = process.env.NODE_ENV === 'development' ? [createLogger({ collapsed: true })] : [] - const duckRuntime = new DuckRuntime( - new Duck(), - ...middlewares, - ...extraMiddlewares - ) + const duckRuntime = new DuckRuntime(new Duck(), ...middlewares, ...extraMiddlewares) const ConnectedComponent = duckRuntime.connectRoot()(Component) return { duckRuntime, - ConnectedComponent + ConnectedComponent, } }, []) diff --git a/web/src/polaris/common/util/apiRequest.ts b/web/src/polaris/common/util/apiRequest.ts index 16c69f13..eaca41c1 100644 --- a/web/src/polaris/common/util/apiRequest.ts +++ b/web/src/polaris/common/util/apiRequest.ts @@ -59,10 +59,10 @@ export async function apiRequest(options: APIRequestOption) { } })) as AxiosResponse - if (res.data.code > 200000 && !noError) { - throw res.data.info + if (res?.data.code > 200000 && !noError) { + throw res?.data.info } - return res.data + return res?.data } catch (e) { console.error(e) } finally { @@ -99,10 +99,10 @@ export async function getApiRequest(options: APIRequestOption) { }) } })) as AxiosResponse - if (res.data.code > 200000 && !noError) { - throw res.data.info + if (res?.data.code > 200000 && !noError) { + throw res?.data.info } - return res.data + return res?.data } catch (e) { console.error(e) } finally { @@ -138,10 +138,10 @@ export async function putApiRequest(options: APIRequestOption) { }) } })) as AxiosResponse - if (res.data.code > 200000 && !noError) { - throw res.data.info + if (res?.data.code > 200000 && !noError) { + throw res?.data.info } - return res.data + return res?.data } catch (e) { console.error(e) } finally { @@ -178,10 +178,10 @@ export async function deleteApiRequest(options: APIRequestOption) { }) } })) as AxiosResponse - if (res.data.code > 200000 && !noError) { - throw res.data.info + if (res?.data.code > 200000 && !noError) { + throw res?.data.info } - return res.data + return res?.data } catch (e) { console.error(e) } finally { diff --git a/web/src/polaris/common/util/router.ts b/web/src/polaris/common/util/router.ts index 69829dbf..e50397e9 100644 --- a/web/src/polaris/common/util/router.ts +++ b/web/src/polaris/common/util/router.ts @@ -1,8 +1,6 @@ -import render, { history } from '@src/index' - +import { history } from '@src/index' export default { navigate(url: string) { history.push(url) - render() }, } diff --git a/web/src/polaris/service/detail/instance/Page.tsx b/web/src/polaris/service/detail/instance/Page.tsx index 0d958128..cd473660 100644 --- a/web/src/polaris/service/detail/instance/Page.tsx +++ b/web/src/polaris/service/detail/instance/Page.tsx @@ -19,7 +19,7 @@ import { } from 'tea-component' import GridPageGrid from '@src/polaris/common/duckComponents/GridPageGrid' import GridPagePagination from '@src/polaris/common/duckComponents/GridPagePagination' -import getColumns from './getColumns' +import getColumns, { getSourcePolairisIp } from './getColumns' import { selectable, expandable, filterable } from 'tea-component/lib/table/addons' import insertCSS from '@src/polaris/common/helpers/insertCSS' import csvColumns from './csvColumns' @@ -110,6 +110,7 @@ export const DefaultHostTagAttribute = { key: HostTagKey, name: '实例IP', } + function getTagAttributes(props: DuckCmpProps) { const { duck, store } = props const { customFilters } = duck.selector(store) @@ -359,6 +360,22 @@ export default function ServiceInstancePage(props: DuckCmpProps // 选项列表 options: HealthStatusOptions, }), + filterable({ + type: 'single', + column: 'sourceIp', + value: customFilters.sourceIp, + all: { + text: '全部', + value: '', + }, + onChange: value => { + handlers.setCustomFilters({ ...customFilters, sourceIp: value }) + }, + options: list + .map(item => getSourcePolairisIp(item) as string) + .filter(item => item) + .map(item => ({ text: item, value: item })), + }), filterable({ type: 'single', column: 'isolate', @@ -373,7 +390,6 @@ export default function ServiceInstancePage(props: DuckCmpProps handlers.changeTags(replacedTags) }, - // 选项列表 options: IsolateStatusOptions, }), expandable({ diff --git a/web/src/polaris/service/detail/instance/PageDuck.ts b/web/src/polaris/service/detail/instance/PageDuck.ts index 0531fd64..14dd6009 100644 --- a/web/src/polaris/service/detail/instance/PageDuck.ts +++ b/web/src/polaris/service/detail/instance/PageDuck.ts @@ -12,8 +12,9 @@ import CreateDuck from './operations/CreateDuck' import Create from './operations/Create' import { Modal, TagValue } from 'tea-component' import { KeyValuePair } from '@src/polaris/configuration/fileGroup/types' -import { MetadataTagKey, HealthyTagKey, DefaultHostTagAttribute, HostTagKey, HealthStatusOptions } from './Page' +import { MetadataTagKey, HealthyTagKey, DefaultHostTagAttribute, HostTagKey } from './Page' import { Service } from '../../types' +import { InternalSyncKey } from '../../utils' export const EmptyCustomFilter = { host: '', @@ -26,6 +27,7 @@ export const EmptyCustomFilter = { healthy: '', isolate: null, metadata: { key: '', value: '' }, + sourceIp: '', } interface Filter extends BaseFilter { @@ -52,6 +54,7 @@ interface CustomFilters { healthy?: any isolate?: any keys?: string + sourceIp?: string } interface ComposedId { name: string @@ -289,9 +292,13 @@ export default class ServicePageDuck extends GridPageDuck { count, namespace, service, - customFilters: { host, port, weight, protocol, version, healthy, isolate, metadata }, + customFilters: { host, port, weight, protocol, version, healthy, isolate, metadata, sourceIp }, } = filters - const { key, value } = metadata || {} + let { key, value } = metadata || {} + if (sourceIp) { + key = InternalSyncKey + value = sourceIp + } const searchParams = { limit: count, offset: (page - 1) * count, diff --git a/web/src/polaris/service/operation/Create.tsx b/web/src/polaris/service/operation/Create.tsx index 18cb3966..23e09ba3 100644 --- a/web/src/polaris/service/operation/Create.tsx +++ b/web/src/polaris/service/operation/Create.tsx @@ -91,6 +91,7 @@ const CreateForm = purify(function CreateForm(props: DuckCmpProps) { }} disabled={options.isModify} size={'l'} + placeholder={'请选择或输入命名空间'} /> )} diff --git a/web/src/polaris/service/utils.tsx b/web/src/polaris/service/utils.tsx index 10309348..491a775f 100644 --- a/web/src/polaris/service/utils.tsx +++ b/web/src/polaris/service/utils.tsx @@ -26,10 +26,8 @@ export const showAllLabels = labels => { ), }) } - +export const InternalSyncKey = 'internal-sync-from-local-registry' export const checkGlobalRegistry = x => { - const hasSyncGlobal = Object.entries(x.metadata).find( - ([key, value]) => key === 'internal-sync-from-local-registry' && value === 'true', - ) + const hasSyncGlobal = Object.entries(x.metadata).find(([key, value]) => key === InternalSyncKey && value === 'true') return !!hasSyncGlobal }