From ca604e83b7b484e8c98c0eee8ff0babd79d2afd1 Mon Sep 17 00:00:00 2001
From: sealday <zhanglin@daoyoucloud.com>
Date: Sun, 21 Apr 2024 22:09:10 +0800
Subject: [PATCH] chore: add translations for embed page (#789)

Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/789
---
 .../src/client/features/departments/index.tsx | 3982 ++++++++---------
 .../@hera/plugin-core/src/locale/en-US.json   |    3 +
 .../@hera/plugin-core/src/locale/zh-CN.json   |    3 +
 3 files changed, 1997 insertions(+), 1991 deletions(-)

diff --git a/packages/plugins/@hera/plugin-core/src/client/features/departments/index.tsx b/packages/plugins/@hera/plugin-core/src/client/features/departments/index.tsx
index 040902083..3fbe7b019 100644
--- a/packages/plugins/@hera/plugin-core/src/client/features/departments/index.tsx
+++ b/packages/plugins/@hera/plugin-core/src/client/features/departments/index.tsx
@@ -3,6 +3,7 @@ import {
   CollectionContext,
   SchemaSettings,
   SchemaComponentContext,
+  ResourceActionProvider,
   useSchemaComponentContext,
   useFilterFieldProps,
   useFieldModeOptions,
@@ -51,8 +52,8 @@ import {
   TreeSelect,
   theme,
 } from 'antd';
-import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
-import * as jsxRuntime from 'react/jsx-runtime';
+import React, { useCallback, useContext, useEffect, useMemo, useRef, useState, Fragment } from 'react';
+import { jsx, jsxs } from 'react/jsx-runtime';
 import { useTranslation, tval } from '../../locale';
 
 var wt = Object.defineProperty,
@@ -61,7 +62,8 @@ var Mt = Object.getOwnPropertyDescriptors;
 var me = Object.getOwnPropertySymbols;
 var Tt = Object.prototype.hasOwnProperty,
   It = Object.prototype.propertyIsEnumerable;
-var de = (w, s, n) => (s in w ? wt(w, s, { enumerable: true, configurable: true, writable: true, value: n }) : (w[s] = n)),
+var de = (w, s, n) =>
+    s in w ? wt(w, s, { enumerable: true, configurable: true, writable: true, value: n }) : (w[s] = n),
   y = (w, s) => {
     for (var n in s || (s = {})) Tt.call(s, n) && de(w, n, s[n]);
     if (me) for (var n of me(s)) It.call(s, n) && de(w, n, s[n]);
@@ -88,50 +90,49 @@ var k = (w, s, n) =>
     N((n = n.apply(w, s)).next());
   });
 const xe = () => {
-    const { t: e } = useTranslation();
-    return jsxRuntime.jsx(SchemaComponent, {
-      scope: { t: e },
-      schema: {
-        type: 'void',
-        properties: {
-          newDepartment: {
-            type: 'void',
-            title: e('New department'),
-            'x-component': 'Action',
-            'x-component-props': { type: 'text', icon: 'PlusOutlined', style: { width: '100%', textAlign: 'left' } },
-            properties: {
-              drawer: {
-                type: 'void',
-                'x-component': 'Action.Drawer',
-                'x-decorator': 'Form',
-                title: e('New department'),
-                properties: {
-                  title: { 'x-component': 'CollectionField', 'x-decorator': 'FormItem', required: true },
-                  parent: {
-                    'x-component': 'CollectionField',
-                    'x-decorator': 'FormItem',
-                    'x-collection-field': 'departments.parent',
-                    'x-component-props': { component: 'DepartmentSelect' },
-                  },
-                  roles: {
-                    'x-component': 'CollectionField',
-                    'x-decorator': 'FormItem',
-                    'x-collection-field': 'departments.roles',
-                  },
-                  footer: {
-                    type: 'void',
-                    'x-component': 'Action.Drawer.Footer',
-                    properties: {
-                      cancel: {
-                        title: '{{t("Cancel")}}',
-                        'x-component': 'Action',
-                        'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
-                      },
-                      submit: {
-                        title: '{{t("Submit")}}',
-                        'x-component': 'Action',
-                        'x-component-props': { type: 'primary', useAction: '{{ useCreateDepartment }}' },
-                      },
+  const { t: e } = useTranslation();
+  return jsx(SchemaComponent, {
+    scope: { t: e },
+    schema: {
+      type: 'void',
+      properties: {
+        newDepartment: {
+          type: 'void',
+          title: e('New department'),
+          'x-component': 'Action',
+          'x-component-props': { type: 'text', icon: 'PlusOutlined', style: { width: '100%', textAlign: 'left' } },
+          properties: {
+            drawer: {
+              type: 'void',
+              'x-component': 'Action.Drawer',
+              'x-decorator': 'Form',
+              title: e('New department'),
+              properties: {
+                title: { 'x-component': 'CollectionField', 'x-decorator': 'FormItem', required: true },
+                parent: {
+                  'x-component': 'CollectionField',
+                  'x-decorator': 'FormItem',
+                  'x-collection-field': 'departments.parent',
+                  'x-component-props': { component: 'DepartmentSelect' },
+                },
+                roles: {
+                  'x-component': 'CollectionField',
+                  'x-decorator': 'FormItem',
+                  'x-collection-field': 'departments.roles',
+                },
+                footer: {
+                  type: 'void',
+                  'x-component': 'Action.Drawer.Footer',
+                  properties: {
+                    cancel: {
+                      title: '{{t("Cancel")}}',
+                      'x-component': 'Action',
+                      'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
+                    },
+                    submit: {
+                      title: '{{t("Submit")}}',
+                      'x-component': 'Action',
+                      'x-component-props': { type: 'primary', useAction: '{{ useCreateDepartment }}' },
                     },
                   },
                 },
@@ -140,123 +141,124 @@ const xe = () => {
           },
         },
       },
-    });
-  },
-  ye = {
-    type: 'object',
-    properties: {
-      [uid()]: {
-        type: 'void',
-        'x-component': 'Action.Drawer',
-        'x-decorator': 'Form',
-        'x-decorator-props': {
-          useValues(e) {
-            const t = useActionContext(),
-              o = useRecord();
-            return useRequest(
-              () => Promise.resolve({ data: { parent: y({}, o) } }),
-              T(y({}, e), { refreshDeps: [t.visible] }),
-            );
-          },
+    },
+  });
+};
+const ye = {
+  type: 'object',
+  properties: {
+    [uid()]: {
+      type: 'void',
+      'x-component': 'Action.Drawer',
+      'x-decorator': 'Form',
+      'x-decorator-props': {
+        useValues(e) {
+          const t = useActionContext(),
+            o = useRecord();
+          return useRequest(
+            () => Promise.resolve({ data: { parent: { ...o } } }),
+            T({ ...e }, { refreshDeps: [t.visible] }),
+          );
         },
-        title: '{{t("New sub department")}}',
-        properties: {
-          title: { 'x-component': 'CollectionField', 'x-decorator': 'FormItem' },
-          parent: {
-            'x-component': 'CollectionField',
-            'x-decorator': 'FormItem',
-            'x-collection-field': 'departments.parent',
-            'x-component-props': { component: 'DepartmentSelect' },
-          },
-          roles: {
-            'x-component': 'CollectionField',
-            'x-decorator': 'FormItem',
-            'x-collection-field': 'departments.roles',
-          },
-          footer: {
-            type: 'void',
-            'x-component': 'Action.Drawer.Footer',
-            properties: {
-              cancel: {
-                title: '{{t("Cancel")}}',
-                'x-component': 'Action',
-                'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
-              },
-              submit: {
-                title: '{{t("Submit")}}',
-                'x-component': 'Action',
-                'x-component-props': { type: 'primary', useAction: '{{ useCreateDepartment }}' },
-              },
+      },
+      title: '{{t("New sub department")}}',
+      properties: {
+        title: { 'x-component': 'CollectionField', 'x-decorator': 'FormItem' },
+        parent: {
+          'x-component': 'CollectionField',
+          'x-decorator': 'FormItem',
+          'x-collection-field': 'departments.parent',
+          'x-component-props': { component: 'DepartmentSelect' },
+        },
+        roles: {
+          'x-component': 'CollectionField',
+          'x-decorator': 'FormItem',
+          'x-collection-field': 'departments.roles',
+        },
+        footer: {
+          type: 'void',
+          'x-component': 'Action.Drawer.Footer',
+          properties: {
+            cancel: {
+              title: '{{t("Cancel")}}',
+              'x-component': 'Action',
+              'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
+            },
+            submit: {
+              title: '{{t("Submit")}}',
+              'x-component': 'Action',
+              'x-component-props': { type: 'primary', useAction: '{{ useCreateDepartment }}' },
             },
           },
         },
       },
     },
   },
-  he = {
-    type: 'object',
-    properties: {
-      [uid()]: {
-        type: 'void',
-        'x-component': 'Action.Drawer',
-        'x-decorator': 'Form',
-        'x-decorator-props': {
-          useValues(e) {
-            const t = useAPIClient(),
-              o = useActionContext(),
-              a = useRecord(),
-              r = useRequest(
-                () =>
-                  t
-                    .resource('departments')
-                    .get({ filterByTk: a.id, appends: ['parent(recursively=true)', 'roles', 'owners'] })
-                    .then((c) => (c == null ? void 0 : c.data)),
-                T(y({}, e), { manual: true }),
-              );
-            return (
-              useEffect(() => {
-                o.visible && r.run();
-              }, [o.visible]),
-              r
+};
+const he = {
+  type: 'object',
+  properties: {
+    [uid()]: {
+      type: 'void',
+      'x-component': 'Action.Drawer',
+      'x-decorator': 'Form',
+      'x-decorator-props': {
+        useValues(e) {
+          const t = useAPIClient(),
+            o = useActionContext(),
+            a = useRecord(),
+            r = useRequest(
+              () =>
+                t
+                  .resource('departments')
+                  .get({ filterByTk: a.id, appends: ['parent(recursively=true)', 'roles', 'owners'] })
+                  .then((c) => (c == null ? void 0 : c.data)),
+              T({ ...e }, { manual: true }),
             );
-          },
+          return (
+            useEffect(() => {
+              o.visible && r.run();
+            }, [o.visible]),
+            r
+          );
         },
-        title: '{{t("Edit department")}}',
-        properties: {
-          title: { 'x-component': 'CollectionField', 'x-decorator': 'FormItem' },
-          parent: {
-            'x-component': 'CollectionField',
-            'x-decorator': 'FormItem',
-            'x-collection-field': 'departments.parent',
-            'x-component-props': { component: 'SuperiorDepartmentSelect' },
-          },
-          roles: {
-            'x-component': 'CollectionField',
-            'x-decorator': 'FormItem',
-            'x-collection-field': 'departments.roles',
-          },
-          owners: { title: '{{t("Owners")}}', 'x-component': 'DepartmentOwnersField', 'x-decorator': 'FormItem' },
-          footer: {
-            type: 'void',
-            'x-component': 'Action.Drawer.Footer',
-            properties: {
-              cancel: {
-                title: '{{t("Cancel")}}',
-                'x-component': 'Action',
-                'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
-              },
-              submit: {
-                title: '{{t("Submit")}}',
-                'x-component': 'Action',
-                'x-component-props': { type: 'primary', useAction: '{{ useUpdateDepartment }}' },
-              },
+      },
+      title: '{{t("Edit department")}}',
+      properties: {
+        title: { 'x-component': 'CollectionField', 'x-decorator': 'FormItem' },
+        parent: {
+          'x-component': 'CollectionField',
+          'x-decorator': 'FormItem',
+          'x-collection-field': 'departments.parent',
+          'x-component-props': { component: 'SuperiorDepartmentSelect' },
+        },
+        roles: {
+          'x-component': 'CollectionField',
+          'x-decorator': 'FormItem',
+          'x-collection-field': 'departments.roles',
+        },
+        owners: { title: '{{t("Owners")}}', 'x-component': 'DepartmentOwnersField', 'x-decorator': 'FormItem' },
+        footer: {
+          type: 'void',
+          'x-component': 'Action.Drawer.Footer',
+          properties: {
+            cancel: {
+              title: '{{t("Cancel")}}',
+              'x-component': 'Action',
+              'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
+            },
+            submit: {
+              title: '{{t("Submit")}}',
+              'x-component': 'Action',
+              'x-component-props': { type: 'primary', useAction: '{{ useUpdateDepartment }}' },
             },
           },
         },
       },
     },
   },
-  fe = {
+};
+const fe = {
     type: 'void',
     properties: {
       drawer: {
@@ -410,218 +412,218 @@ const xe = () => {
         },
       },
     ],
-  },
-  ve = {
-    name: 'users',
-    fields: [
-      {
-        name: 'id',
-        type: 'bigInt',
-        autoIncrement: true,
-        primaryKey: true,
-        allowNull: !1,
-        uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },
-        interface: 'id',
-      },
-      {
-        interface: 'input',
-        type: 'string',
-        name: 'nickname',
-        uiSchema: { type: 'string', title: '{{t("Nickname")}}', 'x-component': 'Input' },
-      },
-      {
-        interface: 'input',
-        type: 'string',
-        name: 'username',
-        unique: true,
-        uiSchema: {
-          type: 'string',
-          title: '{{t("Username")}}',
-          'x-component': 'Input',
-          'x-validator': { username: true },
-          required: true,
-        },
-      },
-      {
-        interface: 'email',
-        type: 'string',
-        name: 'email',
-        unique: true,
-        uiSchema: {
-          type: 'string',
-          title: '{{t("Email")}}',
-          'x-component': 'Input',
-          'x-validator': 'email',
-          required: true,
-        },
-      },
-      {
-        interface: 'phone',
-        type: 'string',
-        name: 'phone',
-        unique: true,
-        uiSchema: {
-          type: 'string',
-          title: '{{t("Phone")}}',
-          'x-component': 'Input',
-          'x-validator': 'phone',
-          required: true,
-        },
-      },
-      {
-        interface: 'm2m',
-        type: 'belongsToMany',
-        name: 'roles',
-        target: 'roles',
-        foreignKey: 'userId',
-        otherKey: 'roleName',
-        onDelete: 'CASCADE',
-        sourceKey: 'id',
-        targetKey: 'name',
-        through: 'rolesUsers',
-        uiSchema: {
-          type: 'array',
-          title: '{{t("Roles")}}',
-          'x-component': 'AssociationField',
-          'x-component-props': { multiple: true, fieldNames: { label: 'title', value: 'name' } },
-        },
-      },
-      {
-        name: 'departments',
-        type: 'belongsToMany',
-        interface: 'm2m',
-        target: 'departments',
-        foreignKey: 'userId',
-        otherKey: 'departmentId',
-        onDelete: 'CASCADE',
-        sourceKey: 'id',
-        targetKey: 'id',
-        through: 'departmentsUsers',
-        uiSchema: { type: 'array', title: '{{t("Departments")}}', 'x-component': 'DepartmentField' },
-      },
-      {
-        interface: 'm2m',
-        type: 'belongsToMany',
-        name: 'mainDepartment',
-        target: 'departments',
-        foreignKey: 'userId',
-        otherKey: 'departmentId',
-        onDelete: 'CASCADE',
-        sourceKey: 'id',
-        targetKey: 'id',
-        through: 'departmentsUsers',
-        throughScope: { isMain: true },
-        uiSchema: { type: 'array', title: '{{t("Main department")}}', 'x-component': 'DepartmentField' },
-      },
-    ],
-  },
-  K = React.createContext({ user: {}, department: {} }),
-  ge = (e) => {
-    const [t, o] = useState(null),
-      [a, r] = useState(null),
-      c = useRequest({
-        resource: 'users',
-        action: 'list',
-        params: {
-          appends: ['departments', 'departments.parent(recursively=true)'],
-          filter: a ? { 'departments.id': a.id } : {},
-          pageSize: 50,
-        },
-      });
-    useEffect(() => {
-      c.run();
-    }, [a]);
-    const i = { resource: 'departments', action: 'list', params: { pagination: !1, filter: { parentId: null } } },
-      x = useRequest(i);
-    return jsxRuntime.jsx(K.Provider, {
-      value: {
-        user: t,
-        setUser: o,
-        department: a,
-        setDepartment: r,
-        usersResource: { service: c },
-        departmentsResource: { service: x },
-      },
-      children: e.children,
-    });
-  },
-  Ce = (e) => {
-    const { departmentsResource: t } = useContext(K),
-      { service: o } = t || {};
-    return jsxRuntime.jsx(ResourceActionContext.Provider, {
-      value: y({}, o),
-      children: jsxRuntime.jsx(CollectionProvider_deprecated, { collection: Q, children: e.children }),
-    });
-  },
-  be = (e) => {
-    const { usersResource: t } = useContext(K),
-      { service: o } = t || {};
-    return jsxRuntime.jsx(ResourceActionContext.Provider, {
-      value: y({}, o),
-      children: jsxRuntime.jsx(CollectionProvider_deprecated, { collection: ve, children: e.children }),
-    });
-  },
-  X = () => {
-    const { data: e, loading: t } = useResourceActionContext(),
-      { department: o, setDepartment: a, setUser: r } = useContext(K),
-      {
-        treeData: c,
-        nodeMap: i,
-        loadData: x,
-        loadedKeys: m,
-        setLoadedKeys: g,
-        initData: d,
-        expandedKeys: A,
-        setExpandedKeys: b,
-      } = useContext(_),
-      h = (v) => {
-        if (!v.length) return;
-        const l = i[v[0]];
-        a(l), r(null);
-      },
-      F = (v) => {
-        b(v);
-      },
-      C = (v) => {
-        g(v);
-      };
-    return (
-      useEffect(() => {
-        d(e == null ? void 0 : e.data);
-      }, [e, d, t]),
-      useEffect(() => {
-        if (!o) return;
-        const v = (u) => (u.parent ? [u.parent.id, ...v(u.parent)] : []),
-          l = v(o);
-        b((u) => Array.from(new Set([...u, ...l])));
-      }, [o, b]),
-      jsxRuntime.jsx('div', {
-        className: css`
-          height: 57vh;
-          overflow: auto;
-          .ant-tree-node-content-wrapper {
-            overflow: hidden;
-          }
-        `,
-        children:
-          c != null && c.length
-            ? jsxRuntime.jsx(Tree.DirectoryTree, {
-                loadData: x,
-                treeData: c,
-                loadedKeys: m,
-                onSelect: h,
-                selectedKeys: [o == null ? void 0 : o.id],
-                onExpand: F,
-                onLoad: C,
-                expandedKeys: A,
-                expandAction: !1,
-                showIcon: !1,
-                fieldNames: { key: 'id' },
-              })
-            : jsxRuntime.jsx(Empty, { image: Empty.PRESENTED_IMAGE_SIMPLE }),
-      })
-    );
   };
+const ve = {
+  name: 'users',
+  fields: [
+    {
+      name: 'id',
+      type: 'bigInt',
+      autoIncrement: true,
+      primaryKey: true,
+      allowNull: false,
+      uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },
+      interface: 'id',
+    },
+    {
+      interface: 'input',
+      type: 'string',
+      name: 'nickname',
+      uiSchema: { type: 'string', title: '{{t("Nickname")}}', 'x-component': 'Input' },
+    },
+    {
+      interface: 'input',
+      type: 'string',
+      name: 'username',
+      unique: true,
+      uiSchema: {
+        type: 'string',
+        title: '{{t("Username")}}',
+        'x-component': 'Input',
+        'x-validator': { username: true },
+        required: true,
+      },
+    },
+    {
+      interface: 'email',
+      type: 'string',
+      name: 'email',
+      unique: true,
+      uiSchema: {
+        type: 'string',
+        title: '{{t("Email")}}',
+        'x-component': 'Input',
+        'x-validator': 'email',
+        required: true,
+      },
+    },
+    {
+      interface: 'phone',
+      type: 'string',
+      name: 'phone',
+      unique: true,
+      uiSchema: {
+        type: 'string',
+        title: '{{t("Phone")}}',
+        'x-component': 'Input',
+        'x-validator': 'phone',
+        required: true,
+      },
+    },
+    {
+      interface: 'm2m',
+      type: 'belongsToMany',
+      name: 'roles',
+      target: 'roles',
+      foreignKey: 'userId',
+      otherKey: 'roleName',
+      onDelete: 'CASCADE',
+      sourceKey: 'id',
+      targetKey: 'name',
+      through: 'rolesUsers',
+      uiSchema: {
+        type: 'array',
+        title: '{{t("Roles")}}',
+        'x-component': 'AssociationField',
+        'x-component-props': { multiple: true, fieldNames: { label: 'title', value: 'name' } },
+      },
+    },
+    {
+      name: 'departments',
+      type: 'belongsToMany',
+      interface: 'm2m',
+      target: 'departments',
+      foreignKey: 'userId',
+      otherKey: 'departmentId',
+      onDelete: 'CASCADE',
+      sourceKey: 'id',
+      targetKey: 'id',
+      through: 'departmentsUsers',
+      uiSchema: { type: 'array', title: '{{t("Departments")}}', 'x-component': 'DepartmentField' },
+    },
+    {
+      interface: 'm2m',
+      type: 'belongsToMany',
+      name: 'mainDepartment',
+      target: 'departments',
+      foreignKey: 'userId',
+      otherKey: 'departmentId',
+      onDelete: 'CASCADE',
+      sourceKey: 'id',
+      targetKey: 'id',
+      through: 'departmentsUsers',
+      throughScope: { isMain: true },
+      uiSchema: { type: 'array', title: '{{t("Main department")}}', 'x-component': 'DepartmentField' },
+    },
+  ],
+};
+const K = React.createContext({ user: {}, department: {} });
+const ge = (e) => {
+  const [t, o] = useState(null),
+    [a, r] = useState(null),
+    c = useRequest({
+      resource: 'users',
+      action: 'list',
+      params: {
+        appends: ['departments', 'departments.parent(recursively=true)'],
+        filter: a ? { 'departments.id': a.id } : {},
+        pageSize: 50,
+      },
+    });
+  useEffect(() => {
+    c.run();
+  }, [a]);
+  const i = { resource: 'departments', action: 'list', params: { pagination: false, filter: { parentId: null } } },
+    x = useRequest(i);
+  return jsx(K.Provider, {
+    value: {
+      user: t,
+      setUser: o,
+      department: a,
+      setDepartment: r,
+      usersResource: { service: c },
+      departmentsResource: { service: x },
+    },
+    children: e.children,
+  });
+};
+const Ce = (e) => {
+  const { departmentsResource: t } = useContext(K),
+    { service: o } = t || {};
+  return jsx(ResourceActionContext.Provider, {
+    value: { ...o },
+    children: jsx(CollectionProvider_deprecated, { collection: Q, children: e.children }),
+  });
+};
+const be = (e) => {
+  const { usersResource: t } = useContext(K),
+    { service: o } = t || {};
+  return jsx(ResourceActionContext.Provider, {
+    value: { ...o },
+    children: jsx(CollectionProvider_deprecated, { collection: ve, children: e.children }),
+  });
+};
+const X = () => {
+  const { data: e, loading: t } = useResourceActionContext(),
+    { department: o, setDepartment: a, setUser: r } = useContext(K),
+    {
+      treeData: c,
+      nodeMap: i,
+      loadData: x,
+      loadedKeys: m,
+      setLoadedKeys: g,
+      initData: d,
+      expandedKeys: A,
+      setExpandedKeys: b,
+    } = useContext(_),
+    h = (v) => {
+      if (!v.length) return;
+      const l = i[v[0]];
+      a(l), r(null);
+    },
+    F = (v) => {
+      b(v);
+    },
+    C = (v) => {
+      g(v);
+    };
+  return (
+    useEffect(() => {
+      d(e == null ? void 0 : e.data);
+    }, [e, d, t]),
+    useEffect(() => {
+      if (!o) return;
+      const v = (u) => (u.parent ? [u.parent.id, ...v(u.parent)] : []),
+        l = v(o);
+      b((u) => Array.from(new Set([...u, ...l])));
+    }, [o, b]),
+    jsx('div', {
+      className: css`
+        height: 57vh;
+        overflow: auto;
+        .ant-tree-node-content-wrapper {
+          overflow: hidden;
+        }
+      `,
+      children:
+        c != null && c.length
+          ? jsx(Tree.DirectoryTree, {
+              loadData: x,
+              treeData: c,
+              loadedKeys: m,
+              onSelect: h,
+              selectedKeys: [o == null ? void 0 : o.id],
+              onExpand: F,
+              onLoad: C,
+              expandedKeys: A,
+              expandAction: false,
+              showIcon: false,
+              fieldNames: { key: 'id' },
+            })
+          : jsx(Empty, { image: Empty.PRESENTED_IMAGE_SIMPLE }),
+    })
+  );
+};
 X.Item = function ({ node: t, setVisible: o, setDrawer: a }) {
   const { t: r } = useTranslation(),
     { refreshAsync: c } = useResourceActionContext(),
@@ -657,14 +659,14 @@ X.Item = function ({ node: t, setVisible: o, setDrawer: a }) {
           b();
       }
     };
-  return jsxRuntime.jsxs('div', {
+  return jsxs('div', {
     style: { display: 'flex', justifyContent: 'space-between', overflow: 'hidden' },
     children: [
-      jsxRuntime.jsx('div', {
+      jsx('div', {
         style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
         children: t.title,
       }),
-      jsxRuntime.jsx(Dropdown, {
+      jsx(Dropdown, {
         menu: {
           items: [
             { label: r('New sub department'), key: 'new-sub' },
@@ -673,249 +675,249 @@ X.Item = function ({ node: t, setVisible: o, setDrawer: a }) {
           ],
           onClick: F,
         },
-        children: jsxRuntime.jsx('div', {
+        children: jsx('div', {
           style: { marginLeft: '15px' },
-          children: jsxRuntime.jsx(MoreOutlined, {}),
+          children: jsx(MoreOutlined, {}),
         }),
       }),
     ],
   });
 };
 const Ae = createStyles(({ css: e }) => ({
-    searchDropdown: e`
+  searchDropdown: e`
       .ant-dropdown-menu {
         max-height: 500px;
         overflow-y: scroll;
       }
     `,
-  })),
-  Se = () => {
-    const { t: e } = useTranslation(),
-      { token: t } = theme.useToken(),
-      { setDepartment: o, setUser: a } = useContext(K),
-      [r, c] = useState(!1),
-      [i, x] = useState(''),
-      [m, g] = useState([]),
-      [d, A] = useState([]),
-      [b, h] = useState(true),
-      [F, C] = useState(true),
-      { styles: v } = Ae(),
-      l = 10,
-      u = useAPIClient(),
-      f = useRequest(
-        (M) =>
-          u
-            .resource('departments')
-            .aggregateSearch(M)
-            .then((P) => {
-              var q;
-              return (q = P == null ? void 0 : P.data) == null ? void 0 : q.data;
-            }),
-        {
-          manual: true,
-          onSuccess: (M, P) => {
-            const {
-              values: { type: q },
-            } = P[0] || {};
-            M &&
-              ((!q || q === 'user') && M.users.length < l && h(!1),
-              (!q || q === 'department') && M.departments.length < l && C(!1),
-              g((se) => [...se, ...M.users]),
-              A((se) => [...se, ...M.departments]));
-          },
+}));
+const Se = () => {
+  const { t: e } = useTranslation(),
+    { token: t } = theme.useToken(),
+    { setDepartment: o, setUser: a } = useContext(K),
+    [r, c] = useState(false),
+    [i, x] = useState(''),
+    [m, g] = useState([]),
+    [d, A] = useState([]),
+    [b, h] = useState(true),
+    [F, C] = useState(true),
+    { styles: v } = Ae(),
+    l = 10,
+    u = useAPIClient(),
+    f = useRequest(
+      (M) =>
+        u
+          .resource('departments')
+          .aggregateSearch(M)
+          .then((P) => {
+            var q;
+            return (q = P == null ? void 0 : P.data) == null ? void 0 : q.data;
+          }),
+      {
+        manual: true,
+        onSuccess: (M, P) => {
+          const {
+            values: { type: q },
+          } = P[0] || {};
+          M &&
+            ((!q || q === 'user') && M.users.length < l && h(false),
+            (!q || q === 'department') && M.departments.length < l && C(false),
+            g((se) => [...se, ...M.users]),
+            A((se) => [...se, ...M.departments]));
         },
-      ),
-      { run: S } = f,
-      O = (M) => {
-        x(M), g([]), A([]), h(true), C(true), M && (S({ values: { keyword: M, limit: l } }), c(true));
       },
-      $ = (M) => {
-        M.target.value || (a(null), x(''), c(!1), f.mutate({}), g([]), A([]));
-      },
-      W = (M) => {
-        const P = M.title,
-          q = M.parent;
-        return q ? W(q) + ' / ' + P : P;
-      },
-      H = (M) =>
-        jsxRuntime.jsx(Button, {
-          type: 'link',
-          style: { padding: '0 8px' },
-          onClick: (P) => {
-            c(true), S({ values: y({ keyword: i, limit: l }, M) });
-          },
-          children: e('Load more'),
-        }),
-      J = () => {
-        const M = [];
-        return !m.length && !d.length
-          ? [
-              {
-                key: '0',
-                label: jsxRuntime.jsx(Empty, {
-                  description: e('No results'),
-                  image: Empty.PRESENTED_IMAGE_SIMPLE,
-                }),
-                disabled: true,
-              },
-            ]
-          : (m.length &&
-              (M.push({
-                key: '0',
-                type: 'group',
-                label: e('Users'),
-                children: m.map((P) => ({
-                  key: P.username,
-                  label: jsxRuntime.jsxs('div', {
-                    onClick: () => a(P),
-                    children: [
-                      jsxRuntime.jsx('div', { children: P.nickname || P.username }),
-                      jsxRuntime.jsx('div', {
-                        style: { fontSize: t.fontSizeSM, color: t.colorTextDescription },
-                        children: `${P.username}${P.phone ? ' | ' + P.phone : ''}${P.email ? ' | ' + P.email : ''}`,
-                      }),
-                    ],
-                  }),
-                })),
-              }),
-              b &&
-                M.push({
-                  type: 'group',
-                  key: '0-loadMore',
-                  label: jsxRuntime.jsx(H, { type: 'user', last: m[m.length - 1].id }),
-                })),
-            d.length &&
-              (M.push({
-                key: '1',
-                type: 'group',
-                label: e('Departments'),
-                children: d.map((P) => ({
-                  key: P.id,
-                  label: jsxRuntime.jsx('div', { onClick: () => o(P), children: W(P) }),
-                })),
-              }),
-              F &&
-                M.push({
-                  type: 'group',
-                  key: '1-loadMore',
-                  label: jsxRuntime.jsx(H, { type: 'department', last: d[d.length - 1].id }),
-                })),
-            M);
-      };
-    return jsxRuntime.jsx(Dropdown, {
-      menu: { items: J() },
-      overlayClassName: v.searchDropdown,
-      trigger: ['click'],
-      open: r,
-      onOpenChange: (M) => c(M),
-      children: jsxRuntime.jsx(Input.Search, {
-        allowClear: true,
-        onClick: () => {
-          i || c(!1);
+    ),
+    { run: S } = f,
+    O = (M) => {
+      x(M), g([]), A([]), h(true), C(true), M && (S({ values: { keyword: M, limit: l } }), c(true));
+    },
+    $ = (M) => {
+      M.target.value || (a(null), x(''), c(false), f.mutate({}), g([]), A([]));
+    },
+    W = (M) => {
+      const P = M.title,
+        q = M.parent;
+      return q ? W(q) + ' / ' + P : P;
+    },
+    H = (M) =>
+      jsx(Button, {
+        type: 'link',
+        style: { padding: '0 8px' },
+        onClick: (P) => {
+          c(true), S({ values: { keyword: i, limit: l, ...M } });
         },
-        onFocus: () => o(null),
-        onSearch: O,
-        onChange: $,
-        placeholder: e('Search for departments, users'),
-        style: { marginBottom: '20px' },
+        children: e('Load more'),
       }),
-    });
-  },
-  De = (e) => {
-    const { label: t } = e || {},
-      [o, a] = useState([]),
-      [r, c] = useState({}),
-      [i, x] = useState([]),
-      [m, g] = useState([]),
-      d = useCallback((C) => {
-        const v = {},
-          l = (f) => {
-            let S = f ? y({}, f) : null;
-            for (; S; ) {
-              const O = S.parentId || 'root';
-              v[O]
-                ? (v[O].childrenMap[S.id] = S)
-                : (v[O] = T(y({}, S.parent || { id: O }), { childrenMap: { [S.id]: S } })),
-                (S = S.parent);
-            }
-          },
-          u = (f) => {
-            const S = {};
-            f.children &&
-              f.children.length &&
-              f.children.forEach((O) => {
-                (S[O.id] = O), u(O);
+    J = () => {
+      const M = [];
+      return !m.length && !d.length
+        ? [
+            {
+              key: '0',
+              label: jsx(Empty, {
+                description: e('No results'),
+                image: Empty.PRESENTED_IMAGE_SIMPLE,
               }),
-              (v[f.id] = T(y({}, f), { childrenMap: S }));
-          };
-        return (
-          C &&
-            C.length &&
-            C.forEach((f) => {
-              l(f), u(f);
+              disabled: true,
+            },
+          ]
+        : (m.length &&
+            (M.push({
+              key: '0',
+              type: 'group',
+              label: e('Users'),
+              children: m.map((P) => ({
+                key: P.username,
+                label: jsxs('div', {
+                  onClick: () => a(P),
+                  children: [
+                    jsx('div', { children: P.nickname || P.username }),
+                    jsx('div', {
+                      style: { fontSize: t.fontSizeSM, color: t.colorTextDescription },
+                      children: `${P.username}${P.phone ? ' | ' + P.phone : ''}${P.email ? ' | ' + P.email : ''}`,
+                    }),
+                  ],
+                }),
+              })),
             }),
+            b &&
+              M.push({
+                type: 'group',
+                key: '0-loadMore',
+                label: jsx(H, { type: 'user', last: m[m.length - 1].id }),
+              })),
+          d.length &&
+            (M.push({
+              key: '1',
+              type: 'group',
+              label: e('Departments'),
+              children: d.map((P) => ({
+                key: P.id,
+                label: jsx('div', { onClick: () => o(P), children: W(P) }),
+              })),
+            }),
+            F &&
+              M.push({
+                type: 'group',
+                key: '1-loadMore',
+                label: jsx(H, { type: 'department', last: d[d.length - 1].id }),
+              })),
+          M);
+    };
+  return jsx(Dropdown, {
+    menu: { items: J() },
+    overlayClassName: v.searchDropdown,
+    trigger: ['click'],
+    open: r,
+    onOpenChange: (M) => c(M),
+    children: jsx(Input.Search, {
+      allowClear: true,
+      onClick: () => {
+        i || c(false);
+      },
+      onFocus: () => o(null),
+      onSearch: O,
+      onChange: $,
+      placeholder: e('Search for departments, users'),
+      style: { marginBottom: '20px' },
+    }),
+  });
+};
+const De = (e) => {
+  const { label: t } = e || {},
+    [o, a] = useState([]),
+    [r, c] = useState({}),
+    [i, x] = useState([]),
+    [m, g] = useState([]),
+    d = useCallback((C) => {
+      const v = {},
+        l = (f) => {
+          let S = f ? { ...f } : null;
+          for (; S; ) {
+            const O = S.parentId || 'root';
+            v[O]
+              ? (v[O].childrenMap[S.id] = S)
+              : (v[O] = T({ ...(S.parent || { id: O }) }, { childrenMap: { [S.id]: S } })),
+              (S = S.parent);
+          }
+        },
+        u = (f) => {
+          const S = {};
+          f.children &&
+            f.children.length &&
+            f.children.forEach((O) => {
+              (S[O.id] = O), u(O);
+            }),
+            (v[f.id] = T({ ...f }, { childrenMap: S }));
+        };
+      return (
+        C &&
+          C.length &&
+          C.forEach((f) => {
+            l(f), u(f);
+          }),
+        v
+      );
+    }, []),
+    A = useCallback((C) => {
+      const v = (l) => {
+        var u;
+        return !C[l] || C[l].isLeaf
+          ? null
+          : Object.values(((u = C[l]) == null ? void 0 : u.childrenMap) || {}).map((f: object) =>
+              T({ ...f }, { title: t ? React.createElement(t, { node: f }) : f.title, children: v(f.id) }),
+            );
+      };
+      return v('root');
+    }, []),
+    b = useCallback(
+      (C) => {
+        const v = d(C);
+        c(v);
+        const l = A(v) || [];
+        a(l);
+      },
+      [a, d, A],
+    ),
+    h = (C, v) => {
+      const l = d(v),
+        u = { ...l, ...r };
+      return (
+        v.forEach((f) => {
+          u[C].childrenMap[f.id] = f;
+        }),
+        c(u),
+        A(u)
+      );
+    },
+    F = useCallback(
+      (C) => {
+        if (!r[C]) return [];
+        const v = [];
+        return (
+          v.push(...Object.keys(r[C].childrenMap).map((l) => Number(l))),
+          Object.keys(r[C].childrenMap).forEach((l) => {
+            v.push(...F(l));
+          }),
           v
         );
-      }, []),
-      A = useCallback((C) => {
-        const v = (l) => {
-          var u;
-          return !C[l] || C[l].isLeaf
-            ? null
-            : Object.values(((u = C[l]) == null ? void 0 : u.childrenMap) || {}).map((f) =>
-                T(y({}, f), { title: t ? React.createElement(t, { node: f }) : f.title, children: v(f.id) }),
-              );
-        };
-        return v('root');
-      }, []),
-      b = useCallback(
-        (C) => {
-          const v = d(C);
-          c(v);
-          const l = A(v) || [];
-          a(l);
-        },
-        [a, d, A],
-      ),
-      h = (C, v) => {
-        const l = d(v),
-          u = y(y({}, l), r);
-        return (
-          v.forEach((f) => {
-            u[C].childrenMap[f.id] = f;
-          }),
-          c(u),
-          A(u)
-        );
       },
-      F = useCallback(
-        (C) => {
-          if (!r[C]) return [];
-          const v = [];
-          return (
-            v.push(...Object.keys(r[C].childrenMap).map((l) => Number(l))),
-            Object.keys(r[C].childrenMap).forEach((l) => {
-              v.push(...F(l));
-            }),
-            v
-          );
-        },
-        [r],
-      );
-    return {
-      initData: b,
-      treeData: o,
-      setTreeData: a,
-      nodeMap: r,
-      updateTreeData: h,
-      constructTreeData: A,
-      getChildrenIds: F,
-      loadedKeys: m,
-      setLoadedKeys: g,
-      expandedKeys: i,
-      setExpandedKeys: x,
-    };
+      [r],
+    );
+  return {
+    initData: b,
+    treeData: o,
+    setTreeData: a,
+    nodeMap: r,
+    updateTreeData: h,
+    constructTreeData: A,
+    getChildrenIds: F,
+    loadedKeys: m,
+    setLoadedKeys: g,
+    expandedKeys: i,
+    setExpandedKeys: x,
   };
+};
 function we(e) {
   return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, 'default') ? e.default : e;
 }
@@ -938,7 +940,7 @@ function ke(e) {
   return Array.isArray(e) ? [] : {};
 }
 function L(e, t) {
-  return t.clone !== !1 && t.isMergeableObject(e) ? B(ke(e), e, t) : e;
+  return t.clone !== false && t.isMergeableObject(e) ? B(ke(e), e, t) : e;
 }
 function Ee(e, t, o) {
   return e.concat(t).map(function (a) {
@@ -964,7 +966,7 @@ function ce(e, t) {
   try {
     return t in e;
   } catch (o) {
-    return !1;
+    return false;
   }
 }
 function qe(e, t) {
@@ -999,1184 +1001,1137 @@ B.all = function (t, o) {
     return B(a, r, o);
   }, {});
 };
-var je = B,
-  Ue = je;
-const ie = we(Ue),
-  G = (e) => {
-    const { resource: t = 'departments', resourceOf: o, params: a = {} } = e || {},
-      c = useAPIClient().resource(t, o),
-      i = De(e),
-      { setTreeData: x, updateTreeData: m, setLoadedKeys: g, initData: d } = i,
-      A = (C) =>
-        k(this, [C], function* ({ key: h, children: F }) {
-          var l;
-          if (F != null && F.length) return;
-          const { data: v } = yield c.list(
-            ie(a, { pagination: !1, appends: ['parent(recursively=true)'], filter: { parentId: h } }),
-          );
-          (l = v == null ? void 0 : v.data) != null && l.length && x(m(h, v == null ? void 0 : v.data));
-        }),
-      b = (h) =>
-        k(this, null, function* () {
-          const { data: F } = yield c.list(
-            ie(a, {
-              pagination: !1,
-              filter: { title: { $includes: h } },
-              appends: ['parent(recursively=true)'],
-              pageSize: 100,
-            }),
-          );
-          d(F == null ? void 0 : F.data);
-        });
-    return T(y({}, i), { loadData: A, getByKeyword: b });
-  },
-  Z = () => {
-    var a, r;
-    const e = useContext(CollectionContext),
-      t = useFilterFieldOptions(e.fields),
-      o = useResourceActionContext();
-    return useFilterFieldProps({
-      options: t,
-      params: ((r = (a = o.state) == null ? void 0 : a.params) == null ? void 0 : r[0]) || o.params,
-      service: o,
-    });
-  },
-  Be = () => {
-    const [e, t] = useState(!1),
-      o = useRecord(),
-      a = useField(),
-      [r, c] = useState([]),
-      i = useRef([]),
-      x = (d, A) => {
-        i.current = A;
-      },
-      m = () => {
-        const { setVisible: d } = useActionContext();
-        return {
-          run() {
-            const A = a.value || [];
-            a.setValue([...A, ...i.current]), (i.current = []), d(!1);
-          },
-        };
-      };
-    useEffect(() => {
-      a.value && c(a.value.map((d) => ({ value: d.id, label: d.nickname || d.username })));
-    }, [a.value]);
-    const g = (d) => {
-      var A;
-      return jsxRuntime.jsx(ResourceActionProvider, {
-        collection: 'users',
-        request: {
-          resource: `departments/${o.id}/members`,
-          action: 'list',
-          params: { filter: (A = a.value) != null && A.length ? { id: { $notIn: a.value.map((b) => b.id) } } : {} },
-        },
-        children: d.children,
+const je = B;
+const Ue = je;
+const ie = we(Ue);
+const G = (e) => {
+  const { resource: t = 'departments', resourceOf: o, params: a = {} } = e || {},
+    c = useAPIClient().resource(t, o),
+    i = De(e),
+    { setTreeData: x, updateTreeData: m, setLoadedKeys: g, initData: d } = i,
+    A = (C) =>
+      k(this, [C], function* ({ key: h, children: F }) {
+        var l;
+        if (F != null && F.length) return;
+        const { data: v } = yield c.list(
+          ie(a, { pagination: false, appends: ['parent(recursively=true)'], filter: { parentId: h } }),
+        );
+        (l = v == null ? void 0 : v.data) != null && l.length && x(m(h, v == null ? void 0 : v.data));
+      }),
+    b = (h) =>
+      k(this, null, function* () {
+        const { data: F } = yield c.list(
+          ie(a, {
+            pagination: false,
+            filter: { title: { $includes: h } },
+            appends: ['parent(recursively=true)'],
+            pageSize: 100,
+          }),
+        );
+        d(F == null ? void 0 : F.data);
       });
-    };
-    return jsxRuntime.jsxs(ActionContextProvider, {
-      value: { visible: e, setVisible: t },
-      children: [
-        jsxRuntime.jsx(Select, {
-          open: !1,
-          onChange: (d) => {
-            if (!d) {
-              a.setValue([]);
-              return;
-            }
-            a.setValue(d.map(({ label: A, value: b }) => ({ id: b, nickname: A })));
-          },
-          mode: 'multiple',
-          value: r,
-          labelInValue: true,
-          onDropdownVisibleChange: (d) => t(d),
-        }),
-        jsxRuntime.jsx(SchemaComponent, {
-          schema: fe,
-          components: { RequestProvider: g },
-          scope: { department: o, handleSelect: x, useSelectOwners: m },
-        }),
-      ],
-    });
-  },
-  _ = React.createContext({}),
-  $e = () => {
-    const e = useForm(),
-      t = useField(),
-      o = useActionContext(),
-      { refreshAsync: a } = useResourceActionContext(),
-      r = useAPIClient(),
-      { expandedKeys: c, setLoadedKeys: i, setExpandedKeys: x } = useContext(_);
-    return {
-      run() {
-        return k(this, null, function* () {
-          try {
-            yield e.submit(),
-              (t.data = t.data || {}),
-              (t.data.loading = true),
-              yield r.resource('departments').create({ values: e.values }),
-              o.setVisible(!1),
-              yield e.reset(),
-              (t.data.loading = !1);
-            const g = [...c];
-            i([]), x([]), yield a(), x(g);
-          } catch (g) {
-            t.data && (t.data.loading = !1);
-          }
-        });
-      },
-    };
-  },
-  Le = () => {
-    const e = useField(),
-      t = useForm(),
-      o = useActionContext(),
-      { refreshAsync: a } = useResourceActionContext(),
-      r = useAPIClient(),
-      { id: c } = useRecord(),
-      { expandedKeys: i, setLoadedKeys: x, setExpandedKeys: m } = useContext(_),
-      { department: g, setDepartment: d } = useContext(K);
-    return {
-      run() {
-        return k(this, null, function* () {
-          yield t.submit(), (e.data = e.data || {}), (e.data.loading = true);
-          try {
-            yield r.resource('departments').update({ filterByTk: c, values: t.values }),
-              d(y({ department: g }, t.values)),
-              o.setVisible(!1),
-              yield t.reset();
-            const b = [...i];
-            x([]), m([]), yield a(), m(b);
-          } catch (b) {
-            console.log(b);
-          } finally {
-            e.data.loading = !1;
-          }
-        });
-      },
-    };
-  },
-  _e = () => {
-    const { t: e } = useTranslation(),
-      [t, o] = useState(!1),
-      [a, r] = useState({}),
-      { department: c, setDepartment: i } = useContext(K),
-      { token: x } = theme.useToken(),
-      m = G({ label: ({ node: g }) => jsxRuntime.jsx(X.Item, { node: g, setVisible: o, setDrawer: r }) });
-    return jsxRuntime.jsx(SchemaComponentOptions, {
-      scope: { useCreateDepartment: $e, useUpdateDepartment: Le },
-      children: jsxRuntime.jsxs(_.Provider, {
-        value: m,
-        children: [
-          jsxRuntime.jsxs(Row, {
-            children: [
-              jsxRuntime.jsx(Se, {}),
-              jsxRuntime.jsx(Button, {
-                type: 'text',
-                icon: jsxRuntime.jsx(UserOutlined, {}),
-                style: { textAlign: 'left', marginBottom: '5px', background: c ? '' : x.colorBgTextHover },
-                onClick: () => {
-                  i(null);
-                },
-                block: true,
-                children: e('All users'),
-              }),
-              jsxRuntime.jsx(xe, {}),
-            ],
-          }),
-          jsxRuntime.jsx(Divider, { style: { margin: '12px 0' } }),
-          jsxRuntime.jsx(X, {}),
-          jsxRuntime.jsx(ActionContextProvider, {
-            value: { visible: t, setVisible: o },
-            children: jsxRuntime.jsx(RecordProvider, {
-              record: a.node || {},
-              children: jsxRuntime.jsx(SchemaComponent, {
-                scope: { t: e },
-                components: { DepartmentOwnersField: Be },
-                schema: a.schema || {},
-              }),
-            }),
-          }),
-        ],
-      }),
-    });
-  },
-  ze = {
-    type: 'void',
-    'x-component': 'Space',
-    properties: {
-      remove: {
-        type: 'void',
-        title: '{{t("Remove")}}',
-        'x-component': 'Action',
-        'x-component-props': {
-          icon: 'UserDeleteOutlined',
-          confirm: {
-            title: "{{t('Remove members')}}",
-            content: "{{t('Are you sure you want to remove these members?')}}",
-          },
-          style: { marginRight: 8 },
-          useAction: '{{ useBulkRemoveMembersAction }}',
-        },
-      },
-      create: {
-        type: 'void',
-        title: '{{t("Add members")}}',
-        'x-component': 'Action',
-        'x-component-props': { type: 'primary', icon: 'UserAddOutlined' },
-        properties: { drawer: { type: 'void', 'x-component': 'AddMembers' } },
-      },
+  return T({ ...i }, { loadData: A, getByKeyword: b });
+};
+const Z = () => {
+  var a, r;
+  const e = useContext(CollectionContext),
+    t = useFilterFieldOptions(e.fields),
+    o = useResourceActionContext();
+  return useFilterFieldProps({
+    options: t,
+    params: ((r = (a = o.state) == null ? void 0 : a.params) == null ? void 0 : r[0]) || o.params,
+    service: o,
+  });
+};
+const Be = () => {
+  const [e, t] = useState(false),
+    o = useRecord(),
+    a = useField(),
+    [r, c] = useState([]),
+    i = useRef([]),
+    x = (d, A) => {
+      i.current = A;
     },
-  },
-  We = {
-    type: 'void',
-    properties: {
-      remove: {
-        title: '{{ t("Remove") }}',
-        'x-component': 'Action.Link',
-        'x-component-props': {
-          confirm: { title: "{{t('Remove member')}}", content: "{{t('Are you sure you want to remove it?')}}" },
-          useAction: '{{ useRemoveMemberAction }}',
+    m = () => {
+      const { setVisible: d } = useActionContext();
+      return {
+        run() {
+          const A = a.value || [];
+          a.setValue([...A, ...i.current]), (i.current = []), d(false);
         },
-      },
-    },
-  },
-  He = (e, t) => ({
-    type: 'void',
-    properties: T(
-      y(
-        {},
-        t
-          ? {}
-          : {
-              actions: {
-                type: 'void',
-                'x-component': 'ActionBar',
-                'x-component-props': { style: { marginBottom: 16 } },
-                properties: {
-                  [uid()]: {
-                    type: 'void',
-                    title: '{{ t("Filter") }}',
-                    'x-action': 'filter',
-                    'x-component': 'Filter.Action',
-                    'x-use-component-props': 'useFilterActionProps',
-                    'x-component-props': { icon: 'FilterOutlined' },
-                    'x-align': 'left',
-                  },
-                  actions: { type: 'void', 'x-component': 'MemberActions' },
-                },
-              },
-            },
-      ),
-      {
-        table: {
-          type: 'void',
-          'x-component': 'Table.Void',
-          'x-component-props': {
-            rowKey: 'id',
-            rowSelection: { type: 'checkbox' },
-            useDataSource: '{{ useMembersDataSource }}',
-            pagination: { showTotal: '{{ useShowTotal }}' },
-          },
-          properties: T(
-            y(
-              {
-                nickname: {
-                  type: 'void',
-                  'x-decorator': 'Table.Column.Decorator',
-                  'x-component': 'Table.Column',
-                  properties: { nickname: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
-                },
-                username: {
-                  type: 'void',
-                  'x-decorator': 'Table.Column.Decorator',
-                  'x-component': 'Table.Column',
-                  properties: { username: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
-                },
-                departments: {
-                  type: 'void',
-                  'x-decorator': 'Table.Column.Decorator',
-                  'x-component': 'Table.Column',
-                  properties: {
-                    departments: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true },
-                  },
-                },
-              },
-              e
-                ? {
-                    isOwner: {
-                      type: 'void',
-                      'x-decorator': 'Table.Column.Decorator',
-                      'x-component': 'Table.Column',
-                      'x-component-props': { style: { minWidth: 100 } },
-                      title: '{{t("Owner")}}',
-                      properties: { isOwner: { type: 'boolean', 'x-component': 'IsOwnerField' } },
-                    },
-                  }
-                : {},
-            ),
-            {
-              phone: {
-                type: 'void',
-                'x-decorator': 'Table.Column.Decorator',
-                'x-component': 'Table.Column',
-                properties: { phone: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
-              },
-              email: {
-                type: 'void',
-                'x-decorator': 'Table.Column.Decorator',
-                'x-component': 'Table.Column',
-                properties: { email: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
-              },
-              actions: {
-                type: 'void',
-                title: '{{t("Actions")}}',
-                'x-component': 'Table.Column',
-                properties: {
-                  actions: {
-                    type: 'void',
-                    'x-component': 'Space',
-                    'x-component-props': { split: '|' },
-                    properties: y(
-                      {
-                        update: {
-                          type: 'void',
-                          title: '{{t("Configure")}}',
-                          'x-component': 'Action.Link',
-                          'x-component-props': { type: 'primary' },
-                          properties: {
-                            drawer: {
-                              type: 'void',
-                              'x-component': 'Action.Drawer',
-                              'x-decorator': 'FormV2',
-                              title: '{{t("Configure")}}',
-                              properties: {
-                                departments: {
-                                  title: '{{t("Departments")}}',
-                                  'x-decorator': 'FormItem',
-                                  'x-component': 'UserDepartmentsField',
-                                },
-                              },
-                            },
-                          },
-                        },
-                      },
-                      e ? { remove: { type: 'void', 'x-component': 'RowRemoveAction' } } : {},
-                    ),
-                  },
-                },
-              },
-            },
-          ),
-        },
-      },
-    ),
-  }),
-  Ge = {
-    type: 'object',
-    properties: {
-      drawer: {
-        type: 'void',
-        'x-component': 'Action.Drawer',
-        'x-decorator': 'Form',
-        title: '{{t("Add members")}}',
-        properties: {
-          resource: {
-            type: 'void',
-            'x-decorator': 'FormItem',
-            'x-component': 'ResourceActionProvider',
-            'x-component-props': {
-              collection: 'users',
-              request: {
-                resource: 'users',
-                action: 'listExcludeDept',
-                params: { departmentId: '{{ department?.id }}' },
-              },
-            },
-            properties: {
-              actions: {
-                type: 'void',
-                'x-component': 'ActionBar',
-                'x-component-props': { style: { marginBottom: 16 } },
-                properties: {
-                  filter: {
-                    type: 'void',
-                    title: '{{ t("Filter") }}',
-                    default: { $and: [{ username: { $includes: '' } }, { nickname: { $includes: '' } }] },
-                    'x-action': 'filter',
-                    'x-component': 'Filter.Action',
-                    'x-use-component-props': 'useFilterActionProps',
-                    'x-component-props': { icon: 'FilterOutlined' },
-                    'x-align': 'left',
-                  },
-                },
-              },
-              table: {
-                type: 'void',
-                'x-component': 'Table.Void',
-                'x-component-props': {
-                  rowKey: 'id',
-                  rowSelection: { type: 'checkbox', onChange: '{{ handleSelect }}' },
-                  useDataSource: '{{ cm.useDataSourceFromRAC }}',
-                },
-                properties: {
-                  username: {
-                    type: 'void',
-                    'x-decorator': 'Table.Column.Decorator',
-                    'x-component': 'Table.Column',
-                    properties: {
-                      username: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true },
-                    },
-                  },
-                  nickname: {
-                    type: 'void',
-                    'x-decorator': 'Table.Column.Decorator',
-                    'x-component': 'Table.Column',
-                    properties: {
-                      nickname: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true },
-                    },
-                  },
-                  phone: {
-                    type: 'void',
-                    'x-decorator': 'Table.Column.Decorator',
-                    'x-component': 'Table.Column',
-                    properties: { phone: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
-                  },
-                  email: {
-                    type: 'void',
-                    'x-decorator': 'Table.Column.Decorator',
-                    'x-component': 'Table.Column',
-                    properties: { email: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
-                  },
-                },
-              },
-            },
-          },
-          footer: {
-            type: 'void',
-            'x-component': 'Action.Drawer.Footer',
-            properties: {
-              cancel: {
-                title: '{{t("Cancel")}}',
-                'x-component': 'Action',
-                'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
-              },
-              submit: {
-                title: '{{t("Submit")}}',
-                'x-component': 'Action',
-                'x-component-props': { type: 'primary', useAction: '{{ useAddMembersAction }}' },
-              },
-            },
-          },
-        },
-      },
-    },
-  },
-  Je = {
-    type: 'void',
-    properties: {
-      drawer: {
-        title: '{{t("Select Departments")}}',
-        'x-decorator': 'Form',
-        'x-component': 'Action.Drawer',
-        properties: {
-          table: {
-            type: 'void',
-            'x-decorator': 'FormItem',
-            'x-component': 'DepartmentTable',
-            'x-component-props': { useDataSource: '{{ useDataSource }}', useDisabled: '{{ useDisabled }}' },
-          },
-          footer: {
-            type: 'void',
-            'x-component': 'Action.Drawer.Footer',
-            properties: {
-              cancel: {
-                title: '{{t("Cancel")}}',
-                'x-component': 'Action',
-                'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
-              },
-              confirm: {
-                title: '{{t("Submit")}}',
-                'x-component': 'Action',
-                'x-component-props': { type: 'primary', useAction: '{{ useAddDepartments }}' },
-              },
-            },
-          },
-        },
-      },
-    },
-  },
-  z = (e) => {
-    const t = e.title,
-      o = e.parent;
-    return o ? z(o) + ' / ' + t : t;
-  },
-  Ye = () => {
-    const { setDepartment: e } = useContext(K),
-      o = useField().value || [],
-      a = o.reduce((c, i) => ((c[i.id] = i), c), {}),
-      r = o.map((c, i) =>
-        jsxRuntime.jsxs(
-          'span',
-          {
-            children: [
-              jsxRuntime.jsx('a', {
-                onClick: (x) => {
-                  x.preventDefault(), e(a[c.id]);
-                },
-                children: z(c),
-              }),
-              i !== o.length - 1
-                ? jsxRuntime.jsx('span', { style: { marginRight: 4, color: '#aaa' }, children: ',' })
-                : '',
-            ],
-          },
-          i,
-        ),
-      );
-    return jsxRuntime.jsx(EllipsisWithTooltip, { ellipsis: true, children: r });
-  },
-  Qe = () => {
-    const { department: e } = useContext(K),
-      o = (useRecord().departments || []).find((a) => (a == null ? void 0 : a.id) === (e == null ? void 0 : e.id));
-    return jsxRuntime.jsx(Checkbox.ReadPretty, { value: o == null ? void 0 : o.departmentsUsers.isOwner });
-  },
-  R = React.createContext({}),
-  Xe = () => {
-    const { setHasFilter: e, setExpandedKeys: t } = useContext(R),
-      { t: o } = useTranslation(),
-      a = useContext(CollectionContext),
-      r = useFilterFieldOptions(a.fields),
-      c = useResourceActionContext(),
-      { run: i, defaultRequest: x } = c,
-      m = useField(),
-      { params: g } = x || {};
-    return {
-      options: r,
-      onSubmit: (d) =>
-        k(this, null, function* () {
-          const A = g.filter,
-            b = removeNullCondition(d == null ? void 0 : d.filter);
-          i(T(y({}, g), { page: 1, pageSize: 10, filter: mergeFilter([b, A]) }));
-          const h = (b == null ? void 0 : b.$and) || (b == null ? void 0 : b.$or);
-          h != null && h.length
-            ? ((m.title = o('{{count}} filter items', { count: (h == null ? void 0 : h.length) || 0 })), e(true))
-            : ((m.title = o('Filter')), e(!1));
-        }),
-      onReset() {
-        i(
-          T(y({}, g || {}), {
-            filter: T(y({}, (g == null ? void 0 : g.filter) || {}), { parentId: null }),
-            page: 1,
-            pageSize: 10,
-          }),
-        ),
-          (m.title = o('Filter')),
-          e(!1),
-          t([]);
-      },
+      };
     };
-  },
-  Ze = () => ({ disabled: () => !1 }),
-  Re = ({ useDisabled: e = Ze }) => {
-    const { t } = useTranslation(),
-      o = useResourceActionContext();
-    console.log(o);
-    const { run: a, data: r, loading: c, defaultRequest: i } = o,
-      { resource: x, resourceOf: m, params: g } = i || {},
-      { treeData: d, initData: A, loadData: b } = G({ resource: x, resourceOf: m, params: g }),
-      h = useField(),
-      { disabled: F } = e(),
-      { hasFilter: C, expandedKeys: v, setExpandedKeys: l } = useContext(R);
-    useEffect(() => {
-      C || A(r == null ? void 0 : r.data);
-    }, [r, A, c, C]);
-    const u = {};
-    if ((g != null && g.pageSize && (u.defaultPageSize = g.pageSize), !u.total && r != null && r.meta)) {
-      const { count: f, page: S, pageSize: O } = r.meta;
-      (u.total = f), (u.current = S), (u.pageSize = O);
-    }
-    return jsxRuntime.jsx(Table, {
-      rowKey: 'id',
-      columns: [{ dataIndex: 'title', title: t('Department name'), render: (f, S) => (C ? z(S) : f) }],
-      rowSelection: {
-        selectedRowKeys: ((h == null ? void 0 : h.value) || []).map((f) => f.id),
-        onChange: (f, S) => {
-          var O;
-          return (O = h == null ? void 0 : h.setValue) == null ? void 0 : O.call(h, S);
-        },
-        getCheckboxProps: (f) => ({ disabled: F(f) }),
-      },
-      pagination: T(y({ showSizeChanger: true }, u), {
-        onChange(f, S) {
-          var O;
-          a(T(y({}, ((O = o == null ? void 0 : o.params) == null ? void 0 : O[0]) || {}), { page: f, pageSize: S }));
-        },
-      }),
-      dataSource: C ? (r == null ? void 0 : r.data) || [] : d,
-      expandable: {
-        onExpand: (f, S) => {
-          b({ key: S.id, children: S.children });
-        },
-        expandedRowKeys: v,
-        onExpandedRowsChange: (f) => l(f),
-      },
-    });
-  },
-  et = (e) => {
-    const [t, o] = useState([]),
-      [a, r] = useState(!1),
-      { useDataSource: c } = e,
-      i = c({ manual: true });
-    return (
-      useEffect(() => {
-        i.run({ filter: { parentId: null }, pageSize: 10 });
-      }, []),
-      jsxRuntime.jsx(ResourceActionContext.Provider, {
-        value: y({}, i),
-        children: jsxRuntime.jsx(CollectionProvider_deprecated, {
-          collection: Q,
-          children: jsxRuntime.jsx(R.Provider, {
-            value: { expandedKeys: t, setExpandedKeys: o, hasFilter: a, setHasFilter: r },
-            children: e.children,
-          }),
-        }),
-      })
-    );
-  },
-  pe = ({ useDataSource: e, useDisabled: t }) =>
-    jsxRuntime.jsx(SchemaComponent, {
-      scope: { useDisabled: t, useFilterActionProps: Xe },
-      components: { InternalDepartmentTable: Re, RequestProvider: et },
-      schema: {
-        type: 'void',
-        properties: {
-          [uid()]: {
-            type: 'void',
-            'x-component': 'RequestProvider',
-            'x-component-props': { useDataSource: e },
-            properties: {
-              actions: {
-                type: 'void',
-                'x-component': 'ActionBar',
-                'x-component-props': { style: { marginBottom: 16 } },
-                properties: {
-                  filter: {
-                    type: 'void',
-                    title: '{{ t("Filter") }}',
-                    default: { $and: [{ title: { $includes: '' } }] },
-                    'x-action': 'filter',
-                    'x-component': 'Filter.Action',
-                    'x-use-component-props': 'useFilterActionProps',
-                    'x-component-props': { icon: 'FilterOutlined' },
-                    'x-align': 'left',
-                  },
-                },
-              },
-              departments: {
-                type: 'array',
-                'x-component': 'InternalDepartmentTable',
-                'x-component-props': { useDisabled: '{{ useDisabled }}' },
-              },
-            },
-          },
-        },
-      },
-    }),
-  tt = (e) => {
-    const t = {
-        resource: 'departments',
+  useEffect(() => {
+    a.value && c(a.value.map((d) => ({ value: d.id, label: d.nickname || d.username })));
+  }, [a.value]);
+  const g = (d) => {
+    var A;
+    return jsx(ResourceActionProvider, {
+      collection: 'users',
+      request: {
+        resource: `departments/${o.id}/members`,
         action: 'list',
-        params: { appends: ['parent(recursively=true)'], sort: ['createdAt'] },
+        params: { filter: (A = a.value) != null && A.length ? { id: { $notIn: a.value.map((b) => b.id) } } : {} },
       },
-      o = useRequest(t, e);
-    return T(y({}, o), { defaultRequest: t });
-  },
-  ot = () => {
-    const { modal: e, message: t } = App.useApp(),
-      { t: o } = useTranslation(),
-      [a, r] = useState(!1),
-      c = useRecord(),
-      i = useField(),
-      { refresh: x } = useResourceActionContext(),
-      m = (l) =>
-        l != null && l.length
-          ? l.map((u) => {
-              var f, S;
-              return T(y({}, u), {
-                isMain: (f = u.departmentsUsers) == null ? void 0 : f.isMain,
-                isOwner: (S = u.departmentsUsers) == null ? void 0 : S.isOwner,
-                title: z(u),
-              });
-            })
-          : [],
-      g = useAPIClient();
-    useRequest(
-      () =>
-        g
-          .resource('users.departments', c.id)
-          .list({ appends: ['parent(recursively=true)'], pagination: !1 })
-          .then((l) => {
-            var f;
-            const u = m((f = l == null ? void 0 : l.data) == null ? void 0 : f.data);
-            i.setValue(u);
-          }),
-      { ready: c.id },
-    );
-    const d = () => {
-        const l = useAPIClient(),
-          u = useForm(),
-          { departments: f } = u.values || {};
-        return {
-          run() {
-            return k(this, null, function* () {
-              yield l.resource('users.departments', c.id).add({ values: f.map((O) => O.id) }),
-                u.reset(),
-                i.setValue([
-                  ...i.value,
-                  ...f.map((O, $) => T(y({}, O), { isMain: $ === 0 && i.value.length === 0, title: z(O) })),
-                ]),
-                r(!1),
-                x();
-            });
-          },
-        };
-      },
-      A = (l) => {
-        e.confirm({
-          title: o('Remove department'),
-          content: o('Are you sure you want to remove it?'),
-          onOk: () =>
-            k(this, null, function* () {
-              yield g.resource('users.departments', c.id).remove({ values: [l.id] }),
-                t.success(o('Deleted successfully')),
-                i.setValue(
-                  i.value
-                    .filter((u) => u.id !== l.id)
-                    .map((u, f) => T(y({}, u), { isMain: (l.isMain && f === 0) || u.isMain })),
-                ),
-                x();
-            }),
-        });
-      },
-      b = (l) =>
-        k(this, null, function* () {
-          yield g.resource('users').setMainDepartment({ values: { userId: c.id, departmentId: l.id } }),
-            t.success(o('Set successfully')),
-            i.setValue(i.value.map((u) => T(y({}, u), { isMain: u.id === l.id }))),
-            x();
-        }),
-      h = (l) =>
-        k(this, null, function* () {
-          yield g.resource('departments').setOwner({ values: { userId: c.id, departmentId: l.id } }),
-            t.success(o('Set successfully')),
-            i.setValue(i.value.map((u) => T(y({}, u), { isOwner: u.id === l.id ? true : u.isOwner }))),
-            x();
-        }),
-      F = (l) =>
-        k(this, null, function* () {
-          yield g.resource('departments').removeOwner({ values: { userId: c.id, departmentId: l.id } }),
-            t.success(o('Set successfully')),
-            i.setValue(i.value.map((u) => T(y({}, u), { isOwner: u.id === l.id ? !1 : u.isOwner }))),
-            x();
-        }),
-      C = (l, u) => {
-        switch (l) {
-          case 'setMain':
-            b(u);
-            break;
-          case 'setOwner':
-            h(u);
-            break;
-          case 'removeOwner':
-            F(u);
-            break;
-          case 'remove':
-            A(u);
+      children: d.children,
+    });
+  };
+  return jsxs(ActionContextProvider, {
+    value: { visible: e, setVisible: t },
+    children: [
+      jsx(Select, {
+        open: false,
+        onChange: (d) => {
+          if (!d) {
+            a.setValue([]);
+            return;
+          }
+          a.setValue(d.map(({ label: A, value: b }) => ({ id: b, nickname: A })));
+        },
+        mode: 'multiple',
+        value: r,
+        labelInValue: true,
+        onDropdownVisibleChange: (d) => t(d),
+      }),
+      jsx(SchemaComponent, {
+        schema: fe,
+        components: { RequestProvider: g },
+        scope: { department: o, handleSelect: x, useSelectOwners: m },
+      }),
+    ],
+  });
+};
+const _ = React.createContext({});
+const $e = () => {
+  const e = useForm(),
+    t = useField(),
+    o = useActionContext(),
+    { refreshAsync: a } = useResourceActionContext(),
+    r = useAPIClient(),
+    { expandedKeys: c, setLoadedKeys: i, setExpandedKeys: x } = useContext(_);
+  return {
+    run() {
+      return k(this, null, function* () {
+        try {
+          yield e.submit(),
+            (t.data = t.data || {}),
+            (t.data.loading = true),
+            yield r.resource('departments').create({ values: e.values }),
+            o.setVisible(false),
+            yield e.reset(),
+            (t.data.loading = false);
+          const g = [...c];
+          i([]), x([]), yield a(), x(g);
+        } catch (g) {
+          t.data && (t.data.loading = false);
         }
-      },
-      v = () => ({ disabled: (l) => i.value.some((u) => u.id === l.id) });
-    return jsxRuntime.jsxs(ActionContextProvider, {
-      value: { visible: a, setVisible: r },
+      });
+    },
+  };
+};
+const Le = () => {
+  const e = useField(),
+    t = useForm(),
+    o = useActionContext(),
+    { refreshAsync: a } = useResourceActionContext(),
+    r = useAPIClient(),
+    { id: c } = useRecord(),
+    { expandedKeys: i, setLoadedKeys: x, setExpandedKeys: m } = useContext(_),
+    { department: g, setDepartment: d } = useContext(K);
+  return {
+    run() {
+      return k(this, null, function* () {
+        yield t.submit(), (e.data = e.data || {}), (e.data.loading = true);
+        try {
+          yield r.resource('departments').update({ filterByTk: c, values: t.values }),
+            d({ department: g, ...t.values }),
+            o.setVisible(false),
+            yield t.reset();
+          const b = [...i];
+          x([]), m([]), yield a(), m(b);
+        } catch (b) {
+          console.log(b);
+        } finally {
+          e.data.loading = false;
+        }
+      });
+    },
+  };
+};
+const _e = () => {
+  const { t: e } = useTranslation(),
+    [t, o] = useState(false),
+    [a, r] = useState({}),
+    { department: c, setDepartment: i } = useContext(K),
+    { token: x } = theme.useToken(),
+    m = G({ label: ({ node: g }) => jsx(X.Item, { node: g, setVisible: o, setDrawer: r }) });
+  return jsx(SchemaComponentOptions, {
+    scope: { useCreateDepartment: $e, useUpdateDepartment: Le },
+    children: jsxs(_.Provider, {
+      value: m,
       children: [
-        jsxRuntime.jsxs(jsxRuntime.Fragment, {
+        jsxs(Row, {
           children: [
-            ((i == null ? void 0 : i.value) || []).map((l) =>
-              jsxRuntime.jsxs(
-                Tag,
-                {
-                  style: { padding: '5px 8px', background: 'transparent', marginBottom: '5px' },
-                  children: [
-                    jsxRuntime.jsx('span', { style: { marginRight: '5px' }, children: l.title }),
-                    l.isMain ? jsxRuntime.jsx(Tag, { color: 'processing', bordered: !1, children: o('Main') }) : '',
-                    jsxRuntime.jsx(Dropdown, {
-                      menu: {
-                        items: [
-                          ...(l.isMain ? [] : [{ label: o('Set as main department'), key: 'setMain' }]),
-                          { label: o('Remove'), key: 'remove' },
-                        ],
-                        onClick: ({ key: u }) => C(u, l),
-                      },
-                      children: jsxRuntime.jsx('div', {
-                        style: { float: 'right' },
-                        children: jsxRuntime.jsx(MoreOutlined, {}),
-                      }),
-                    }),
-                  ],
-                },
-                l.id,
-              ),
-            ),
-            jsxRuntime.jsx(Button, { icon: jsxRuntime.jsx(PlusOutlined, {}), onClick: () => r(true) }),
+            jsx(Se, {}),
+            jsx(Button, {
+              type: 'text',
+              icon: jsx(UserOutlined, {}),
+              style: { textAlign: 'left', marginBottom: '5px', background: c ? '' : x.colorBgTextHover },
+              onClick: () => {
+                i(null);
+              },
+              block: true,
+              children: e('All users'),
+            }),
+            jsx(xe, {}),
           ],
         }),
-        jsxRuntime.jsx(SchemaComponent, {
-          schema: Je,
-          components: { DepartmentTable: pe },
-          scope: { user: c, useDataSource: tt, useAddDepartments: d, useDisabled: v },
+        jsx(Divider, { style: { margin: '12px 0' } }),
+        jsx(X, {}),
+        jsx(ActionContextProvider, {
+          value: { visible: t, setVisible: o },
+          children: jsx(RecordProvider, {
+            record: a.node || {},
+            children: jsx(SchemaComponent, {
+              scope: { t: e },
+              components: { DepartmentOwnersField: Be },
+              schema: a.schema || {},
+            }),
+          }),
         }),
       ],
-    });
-  },
-  nt = () => {
-    const { department: e } = useContext(K),
-      { refresh: t } = useResourceActionContext(),
-      o = useRef([]),
-      a = useAPIClient(),
-      r = () => ({
-        run() {
-          return k(this, null, function* () {
-            const x = o.current;
-            x != null &&
-              x.length &&
-              (yield a.resource('departments.members', e.id).add({ values: x }), (o.current = []), t());
-          });
-        },
-      }),
-      c = (i) => {
-        o.current = i;
-      };
-    return jsxRuntime.jsx(SchemaComponent, {
-      scope: { useAddMembersAction: r, department: e, handleSelect: c },
-      schema: Ge,
-    });
-  },
-  rt = () => {
-    const { t: e } = useTranslation(),
-      { message: t } = App.useApp(),
-      o = useAPIClient(),
-      { state: a, setState: r, refresh: c } = useResourceActionContext(),
-      { department: i } = useContext(K);
-    return {
-      run() {
-        return k(this, null, function* () {
-          const m = a == null ? void 0 : a.selectedRowKeys;
-          if (!(m != null && m.length)) {
-            t.warning(e('Please select members'));
-            return;
-          }
-          yield o.resource('departments.members', i.id).remove({ values: m }),
-            r == null || r({ selectedRowKeys: [] }),
-            c();
-        });
-      },
-    };
-  },
-  st = () => {
-    const e = useAPIClient(),
-      { department: t } = useContext(K),
-      { id: o } = useRecord(),
-      { refresh: a } = useResourceActionContext();
-    return {
-      run() {
-        return k(this, null, function* () {
-          yield e.resource('departments.members', t.id).remove({ values: [o] }), a();
-        });
-      },
-    };
-  },
-  at = (e) => {
-    const { user: t } = useContext(K),
-      o = useResourceActionContext();
-    return (
-      useEffect(() => {
-        if (t) {
-          e == null || e.onSuccess({ data: [t] });
-          return;
-        }
-        o.loading || e == null || e.onSuccess(o.data);
-      }, [t, o.loading]),
-      o
-    );
-  },
-  ct = () => {
-    var o;
-    const { data: e } = useResourceActionContext(),
-      { t } = useTranslation();
-    return t('Total {{count}} members', { count: (o = e == null ? void 0 : e.meta) == null ? void 0 : o.count });
-  },
-  it = () => {
-    const { t: e } = useTranslation(),
-      { department: t, user: o } = useContext(K),
-      { data: a, setState: r } = useResourceActionContext();
-    useEffect(() => {
-      r == null || r({ selectedRowKeys: [] });
-    }, [a, r]);
-    const c = () => (t ? jsxRuntime.jsx(SchemaComponent, { schema: ze }) : null),
-      i = () => (t ? jsxRuntime.jsx(SchemaComponent, { scope: { useRemoveMemberAction: st }, schema: We }) : null),
-      x = useMemo(() => He(t, o), [t, o]);
-    return jsxRuntime.jsxs(jsxRuntime.Fragment, {
-      children: [
-        o
-          ? jsxRuntime.jsx('h2', { children: e('Search results') })
-          : jsxRuntime.jsx('h2', { children: e((t == null ? void 0 : t.title) || 'All users') }),
-        jsxRuntime.jsx(SchemaComponent, {
-          scope: {
-            useBulkRemoveMembersAction: rt,
-            useMembersDataSource: at,
-            t: e,
-            useShowTotal: ct,
-            useFilterActionProps: Z,
-          },
-          components: {
-            MemberActions: c,
-            AddMembers: nt,
-            RowRemoveAction: i,
-            DepartmentField: Ye,
-            IsOwnerField: Qe,
-            UserDepartmentsField: ot,
-          },
-          schema: x,
-        }),
-      ],
-    });
-  },
-  le = (e) => {
-    const t = useField(),
-      [o, a] = useState({ label: null, value: null }),
-      { treeData: r, initData: c, getByKeyword: i, loadData: x, loadedKeys: m, setLoadedKeys: g, originData: d } = e,
-      A = (h) =>
-        k(this, null, function* () {
-          if (!h) {
-            c(d);
-            return;
-          }
-          yield i(h);
-        }),
-      b = useCallback((h) => {
-        const F = h.title,
-          C = h.parent;
-        return C ? b(C) + ' / ' + F : F;
-      }, []);
-    return (
-      useEffect(() => {
-        c(d);
-      }, [d, c]),
-      useEffect(() => {
-        if (!t.value) {
-          a({ label: null, value: null });
-          return;
-        }
-        a({ label: b(t.value) || t.value.label, value: t.value.id });
-      }, [t.value, b]),
-      jsxRuntime.jsx(TreeSelect, {
-        value: o,
-        onSelect: (h, F) => {
-          t.setValue(F);
-        },
-        onChange: (h) => {
-          h || t.setValue(null);
-        },
-        treeData: r,
-        treeLoadedKeys: m,
-        onTreeLoad: (h) => g(h),
-        loadData: (h) => x({ key: h.id, children: h.children }),
-        fieldNames: { value: 'id' },
-        showSearch: true,
-        allowClear: true,
-        treeNodeFilterProp: 'title',
-        onSearch: A,
-        labelInValue: true,
-      })
-    );
-  },
-  pt = () => {
-    const e = G(),
-      { departmentsResource: t } = useContext(K),
-      {
-        service: { data: o },
-      } = t || {};
-    return jsxRuntime.jsx(le, T(y({}, e), { originData: o == null ? void 0 : o.data }));
-  },
-  lt = () => {
-    const e = G(),
-      { setTreeData: t, getChildrenIds: o } = e,
-      a = useRecord(),
-      { departmentsResource: r } = useContext(K),
-      {
-        service: { data: c },
-      } = r || {};
-    return (
-      useEffect(() => {
-        if (!a.id) return;
-        const i = o(a.id);
-        i.push(a.id),
-          t((x) => {
-            const m = (g) =>
-              g.map((d) => (i.includes(d.id) && (d.disabled = true), d.children && (d.children = m(d.children)), d));
-            return m(x);
-          });
-      }, [t, a.id, o]),
-      jsxRuntime.jsx(le, T(y({}, e), { originData: c == null ? void 0 : c.data }))
-    );
-  },
-  ut = () =>
-    jsxRuntime.jsx(SchemaComponentOptions, {
-      components: { SuperiorDepartmentSelect: lt, DepartmentSelect: pt },
-      scope: { useFilterActionProps: Z },
-      children: jsxRuntime.jsxs(Row, {
-        gutter: 48,
-        style: { flexWrap: 'nowrap' },
-        children: [
-          jsxRuntime.jsx(Col, {
-            span: 6,
-            style: { borderRight: '1px solid #eee', minWidth: '300px' },
-            children: jsxRuntime.jsx(Ce, { children: jsxRuntime.jsx(_e, {}) }),
-          }),
-          jsxRuntime.jsx(Col, {
-            flex: 'auto',
-            style: { overflow: 'hidden' },
-            children: jsxRuntime.jsx(be, { children: jsxRuntime.jsx(it, {}) }),
-          }),
-        ],
-      }),
     }),
-  mt = () =>
-    jsxRuntime.jsx(SchemaComponent, {
-      components: { DepartmentManagement: ut },
-      schema: {
-        type: 'void',
-        properties: {
-          [uid()]: { type: 'void', 'x-decorator': 'CardItem', 'x-component': 'DepartmentManagement' },
+  });
+};
+const ze = {
+  type: 'void',
+  'x-component': 'Space',
+  properties: {
+    remove: {
+      type: 'void',
+      title: '{{t("Remove")}}',
+      'x-component': 'Action',
+      'x-component-props': {
+        icon: 'UserDeleteOutlined',
+        confirm: {
+          title: "{{t('Remove members')}}",
+          content: "{{t('Are you sure you want to remove these members?')}}",
         },
+        style: { marginRight: 8 },
+        useAction: '{{ useBulkRemoveMembersAction }}',
       },
-    }),
-  dt = () => ({
-    type: 'void',
-    properties: {
-      actions: {
-        type: 'void',
-        'x-component': 'ActionBar',
-        'x-component-props': { style: { marginBottom: 16 } },
-        properties: {
-          [uid()]: {
-            type: 'void',
-            title: '{{ t("Filter") }}',
-            'x-action': 'filter',
-            'x-component': 'Filter.Action',
-            'x-use-component-props': 'useFilterActionProps',
-            'x-component-props': { icon: 'FilterOutlined' },
-            'x-align': 'left',
-          },
-          actions: {
-            type: 'void',
-            'x-component': 'Space',
-            properties: {
-              remove: {
-                type: 'void',
-                title: '{{t("Remove")}}',
-                'x-component': 'Action',
-                'x-component-props': {
-                  icon: 'MinusOutlined',
-                  confirm: {
-                    title: "{{t('Remove')}}",
-                    content: "{{t('Are you sure you want to remove these departments?')}}",
-                  },
-                  style: { marginRight: 8 },
-                  useAction: '{{ useBulkRemoveDepartments }}',
-                },
-              },
-              create: {
-                type: 'void',
-                title: '{{t("Add departments")}}',
-                'x-component': 'Action',
-                'x-component-props': { type: 'primary', icon: 'PlusOutlined' },
-                properties: {
-                  drawer: {
-                    type: 'void',
-                    'x-component': 'Action.Drawer',
-                    'x-decorator': 'FormV2',
-                    title: '{{t("Add departments")}}',
-                    properties: {
-                      table: {
-                        type: 'void',
-                        'x-decorator': 'FormItem',
-                        'x-component': 'DepartmentTable',
-                        'x-component-props': {
-                          useDataSource: '{{ useDataSource }}',
-                          useDisabled: '{{ useDisabled }}',
-                        },
-                      },
-                      footer: {
-                        type: 'void',
-                        'x-component': 'Action.Drawer.Footer',
-                        properties: {
-                          cancel: {
-                            title: '{{t("Cancel")}}',
-                            'x-component': 'Action',
-                            'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
-                          },
-                          submit: {
-                            title: '{{t("Submit")}}',
-                            'x-component': 'Action',
-                            'x-component-props': { type: 'primary', useAction: '{{ useAddDepartments }}' },
-                          },
-                        },
-                      },
-                    },
-                  },
+    },
+    create: {
+      type: 'void',
+      title: '{{t("Add members")}}',
+      'x-component': 'Action',
+      'x-component-props': { type: 'primary', icon: 'UserAddOutlined' },
+      properties: { drawer: { type: 'void', 'x-component': 'AddMembers' } },
+    },
+  },
+};
+const We = {
+  type: 'void',
+  properties: {
+    remove: {
+      title: '{{ t("Remove") }}',
+      'x-component': 'Action.Link',
+      'x-component-props': {
+        confirm: { title: "{{t('Remove member')}}", content: "{{t('Are you sure you want to remove it?')}}" },
+        useAction: '{{ useRemoveMemberAction }}',
+      },
+    },
+  },
+};
+const He = (e, t) => ({
+  type: 'void',
+  properties: T(
+    y(
+      {},
+      t
+        ? {}
+        : {
+            actions: {
+              type: 'void',
+              'x-component': 'ActionBar',
+              'x-component-props': { style: { marginBottom: 16 } },
+              properties: {
+                [uid()]: {
+                  type: 'void',
+                  title: '{{ t("Filter") }}',
+                  'x-action': 'filter',
+                  'x-component': 'Filter.Action',
+                  'x-use-component-props': 'useFilterActionProps',
+                  'x-component-props': { icon: 'FilterOutlined' },
+                  'x-align': 'left',
                 },
+                actions: { type: 'void', 'x-component': 'MemberActions' },
               },
             },
           },
-        },
-      },
+    ),
+    {
       table: {
         type: 'void',
         'x-component': 'Table.Void',
         'x-component-props': {
           rowKey: 'id',
           rowSelection: { type: 'checkbox' },
-          useDataSource: '{{ cm.useDataSourceFromRAC }}',
+          useDataSource: '{{ useMembersDataSource }}',
+          pagination: { showTotal: '{{ useShowTotal }}' },
         },
-        properties: {
-          title: {
-            type: 'void',
-            title: '{{t("Department name")}}',
-            'x-decorator': 'Table.Column.Decorator',
-            'x-component': 'Table.Column',
-            properties: { title: { type: 'string', 'x-component': 'DepartmentTitle' } },
-          },
-          actions: {
-            type: 'void',
-            title: '{{t("Actions")}}',
-            'x-component': 'Table.Column',
-            properties: {
-              actions: {
+        properties: T(
+          y(
+            {
+              nickname: {
                 type: 'void',
-                'x-component': 'Space',
-                'x-component-props': { split: '|' },
+                'x-decorator': 'Table.Column.Decorator',
+                'x-component': 'Table.Column',
+                properties: { nickname: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
+              },
+              username: {
+                type: 'void',
+                'x-decorator': 'Table.Column.Decorator',
+                'x-component': 'Table.Column',
+                properties: { username: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
+              },
+              departments: {
+                type: 'void',
+                'x-decorator': 'Table.Column.Decorator',
+                'x-component': 'Table.Column',
                 properties: {
-                  remove: {
+                  departments: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true },
+                },
+              },
+            },
+            e
+              ? {
+                  isOwner: {
                     type: 'void',
-                    title: '{{ t("Remove") }}',
-                    'x-component': 'Action.Link',
-                    'x-component-props': {
-                      confirm: {
-                        title: "{{t('Remove department')}}",
-                        content: "{{t('Are you sure you want to remove it?')}}",
+                    'x-decorator': 'Table.Column.Decorator',
+                    'x-component': 'Table.Column',
+                    'x-component-props': { style: { minWidth: 100 } },
+                    title: '{{t("Owner")}}',
+                    properties: { isOwner: { type: 'boolean', 'x-component': 'IsOwnerField' } },
+                  },
+                }
+              : {},
+          ),
+          {
+            phone: {
+              type: 'void',
+              'x-decorator': 'Table.Column.Decorator',
+              'x-component': 'Table.Column',
+              properties: { phone: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
+            },
+            email: {
+              type: 'void',
+              'x-decorator': 'Table.Column.Decorator',
+              'x-component': 'Table.Column',
+              properties: { email: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
+            },
+            actions: {
+              type: 'void',
+              title: '{{t("Actions")}}',
+              'x-component': 'Table.Column',
+              properties: {
+                actions: {
+                  type: 'void',
+                  'x-component': 'Space',
+                  'x-component-props': { split: '|' },
+                  properties: y(
+                    {
+                      update: {
+                        type: 'void',
+                        title: '{{t("Configure")}}',
+                        'x-component': 'Action.Link',
+                        'x-component-props': { type: 'primary' },
+                        properties: {
+                          drawer: {
+                            type: 'void',
+                            'x-component': 'Action.Drawer',
+                            'x-decorator': 'FormV2',
+                            title: '{{t("Configure")}}',
+                            properties: {
+                              departments: {
+                                title: '{{t("Departments")}}',
+                                'x-decorator': 'FormItem',
+                                'x-component': 'UserDepartmentsField',
+                              },
+                            },
+                          },
+                        },
+                      },
+                    },
+                    e ? { remove: { type: 'void', 'x-component': 'RowRemoveAction' } } : {},
+                  ),
+                },
+              },
+            },
+          },
+        ),
+      },
+    },
+  ),
+});
+const Ge = {
+  type: 'object',
+  properties: {
+    drawer: {
+      type: 'void',
+      'x-component': 'Action.Drawer',
+      'x-decorator': 'Form',
+      title: '{{t("Add members")}}',
+      properties: {
+        resource: {
+          type: 'void',
+          'x-decorator': 'FormItem',
+          'x-component': 'ResourceActionProvider',
+          'x-component-props': {
+            collection: 'users',
+            request: {
+              resource: 'users',
+              action: 'listExcludeDept',
+              params: { departmentId: '{{ department?.id }}' },
+            },
+          },
+          properties: {
+            actions: {
+              type: 'void',
+              'x-component': 'ActionBar',
+              'x-component-props': { style: { marginBottom: 16 } },
+              properties: {
+                filter: {
+                  type: 'void',
+                  title: '{{ t("Filter") }}',
+                  default: { $and: [{ username: { $includes: '' } }, { nickname: { $includes: '' } }] },
+                  'x-action': 'filter',
+                  'x-component': 'Filter.Action',
+                  'x-use-component-props': 'useFilterActionProps',
+                  'x-component-props': { icon: 'FilterOutlined' },
+                  'x-align': 'left',
+                },
+              },
+            },
+            table: {
+              type: 'void',
+              'x-component': 'Table.Void',
+              'x-component-props': {
+                rowKey: 'id',
+                rowSelection: { type: 'checkbox', onChange: '{{ handleSelect }}' },
+                useDataSource: '{{ cm.useDataSourceFromRAC }}',
+              },
+              properties: {
+                username: {
+                  type: 'void',
+                  'x-decorator': 'Table.Column.Decorator',
+                  'x-component': 'Table.Column',
+                  properties: {
+                    username: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true },
+                  },
+                },
+                nickname: {
+                  type: 'void',
+                  'x-decorator': 'Table.Column.Decorator',
+                  'x-component': 'Table.Column',
+                  properties: {
+                    nickname: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true },
+                  },
+                },
+                phone: {
+                  type: 'void',
+                  'x-decorator': 'Table.Column.Decorator',
+                  'x-component': 'Table.Column',
+                  properties: { phone: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
+                },
+                email: {
+                  type: 'void',
+                  'x-decorator': 'Table.Column.Decorator',
+                  'x-component': 'Table.Column',
+                  properties: { email: { type: 'string', 'x-component': 'CollectionField', 'x-read-pretty': true } },
+                },
+              },
+            },
+          },
+        },
+        footer: {
+          type: 'void',
+          'x-component': 'Action.Drawer.Footer',
+          properties: {
+            cancel: {
+              title: '{{t("Cancel")}}',
+              'x-component': 'Action',
+              'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
+            },
+            submit: {
+              title: '{{t("Submit")}}',
+              'x-component': 'Action',
+              'x-component-props': { type: 'primary', useAction: '{{ useAddMembersAction }}' },
+            },
+          },
+        },
+      },
+    },
+  },
+};
+const Je = {
+  type: 'void',
+  properties: {
+    drawer: {
+      title: '{{t("Select Departments")}}',
+      'x-decorator': 'Form',
+      'x-component': 'Action.Drawer',
+      properties: {
+        table: {
+          type: 'void',
+          'x-decorator': 'FormItem',
+          'x-component': 'DepartmentTable',
+          'x-component-props': { useDataSource: '{{ useDataSource }}', useDisabled: '{{ useDisabled }}' },
+        },
+        footer: {
+          type: 'void',
+          'x-component': 'Action.Drawer.Footer',
+          properties: {
+            cancel: {
+              title: '{{t("Cancel")}}',
+              'x-component': 'Action',
+              'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
+            },
+            confirm: {
+              title: '{{t("Submit")}}',
+              'x-component': 'Action',
+              'x-component-props': { type: 'primary', useAction: '{{ useAddDepartments }}' },
+            },
+          },
+        },
+      },
+    },
+  },
+};
+const z = (e) => {
+  const t = e.title,
+    o = e.parent;
+  return o ? z(o) + ' / ' + t : t;
+};
+const Ye = () => {
+  const { setDepartment: e } = useContext(K),
+    o = useField().value || [],
+    a = o.reduce((c, i) => ((c[i.id] = i), c), {}),
+    r = o.map((c, i) =>
+      jsxs(
+        'span',
+        {
+          children: [
+            jsx('a', {
+              onClick: (x) => {
+                x.preventDefault(), e(a[c.id]);
+              },
+              children: z(c),
+            }),
+            i !== o.length - 1 ? jsx('span', { style: { marginRight: 4, color: '#aaa' }, children: ',' }) : '',
+          ],
+        },
+        i,
+      ),
+    );
+  return jsx(EllipsisWithTooltip, { ellipsis: true, children: r });
+};
+const Qe = () => {
+  const { department: e } = useContext(K),
+    o = (useRecord().departments || []).find((a) => (a == null ? void 0 : a.id) === (e == null ? void 0 : e.id));
+  return jsx(Checkbox.ReadPretty, { value: o == null ? void 0 : o.departmentsUsers.isOwner });
+};
+const R = React.createContext({});
+const Xe = () => {
+  const { setHasFilter: e, setExpandedKeys: t } = useContext(R),
+    { t: o } = useTranslation(),
+    a = useContext(CollectionContext),
+    r = useFilterFieldOptions(a.fields),
+    c = useResourceActionContext(),
+    { run: i, defaultRequest: x } = c,
+    m = useField(),
+    { params: g } = x || {};
+  return {
+    options: r,
+    onSubmit: (d) =>
+      k(this, null, function* () {
+        const A = g.filter,
+          b = removeNullCondition(d == null ? void 0 : d.filter);
+        i(T(y({}, g), { page: 1, pageSize: 10, filter: mergeFilter([b, A]) }));
+        const h = (b == null ? void 0 : b.$and) || (b == null ? void 0 : b.$or);
+        h != null && h.length
+          ? ((m.title = o('{{count}} filter items', { count: (h == null ? void 0 : h.length) || 0 })), e(true))
+          : ((m.title = o('Filter')), e(false));
+      }),
+    onReset() {
+      i(
+        T(y({}, g || {}), {
+          filter: T(y({}, (g == null ? void 0 : g.filter) || {}), { parentId: null }),
+          page: 1,
+          pageSize: 10,
+        }),
+      ),
+        (m.title = o('Filter')),
+        e(false),
+        t([]);
+    },
+  };
+};
+const Ze = () => ({ disabled: () => false });
+const Re = ({ useDisabled: e = Ze }) => {
+  const { t } = useTranslation(),
+    o = useResourceActionContext();
+  console.log(o);
+  const { run: a, data: r, loading: c, defaultRequest: i } = o,
+    { resource: x, resourceOf: m, params: g } = i || {},
+    { treeData: d, initData: A, loadData: b } = G({ resource: x, resourceOf: m, params: g }),
+    h = useField(),
+    { disabled: F } = e(),
+    { hasFilter: C, expandedKeys: v, setExpandedKeys: l } = useContext(R);
+  useEffect(() => {
+    C || A(r == null ? void 0 : r.data);
+  }, [r, A, c, C]);
+  const u = {};
+  if ((g != null && g.pageSize && (u.defaultPageSize = g.pageSize), !u.total && r != null && r.meta)) {
+    const { count: f, page: S, pageSize: O } = r.meta;
+    (u.total = f), (u.current = S), (u.pageSize = O);
+  }
+  return jsx(Table, {
+    rowKey: 'id',
+    columns: [{ dataIndex: 'title', title: t('Department name'), render: (f, S) => (C ? z(S) : f) }],
+    rowSelection: {
+      selectedRowKeys: ((h == null ? void 0 : h.value) || []).map((f) => f.id),
+      onChange: (f, S) => {
+        var O;
+        return (O = h == null ? void 0 : h.setValue) == null ? void 0 : O.call(h, S);
+      },
+      getCheckboxProps: (f) => ({ disabled: F(f) }),
+    },
+    pagination: T(y({ showSizeChanger: true }, u), {
+      onChange(f, S) {
+        var O;
+        a(T(y({}, ((O = o == null ? void 0 : o.params) == null ? void 0 : O[0]) || {}), { page: f, pageSize: S }));
+      },
+    }),
+    dataSource: C ? (r == null ? void 0 : r.data) || [] : d,
+    expandable: {
+      onExpand: (f, S) => {
+        b({ key: S.id, children: S.children });
+      },
+      expandedRowKeys: v,
+      onExpandedRowsChange: (f) => l(f),
+    },
+  });
+};
+const et = (e) => {
+  const [t, o] = useState([]),
+    [a, r] = useState(false),
+    { useDataSource: c } = e,
+    i = c({ manual: true });
+  return (
+    useEffect(() => {
+      i.run({ filter: { parentId: null }, pageSize: 10 });
+    }, []),
+    jsx(ResourceActionContext.Provider, {
+      value: y({}, i),
+      children: jsx(CollectionProvider_deprecated, {
+        collection: Q,
+        children: jsx(R.Provider, {
+          value: { expandedKeys: t, setExpandedKeys: o, hasFilter: a, setHasFilter: r },
+          children: e.children,
+        }),
+      }),
+    })
+  );
+};
+const pe = ({ useDataSource: e, useDisabled: t }) =>
+  jsx(SchemaComponent, {
+    scope: { useDisabled: t, useFilterActionProps: Xe },
+    components: { InternalDepartmentTable: Re, RequestProvider: et },
+    schema: {
+      type: 'void',
+      properties: {
+        [uid()]: {
+          type: 'void',
+          'x-component': 'RequestProvider',
+          'x-component-props': { useDataSource: e },
+          properties: {
+            actions: {
+              type: 'void',
+              'x-component': 'ActionBar',
+              'x-component-props': { style: { marginBottom: 16 } },
+              properties: {
+                filter: {
+                  type: 'void',
+                  title: '{{ t("Filter") }}',
+                  default: { $and: [{ title: { $includes: '' } }] },
+                  'x-action': 'filter',
+                  'x-component': 'Filter.Action',
+                  'x-use-component-props': 'useFilterActionProps',
+                  'x-component-props': { icon: 'FilterOutlined' },
+                  'x-align': 'left',
+                },
+              },
+            },
+            departments: {
+              type: 'array',
+              'x-component': 'InternalDepartmentTable',
+              'x-component-props': { useDisabled: '{{ useDisabled }}' },
+            },
+          },
+        },
+      },
+    },
+  });
+const tt = (e) => {
+  const t = {
+      resource: 'departments',
+      action: 'list',
+      params: { appends: ['parent(recursively=true)'], sort: ['createdAt'] },
+    },
+    o = useRequest(t, e);
+  return T(y({}, o), { defaultRequest: t });
+};
+const ot = () => {
+  const { modal: e, message: t } = App.useApp(),
+    { t: o } = useTranslation(),
+    [a, r] = useState(false),
+    c = useRecord(),
+    i = useField(),
+    { refresh: x } = useResourceActionContext(),
+    m = (l) =>
+      l != null && l.length
+        ? l.map((u) => {
+            var f, S;
+            return T(y({}, u), {
+              isMain: (f = u.departmentsUsers) == null ? void 0 : f.isMain,
+              isOwner: (S = u.departmentsUsers) == null ? void 0 : S.isOwner,
+              title: z(u),
+            });
+          })
+        : [],
+    g = useAPIClient();
+  useRequest(
+    () =>
+      g
+        .resource('users.departments', c.id)
+        .list({ appends: ['parent(recursively=true)'], pagination: false })
+        .then((l) => {
+          var f;
+          const u = m((f = l == null ? void 0 : l.data) == null ? void 0 : f.data);
+          i.setValue(u);
+        }),
+    { ready: c.id },
+  );
+  const d = () => {
+      const l = useAPIClient(),
+        u = useForm(),
+        { departments: f } = u.values || {};
+      return {
+        run() {
+          return k(this, null, function* () {
+            yield l.resource('users.departments', c.id).add({ values: f.map((O) => O.id) }),
+              u.reset(),
+              i.setValue([
+                ...i.value,
+                ...f.map((O, $) => T(y({}, O), { isMain: $ === 0 && i.value.length === 0, title: z(O) })),
+              ]),
+              r(false),
+              x();
+          });
+        },
+      };
+    },
+    A = (l) => {
+      e.confirm({
+        title: o('Remove department'),
+        content: o('Are you sure you want to remove it?'),
+        onOk: () =>
+          k(this, null, function* () {
+            yield g.resource('users.departments', c.id).remove({ values: [l.id] }),
+              t.success(o('Deleted successfully')),
+              i.setValue(
+                i.value
+                  .filter((u) => u.id !== l.id)
+                  .map((u, f) => T(y({}, u), { isMain: (l.isMain && f === 0) || u.isMain })),
+              ),
+              x();
+          }),
+      });
+    },
+    b = (l) =>
+      k(this, null, function* () {
+        yield g.resource('users').setMainDepartment({ values: { userId: c.id, departmentId: l.id } }),
+          t.success(o('Set successfully')),
+          i.setValue(i.value.map((u) => T(y({}, u), { isMain: u.id === l.id }))),
+          x();
+      }),
+    h = (l) =>
+      k(this, null, function* () {
+        yield g.resource('departments').setOwner({ values: { userId: c.id, departmentId: l.id } }),
+          t.success(o('Set successfully')),
+          i.setValue(i.value.map((u) => T(y({}, u), { isOwner: u.id === l.id ? true : u.isOwner }))),
+          x();
+      }),
+    F = (l) =>
+      k(this, null, function* () {
+        yield g.resource('departments').removeOwner({ values: { userId: c.id, departmentId: l.id } }),
+          t.success(o('Set successfully')),
+          i.setValue(i.value.map((u) => T(y({}, u), { isOwner: u.id === l.id ? false : u.isOwner }))),
+          x();
+      }),
+    C = (l, u) => {
+      switch (l) {
+        case 'setMain':
+          b(u);
+          break;
+        case 'setOwner':
+          h(u);
+          break;
+        case 'removeOwner':
+          F(u);
+          break;
+        case 'remove':
+          A(u);
+      }
+    },
+    v = () => ({ disabled: (l) => i.value.some((u) => u.id === l.id) });
+  return jsxs(ActionContextProvider, {
+    value: { visible: a, setVisible: r },
+    children: [
+      jsxs(Fragment, {
+        children: [
+          ((i == null ? void 0 : i.value) || []).map((l) =>
+            jsxs(
+              Tag,
+              {
+                style: { padding: '5px 8px', background: 'transparent', marginBottom: '5px' },
+                children: [
+                  jsx('span', { style: { marginRight: '5px' }, children: l.title }),
+                  l.isMain ? jsx(Tag, { color: 'processing', bordered: false, children: o('Main') }) : '',
+                  jsx(Dropdown, {
+                    menu: {
+                      items: [
+                        ...(l.isMain ? [] : [{ label: o('Set as main department'), key: 'setMain' }]),
+                        { label: o('Remove'), key: 'remove' },
+                      ],
+                      onClick: ({ key: u }) => C(u, l),
+                    },
+                    children: jsx('div', {
+                      style: { float: 'right' },
+                      children: jsx(MoreOutlined, {}),
+                    }),
+                  }),
+                ],
+              },
+              l.id,
+            ),
+          ),
+          jsx(Button, { icon: jsx(PlusOutlined, {}), onClick: () => r(true) }),
+        ],
+      }),
+      jsx(SchemaComponent, {
+        schema: Je,
+        components: { DepartmentTable: pe },
+        scope: { user: c, useDataSource: tt, useAddDepartments: d, useDisabled: v },
+      }),
+    ],
+  });
+};
+const nt = () => {
+  const { department: e } = useContext(K),
+    { refresh: t } = useResourceActionContext(),
+    o = useRef([]),
+    a = useAPIClient(),
+    r = () => ({
+      run() {
+        return k(this, null, function* () {
+          const x = o.current;
+          x != null &&
+            x.length &&
+            (yield a.resource('departments.members', e.id).add({ values: x }), (o.current = []), t());
+        });
+      },
+    }),
+    c = (i) => {
+      o.current = i;
+    };
+  return jsx(SchemaComponent, {
+    scope: { useAddMembersAction: r, department: e, handleSelect: c },
+    schema: Ge,
+  });
+};
+const rt = () => {
+  const { t: e } = useTranslation(),
+    { message: t } = App.useApp(),
+    o = useAPIClient(),
+    { state: a, setState: r, refresh: c } = useResourceActionContext(),
+    { department: i } = useContext(K);
+  return {
+    run() {
+      return k(this, null, function* () {
+        const m = a == null ? void 0 : a.selectedRowKeys;
+        if (!(m != null && m.length)) {
+          t.warning(e('Please select members'));
+          return;
+        }
+        yield o.resource('departments.members', i.id).remove({ values: m }),
+          r == null || r({ selectedRowKeys: [] }),
+          c();
+      });
+    },
+  };
+};
+const st = () => {
+  const e = useAPIClient(),
+    { department: t } = useContext(K),
+    { id: o } = useRecord(),
+    { refresh: a } = useResourceActionContext();
+  return {
+    run() {
+      return k(this, null, function* () {
+        yield e.resource('departments.members', t.id).remove({ values: [o] }), a();
+      });
+    },
+  };
+};
+const at = (e) => {
+  const { user: t } = useContext(K),
+    o = useResourceActionContext();
+  return (
+    useEffect(() => {
+      if (t) {
+        e == null || e.onSuccess({ data: [t] });
+        return;
+      }
+      o.loading || e == null || e.onSuccess(o.data);
+    }, [t, o.loading]),
+    o
+  );
+};
+const ct = () => {
+  var o;
+  const { data: e } = useResourceActionContext(),
+    { t } = useTranslation();
+  return t('Total {{count}} members', { count: (o = e == null ? void 0 : e.meta) == null ? void 0 : o.count });
+};
+const it = () => {
+  const { t: e } = useTranslation(),
+    { department: t, user: o } = useContext(K),
+    { data: a, setState: r } = useResourceActionContext();
+  useEffect(() => {
+    r == null || r({ selectedRowKeys: [] });
+  }, [a, r]);
+  const c = () => (t ? jsx(SchemaComponent, { schema: ze }) : null),
+    i = () => (t ? jsx(SchemaComponent, { scope: { useRemoveMemberAction: st }, schema: We }) : null),
+    x = useMemo(() => He(t, o), [t, o]);
+  return jsxs(Fragment, {
+    children: [
+      o
+        ? jsx('h2', { children: e('Search results') })
+        : jsx('h2', { children: e((t == null ? void 0 : t.title) || 'All users') }),
+      jsx(SchemaComponent, {
+        scope: {
+          useBulkRemoveMembersAction: rt,
+          useMembersDataSource: at,
+          t: e,
+          useShowTotal: ct,
+          useFilterActionProps: Z,
+        },
+        components: {
+          MemberActions: c,
+          AddMembers: nt,
+          RowRemoveAction: i,
+          DepartmentField: Ye,
+          IsOwnerField: Qe,
+          UserDepartmentsField: ot,
+        },
+        schema: x,
+      }),
+    ],
+  });
+};
+const le = (e) => {
+  const t = useField(),
+    [o, a] = useState({ label: null, value: null }),
+    { treeData: r, initData: c, getByKeyword: i, loadData: x, loadedKeys: m, setLoadedKeys: g, originData: d } = e,
+    A = (h) =>
+      k(this, null, function* () {
+        if (!h) {
+          c(d);
+          return;
+        }
+        yield i(h);
+      }),
+    b = useCallback((h) => {
+      const F = h.title,
+        C = h.parent;
+      return C ? b(C) + ' / ' + F : F;
+    }, []);
+  return (
+    useEffect(() => {
+      c(d);
+    }, [d, c]),
+    useEffect(() => {
+      if (!t.value) {
+        a({ label: null, value: null });
+        return;
+      }
+      a({ label: b(t.value) || t.value.label, value: t.value.id });
+    }, [t.value, b]),
+    jsx(TreeSelect, {
+      value: o,
+      onSelect: (h, F) => {
+        t.setValue(F);
+      },
+      onChange: (h) => {
+        h || t.setValue(null);
+      },
+      treeData: r,
+      treeLoadedKeys: m,
+      onTreeLoad: (h) => g(h),
+      loadData: (h) => x({ key: h.id, children: h.children }),
+      fieldNames: { value: 'id' },
+      showSearch: true,
+      allowClear: true,
+      treeNodeFilterProp: 'title',
+      onSearch: A,
+      labelInValue: true,
+    })
+  );
+};
+const pt = () => {
+  const e = G(),
+    { departmentsResource: t } = useContext(K),
+    {
+      service: { data: o },
+    } = t || {};
+  return jsx(le, T(y({}, e), { originData: o == null ? void 0 : o.data }));
+};
+const lt = () => {
+  const e = G(),
+    { setTreeData: t, getChildrenIds: o } = e,
+    a = useRecord(),
+    { departmentsResource: r } = useContext(K),
+    {
+      service: { data: c },
+    } = r || {};
+  return (
+    useEffect(() => {
+      if (!a.id) return;
+      const i = o(a.id);
+      i.push(a.id),
+        t((x) => {
+          const m = (g) =>
+            g.map((d) => (i.includes(d.id) && (d.disabled = true), d.children && (d.children = m(d.children)), d));
+          return m(x);
+        });
+    }, [t, a.id, o]),
+    jsx(le, T(y({}, e), { originData: c == null ? void 0 : c.data }))
+  );
+};
+const ut = () =>
+  jsx(SchemaComponentOptions, {
+    components: { SuperiorDepartmentSelect: lt, DepartmentSelect: pt },
+    scope: { useFilterActionProps: Z },
+    children: jsxs(Row, {
+      gutter: 48,
+      style: { flexWrap: 'nowrap' },
+      children: [
+        jsx(Col, {
+          span: 6,
+          style: { borderRight: '1px solid #eee', minWidth: '300px' },
+          children: jsx(Ce, { children: jsx(_e, {}) }),
+        }),
+        jsx(Col, {
+          flex: 'auto',
+          style: { overflow: 'hidden' },
+          children: jsx(be, { children: jsx(it, {}) }),
+        }),
+      ],
+    }),
+  });
+const mt = () =>
+  jsx(SchemaComponent, {
+    components: { DepartmentManagement: ut },
+    schema: {
+      type: 'void',
+      properties: {
+        [uid()]: { type: 'void', 'x-decorator': 'CardItem', 'x-component': 'DepartmentManagement' },
+      },
+    },
+  });
+const dt = () => ({
+  type: 'void',
+  properties: {
+    actions: {
+      type: 'void',
+      'x-component': 'ActionBar',
+      'x-component-props': { style: { marginBottom: 16 } },
+      properties: {
+        [uid()]: {
+          type: 'void',
+          title: '{{ t("Filter") }}',
+          'x-action': 'filter',
+          'x-component': 'Filter.Action',
+          'x-use-component-props': 'useFilterActionProps',
+          'x-component-props': { icon: 'FilterOutlined' },
+          'x-align': 'left',
+        },
+        actions: {
+          type: 'void',
+          'x-component': 'Space',
+          properties: {
+            remove: {
+              type: 'void',
+              title: '{{t("Remove")}}',
+              'x-component': 'Action',
+              'x-component-props': {
+                icon: 'MinusOutlined',
+                confirm: {
+                  title: "{{t('Remove')}}",
+                  content: "{{t('Are you sure you want to remove these departments?')}}",
+                },
+                style: { marginRight: 8 },
+                useAction: '{{ useBulkRemoveDepartments }}',
+              },
+            },
+            create: {
+              type: 'void',
+              title: '{{t("Add departments")}}',
+              'x-component': 'Action',
+              'x-component-props': { type: 'primary', icon: 'PlusOutlined' },
+              properties: {
+                drawer: {
+                  type: 'void',
+                  'x-component': 'Action.Drawer',
+                  'x-decorator': 'FormV2',
+                  title: '{{t("Add departments")}}',
+                  properties: {
+                    table: {
+                      type: 'void',
+                      'x-decorator': 'FormItem',
+                      'x-component': 'DepartmentTable',
+                      'x-component-props': {
+                        useDataSource: '{{ useDataSource }}',
+                        useDisabled: '{{ useDisabled }}',
+                      },
+                    },
+                    footer: {
+                      type: 'void',
+                      'x-component': 'Action.Drawer.Footer',
+                      properties: {
+                        cancel: {
+                          title: '{{t("Cancel")}}',
+                          'x-component': 'Action',
+                          'x-component-props': { useAction: '{{ cm.useCancelAction }}' },
+                        },
+                        submit: {
+                          title: '{{t("Submit")}}',
+                          'x-component': 'Action',
+                          'x-component-props': { type: 'primary', useAction: '{{ useAddDepartments }}' },
+                        },
                       },
-                      useAction: '{{ useRemoveDepartment }}',
                     },
                   },
                 },
@@ -2186,268 +2141,313 @@ const ie = we(Ue),
         },
       },
     },
-  }),
-  xt = () => {
-    const e = useAPIClient(),
-      { role: t } = useContext(RolesManagerContext),
-      { data: o } = useRecord(),
-      { refresh: a } = useResourceActionContext();
-    return {
-      run() {
-        return k(this, null, function* () {
-          yield e.resource(`roles/${t == null ? void 0 : t.name}/departments`).remove({ values: [o.id] }), a();
-        });
+    table: {
+      type: 'void',
+      'x-component': 'Table.Void',
+      'x-component-props': {
+        rowKey: 'id',
+        rowSelection: { type: 'checkbox' },
+        useDataSource: '{{ cm.useDataSourceFromRAC }}',
       },
-    };
-  },
-  yt = () => {
-    const { t: e } = useTranslation(),
-      { message: t } = App.useApp(),
-      o = useAPIClient(),
-      { state: a, setState: r, refresh: c } = useResourceActionContext(),
-      { role: i } = useContext(RolesManagerContext);
-    return {
-      run() {
-        return k(this, null, function* () {
-          const m = a == null ? void 0 : a.selectedRowKeys;
-          if (!(m != null && m.length)) {
-            t.warning(e('Please select departments'));
-            return;
-          }
-          yield o.resource(`roles/${i == null ? void 0 : i.name}/departments`).remove({ values: m }),
-            r == null || r({ selectedRowKeys: [] }),
-            c();
-        });
-      },
-    };
-  },
-  ht = () => {
-    const e = useRecord(),
-      t = (o) => {
-        const a = o.title,
-          r = o.parent;
-        return r ? t(r) + ' / ' + a : a;
-      };
-    return jsxRuntime.jsx(jsxRuntime.Fragment, { children: t(e) });
-  },
-  ft = (e) => {
-    const t = {
-        resource: 'departments',
-        action: 'list',
-        params: { appends: ['roles', 'parent(recursively=true)'], sort: ['createdAt'] },
-      },
-      o = useRequest(t, e);
-    return T(y({}, o), { defaultRequest: t });
-  },
-  vt = () => {
-    const { role: e } = useContext(RolesManagerContext);
-    return {
-      disabled: (t) => {
-        var o;
-        return (o = t == null ? void 0 : t.roles) == null
-          ? void 0
-          : o.some((a) => a.name === (e == null ? void 0 : e.name));
-      },
-    };
-  },
-  gt = () => {
-    const { role: e } = useContext(RolesManagerContext),
-      t = useAPIClient(),
-      o = useForm(),
-      { setVisible: a } = useActionContext(),
-      { refresh: r } = useResourceActionContext(),
-      { departments: c } = o.values || {};
-    return {
-      run() {
-        return k(this, null, function* () {
-          yield t.resource('roles.departments', e.name).add({ values: c.map((x) => x.id) }), o.reset(), a(!1), r();
-        });
-      },
-    };
-  },
-  Ct = () => {
-    const { t: e } = useTranslation(),
-      { role: t } = useContext(RolesManagerContext),
-      o = useRequest(
-        {
-          resource: `roles/${t == null ? void 0 : t.name}/departments`,
-          action: 'list',
-          params: { appends: ['parent', 'parent.parent(recursively=true)'] },
+      properties: {
+        title: {
+          type: 'void',
+          title: '{{t("Department name")}}',
+          'x-decorator': 'Table.Column.Decorator',
+          'x-component': 'Table.Column',
+          properties: { title: { type: 'string', 'x-component': 'DepartmentTitle' } },
         },
-        { ready: !!t },
-      );
-    useEffect(() => {
-      o.run();
-    }, [t]);
-    const a = useMemo(() => dt(), [t]);
-    return jsxRuntime.jsx(ResourceActionContext.Provider, {
-      value: y({}, o),
-      children: jsxRuntime.jsx(CollectionProvider_deprecated, {
-        collection: Q,
-        children: jsxRuntime.jsx(SchemaComponent, {
-          schema: a,
-          components: { DepartmentTable: pe, DepartmentTitle: ht },
-          scope: {
-            useFilterActionProps: Z,
-            t: e,
-            useRemoveDepartment: xt,
-            useBulkRemoveDepartments: yt,
-            useDataSource: ft,
-            useDisabled: vt,
-            useAddDepartments: gt,
-          },
-        }),
-      }),
-    });
-  },
-  UserDepartmentsField = connect(() => {
-    const { t: e } = useTranslation();
-    return jsxRuntime.jsxs('div', {
-      style: { color: '#ccc' },
-      children: [e('This field is currently not supported for use in form blocks.'), ' '],
-    });
-  }, mapReadPretty(AssociationField.ReadPretty)),
-  te = {
-    name: 'titleField',
-    type: 'select',
-    useComponentProps() {
-      var b, h, F, C;
-      const { t: e } = useTranslation(),
-        t = useField(),
-        { dn: o } = useDesignable(),
-        a = useTitleFieldOptions(),
-        { uiSchema: r, fieldSchema: c, collectionField: i } = oe(),
-        x = useFieldSchema(),
-        m = c || x,
-        g = useCollectionField(),
-        d = i || g,
-        A = y(
-          y(
-            y(
-              {},
-              (h = (b = d == null ? void 0 : d.uiSchema) == null ? void 0 : b['x-component-props']) == null
-                ? void 0
-                : h.fieldNames,
-            ),
-            (F = t == null ? void 0 : t.componentProps) == null ? void 0 : F.fieldNames,
-          ),
-          (C = m == null ? void 0 : m['x-component-props']) == null ? void 0 : C.fieldNames,
-        );
-      return {
-        title: e('Title field'),
-        options: a,
-        value: A == null ? void 0 : A.label,
-        onChange(v) {
-          var S, O, $, W, H, J;
-          const l = { 'x-uid': m['x-uid'] },
-            u = T(
-              y(
-                y(
-                  {},
-                  (O = (S = d == null ? void 0 : d.uiSchema) == null ? void 0 : S['x-component-props']) == null
-                    ? void 0
-                    : O.fieldNames,
-                ),
-                ($ = m['x-component-props']) == null ? void 0 : $.fieldNames,
-              ),
-              { label: v },
-            );
-          (m['x-component-props'] = m['x-component-props'] || {}),
-            (m['x-component-props'].fieldNames = u),
-            (l['x-component-props'] = m['x-component-props']),
-            (t.componentProps.fieldNames = (W = m['x-component-props']) == null ? void 0 : W.fieldNames);
-          const f = (J = t.path) == null ? void 0 : J.splice(((H = t.path) == null ? void 0 : H.length) - 1, 1);
-          t.form.query(`${f.concat('*.' + m.name)}`).forEach((M) => {
-            M.componentProps.fieldNames = A;
-          }),
-            o.emit('patch', { schema: l }),
-            o.refresh();
-        },
-      };
-    },
-  },
-  bt = (e) => e['x-component'] === 'CollectionField',
-  oe = () => {
-    const { getField: e } = useCollection_deprecated(),
-      t = useCompile(),
-      o = useFieldSchema(),
-      { getCollectionJoinField: a } = useCollectionManager_deprecated(),
-      r = o.reduceProperties((i, x) => (bt(x) ? x : i), null);
-    if (!r) return {};
-    const c = e(r.name) || a(r == null ? void 0 : r['x-collection-field']);
-    return { columnSchema: o, fieldSchema: r, collectionField: c, uiSchema: t(c == null ? void 0 : c.uiSchema) };
-  },
-  ne = {
-    name: 'enableLink',
-    type: 'switch',
-    useVisible() {
-      return useField().readPretty;
-    },
-    useComponentProps() {
-      var i;
-      const { t: e } = useTranslation(),
-        t = useField(),
-        { fieldSchema: o } = oe(),
-        a = useFieldSchema(),
-        r = o || a,
-        { dn: c } = useDesignable();
-      return {
-        title: e('Enable link'),
-        checked: ((i = r['x-component-props']) == null ? void 0 : i.enableLink) !== !1,
-        onChange(x) {
-          (r['x-component-props'] = T(y({}, r == null ? void 0 : r['x-component-props']), { enableLink: x })),
-            (t.componentProps.enableLink = x),
-            c.emit('patch', {
-              schema: {
-                'x-uid': r['x-uid'],
-                'x-component-props': y({}, r == null ? void 0 : r['x-component-props']),
+        actions: {
+          type: 'void',
+          title: '{{t("Actions")}}',
+          'x-component': 'Table.Column',
+          properties: {
+            actions: {
+              type: 'void',
+              'x-component': 'Space',
+              'x-component-props': { split: '|' },
+              properties: {
+                remove: {
+                  type: 'void',
+                  title: '{{ t("Remove") }}',
+                  'x-component': 'Action.Link',
+                  'x-component-props': {
+                    confirm: {
+                      title: "{{t('Remove department')}}",
+                      content: "{{t('Are you sure you want to remove it?')}}",
+                    },
+                    useAction: '{{ useRemoveDepartment }}',
+                  },
+                },
               },
-            }),
-            c.refresh();
+            },
+          },
         },
-      };
+      },
     },
   },
-  re = {
-    name: 'fieldComponent',
-    type: 'select',
-    useComponentProps() {
-      const { t: e } = useTranslation(),
-        t = useField(),
-        { fieldSchema: o, collectionField: a } = oe(),
-        r = useFieldSchema(),
-        c = o || r,
-        i = useFieldModeOptions({ fieldSchema: o, collectionField: a }),
-        { dn: x } = useDesignable();
-      return {
-        title: e('Field component'),
-        options: i,
-        value: 'Select',
-        onChange(m) {
-          const g = { 'x-uid': c['x-uid'] };
-          (c['x-component-props'] = c['x-component-props'] || {}),
-            (c['x-component-props'].mode = m),
-            (g['x-component-props'] = c['x-component-props']),
-            (t.componentProps = t.componentProps || {}),
-            (t.componentProps.mode = m),
-            x.emit('patch', { schema: g }),
-            x.refresh();
-        },
-      };
+});
+const xt = () => {
+  const e = useAPIClient(),
+    { role: t } = useContext(RolesManagerContext),
+    { data: o } = useRecord(),
+    { refresh: a } = useResourceActionContext();
+  return {
+    run() {
+      return k(this, null, function* () {
+        yield e.resource(`roles/${t == null ? void 0 : t.name}/departments`).remove({ values: [o.id] }), a();
+      });
     },
-  },
-  At = new SchemaSettings({
-    name: 'fieldSettings:component:UserDepartmentsField',
-    items: [y({}, re), y({}, te), y({}, ne)],
-  }),
-  St = new SchemaSettings({
-    name: 'fieldSettings:component:UserMainDepartmentField',
-    items: [y({}, re), y({}, te), y({}, ne)],
-  }),
-  Dt = new SchemaSettings({
-    name: 'fieldSettings:component:DepartmentOwnersField',
-    items: [y({}, re), y({}, te), y({}, ne)],
+  };
+};
+const yt = () => {
+  const { t: e } = useTranslation(),
+    { message: t } = App.useApp(),
+    o = useAPIClient(),
+    { state: a, setState: r, refresh: c } = useResourceActionContext(),
+    { role: i } = useContext(RolesManagerContext);
+  return {
+    run() {
+      return k(this, null, function* () {
+        const m = a == null ? void 0 : a.selectedRowKeys;
+        if (!(m != null && m.length)) {
+          t.warning(e('Please select departments'));
+          return;
+        }
+        yield o.resource(`roles/${i == null ? void 0 : i.name}/departments`).remove({ values: m }),
+          r == null || r({ selectedRowKeys: [] }),
+          c();
+      });
+    },
+  };
+};
+const ht = () => {
+  const e = useRecord(),
+    t = (o) => {
+      const a = o.title,
+        r = o.parent;
+      return r ? t(r) + ' / ' + a : a;
+    };
+  return jsx(Fragment, { children: t(e) });
+};
+const ft = (e) => {
+  const t = {
+      resource: 'departments',
+      action: 'list',
+      params: { appends: ['roles', 'parent(recursively=true)'], sort: ['createdAt'] },
+    },
+    o = useRequest(t, e);
+  return T(y({}, o), { defaultRequest: t });
+};
+const vt = () => {
+  const { role: e } = useContext(RolesManagerContext);
+  return {
+    disabled: (t) => {
+      var o;
+      return (o = t == null ? void 0 : t.roles) == null
+        ? void 0
+        : o.some((a) => a.name === (e == null ? void 0 : e.name));
+    },
+  };
+};
+const gt = () => {
+  const { role: e } = useContext(RolesManagerContext),
+    t = useAPIClient(),
+    o = useForm(),
+    { setVisible: a } = useActionContext(),
+    { refresh: r } = useResourceActionContext(),
+    { departments: c } = o.values || {};
+  return {
+    run() {
+      return k(this, null, function* () {
+        yield t.resource('roles.departments', e.name).add({ values: c.map((x) => x.id) }), o.reset(), a(false), r();
+      });
+    },
+  };
+};
+const Departments = () => {
+  const { t: e } = useTranslation(),
+    { role: t } = useContext(RolesManagerContext),
+    o = useRequest(
+      {
+        resource: `roles/${t == null ? void 0 : t.name}/departments`,
+        action: 'list',
+        params: { appends: ['parent', 'parent.parent(recursively=true)'] },
+      },
+      { ready: !!t },
+    );
+  useEffect(() => {
+    o.run();
+  }, [t]);
+  const a = useMemo(() => dt(), [t]);
+  return jsx(ResourceActionContext.Provider, {
+    value: y({}, o),
+    children: jsx(CollectionProvider_deprecated, {
+      collection: Q,
+      children: jsx(SchemaComponent, {
+        schema: a,
+        components: { DepartmentTable: pe, DepartmentTitle: ht },
+        scope: {
+          useFilterActionProps: Z,
+          t: e,
+          useRemoveDepartment: xt,
+          useBulkRemoveDepartments: yt,
+          useDataSource: ft,
+          useDisabled: vt,
+          useAddDepartments: gt,
+        },
+      }),
+    }),
   });
+};
+const UserDepartmentsField = connect(() => {
+  const { t: e } = useTranslation();
+  return jsxs('div', {
+    style: { color: '#ccc' },
+    children: [e('This field is currently not supported for use in form blocks.'), ' '],
+  });
+}, mapReadPretty(AssociationField.ReadPretty));
+const te = {
+  name: 'titleField',
+  type: 'select',
+  useComponentProps() {
+    var b, h, F, C;
+    const { t: e } = useTranslation(),
+      t = useField(),
+      { dn: o } = useDesignable(),
+      a = useTitleFieldOptions(),
+      { uiSchema: r, fieldSchema: c, collectionField: i } = oe(),
+      x = useFieldSchema(),
+      m = c || x,
+      g = useCollectionField(),
+      d = i || g,
+      A = y(
+        y(
+          y(
+            {},
+            (h = (b = d == null ? void 0 : d.uiSchema) == null ? void 0 : b['x-component-props']) == null
+              ? void 0
+              : h.fieldNames,
+          ),
+          (F = t == null ? void 0 : t.componentProps) == null ? void 0 : F.fieldNames,
+        ),
+        (C = m == null ? void 0 : m['x-component-props']) == null ? void 0 : C.fieldNames,
+      );
+    return {
+      title: e('Title field'),
+      options: a,
+      value: A == null ? void 0 : A.label,
+      onChange(v) {
+        var S, O, $, W, H, J;
+        const l = { 'x-uid': m['x-uid'] },
+          u = T(
+            y(
+              y(
+                {},
+                (O = (S = d == null ? void 0 : d.uiSchema) == null ? void 0 : S['x-component-props']) == null
+                  ? void 0
+                  : O.fieldNames,
+              ),
+              ($ = m['x-component-props']) == null ? void 0 : $.fieldNames,
+            ),
+            { label: v },
+          );
+        (m['x-component-props'] = m['x-component-props'] || {}),
+          (m['x-component-props'].fieldNames = u),
+          (l['x-component-props'] = m['x-component-props']),
+          (t.componentProps.fieldNames = (W = m['x-component-props']) == null ? void 0 : W.fieldNames);
+        const f = (J = t.path) == null ? void 0 : J.splice(((H = t.path) == null ? void 0 : H.length) - 1, 1);
+        t.form.query(`${f.concat('*.' + m.name)}`).forEach((M) => {
+          M.componentProps.fieldNames = A;
+        }),
+          o.emit('patch', { schema: l }),
+          o.refresh();
+      },
+    };
+  },
+};
+const bt = (e) => e['x-component'] === 'CollectionField';
+const oe = () => {
+  const { getField: e } = useCollection_deprecated(),
+    t = useCompile(),
+    o = useFieldSchema(),
+    { getCollectionJoinField: a } = useCollectionManager_deprecated(),
+    r = o.reduceProperties((i, x) => (bt(x) ? x : i), null);
+  if (!r) return {};
+  const c = e(r.name) || a(r == null ? void 0 : r['x-collection-field']);
+  return { columnSchema: o, fieldSchema: r, collectionField: c, uiSchema: t(c == null ? void 0 : c.uiSchema) };
+};
+const ne = {
+  name: 'enableLink',
+  type: 'switch',
+  useVisible() {
+    return useField().readPretty;
+  },
+  useComponentProps() {
+    var i;
+    const { t: e } = useTranslation(),
+      t = useField(),
+      { fieldSchema: o } = oe(),
+      a = useFieldSchema(),
+      r = o || a,
+      { dn: c } = useDesignable();
+    return {
+      title: e('Enable link'),
+      checked: ((i = r['x-component-props']) == null ? void 0 : i.enableLink) !== false,
+      onChange(x) {
+        (r['x-component-props'] = T(y({}, r == null ? void 0 : r['x-component-props']), { enableLink: x })),
+          (t.componentProps.enableLink = x),
+          c.emit('patch', {
+            schema: {
+              'x-uid': r['x-uid'],
+              'x-component-props': y({}, r == null ? void 0 : r['x-component-props']),
+            },
+          }),
+          c.refresh();
+      },
+    };
+  },
+};
+const re = {
+  name: 'fieldComponent',
+  type: 'select',
+  useComponentProps() {
+    const { t: e } = useTranslation(),
+      t = useField(),
+      { fieldSchema: o, collectionField: a } = oe(),
+      r = useFieldSchema(),
+      c = o || r,
+      i = useFieldModeOptions({ fieldSchema: o, collectionField: a }),
+      { dn: x } = useDesignable();
+    return {
+      title: e('Field component'),
+      options: i,
+      value: 'Select',
+      onChange(m) {
+        const g = { 'x-uid': c['x-uid'] };
+        (c['x-component-props'] = c['x-component-props'] || {}),
+          (c['x-component-props'].mode = m),
+          (g['x-component-props'] = c['x-component-props']),
+          (t.componentProps = t.componentProps || {}),
+          (t.componentProps.mode = m),
+          x.emit('patch', { schema: g }),
+          x.refresh();
+      },
+    };
+  },
+};
+const At = new SchemaSettings({
+  name: 'fieldSettings:component:UserDepartmentsField',
+  items: [{ ...re }, { ...te }, { ...ne }],
+});
+const St = new SchemaSettings({
+  name: 'fieldSettings:component:UserMainDepartmentField',
+  items: [{ ...re }, { ...te }, { ...ne }],
+});
+const Dt = new SchemaSettings({
+  name: 'fieldSettings:component:DepartmentOwnersField',
+  items: [{ ...re }, { ...te }, { ...ne }],
+});
 export class DepartmentsPlugin extends Plugin {
   async load() {
     this.app.addComponents({
@@ -2463,9 +2463,9 @@ export class DepartmentsPlugin extends Plugin {
       title: tval('Departments'),
       Component: () => {
         const o = useSchemaComponentContext();
-        return jsxRuntime.jsx(SchemaComponentContext.Provider, {
-          value: T(y({}, o), { designable: !1 }),
-          children: jsxRuntime.jsx(ge, { children: jsxRuntime.jsx(mt, {}) }),
+        return jsx(SchemaComponentContext.Provider, {
+          value: T({ ...o }, { designable: false }),
+          children: jsx(ge, { children: jsx(mt, {}) }),
         });
       },
       sort: 2,
@@ -2473,7 +2473,7 @@ export class DepartmentsPlugin extends Plugin {
     });
     this.app.pm.get(PluginACLClient).rolesManager.add('departments', {
       title: tval('Departments'),
-      Component: Ct,
+      Component: Departments,
     });
   }
 }
diff --git a/packages/plugins/@hera/plugin-core/src/locale/en-US.json b/packages/plugins/@hera/plugin-core/src/locale/en-US.json
index 90f0431f0..eb1b339c9 100644
--- a/packages/plugins/@hera/plugin-core/src/locale/en-US.json
+++ b/packages/plugins/@hera/plugin-core/src/locale/en-US.json
@@ -10,6 +10,9 @@
   "Association field": "Association field",
   "Chuangxing presets": "Chuangxing presets",
   "Configure": "Configure",
+  "Copy Failed": "Copy Failed",
+  "Copy embedded link": "Copy embedded link",
+  "Copy successful": "Copy successful",
   "Custom filter": "Custom filter",
   "Custom option label": "Custom option label",
   "Delete department": "Delete department",
diff --git a/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json b/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json
index 2ff7da820..2f5b02a4d 100644
--- a/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json
+++ b/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json
@@ -10,6 +10,9 @@
   "Association field": "关联字段",
   "Chuangxing presets": "创兴预置",
   "Configure": "配置",
+  "Copy Failed": "复制失败",
+  "Copy embedded link": "复制嵌入链接",
+  "Copy successful": "复制成功",
   "Custom filter": "自定义筛选",
   "Custom option label": "自定义选项标签",
   "Delete department": "删除部门",