fix: channel affinity (#2799)
* fix: channel affinity log styles * fix: Issue with incorrect data storage when switching key sources * feat: support not retrying after a single rule configuration fails * fix: render channel affinity tooltip as multiline content * feat: channel affinity cache hit * fix: prevent ChannelAffinityUsageCacheModal infinite loading and hide data before fetch * chore: format backend with gofmt and frontend with prettier/eslint autofix
This commit is contained in:
@@ -20,6 +20,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import React from 'react';
|
||||
import {
|
||||
Avatar,
|
||||
Button,
|
||||
Space,
|
||||
Tag,
|
||||
Tooltip,
|
||||
@@ -71,6 +72,34 @@ function formatRatio(ratio) {
|
||||
return String(ratio);
|
||||
}
|
||||
|
||||
function buildChannelAffinityTooltip(affinity, t) {
|
||||
if (!affinity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const keySource = affinity.key_source || '-';
|
||||
const keyPath = affinity.key_path || affinity.key_key || '-';
|
||||
const keyHint = affinity.key_hint || '';
|
||||
const keyFp = affinity.key_fp ? `#${affinity.key_fp}` : '';
|
||||
const keyText = `${keySource}:${keyPath}${keyFp}`;
|
||||
|
||||
const lines = [
|
||||
t('渠道亲和性'),
|
||||
`${t('规则')}:${affinity.rule_name || '-'}`,
|
||||
`${t('分组')}:${affinity.selected_group || '-'}`,
|
||||
`${t('Key')}:${keyText}`,
|
||||
...(keyHint ? [`${t('Key 摘要')}:${keyHint}`] : []),
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ lineHeight: 1.6, display: 'flex', flexDirection: 'column' }}>
|
||||
{lines.map((line, i) => (
|
||||
<div key={i}>{line}</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Render functions
|
||||
function renderType(type, t) {
|
||||
switch (type) {
|
||||
@@ -250,6 +279,7 @@ export const getLogsColumns = ({
|
||||
COLUMN_KEYS,
|
||||
copyText,
|
||||
showUserInfoFunc,
|
||||
openChannelAffinityUsageCacheModal,
|
||||
isAdminUser,
|
||||
}) => {
|
||||
return [
|
||||
@@ -532,42 +562,39 @@ export const getLogsColumns = ({
|
||||
return isAdminUser ? (
|
||||
<Space>
|
||||
<div>{content}</div>
|
||||
{affinity ? (
|
||||
<Tooltip
|
||||
content={
|
||||
<div style={{ lineHeight: 1.6 }}>
|
||||
<Typography.Text strong>{t('渠道亲和性')}</Typography.Text>
|
||||
<div>
|
||||
<Typography.Text type='secondary'>
|
||||
{t('规则')}:{affinity.rule_name || '-'}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text type='secondary'>
|
||||
{t('分组')}:{affinity.selected_group || '-'}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text type='secondary'>
|
||||
{t('Key')}:
|
||||
{(affinity.key_source || '-') +
|
||||
':' +
|
||||
(affinity.key_path || affinity.key_key || '-') +
|
||||
(affinity.key_fp ? `#${affinity.key_fp}` : '')}
|
||||
</Typography.Text>
|
||||
{affinity ? (
|
||||
<Tooltip
|
||||
content={
|
||||
<div>
|
||||
{buildChannelAffinityTooltip(affinity, t)}
|
||||
<div style={{ marginTop: 6 }}>
|
||||
<Button
|
||||
theme='borderless'
|
||||
size='small'
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
openChannelAffinityUsageCacheModal?.(affinity);
|
||||
}}
|
||||
>
|
||||
{t('查看详情')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<span>
|
||||
<Tag className='channel-affinity-tag' color='cyan' shape='circle'>
|
||||
<span className='channel-affinity-tag-content'>
|
||||
<IconStarStroked style={{ fontSize: 13 }} />
|
||||
{t('优选')}
|
||||
</span>
|
||||
</Tag>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<span>
|
||||
<Tag
|
||||
className='channel-affinity-tag'
|
||||
color='cyan'
|
||||
shape='circle'
|
||||
>
|
||||
<span className='channel-affinity-tag-content'>
|
||||
<IconStarStroked style={{ fontSize: 13 }} />
|
||||
{t('优选')}
|
||||
</span>
|
||||
</Tag>
|
||||
</span>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</Space>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user