Skip to content

feat(base): support ranking dashboard blocks - #2306

Open
wanghm25 wants to merge 2 commits into
larksuite:mainfrom
wanghm25:harness/01kzr9mk9zyr006gc53nbhszex
Open

feat(base): support ranking dashboard blocks#2306
wanghm25 wants to merge 2 commits into
larksuite:mainfrom
wanghm25:harness/01kzr9mk9zyr006gc53nbhszex

Conversation

@wanghm25

@wanghm25 wanghm25 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add ranking dashboard block validation and create defaults
  • preserve ranking update patch semantics
  • document ranking data_config and get-data behavior

Tests

  • go test ./shortcuts/base -count=1
  • go test ./tests/cli_e2e/base -run TestBaseDashboardBlockRanking -count=1
  • node scripts/skill-format-check/index.js

Summary by CodeRabbit

  • New Features

    • Added support for ranking (Top N) dashboard blocks.
    • Ranking blocks support configurable limits, grouping, aggregation, and value-based sorting.
    • Updates can change ranking limits without overwriting unrelated settings.
    • Creation applies defaults of 10 results and descending value sorting.
  • Bug Fixes

    • Added validation for required ranking settings, supported options, sorting, and limit ranges.
  • Documentation

    • Added ranking block examples, configuration guidance, and create/update templates.

@github-actions github-actions Bot added domain/base PR touches the base domain size/M Single-domain feat or fix with limited business impact labels Aug 11, 2026
@CLAassistant

CLAassistant commented Aug 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI now supports ranking dashboard blocks with normalized defaults, strict configuration validation, partial limit_size updates, dry-run coverage, command examples, and reference documentation.

Changes

Ranking dashboard blocks

Layer / File(s) Summary
Ranking normalization and validation
shortcuts/base/helpers.go, shortcuts/base/dashboard_block_create.go
Ranking creation defaults limit_size to 10 and value sorting to descending order. Validation enforces ranking fields, grouping, aggregation, sorting, and limits from 1 through 500.
Ranking command behavior and tests
shortcuts/base/dashboard_block_create.go, shortcuts/base/dashboard_block_update.go, shortcuts/base/*test.go, tests/cli_e2e/base/base_dashboard_block_ranking_dryrun_test.go
Commands include ranking examples. Tests verify create normalization, partial updates, request payloads, and invalid configurations.
Ranking contracts and usage documentation
skills/lark-base/references/dashboard-block-data-config.md, skills/lark-base/references/lark-base-dashboard*.md
Documentation defines ranking configuration, Top N behavior, result ordering, creation examples, and patch update semantics.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant DataConfigNormalizer
  participant RankingValidator
  participant DashboardBlockAPI
  CLI->>DataConfigNormalizer: normalize ranking data-config
  DataConfigNormalizer->>RankingValidator: validate ranking fields and limits
  RankingValidator-->>CLI: return normalized configuration
  CLI->>DashboardBlockAPI: create or patch ranking block
  DashboardBlockAPI-->>CLI: return ranking block request result
Loading

Possibly related PRs

  • larksuite/cli#2229: Both changes modify dashboard block data-config normalization and validation.
  • larksuite/cli#2231: Both changes modify dashboard block validation in shortcuts/base/helpers.go.
  • larksuite/cli#2307: Both changes modify dashboard block data-config normalization and validation in shortcuts/base/helpers.go.

Suggested reviewers: kongenpei

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a summary and test commands, but it omits the required Changes and Related Issues sections and does not use the Test Plan format. Add the required Changes, Test Plan, and Related Issues sections, and mark the applicable test-plan items.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: support for ranking dashboard blocks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shortcuts/base/base_dashboard_execute_test.go`:
- Around line 733-735: Update the error assertion around runShortcut to use
errors.As and inspect the resulting *errs.ValidationError. Assert that the typed
validation error has Param equal to "--data-config" and the expected
invalid-argument subtype, while preserving the existing failure handling; do not
rely on matching err.Error() as the sole validation.

In `@shortcuts/base/dashboard_block_create.go`:
- Around line 51-55: Add a nearby regression test for the ranking creation path
without --data-config, asserting it returns the typed validation error metadata
and includes the --data-config parameter. Use the existing ranking creation test
setup and ensure the test fails if the ranking case is removed from the switch
in the validation flow.

In `@skills/lark-base/references/dashboard-block-data-config.md`:
- Line 108: Unify the documented ranking filter-patch semantics across
skills/lark-base/references/dashboard-block-data-config.md:108-108 and
skills/lark-base/references/lark-base-dashboard.md:145-150. Align the
limit_size-only update with the implementation and partial-update contract: if
omitting filter resets to all records, update the dashboard example accordingly;
otherwise document and preserve the existing filter consistently. No direct code
change is required.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 14fbe1be-658c-4be1-8d77-576ecc6e6ef5

📥 Commits

Reviewing files that changed from the base of the PR and between e1f9872 and 96973a6.

📒 Files selected for processing (9)
  • shortcuts/base/base_dashboard_execute_test.go
  • shortcuts/base/base_shortcuts_test.go
  • shortcuts/base/dashboard_block_create.go
  • shortcuts/base/dashboard_block_update.go
  • shortcuts/base/helpers.go
  • skills/lark-base/references/dashboard-block-data-config.md
  • skills/lark-base/references/lark-base-dashboard-block-get-data.md
  • skills/lark-base/references/lark-base-dashboard.md
  • tests/cli_e2e/base/base_dashboard_block_ranking_dryrun_test.go

Comment on lines +733 to +735
err := runShortcut(t, BaseDashboardBlockCreate, args, factory, stdout)
if err == nil || !strings.Contains(err.Error(), tc.want) {
t.Fatalf("err=%v, want %q", err, tc.want)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert the typed validation error contract.

Do not use message matching as the only assertion. Assert the validation category and invalid-argument subtype. Use errors.As to inspect *errs.ValidationError and assert Param == "--data-config".

Based on learnings, errs.ProblemOf(err) does not expose Param. As per coding guidelines, “Error tests must assert typed metadata and cause preservation rather than message text alone.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/base/base_dashboard_execute_test.go` around lines 733 - 735, Update
the error assertion around runShortcut to use errors.As and inspect the
resulting *errs.ValidationError. Assert that the typed validation error has
Param equal to "--data-config" and the expected invalid-argument subtype, while
preserving the existing failure handling; do not rely on matching err.Error() as
the sole validation.

Sources: Coding guidelines, Learnings

Comment on lines +51 to +55
switch strings.ToLower(runtime.Str("type")) {
case "text":
return errs.NewValidationError(errs.SubtypeInvalidArgument, "text 类型组件必须提供 data-config,包含必填字段 text").WithParam("--data-config")
case "ranking":
return errs.NewValidationError(errs.SubtypeInvalidArgument, "ranking 类型组件必须提供 data-config").WithParam("--data-config")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a regression test for the missing ranking configuration path.

No supplied test runs ranking creation without --data-config. Removing case "ranking" would preserve the current ranking tests. Add a test that asserts the typed validation metadata and --data-config parameter.

As per coding guidelines, “Every behavior change requires a nearby regression test that fails when the implementation is reverted.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/base/dashboard_block_create.go` around lines 51 - 55, Add a nearby
regression test for the ranking creation path without --data-config, asserting
it returns the typed validation error metadata and includes the --data-config
parameter. Use the existing ranking creation test setup and ensure the test
fails if the ranking case is removed from the switch in the validation flow.

Source: Coding guidelines

- `limit_size` 是 Top N,取值为 `1..500` 的整数,创建时省略默认 `10`。
- 不支持顶层 `sort`、公开 `ranking` 对象或头像开关。

更新 `ranking` 时,`data_config` 是顶层 patch:只传 `limit_size` 只改 Top N;只传 `group_by` 只替换唯一分组和排序;只传 `series` 或 `count_all:true` 只切换指标;只传 `filter` 只替换筛选。切换 `table_name` 时必须在同一 patch 提供新的 `group_by` 以及 `series` 或 `count_all:true`;未传 `filter` 会重置为全部记录,未传 `limit_size` 保留原 Top N。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Unify ranking filter patch semantics.

The two references document different behavior for a ranking update that only changes limit_size.

  • skills/lark-base/references/dashboard-block-data-config.md#L108-L108: align the documented filter behavior with the implementation and the partial-update contract.
  • skills/lark-base/references/lark-base-dashboard.md#L145-L150: update the example if omitted filter intentionally resets to all records; otherwise preserve the existing filter consistently.
📍 Affects 2 files
  • skills/lark-base/references/dashboard-block-data-config.md#L108-L108 (this comment)
  • skills/lark-base/references/lark-base-dashboard.md#L145-L150
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/lark-base/references/dashboard-block-data-config.md` at line 108,
Unify the documented ranking filter-patch semantics across
skills/lark-base/references/dashboard-block-data-config.md:108-108 and
skills/lark-base/references/lark-base-dashboard.md:145-150. Align the
limit_size-only update with the implementation and partial-update contract: if
omitting filter resets to all records, update the dashboard example accordingly;
otherwise document and preserve the existing filter consistently. No direct code
change is required.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/cli_e2e/base/base_dashboard_block_ranking_dryrun_test.go`:
- Around line 74-75: Update the table cases in the dry-run validation tests to
include expected error.type, error.subtype, error.param, and error.message
values, and import encoding/json. Parse result.Stderr as the validation JSON
envelope and assert those typed fields for each case, replacing the
message-substring-only check while preserving the existing exit-code and
empty-stdout assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7e3450a2-db75-41b0-8ef2-f73cd1252cf2

📥 Commits

Reviewing files that changed from the base of the PR and between 96973a6 and 2190d09.

📒 Files selected for processing (3)
  • shortcuts/base/base_dashboard_execute_test.go
  • shortcuts/base/helpers.go
  • tests/cli_e2e/base/base_dashboard_block_ranking_dryrun_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • shortcuts/base/helpers.go
  • shortcuts/base/base_dashboard_execute_test.go

Comment on lines +74 to +75
require.Contains(t, result.Stderr, tc.want)
require.Empty(t, result.Stdout)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the typed validation envelope.

The message substring check can pass when error.type, error.subtype, or error.param is wrong or missing. Parse result.Stderr as the validation JSON envelope and assert error.type, error.subtype, error.param, and error.message for each table case. Keep the existing exit-code and empty-stdout checks.

As per coding guidelines, error tests must assert typed metadata and cause preservation rather than message text alone. Based on learnings, validation-stage E2E failures must write the typed envelope to stderr and assert these fields.

Suggested assertion shape
-			require.Contains(t, result.Stderr, tc.want)
+			var envelope struct {
+				Error struct {
+					Type    string `json:"type"`
+					Subtype string `json:"subtype"`
+					Param   string `json:"param"`
+					Message string `json:"message"`
+				} `json:"error"`
+			}
+			require.NoError(t, json.Unmarshal([]byte(result.Stderr), &envelope))
+			require.Equal(t, tc.wantType, envelope.Error.Type)
+			require.Equal(t, tc.wantSubtype, envelope.Error.Subtype)
+			require.Equal(t, tc.wantParam, envelope.Error.Param)
+			require.Equal(t, tc.want, envelope.Error.Message)

Add the expected typed fields to each table case and import encoding/json.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/cli_e2e/base/base_dashboard_block_ranking_dryrun_test.go` around lines
74 - 75, Update the table cases in the dry-run validation tests to include
expected error.type, error.subtype, error.param, and error.message values, and
import encoding/json. Parse result.Stderr as the validation JSON envelope and
assert those typed fields for each case, replacing the message-substring-only
check while preserving the existing exit-code and empty-stdout assertions.

Sources: Coding guidelines, Learnings

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

Labels

domain/base PR touches the base domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants