@giteeteam/apps-team-components 1.0.32 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,5 +9,6 @@ export type BaseTreeProps = TreeSelectProps<any> & FieldProps & {
9
9
  value?: string;
10
10
  options?: selectValue[];
11
11
  onChange?: (e: any) => void;
12
+ showParentPath?: boolean;
12
13
  };
13
14
  export {};
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import type { BaseTreeProps } from './BaseField';
3
- declare const TreeReadView: React.FC<Pick<BaseTreeProps, 'value' | 'options' | 'multiple' | 'readonly'>>;
3
+ declare const TreeReadView: React.FC<BaseTreeProps>;
4
4
  export default TreeReadView;
@@ -3,34 +3,36 @@ import { memo, useEffect, useMemo, useState } from 'react';
3
3
  import { cloneDeep } from 'lodash-es';
4
4
  import EmptyField from '../../common/EmptyField';
5
5
  import BaseOverflowTooltip from '../../common/overflow-tooltip/BaseOverflowTooltip';
6
- import { toTree } from './utils';
7
- const TreeReadView = memo(({ value: propsValue, options: propsOptions, multiple, readonly }) => {
6
+ import { toFlatten, toTree } from './utils';
7
+ const TreeReadView = memo(({ value: propsValue, options: originalOptions, multiple, readonly, showParentPath }) => {
8
8
  const [value, setValue] = useState(null);
9
- const options = useMemo(() => {
10
- return propsOptions ? toTree(cloneDeep(propsOptions)) : [];
11
- }, [propsOptions]);
9
+ const { options, optionList } = useMemo(() => {
10
+ const options = originalOptions ? toTree(cloneDeep(originalOptions), showParentPath) : [];
11
+ const optionList = toFlatten(options);
12
+ return { options, optionList };
13
+ }, [originalOptions, showParentPath]);
12
14
  useEffect(() => {
13
15
  if (options.length) {
14
16
  const val = Array.isArray(propsValue) ? propsValue : [];
15
- const filterValue = val.filter(v => propsOptions.find(item => item.value === v));
17
+ const filterValue = val.filter(v => optionList.find(item => item.value === v));
16
18
  setValue(multiple ? filterValue : filterValue[0]);
17
19
  }
18
20
  else {
19
21
  setValue(undefined);
20
22
  }
21
- }, [propsOptions, propsValue, setValue, options, multiple]);
23
+ }, [optionList, propsValue, setValue, options, multiple]);
22
24
  const showValue = useMemo(() => {
23
25
  let showValue = null;
24
26
  if (multiple) {
25
- if (Array.isArray(propsOptions) && propsOptions.length >= 1 && value && Array.isArray(value)) {
27
+ if (Array.isArray(optionList) && optionList.length >= 1 && value && Array.isArray(value)) {
26
28
  showValue = value.reduce((showValue, val) => {
27
- const opt = propsOptions.filter(item => item.value === val);
29
+ const opt = optionList.filter(item => item.value === val);
28
30
  if (opt.length) {
29
31
  if (showValue) {
30
- return showValue + ',' + opt[0].title;
32
+ return showValue + ',' + opt[0].fullTitle;
31
33
  }
32
34
  else {
33
- return showValue + opt[0].title;
35
+ return showValue + opt[0].fullTitle;
34
36
  }
35
37
  }
36
38
  return '';
@@ -38,15 +40,15 @@ const TreeReadView = memo(({ value: propsValue, options: propsOptions, multiple,
38
40
  }
39
41
  }
40
42
  else {
41
- if (Array.isArray(propsOptions) && propsOptions.length >= 1 && value) {
42
- const opt = propsOptions.filter(item => item.value === value);
43
+ if (Array.isArray(optionList) && optionList.length >= 1 && value) {
44
+ const opt = optionList.filter(item => item.value === value);
43
45
  if (opt.length >= 1) {
44
- showValue = opt[0].title;
46
+ showValue = opt[0].fullTitle;
45
47
  }
46
48
  }
47
49
  }
48
50
  return showValue;
49
- }, [value, multiple, propsOptions]);
51
+ }, [value, multiple, optionList]);
50
52
  if (!showValue) {
51
53
  return _jsx(EmptyField, { readonly: readonly });
52
54
  }
@@ -0,0 +1,9 @@
1
+ export interface SelectValue {
2
+ id: string;
3
+ label: string;
4
+ value: string | number;
5
+ title?: string;
6
+ fullTitle?: string;
7
+ children?: SelectValue[];
8
+ parentId?: string;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,3 @@
1
- export declare const toTree: (data: any[]) => any[];
2
- export declare const toflatten: (data: any[]) => any[];
1
+ import { SelectValue } from './types';
2
+ export declare const toTree: (data: SelectValue[], showParentPath?: boolean) => SelectValue[];
3
+ export declare const toFlatten: (data: SelectValue[]) => SelectValue[];
@@ -1,4 +1,22 @@
1
- export const toTree = (data) => {
1
+ const titleDelimiter = '/';
2
+ const addFullTitle = (showParentPath, tree, parentTitle) => {
3
+ if (!tree)
4
+ return;
5
+ for (const item of tree) {
6
+ if (showParentPath) {
7
+ let suffix = '';
8
+ if (parentTitle) {
9
+ suffix = `${parentTitle}${titleDelimiter}`;
10
+ }
11
+ item.fullTitle = `${suffix}${item.title}`;
12
+ }
13
+ else {
14
+ item.fullTitle = item.title;
15
+ }
16
+ addFullTitle(showParentPath, item.children, item.fullTitle);
17
+ }
18
+ };
19
+ export const toTree = (data, showParentPath = false) => {
2
20
  const temp = {};
3
21
  const tree = [];
4
22
  for (const i in data) {
@@ -15,8 +33,9 @@ export const toTree = (data) => {
15
33
  tree.push(temp[i]);
16
34
  }
17
35
  }
36
+ addFullTitle(showParentPath, tree);
18
37
  return tree;
19
38
  };
20
- export const toflatten = (data) => {
21
- return data.reduce((arr, { id, title, parentId, value, label, children = [] }) => arr.concat([{ id, title, parentId, value, label }], toflatten(children)), []);
39
+ export const toFlatten = (data) => {
40
+ return data.reduce((arr, { id, title, parentId, value, label, fullTitle, children = [] }) => arr.concat([{ id, title, parentId, value, label, fullTitle }], toFlatten(children)), []);
22
41
  };
@@ -13,10 +13,16 @@ const UserReadView = memo(({ value, readonly }) => {
13
13
  return (_jsxs("span", { children: [i ? ',' : '', _jsx(ClassNames, { children: ({ cx, css }) => (_jsx("span", { className: cx({ [css(userDeletedStyle)]: isUserDeleted(item) }, { [css(userDisabledStyle)]: isUserDisabled(item) }), children: generateUserDisplayName(item) })) })] }, i));
14
14
  })) || EMPTY_ARRAY);
15
15
  }, [value]);
16
+ const tooltipValues = useMemo(() => {
17
+ return value === null || value === void 0 ? void 0 : value.map((val) => {
18
+ const item = userDataFormat(val);
19
+ return generateUserDisplayName(item);
20
+ });
21
+ }, [value]);
16
22
  if (!displayValues.length) {
17
23
  return _jsx(EmptyField, { readonly: readonly, isUser: true });
18
24
  }
19
- return _jsx(BaseOverflowTooltip, { title: displayValues, maxline: 1, children: displayValues });
25
+ return _jsx(BaseOverflowTooltip, { title: tooltipValues.join(','), maxline: 1, children: displayValues });
20
26
  });
21
27
  UserReadView.displayName = 'UserReadView';
22
28
  export default UserReadView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-team-components",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "Gitee team components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",