@giteeteam/apps-team-components 1.0.33 → 1.0.35

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,10 @@
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
+ disabled?: boolean;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,4 @@
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 titleDelimiter = "/";
3
+ export declare const toTree: (data: SelectValue[], showParentPath?: boolean) => SelectValue[];
4
+ export declare const toFlatten: (data: SelectValue[]) => SelectValue[];
@@ -1,4 +1,23 @@
1
- export const toTree = (data) => {
1
+ export 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
+ const nextTitle = item.disabled ? '' : item.fullTitle;
17
+ addFullTitle(showParentPath, item.children, nextTitle);
18
+ }
19
+ };
20
+ export const toTree = (data, showParentPath = false) => {
2
21
  const temp = {};
3
22
  const tree = [];
4
23
  for (const i in data) {
@@ -15,8 +34,9 @@ export const toTree = (data) => {
15
34
  tree.push(temp[i]);
16
35
  }
17
36
  }
37
+ addFullTitle(showParentPath, tree);
18
38
  return tree;
19
39
  };
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)), []);
40
+ export const toFlatten = (data) => {
41
+ return data.reduce((arr, { id, title, parentId, value, label, fullTitle, children = [] }) => arr.concat([{ id, title, parentId, value, label, fullTitle }], toFlatten(children)), []);
22
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-team-components",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "Gitee team components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",