react-toolkits 2.13.36 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 17b672d: feat: refactor InifinitList
8
+
3
9
  ## 2.13.36
4
10
 
5
11
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -60,7 +60,7 @@ interface InfiniteListRef<Item = any, Values = any, Data = any> {
60
60
  }
61
61
  interface InfiniteListProps<Item, Values, Data> extends Pick<TableProps<Item>, 'columns' | 'rowKey' | 'tableLayout' | 'expandable' | 'rowSelection' | 'bordered'>, Pick<FilterFormWrapperProps, 'buttonsAlign' | 'showReset'> {
62
62
  url: string;
63
- getRowKey: (response: Data | undefined) => any;
63
+ getRowKey?: (response: Data | undefined, pageIndex: number) => any;
64
64
  getDataSource: (data: Data[] | undefined) => Item[];
65
65
  form?: FormInstance<Values>;
66
66
  code?: string;
@@ -70,10 +70,10 @@ interface InfiniteListProps<Item, Values, Data> extends Pick<TableProps<Item>, '
70
70
  [key: string]: AxiosHeaderValue;
71
71
  });
72
72
  renderForm?: (form: FormInstance<Values>) => ReactElement;
73
- params: (values: Values, rowKey?: string) => Record<any, any>;
73
+ params: (values: Values, pageIndex: number, rowKey?: string) => Record<any, any>;
74
74
  getHasMore?: (data: Data | undefined) => boolean;
75
- tableExtra?: ReactNode | ((form: FormInstance<Values>) => ReactNode);
76
- footer?: (data: (Data | undefined)[] | undefined) => ReactNode;
75
+ tableExtra?: ReactNode | ((form: FormInstance<Values>, data?: Item[]) => ReactNode);
76
+ footer?: (data: Data[] | undefined) => ReactNode;
77
77
  }
78
78
  declare const InfiniteList: <Item extends AnyObject = AnyObject, Values extends object | undefined = undefined, Data = any>(props: InfiniteListProps<Item, Values, Data> & {
79
79
  ref?: Ref<InfiniteListRef<Item, Data>>;
package/lib/index.js CHANGED
@@ -5,10 +5,10 @@ import { persist, createJSONStorage } from 'zustand/middleware';
5
5
  import logoUrl from './logo-L6MFCL6M.png';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
7
  import * as Antd2 from 'antd';
8
- import { Modal, Form, Spin, Result, Table, Button, Card, Input, Select, App, Switch, InputNumber, theme, Space, Tag, Typography, Alert, Divider, Menu, Popconfirm, Row, Col, Breadcrumb, Descriptions, Skeleton, Empty, Dropdown, Tooltip, Collapse, Checkbox } from 'antd';
8
+ import { Modal, Form, Spin, Result, Table, Button, Card, Input, Select, App, Switch, InputNumber, theme, Space, Tag, Typography, Alert, Divider, Menu, Popconfirm, Row, Col, Breadcrumb, Descriptions, Skeleton, Empty, Dropdown, Tooltip, Checkbox, Collapse } from 'antd';
9
9
  import { Routes, Route, Navigate, useNavigate, useParams, useLocation, Link } from 'react-router-dom';
10
10
  import useSWR6, { mutate, unstable_serialize, useSWRConfig } from 'swr';
11
- import { forwardRef, lazy, useContext, useMemo, useState, useEffect, useImperativeHandle, cloneElement, useRef, createContext, memo, useCallback, Fragment as Fragment$1, Suspense } from 'react';
11
+ import { forwardRef, lazy, useContext, useMemo, useState, useEffect, useImperativeHandle, cloneElement, useRef, createContext, memo, useCallback, Fragment as Fragment$1, Suspense, useTransition } from 'react';
12
12
  import { last, has, template, get, isEqual, first } from 'lodash-es';
13
13
  import { flushSync } from 'react-dom';
14
14
  import { createRoot } from 'react-dom/client';
@@ -2288,6 +2288,7 @@ var init_permissionCollapse = __esm({
2288
2288
  const [checkedMap, setCheckedMap] = useState({});
2289
2289
  const [internalValue, setInternalValue] = useState(value ?? []);
2290
2290
  const { t } = useTranslation();
2291
+ const [, startTransition] = useTransition();
2291
2292
  const onCollapseChange = useCallback((key) => {
2292
2293
  setActiveKey(key);
2293
2294
  }, []);
@@ -2316,9 +2317,11 @@ var init_permissionCollapse = __esm({
2316
2317
  }, [value]);
2317
2318
  useEffect(() => {
2318
2319
  if (expand) {
2319
- setActiveKey((permissions ?? []).map(({ category }) => category));
2320
+ startTransition(() => {
2321
+ setActiveKey((permissions ?? []).map(({ category }) => category));
2322
+ });
2320
2323
  }
2321
- }, [expand, permissions]);
2324
+ }, []);
2322
2325
  useEffect(() => {
2323
2326
  const checkedValue = (permissions ?? []).reduce(
2324
2327
  (acc, curr) => {
@@ -2329,39 +2332,40 @@ var init_permissionCollapse = __esm({
2329
2332
  );
2330
2333
  setCheckedMap(checkedValue);
2331
2334
  }, [internalValue, permissions]);
2335
+ const items = (permissions ?? []).map((item) => ({
2336
+ key: item.category,
2337
+ label: item.category,
2338
+ extra: !readonly && /* @__PURE__ */ jsx(
2339
+ Checkbox,
2340
+ {
2341
+ checked: checkedMap[item.category],
2342
+ onChange: (e) => {
2343
+ onCheckChange(
2344
+ e,
2345
+ item.permissions?.map((permission) => permission.value)
2346
+ );
2347
+ },
2348
+ children: t("global.selectAll")
2349
+ }
2350
+ ),
2351
+ children: /* @__PURE__ */ jsx(Checkbox.Group, { style: { width: "100%" }, value: internalValue, disabled: readonly, children: /* @__PURE__ */ jsx(Row, { gutter: [10, 10], style: { width: "100%" }, children: item.permissions?.map((permission) => /* @__PURE__ */ jsx(Col, { span: 6, children: /* @__PURE__ */ jsx(
2352
+ Checkbox,
2353
+ {
2354
+ value: permission.value,
2355
+ onChange: (e) => {
2356
+ onCheckChange(e, [permission.value]);
2357
+ },
2358
+ children: permission.label
2359
+ }
2360
+ ) }, permission.value)) }) })
2361
+ }));
2332
2362
  return /* @__PURE__ */ jsx(
2333
2363
  Collapse,
2334
2364
  {
2335
2365
  style: { width: "100%" },
2336
2366
  collapsible: "header",
2337
2367
  activeKey,
2338
- items: (permissions ?? []).map((item) => ({
2339
- key: item.category,
2340
- label: item.category,
2341
- extra: !readonly && /* @__PURE__ */ jsx(
2342
- Checkbox,
2343
- {
2344
- checked: checkedMap[item.category],
2345
- onChange: (e) => {
2346
- onCheckChange(
2347
- e,
2348
- item.permissions?.map((permission) => permission.value)
2349
- );
2350
- },
2351
- children: t("global.selectAll")
2352
- }
2353
- ),
2354
- children: /* @__PURE__ */ jsx(Checkbox.Group, { style: { width: "100%" }, value: internalValue, disabled: readonly, children: /* @__PURE__ */ jsx(Row, { gutter: [10, 10], style: { width: "100%" }, children: item.permissions?.map((permission) => /* @__PURE__ */ jsx(Col, { span: 6, children: /* @__PURE__ */ jsx(
2355
- Checkbox,
2356
- {
2357
- value: permission.value,
2358
- onChange: (e) => {
2359
- onCheckChange(e, [permission.value]);
2360
- },
2361
- children: permission.label
2362
- }
2363
- ) }, permission.value)) }) })
2364
- })),
2368
+ items,
2365
2369
  onChange: onCollapseChange
2366
2370
  }
2367
2371
  );
@@ -2572,6 +2576,7 @@ var init_userList = __esm({
2572
2576
  const remove = useRemoveUser();
2573
2577
  const { mutate: mutate2, refetch } = useQueryListStore();
2574
2578
  const { permissionVersion } = useToolkitsStore((s) => s);
2579
+ const isV1 = permissionVersion === "v1" /* V1 */;
2575
2580
  const isV3 = permissionVersion === "v3" /* V3 */;
2576
2581
  const { show: showCreateModal, modal: createModal } = useCreateUserModal({
2577
2582
  onSuccess() {
@@ -2614,7 +2619,7 @@ var init_userList = __esm({
2614
2619
  dataIndex: "id",
2615
2620
  key: "id"
2616
2621
  },
2617
- isV3 && {
2622
+ (isV1 || isV3) && {
2618
2623
  title: t("global.role"),
2619
2624
  dataIndex: "roles",
2620
2625
  key: "roles",
@@ -3286,8 +3291,8 @@ var InternalInfiniteList = (props, ref) => {
3286
3291
  const { axios: axios2 } = useToolkitsStore((s) => s);
3287
3292
  const getKey = (pageIndex, previousPageData) => {
3288
3293
  if (!isValid) return null;
3289
- const rowKey = pageIndex !== 0 ? getRowKey(previousPageData) : void 0;
3290
- const args = params(formValues, rowKey);
3294
+ const rowKey = getRowKey?.(previousPageData, pageIndex);
3295
+ const args = params(formValues, pageIndex, rowKey);
3291
3296
  const queryString = qs.stringify(args);
3292
3297
  return queryString ? `${url4}?${qs.stringify(args)}` : url4;
3293
3298
  };
@@ -3313,7 +3318,7 @@ var InternalInfiniteList = (props, ref) => {
3313
3318
  );
3314
3319
  const dataSource = getDataSource(data);
3315
3320
  const isLoadingMore = isListValidating || size > 0 && data && typeof data[size - 1] === "undefined";
3316
- const isReachingEnd = typeof getHasMore !== "undefined" ? !getHasMore(last(data)) : true;
3321
+ const isReachingEnd = typeof getHasMore !== "undefined" ? !getHasMore(last(data)) : false;
3317
3322
  const isEmpty = !dataSource || dataSource.length === 0;
3318
3323
  const onConfirm = async () => {
3319
3324
  const values = await _form.getFieldsValue();
@@ -3398,7 +3403,7 @@ var InternalInfiniteList = (props, ref) => {
3398
3403
  );
3399
3404
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3400
3405
  formRenderer,
3401
- typeof tableExtra === "function" ? tableExtra(_form) : tableExtra,
3406
+ typeof tableExtra === "function" ? tableExtra(_form, dataSource) : tableExtra,
3402
3407
  /* @__PURE__ */ jsx(Table, { ...tableProps, dataSource, loading: isLoadingMore, pagination: false, footer: renderFooter }),
3403
3408
  !isEmpty && /* @__PURE__ */ jsx(
3404
3409
  Button,