Skip to content

Commit

Permalink
fix: 修复跳转问题
Browse files Browse the repository at this point in the history
  • Loading branch information
tingfuyeh committed Nov 28, 2024
1 parent aeb2fa9 commit 242b41e
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 46 deletions.
11 changes: 8 additions & 3 deletions web/src/polaris/auth/login/PageDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
Expand Down
18 changes: 12 additions & 6 deletions web/src/polaris/common/ducks/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -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[] {
Expand Down Expand Up @@ -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() {
Expand Down
19 changes: 6 additions & 13 deletions web/src/polaris/common/helpers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,31 @@ import { DuckRuntime, DuckCmpProps } from 'saga-duck'

type OMIT_DUCK_CMP<TProps> = Omit<TProps, 'duck' | 'store' | 'dispatch'>
interface DuckClass<TDuck> {
new(...any: any[]): TDuck
new (...any: any[]): TDuck
}
export function connectWithDuck<TProps extends DuckCmpProps<TDuck>, TState, TDuck>(
Component: React.ComponentClass<TProps, TState>,
Duck: DuckClass<TDuck>,
extraMiddlewares?: any[]
extraMiddlewares?: any[],
): React.StatelessComponent<OMIT_DUCK_CMP<TProps>>
export function connectWithDuck<TProps, TDuck>(
Component: React.StatelessComponent<TProps>,
Duck: DuckClass<TDuck>,
extraMiddlewares?: any[]
extraMiddlewares?: any[],
): React.StatelessComponent<OMIT_DUCK_CMP<TProps>>

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,
}
}, [])

Expand Down
24 changes: 12 additions & 12 deletions web/src/polaris/common/util/apiRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export async function apiRequest<T>(options: APIRequestOption) {
}
})) as AxiosResponse<T & ApiResponse>

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 {
Expand Down Expand Up @@ -99,10 +99,10 @@ export async function getApiRequest<T>(options: APIRequestOption) {
})
}
})) as AxiosResponse<T & ApiResponse>
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 {
Expand Down Expand Up @@ -138,10 +138,10 @@ export async function putApiRequest<T>(options: APIRequestOption) {
})
}
})) as AxiosResponse<T & ApiResponse>
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 {
Expand Down Expand Up @@ -178,10 +178,10 @@ export async function deleteApiRequest<T>(options: APIRequestOption) {
})
}
})) as AxiosResponse<T & ApiResponse>
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 {
Expand Down
4 changes: 1 addition & 3 deletions web/src/polaris/common/util/router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import render, { history } from '@src/index'

import { history } from '@src/index'
export default {
navigate(url: string) {
history.push(url)
render()
},
}
20 changes: 18 additions & 2 deletions web/src/polaris/service/detail/instance/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -110,6 +110,7 @@ export const DefaultHostTagAttribute = {
key: HostTagKey,
name: '实例IP',
}

function getTagAttributes(props: DuckCmpProps<ServicePageDuck>) {
const { duck, store } = props
const { customFilters } = duck.selector(store)
Expand Down Expand Up @@ -359,6 +360,22 @@ export default function ServiceInstancePage(props: DuckCmpProps<ServicePageDuck>
// 选项列表
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',
Expand All @@ -373,7 +390,6 @@ export default function ServiceInstancePage(props: DuckCmpProps<ServicePageDuck>
handlers.changeTags(replacedTags)
},

// 选项列表
options: IsolateStatusOptions,
}),
expandable({
Expand Down
13 changes: 10 additions & 3 deletions web/src/polaris/service/detail/instance/PageDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -26,6 +27,7 @@ export const EmptyCustomFilter = {
healthy: '',
isolate: null,
metadata: { key: '', value: '' },
sourceIp: '',
}

interface Filter extends BaseFilter {
Expand All @@ -52,6 +54,7 @@ interface CustomFilters {
healthy?: any
isolate?: any
keys?: string
sourceIp?: string
}
interface ComposedId {
name: string
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions web/src/polaris/service/operation/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const CreateForm = purify(function CreateForm(props: DuckCmpProps<Duck>) {
}}
disabled={options.isModify}
size={'l'}
placeholder={'请选择或输入命名空间'}
/>
)}
</AutoComplete>
Expand Down
6 changes: 2 additions & 4 deletions web/src/polaris/service/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 242b41e

Please sign in to comment.