react-toolkits 2.13.35 → 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,17 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 17b672d: feat: refactor InifinitList
8
+
9
+ ## 2.13.36
10
+
11
+ ### Patch Changes
12
+
13
+ - dba6e3c: feat: usePermission hook default return true
14
+
3
15
  ## 2.13.35
4
16
 
5
17
  ### 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';
@@ -633,22 +633,14 @@ function usePermission(code, config) {
633
633
  permissionCodes.length > 0 ? [url4, body, config] : null,
634
634
  (args) => axios2.post(...args).then((response) => response.data.data)
635
635
  );
636
- let newData;
637
- if (data !== void 0) {
638
- if (typeof code === "undefined") {
639
- newData = true;
640
- } else if (typeof code === "string") {
641
- newData = data.has_all ? true : data[code] ?? false;
642
- } else {
643
- if (code.length === 0) {
644
- newData = { [code[0]]: true };
645
- } else {
646
- newData = permissionCodes.reduce((acc, curr) => {
647
- acc[curr] = data.has_all ? true : data[curr] ?? false;
648
- return acc;
649
- }, {});
650
- }
651
- }
636
+ let newData = true;
637
+ if (typeof code === "string") {
638
+ newData = data?.has_all ? true : data?.[code] ?? false;
639
+ } else if (Array.isArray(code) && code.length > 0) {
640
+ newData = permissionCodes.reduce((acc, curr) => {
641
+ acc[curr] = data?.has_all ? true : data?.[curr] ?? false;
642
+ return acc;
643
+ }, {});
652
644
  }
653
645
  return {
654
646
  ...rest,
@@ -2296,6 +2288,7 @@ var init_permissionCollapse = __esm({
2296
2288
  const [checkedMap, setCheckedMap] = useState({});
2297
2289
  const [internalValue, setInternalValue] = useState(value ?? []);
2298
2290
  const { t } = useTranslation();
2291
+ const [, startTransition] = useTransition();
2299
2292
  const onCollapseChange = useCallback((key) => {
2300
2293
  setActiveKey(key);
2301
2294
  }, []);
@@ -2324,9 +2317,11 @@ var init_permissionCollapse = __esm({
2324
2317
  }, [value]);
2325
2318
  useEffect(() => {
2326
2319
  if (expand) {
2327
- setActiveKey((permissions ?? []).map(({ category }) => category));
2320
+ startTransition(() => {
2321
+ setActiveKey((permissions ?? []).map(({ category }) => category));
2322
+ });
2328
2323
  }
2329
- }, [expand, permissions]);
2324
+ }, []);
2330
2325
  useEffect(() => {
2331
2326
  const checkedValue = (permissions ?? []).reduce(
2332
2327
  (acc, curr) => {
@@ -2337,39 +2332,40 @@ var init_permissionCollapse = __esm({
2337
2332
  );
2338
2333
  setCheckedMap(checkedValue);
2339
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
+ }));
2340
2362
  return /* @__PURE__ */ jsx(
2341
2363
  Collapse,
2342
2364
  {
2343
2365
  style: { width: "100%" },
2344
2366
  collapsible: "header",
2345
2367
  activeKey,
2346
- items: (permissions ?? []).map((item) => ({
2347
- key: item.category,
2348
- label: item.category,
2349
- extra: !readonly && /* @__PURE__ */ jsx(
2350
- Checkbox,
2351
- {
2352
- checked: checkedMap[item.category],
2353
- onChange: (e) => {
2354
- onCheckChange(
2355
- e,
2356
- item.permissions?.map((permission) => permission.value)
2357
- );
2358
- },
2359
- children: t("global.selectAll")
2360
- }
2361
- ),
2362
- 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(
2363
- Checkbox,
2364
- {
2365
- value: permission.value,
2366
- onChange: (e) => {
2367
- onCheckChange(e, [permission.value]);
2368
- },
2369
- children: permission.label
2370
- }
2371
- ) }, permission.value)) }) })
2372
- })),
2368
+ items,
2373
2369
  onChange: onCollapseChange
2374
2370
  }
2375
2371
  );
@@ -2580,6 +2576,7 @@ var init_userList = __esm({
2580
2576
  const remove = useRemoveUser();
2581
2577
  const { mutate: mutate2, refetch } = useQueryListStore();
2582
2578
  const { permissionVersion } = useToolkitsStore((s) => s);
2579
+ const isV1 = permissionVersion === "v1" /* V1 */;
2583
2580
  const isV3 = permissionVersion === "v3" /* V3 */;
2584
2581
  const { show: showCreateModal, modal: createModal } = useCreateUserModal({
2585
2582
  onSuccess() {
@@ -2622,7 +2619,7 @@ var init_userList = __esm({
2622
2619
  dataIndex: "id",
2623
2620
  key: "id"
2624
2621
  },
2625
- isV3 && {
2622
+ (isV1 || isV3) && {
2626
2623
  title: t("global.role"),
2627
2624
  dataIndex: "roles",
2628
2625
  key: "roles",
@@ -3294,8 +3291,8 @@ var InternalInfiniteList = (props, ref) => {
3294
3291
  const { axios: axios2 } = useToolkitsStore((s) => s);
3295
3292
  const getKey = (pageIndex, previousPageData) => {
3296
3293
  if (!isValid) return null;
3297
- const rowKey = pageIndex !== 0 ? getRowKey(previousPageData) : void 0;
3298
- const args = params(formValues, rowKey);
3294
+ const rowKey = getRowKey?.(previousPageData, pageIndex);
3295
+ const args = params(formValues, pageIndex, rowKey);
3299
3296
  const queryString = qs.stringify(args);
3300
3297
  return queryString ? `${url4}?${qs.stringify(args)}` : url4;
3301
3298
  };
@@ -3321,7 +3318,7 @@ var InternalInfiniteList = (props, ref) => {
3321
3318
  );
3322
3319
  const dataSource = getDataSource(data);
3323
3320
  const isLoadingMore = isListValidating || size > 0 && data && typeof data[size - 1] === "undefined";
3324
- const isReachingEnd = typeof getHasMore !== "undefined" ? !getHasMore(last(data)) : true;
3321
+ const isReachingEnd = typeof getHasMore !== "undefined" ? !getHasMore(last(data)) : false;
3325
3322
  const isEmpty = !dataSource || dataSource.length === 0;
3326
3323
  const onConfirm = async () => {
3327
3324
  const values = await _form.getFieldsValue();
@@ -3406,7 +3403,7 @@ var InternalInfiniteList = (props, ref) => {
3406
3403
  );
3407
3404
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3408
3405
  formRenderer,
3409
- typeof tableExtra === "function" ? tableExtra(_form) : tableExtra,
3406
+ typeof tableExtra === "function" ? tableExtra(_form, dataSource) : tableExtra,
3410
3407
  /* @__PURE__ */ jsx(Table, { ...tableProps, dataSource, loading: isLoadingMore, pagination: false, footer: renderFooter }),
3411
3408
  !isEmpty && /* @__PURE__ */ jsx(
3412
3409
  Button,