Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: headerActionIcons 支持细粒度配置 & 修复异步渲染导致无法获取实例的问题 #2301

Merged
merged 2 commits into from
Aug 31, 2023

Conversation

lijinke666
Copy link
Member

👀 PR includes

✨ Feature

  • New feature

🐛 Bugfix

  • Solve the issue and close #0

📝 Description

headerActionIcons 支持细粒度配置

当同一个单元格配置了多个 icon 时, 为了区分是哪个 icon , 第二参数传入了 iconName, 那么在 icon 很多的场景

尤其是配置了 defaultHide, displayConditions, onClick 之类的动态展示场景,写法比较繁琐.

const headerActionIcons = {
  icons: ['iconA', 'iconB', 'iconC'],
  defaultHide: (meta, iconName) => {
    if(iconName === 'iconA') {
     
    }

    if(iconName === 'iconB') {

    }

    if(iconName === 'iconC') {

    }
  },

  displayConditions: (meta, iconName) => {
    if(iconName === 'iconA') {
     
    }

    if(iconName === 'iconB') {

    }

    if(iconName === 'iconC') {

    }
  },

  onClick: (meta, iconName) => {
    if(iconName === 'iconA') {
     
    }

    if(iconName === 'iconB') {

    }

    if(iconName === 'iconC') {

    }
  }
}

现在修改为, 支持单个 icon 粒度的 hook

单个 icon 粒度的hook 优先级 > 所有 icon 的 hook, 这样可以满足对所有 icon 统一控制 和单独控制的场景诉求

const headerActionIcons = [
  {
    icons: [
      {
        name: 'iconA',
        displayCondition: (meta) => {},
        defaultHide: (meta) => {},
        onClick: (meta) => {}
      },
      {
        name: 'iconB',
        displayCondition: (meta) => {},
        defaultHide: (meta) => {},
        onClick: (meta) => {}
      },
    ],
    belongsCell: 'rowCell',
    displayCondition: (meta) => {},
    defaultHide: (meta) => {},
    onClick: (meta) => {}
  },
]

修复异步渲染导致无法获取实例的问题

改为异步渲染后, 原先通过 useEffect 转发 ref 的方式不可用了

image

await spreadsheet.render();
setLoading(false);
s2Ref.current = spreadsheet;
/*
* 子 hooks 内使用了 s2Ref.current 作为 dep
* forceUpdate 一下保证子 hooks 能 rerender
*/
forceUpdate();
props.onMounted?.(s2Ref.current);

统一为 context 分发的方式, 修复下钻/编辑表 等场景报错的问题

🖼️ Screenshot

Before After

🔗 Related issue link

🔍 Self-Check before the merge

  • Add or update relevant docs.
  • Add or update relevant demos.
  • Add or update test case.
  • Add or update relevant TypeScript definitions.

@vercel
Copy link

vercel bot commented Jul 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
antvis-s2 ❌ Failed (Inspect) Jul 31, 2023 6:56am

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2023

Size Change: -15 B (0%)

Total Size: 320 kB

Filename Size Change
./packages/s2-core/dist/index.min.js 226 kB +49 B (0%)
./packages/s2-react/dist/index.min.js 67 kB -64 B (0%)
./packages/s2-react/dist/style.min.css 3.92 kB +3 B (0%)
./packages/s2-vue/dist/index.min.js 20.2 kB -7 B (0%)
./packages/s2-vue/dist/style.min.css 1.91 kB +4 B (0%)
ℹ️ View Unchanged
Filename Size
./packages/s2-core/dist/style.min.css 401 B

compressed-size-action

@github-actions
Copy link
Contributor

你好, @lijinke666 CI 执行失败, 请点击 [Details] 按钮查看, 并根据日志修复。

Hello, @lijinke666 CI run failed, please click the [Details] button for detailed log information and fix it.

@github-actions github-actions bot added the 🚨 test failed 单元测试挂了 label Jul 28, 2023
@codecov
Copy link

codecov bot commented Jul 31, 2023

Codecov Report

Patch coverage has no change and project coverage change: +1.05% 🎉

Comparison is base (ecdc9c8) 75.77% compared to head (40fd9fd) 76.82%.
Report is 205 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2301      +/-   ##
==========================================
+ Coverage   75.77%   76.82%   +1.05%     
==========================================
  Files         257      268      +11     
  Lines       11994    12188     +194     
  Branches     2464     2482      +18     
==========================================
+ Hits         9088     9363     +275     
+ Misses       1398     1286     -112     
- Partials     1508     1539      +31     
Files Changed Coverage Δ
packages/s2-core/src/cell/base-cell.ts 83.85% <ø> (-0.36%) ⬇️
packages/s2-core/src/cell/col-cell.ts 88.80% <ø> (+2.04%) ⬆️
packages/s2-core/src/cell/corner-cell.ts 81.00% <ø> (-1.70%) ⬇️
packages/s2-core/src/cell/data-cell.ts 76.12% <ø> (+9.46%) ⬆️
packages/s2-core/src/cell/header-cell.ts 63.69% <ø> (-2.13%) ⬇️
packages/s2-core/src/cell/index.ts 100.00% <ø> (ø)
packages/s2-core/src/cell/merged-cell.ts 91.66% <ø> (+54.16%) ⬆️
packages/s2-core/src/cell/row-cell.ts 71.42% <ø> (+0.62%) ⬆️
packages/s2-core/src/cell/series-number-cell.ts 90.90% <ø> (-2.20%) ⬇️
packages/s2-core/src/cell/table-col-cell.ts 84.61% <ø> (+3.48%) ⬆️
... and 98 more

... and 73 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lijinke666 lijinke666 merged commit b2d6f1f into next Aug 31, 2023
6 checks passed
@lijinke666 lijinke666 deleted the feat-header-action-icons branch August 31, 2023 08:07
@lijinke666
Copy link
Member Author

🎉 This PR is included in version @antv/s2-v2.0.0-next.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lijinke666
Copy link
Member Author

🎉 This PR is included in version @antv/s2-react-v2.0.0-next.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next 2.0-next 版本的问题 pr(feature) new feature released on @next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant