Skip to content

feat(datasource-select): migrate pages to DatasourceSelectV3 - #2290

Merged
jsers merged 9 commits into
mainfrom
optimize-datasource-selectors
Sep 10, 2026
Merged

jsers merged 9 commits into
mainfrom
optimize-datasource-selectors

Conversation

@jsers

@jsers jsers commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Extend DatasourceSelectV3 with filterKey/showHost/className passthrough, array-aware onChange, and a styled default tag. Migrate alert rules, history events, shield, subscribe, metrics-builtin and alert-rule form off the legacy per-group DatasourceSelect.

Extend DatasourceSelectV3 with filterKey/showHost/className passthrough,
array-aware onChange, and a styled default tag. Migrate alert rules, history
events, shield, subscribe, metrics-builtin and alert-rule form off the
legacy per-group DatasourceSelect.
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

jsers and others added 8 commits August 31, 2026 15:41
…label

- merge props.className into base class and omit it from the rest spread
  to avoid duplicate className on Select
- switch optionLabel to flex layout with overflow-hidden / truncate so
  long datasource names no longer overflow the selected display
Render a warning label for selected datasource values that no longer
exist in the list, while keeping the parent-facing onChange contract
on primitive string|number values via labelInValue wrap/unwrap.
- migrate DatasourceValueSelect in alertRules Form/FormNG to DatasourceSelectV3
- add "all datasources" option with icon and i18n for prometheus/loki
- mark default/deleted tags via i18n, remove selected checkmark icon
- export DatasourceItem type to drop as-any in consumers
- add jsonapi logo asset
ajustDatasourceList may inject datasource variable options (e.g. from
dashboard). The deleted-value check only looked at the original list,
so an injected selected value was wrongly flagged as deleted. Also
check the adjusted list before marking a value as deleted, and add a
regression test.
@jsers
jsers marked this pull request as ready for review September 10, 2026 08:43
Copilot AI lite review requested due to automatic review settings September 10, 2026 08:43
@jsers
jsers merged commit 060c83b into main Sep 10, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

There is a confirmed logic bug in DatasourceSelectV3 where the 'mixed' fallback cate detection is incorrect when mode='multiple' because it checks the whole selected array instead of the current value.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR upgrades datasource picking across multiple pages by migrating from legacy/per-group datasource selectors to DatasourceSelectV3, while extending DatasourceSelectV3 to better support filtering, multi-select, host selection, and clearer rendering (default/deleted states) with localized labels.

Changes:

  • Extend DatasourceSelectV3 with filtering (filterKey), showHost, passthrough className, array-aware onChange, and improved option/value rendering (default tag + deleted value label).
  • Migrate alert rules, history events, shield, subscribe, and metrics-builtin filter modal to use DatasourceSelectV3 (mostly with multi-select + responsive tags).
  • Add new i18n strings and styles for the new UI states, plus a regression test for injected datasource-variable values.
File summaries
File Description
src/pages/warning/subscribe/ListNG.tsx Migrate list filters to DatasourceSelectV3 with multi-select + clear handling.
src/pages/warning/shield/index.tsx Migrate shield filters to DatasourceSelectV3 with multi-select + clear handling.
src/pages/metricsBuiltin/components/Filters/FormModal.tsx Replace prometheus datasource <Select> with DatasourceSelectV3 plus list adjustment.
src/pages/historyEvents/ListNG/index.tsx Migrate history event filters to DatasourceSelectV3 with multi-select + clear handling.
src/pages/alertRules/locale/zh_HK.ts Add all_datasources translation.
src/pages/alertRules/locale/zh_CN.ts Add all_datasources translation.
src/pages/alertRules/locale/ru_RU.ts Add all_datasources translation.
src/pages/alertRules/locale/ja_JP.ts Add all_datasources translation.
src/pages/alertRules/locale/en_US.ts Add all_datasources translation.
src/pages/alertRules/List/ListNG.tsx Migrate alert rules list datasource filter to DatasourceSelectV3 (multi-select + clear).
src/pages/alertRules/FormNG/components/DatasourceValueSelect/index.tsx Update types and use DatasourceSelectV3 for match_type=0 selection path.
src/pages/alertRules/Form/components/DatasourceValueSelect/index.tsx Replace <Select> with DatasourceSelectV3, inject “all datasources” option, and adjust filtering.
src/components/DatasourceSelect/style.less Minor formatting fixes.
src/components/DatasourceSelect/locale/zh_HK.ts Add deleted / default translations.
src/components/DatasourceSelect/locale/zh_CN.ts Add deleted / default translations.
src/components/DatasourceSelect/locale/ru_RU.ts Add deleted / default translations.
src/components/DatasourceSelect/locale/ja_JP.ts Add deleted / default translations.
src/components/DatasourceSelect/locale/en_US.ts Add deleted / default translations.
src/components/DatasourceSelect/index.tsx Re-export DatasourceItem type from V3.
src/components/DatasourceSelect/DatasourceSelectV3/style.less Add styles for default tag, deleted value, and open-state icon treatment.
src/components/DatasourceSelect/DatasourceSelectV3/index.tsx Implement V3 behavior extensions (filtering, host option, deleted marking, labelInValue normalization, etc.).
src/components/DatasourceSelect/DatasourceSelectV3/index.test.tsx Add test ensuring injected datasource variable values aren’t marked deleted.
Review details

Suppressed comments (1)

src/pages/alertRules/Form/components/DatasourceValueSelect/index.tsx:175

  • Use Array.isArray for type narrowing here. _.isArray may not be recognized as a type guard by TS (depending on lodash typings), and the extra typeof v !== 'number' check is redundant inside the array branch.
            if (_.isArray(v)) {
              const curVal = _.last(v);
              if (curVal === DATASOURCE_ALL) {
                setFieldsValue({ datasource_ids: [DATASOURCE_ALL] });
              } else if (typeof v !== 'number' && v.includes(DATASOURCE_ALL)) {
  • Files reviewed: 22/23 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +205 to +208
const selectedValue = Array.isArray(value) ? value.map(getRawValue) : getRawValue(value);
const curValue = Array.isArray(selectedValue) ? _.last(selectedValue) : selectedValue;
const curCate = _.find(currentDatasourceList, { id: curValue })?.plugin_type;
onChange(selectedValue, curCate ?? (selectedValue === 'mixed' ? 'mixed' : ''));
@flashduty

flashduty Bot commented Sep 10, 2026

Copy link
Copy Markdown

cat-fe 每日 i18n Review(2026-09-10)发现本 PR 引入的 locale key 双语缺失

本 PR 新增的 3 个 key 只在 zh_CN / zh_HK / en_US / ja_JP / ru_RU 补齐,es_ES / fr_FR / id_ID / ko_KR / pt_BR 缺失,这些语言会回退到基础语言:

  • src/components/DatasourceSelect/locale/*:default、deleted
  • src/pages/alertRules/locale/*:all_datasources

已提交修复 PR:#2329

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.

3 participants