mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-01 19:28:43 +08:00
✨ feat(redis): 优化数据库别名与计数展示
- Redis DB 标题不再重复拼接 key 数量 - 将别名单独渲染为浅色文本并支持设置后即时刷新 Fixes #593
This commit is contained in:
@@ -68,13 +68,12 @@ describe('redisDbAlias helpers', () => {
|
||||
});
|
||||
|
||||
it('builds the sidebar label with and without an alias', () => {
|
||||
expect(buildRedisDbNodeLabel(0, 'cache')).toBe('db0 (cache)');
|
||||
expect(buildRedisDbNodeLabel(0, 'cache')).toBe('db0 cache');
|
||||
expect(buildRedisDbNodeLabel(3, '')).toBe('db3');
|
||||
expect(buildRedisDbNodeLabel(0, ' ')).toBe('db0');
|
||||
});
|
||||
|
||||
it('appends the key-count suffix after the alias', () => {
|
||||
expect(buildRedisDbNodeLabel(0, 'cache', ' (12)')).toBe('db0 (cache) (12)');
|
||||
expect(buildRedisDbNodeLabel(0, '', ' (12)')).toBe('db0 (12)');
|
||||
it('does not append key counts to the sidebar label', () => {
|
||||
expect(buildRedisDbNodeLabel(0, '12')).toBe('db0 12');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* user works with several connections that each use those indices for a
|
||||
* different purpose, the numbers are indistinguishable in the sidebar. An alias
|
||||
* map lets the user label, for example, `db0` as `cache` and have the sidebar
|
||||
* render `db0 (cache)`.
|
||||
* render `db0 cache`.
|
||||
*
|
||||
* The map is purely a client-side display preference and is keyed by
|
||||
* connection id so aliases stay independent across connections. The underlying
|
||||
@@ -128,17 +128,14 @@ export const setRedisDbAlias = (
|
||||
|
||||
/**
|
||||
* Build the sidebar label for a Redis DB node. Returns `dbN` when there is no
|
||||
* alias, and `dbN (alias)` when one is set. `suffix` carries the existing
|
||||
* key-count fragment (e.g. ` (12)`) and is always appended last so the alias
|
||||
* stays adjacent to the index.
|
||||
* alias, and `dbN alias` when one is set. Key counts are intentionally not
|
||||
* included here: V2 renders them via the node meta slot to avoid duplicates.
|
||||
*/
|
||||
export const buildRedisDbNodeLabel = (
|
||||
dbIndex: number,
|
||||
alias: string,
|
||||
suffix = '',
|
||||
): string => {
|
||||
const base = `db${dbIndex}`;
|
||||
const sanitizedAlias = sanitizeRedisDbAlias(alias);
|
||||
const labelled = sanitizedAlias ? `${base} (${sanitizedAlias})` : base;
|
||||
return `${labelled}${suffix}`;
|
||||
return sanitizedAlias ? `${base} ${sanitizedAlias}` : base;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user