Skip to content

feat(redis): edit JSON values as source with compact saves#3460

Merged
t8y2 merged 2 commits into
t8y2:mainfrom
onenewcode:redis-json-show
Jul 15, 2026
Merged

feat(redis): edit JSON values as source with compact saves#3460
t8y2 merged 2 commits into
t8y2:mainfrom
onenewcode:redis-json-show

Conversation

@onenewcode

@onenewcode onenewcode commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

变更说明

实现 Redis JSON 值的源码编辑与无损读写:

  • string 键、hash 字段在 JSON 视图可直接编辑并保存
  • 保存前校验 JSON,并自动压缩为紧凑文本(去掉非数据换行/空格)
  • 原生 RedisJSON(ReJSON)改为保留 JSON.GET 原始文本,避免大整数/高精度数字被 JS 解析丢失
  • 用 foldable CodeMirror 源码编辑器替换 JSON tree 编辑路径,并支持保存快捷键
  • 未保存草稿会阻止自动刷新覆盖,hash 草稿在切换 member 前需先保存/丢弃

变更类型

  • 新功能
  • Bug 修复
  • 性能优化
  • 代码重构
  • 文档更新
  • CI / 构建

涉及前端

  • 本 PR 涉及前端改动,已附截图/录屏(见下方)
image image

验证

  • make check 通过
  • make cargo-check-fast 通过
  • 相关测试通过

补充验证:

手动建议:

  1. 打开 string 类型且值为 JSON 的 key,在 JSON 视图直接编辑后保存,确认写入为紧凑 JSON
  2. 打开 hash 字段为 JSON 的值,确认同样可编辑/保存
  3. 打开原生 RedisJSON key,确认大整数/高精度数字不丢精度
  4. 编辑中触发自动刷新,确认草稿不会被覆盖

关联 Issue

Close #3371

Allow string keys, hash fields, and native RedisJSON to be edited in a
foldable source editor, validate/compact on save, keep large numeric
literals lossless end-to-end, and protect unsaved drafts from refresh.

Close t8y2#3371

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to request changes for now. The compact-save path is not lossless for Redis string and hash JSON values.

normalizeRedisJsonDraft uses safeJsonFormat, which reconstructs the document through JSON.parse and JSON.stringify. The editor baseline is formatted through the same path. As a result, valid source such as:

{"role":"reader","role":"writer"}

is silently changed to:

{"role":"writer"}

before it is written back. Redis string and hash values are raw text, and this feature is expected to remove only non-data whitespace, so an unrelated edit must not delete duplicate object members.

Please use a source-preserving JSON validation/formatting and minification path, and add regression coverage for duplicate members in both string and hash JSON editors.

Use a source-preserving JSON pretty/minify path for Redis string, hash,
and RedisJSON editors so compact saves only strip insignificant whitespace
and keep duplicate object members. Add regression coverage for both
string and hash open+save flows.
@onenewcode

Copy link
Copy Markdown
Contributor Author

I'm going to request changes for now. The compact-save path is not lossless for Redis string and hash JSON values.

normalizeRedisJsonDraft uses safeJsonFormat, which reconstructs the document through JSON.parse and JSON.stringify. The editor baseline is formatted through the same path. As a result, valid source such as:

{"role":"reader","role":"writer"}

is silently changed to:

{"role":"writer"}

before it is written back. Redis string and hash values are raw text, and this feature is expected to remove only non-data whitespace, so an unrelated edit must not delete duplicate object members.

Please use a source-preserving JSON validation/formatting and minification path, and add regression coverage for duplicate members in both string and hash JSON editors.

已改为 source-preserving 的 formatJsonSource():只校验并重排空白,不再走 JSON.parse/stringify,因此不会丢掉重复 key。

回归测试覆盖 reviewer 的 {"role":"reader","role":"writer"} fixture, 以及 string SET / hash HSET 两条保存路径。

@onenewcode
onenewcode requested a review from t8y2 July 15, 2026 01:29
@t8y2
t8y2 merged commit ceadf73 into t8y2:main Jul 15, 2026
7 checks passed
@t8y2

t8y2 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in ceadf73, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] redis的值如果是json字符串,期望能在json视图下能直接编辑,不然切换到utf-8视图才能编辑太麻烦了,也不直观.

2 participants