From e7fe0b2c580bae9654bf2796ed13dbcb3cc4aa1d Mon Sep 17 00:00:00 2001 From: zindlerzeng Date: Wed, 24 May 2023 21:41:04 +0800 Subject: [PATCH 1/3] fix($table): synchronize the colspan state of the table component --- src/table/hooks/useRowspanAndColspan.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/table/hooks/useRowspanAndColspan.ts b/src/table/hooks/useRowspanAndColspan.ts index c4ff27dc39..f631849fcf 100644 --- a/src/table/hooks/useRowspanAndColspan.ts +++ b/src/table/hooks/useRowspanAndColspan.ts @@ -23,7 +23,7 @@ export default function useRowspanAndColspan( rowKey: string, rowspanAndColspan: TableRowspanAndColspanFunc, ) { - const [skipSpansMap] = useState(new Map()); + const [skipSpansMap, setSpansMap] = useState(new Map()); // 计算单元格是否跳过渲染 const onTrRowspanOrColspan = (params: BaseTableCellParams, skipSpansValue: SkipSpansValue) => { @@ -78,7 +78,8 @@ export default function useRowspanAndColspan( useEffect(() => { updateSkipSpansMap(data, columns, rowspanAndColspan); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [data, columns, rowspanAndColspan]); + setSpansMap(pre => new Map([...pre.entries()])) + }, [data, columns, rowspanAndColspan, setSpansMap]); - return { skipSpansMap, updateSkipSpansMap }; + return { skipSpansMap }; } From 759a080cbf533363fde39caa05a60add14a267e1 Mon Sep 17 00:00:00 2001 From: zindler <410524878@qq.com> Date: Fri, 26 May 2023 20:13:37 +0800 Subject: [PATCH 2/3] fix(table): remove unnecessary effect --- src/table/hooks/useRowspanAndColspan.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/table/hooks/useRowspanAndColspan.ts b/src/table/hooks/useRowspanAndColspan.ts index f631849fcf..26d5836738 100644 --- a/src/table/hooks/useRowspanAndColspan.ts +++ b/src/table/hooks/useRowspanAndColspan.ts @@ -1,4 +1,3 @@ -import { useEffect, useState } from 'react'; import get from 'lodash/get'; import log from '../../_common/js/log'; import { BaseTableCellParams, BaseTableCol, TableRowData, TableRowspanAndColspanFunc } from '../type'; @@ -23,7 +22,7 @@ export default function useRowspanAndColspan( rowKey: string, rowspanAndColspan: TableRowspanAndColspanFunc, ) { - const [skipSpansMap, setSpansMap] = useState(new Map()); + const skipSpansMap = new Map(); // 计算单元格是否跳过渲染 const onTrRowspanOrColspan = (params: BaseTableCellParams, skipSpansValue: SkipSpansValue) => { @@ -45,12 +44,7 @@ export default function useRowspanAndColspan( }; // 计算单元格是否需要设置 rowspan 和 colspan - const updateSkipSpansMap = ( - data: TableRowData[], - columns: BaseTableCol[], - rowspanAndColspan: TableRowspanAndColspanFunc, - ) => { - skipSpansMap.clear(); + (() => { if (!data || !rowspanAndColspan) return; for (let i = 0, len = data.length; i < len; i++) { const row = data[i]; @@ -73,13 +67,7 @@ export default function useRowspanAndColspan( onTrRowspanOrColspan?.(params, state); } } - }; - - useEffect(() => { - updateSkipSpansMap(data, columns, rowspanAndColspan); - // eslint-disable-next-line react-hooks/exhaustive-deps - setSpansMap(pre => new Map([...pre.entries()])) - }, [data, columns, rowspanAndColspan, setSpansMap]); + })(); return { skipSpansMap }; } From bf83e0417585dce21574c43c5f70f3d6f9611069 Mon Sep 17 00:00:00 2001 From: xiaosansiji Date: Tue, 30 May 2023 10:45:34 +0800 Subject: [PATCH 3/3] test: update snapshot --- test/snap/__snapshots__/ssr.test.jsx.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap index e1d4a54e99..133c648e4e 100644 --- a/test/snap/__snapshots__/ssr.test.jsx.snap +++ b/test/snap/__snapshots__/ssr.test.jsx.snap @@ -918,7 +918,7 @@ exports[`ssr snapshot test > ssr test src/table/_example/lazy.jsx 1`] = `"
ssr test src/table/_example/loading.jsx 1`] = `"
集群名称
状态
管理员
描述
集群名称
状态
管理员
描述
自定义加载状态文本
集群名称
状态
管理员
描述
  渲染函数自定义加载中(可单独去除内置加载图标)
"`; -exports[`ssr snapshot test > ssr test src/table/_example/merge-cells.jsx 1`] = `"
申请人
申请状态
审批事项
邮箱地址
其他信息
贾明审批通过宣传物料制作费用w.cezkdudy@lhll.au电子签署2021-11-01
张三审批失败algolia 服务报销r.nmgw@peurezgn.sl纸质签署2021-11-01
王芳审批过期相关周边制作费p.cumx@rampblpa.ru纸质签署2021-11-01
贾明审批通过激励奖品快递费b.nmgw@peurezgn.sl电子签署2021-11-01
张三审批失败宣传物料制作费用d.cumx@rampblpa.ru纸质签署2021-11-01
王芳审批过期algolia 服务报销w.cezkdudy@lhll.au纸质签署2021-11-01
"`; +exports[`ssr snapshot test > ssr test src/table/_example/merge-cells.jsx 1`] = `"
申请人
申请状态
审批事项
邮箱地址
其他信息
贾明审批通过宣传物料制作费用w.cezkdudy@lhll.au电子签署2021-11-01
审批失败algolia 服务报销纸质签署2021-11-01
王芳审批过期纸质签署2021-11-01
审批通过激励奖品快递费b.nmgw@peurezgn.sl电子签署2021-11-01
张三审批失败宣传物料制作费用d.cumx@rampblpa.ru纸质签署2021-11-01
审批过期algolia 服务报销w.cezkdudy@lhll.au纸质签署2021-11-01
"`; exports[`ssr snapshot test > ssr test src/table/_example/multi-header.jsx 1`] = `"
申请人
申请汇总
住宿费
交通费
物料费
奖品激励费
审批汇总
申请时间
申请状态
申请渠道和金额
审批状态
说明
类型
申请耗时(天)
审批单号
邮箱地址
贾明审批通过电子签署3100100100100组长审批审批单号001
w.cezkdudy@lhll.au
2022-01-01
张三审批失败纸质签署2200200200200部门审批审批单号002
r.nmgw@peurezgn.sl
2022-02-01
王芳审批过期纸质签署4400400400400财务审批审批单号003
p.cumx@rampblpa.ru
2022-03-01
贾明审批通过电子签署1500500500500组长审批审批单号004
w.cezkdudy@lhll.au
2022-04-01
张三审批失败纸质签署3100100100100部门审批审批单号005
r.nmgw@peurezgn.sl
2022-01-01
王芳审批过期纸质签署2200200200200财务审批审批单号006
p.cumx@rampblpa.ru
2022-02-01
贾明审批通过电子签署4400400400400组长审批审批单号007
w.cezkdudy@lhll.au
2022-03-01
张三审批失败纸质签署1500500500500部门审批审批单号008
r.nmgw@peurezgn.sl
2022-04-01
王芳审批过期纸质签署3100100100100财务审批审批单号009
p.cumx@rampblpa.ru
2022-01-01
贾明审批通过电子签署2200200200200组长审批审批单号0010
w.cezkdudy@lhll.au
2022-02-01
张三审批失败纸质签署4400400400400部门审批审批单号0011
r.nmgw@peurezgn.sl
2022-03-01
王芳审批过期纸质签署1500500500500财务审批审批单号0012
p.cumx@rampblpa.ru
2022-04-01
贾明审批通过电子签署3100100100100组长审批审批单号0013
w.cezkdudy@lhll.au
2022-01-01
张三审批失败纸质签署2200200200200部门审批审批单号0014
r.nmgw@peurezgn.sl
2022-02-01
王芳审批过期纸质签署4400400400400财务审批审批单号0015
p.cumx@rampblpa.ru
2022-03-01
贾明审批通过电子签署1500500500500组长审批审批单号0016
w.cezkdudy@lhll.au
2022-04-01
张三审批失败纸质签署3100100100100部门审批审批单号0017
r.nmgw@peurezgn.sl
2022-01-01
王芳审批过期纸质签署2200200200200财务审批审批单号0018
p.cumx@rampblpa.ru
2022-02-01
贾明审批通过电子签署4400400400400组长审批审批单号0019
w.cezkdudy@lhll.au
2022-03-01
张三审批失败纸质签署1500500500500部门审批审批单号0020
r.nmgw@peurezgn.sl
2022-04-01
"`;