@boarteam/boar-pack-common-frontend 3.1.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/components/Descriptions/Descriptions.tsx +5 -28
- package/src/components/Descriptions/descriptionTypes.ts +2 -8
- package/src/components/Table/CreateEntityModal.tsx +1 -5
- package/src/components/Table/Table.tsx +0 -2
- package/src/components/Table/tableTypes.ts +0 -2
- package/src/components/Table/useCreation.tsx +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boarteam/boar-pack-common-frontend",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Common frontend package for Boar Pack",
|
|
5
5
|
"repository": "git@github.com:boarteam/boar-pack.git",
|
|
6
6
|
"author": "Andrew Balakirev <balakirev.andrey@gmail.com>",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"scripts": {
|
|
48
48
|
"yalc:push": "yalc push"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "84d2c3f084f48afc57cb93f7eb2639c971bba5d2"
|
|
51
51
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionType } from "@ant-design/pro-table";
|
|
2
2
|
import React, { Key, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { Badge, Button,
|
|
3
|
+
import { Badge, Button, Result, Tabs, TabsProps, Tooltip } from "antd";
|
|
4
4
|
import { DeleteOutlined, StopOutlined } from "@ant-design/icons";
|
|
5
5
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
6
6
|
import { DescriptionsRefType, FieldsEdit, TDescriptionsProps, TGetOneParams } from "./descriptionTypes";
|
|
@@ -21,7 +21,7 @@ import { debounce } from "lodash";
|
|
|
21
21
|
import { NamePath } from "antd/lib/form/interface";
|
|
22
22
|
import { FieldData } from "rc-field-form/lib/interface";
|
|
23
23
|
|
|
24
|
-
const useStyles = createStyles(({
|
|
24
|
+
const useStyles = createStyles(({css}) => {
|
|
25
25
|
return {
|
|
26
26
|
antDescriptionsStyles: css`
|
|
27
27
|
.ant-descriptions-item-content {
|
|
@@ -62,7 +62,7 @@ const DescriptionsComponent = <Entity extends Record<string | symbol, any>,
|
|
|
62
62
|
columns,
|
|
63
63
|
params,
|
|
64
64
|
onEntityChange,
|
|
65
|
-
|
|
65
|
+
contentViewMode: contentViewModeProp,
|
|
66
66
|
...rest
|
|
67
67
|
}: TDescriptionsProps<Entity,
|
|
68
68
|
CreateDto,
|
|
@@ -81,36 +81,13 @@ const DescriptionsComponent = <Entity extends Record<string | symbol, any>,
|
|
|
81
81
|
}
|
|
82
82
|
form = editable.form;
|
|
83
83
|
|
|
84
|
-
const watchedValue = conditionalFieldsConfig
|
|
85
|
-
? Form.useWatch(conditionalFieldsConfig.field, form)
|
|
86
|
-
: undefined;
|
|
87
|
-
|
|
88
|
-
const filteredColumns = React.useMemo(() => {
|
|
89
|
-
if (!conditionalFieldsConfig) {
|
|
90
|
-
return columns;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { field, deps } = conditionalFieldsConfig;
|
|
94
|
-
const depsList = deps[watchedValue as string];
|
|
95
|
-
|
|
96
|
-
if (!depsList?.length) {
|
|
97
|
-
return columns;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Always include the watched field itself
|
|
101
|
-
return columns.filter(col => {
|
|
102
|
-
const idx = col.dataIndex as string;
|
|
103
|
-
return idx === field || depsList.includes(idx);
|
|
104
|
-
});
|
|
105
|
-
}, [columns, watchedValue, conditionalFieldsConfig]);
|
|
106
|
-
|
|
107
84
|
const actionRefComponent = useRef<ActionType>();
|
|
108
85
|
const actionRef = actionRefProp || actionRefComponent;
|
|
109
86
|
const intl = useIntl();
|
|
110
87
|
const [data, setData] = useState<Partial<Entity> | undefined>(entity);
|
|
111
88
|
const [loading, setLoading] = useState(false);
|
|
112
89
|
|
|
113
|
-
const sections = columnsToDescriptionItemProps(
|
|
90
|
+
const sections = columnsToDescriptionItemProps(columns, mainTitle);
|
|
114
91
|
|
|
115
92
|
const columnDataIndexToSection = sections.reduce((acc, section) => {
|
|
116
93
|
section.columns.forEach(column => {
|
|
@@ -127,7 +104,7 @@ const DescriptionsComponent = <Entity extends Record<string | symbol, any>,
|
|
|
127
104
|
contentViewModeButton,
|
|
128
105
|
contentViewMode
|
|
129
106
|
} = useContentViewMode({
|
|
130
|
-
mode: sections.length > 1 ? VIEW_MODE_TYPE.TABS : VIEW_MODE_TYPE.GENERAL
|
|
107
|
+
mode: contentViewModeProp || (sections.length > 1 ? VIEW_MODE_TYPE.TABS : VIEW_MODE_TYPE.GENERAL)
|
|
131
108
|
});
|
|
132
109
|
const [errorsPerSection, setErrorsPerSection] = useState<Map<TDescriptionSection<Entity>['key'], number>>(
|
|
133
110
|
new Map(sections.map(section => [section.key, 0]))
|
|
@@ -5,6 +5,7 @@ import { QueryJoin } from "@nestjsx/crud-request";
|
|
|
5
5
|
import { ProColumns } from "@ant-design/pro-components";
|
|
6
6
|
import { ProDescriptionsProps } from "@ant-design/pro-descriptions";
|
|
7
7
|
import { FieldData } from "rc-field-form/lib/interface";
|
|
8
|
+
import { VIEW_MODE_TYPE } from "./useContentViewMode";
|
|
8
9
|
|
|
9
10
|
export type TGetOneParams = {
|
|
10
11
|
/**
|
|
@@ -35,15 +36,7 @@ export enum FieldsEdit {
|
|
|
35
36
|
All = 'all'
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export interface ConditionalFieldsConfig {
|
|
39
|
-
/** Which field to watch */
|
|
40
|
-
field: string;
|
|
41
|
-
/** Map of watched-value → array of dataIndex you want to show */
|
|
42
|
-
deps: Record<string, string[]>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
39
|
export type TDescriptionsProps<Entity, CreateDto, UpdateDto, TPathParams = object> = {
|
|
46
|
-
conditionalFieldsConfig?: ConditionalFieldsConfig;
|
|
47
40
|
mainTitle?: ProColumns<Entity>['title'] | null,
|
|
48
41
|
entity?: Partial<Entity>,
|
|
49
42
|
getOne?: ({}: TGetOneParams & TPathParams) => Promise<Entity | null>,
|
|
@@ -65,6 +58,7 @@ export type TDescriptionsProps<Entity, CreateDto, UpdateDto, TPathParams = objec
|
|
|
65
58
|
params?: TDescriptionGetRequestParams,
|
|
66
59
|
columns: ProColumns<Entity>[],
|
|
67
60
|
onEntityChange?: (entity: Entity | null) => void;
|
|
61
|
+
contentViewMode?: VIEW_MODE_TYPE,
|
|
68
62
|
ref?: React.Ref<DescriptionsRefType<Entity>>,
|
|
69
63
|
} & Omit<ProDescriptionsProps<Entity>, 'columns'>;
|
|
70
64
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProColumns } from "@ant-design/pro-components";
|
|
2
2
|
import { Button, Modal } from "antd";
|
|
3
3
|
import { MutableRefObject, useRef } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { Descriptions, DescriptionsRefType } from "../Descriptions";
|
|
5
5
|
import { buildFieldsFromColumnsForDescriptionsDisplay } from "./tableTools";
|
|
6
6
|
|
|
7
7
|
export interface CreateEntityModalProps<Entity> {
|
|
@@ -24,8 +24,6 @@ export interface CreateEntityModalProps<Entity> {
|
|
|
24
24
|
* Receives the validated form data.
|
|
25
25
|
*/
|
|
26
26
|
onSubmit: (data: any, descriptionsRef: MutableRefObject<DescriptionsRefType<Entity>>) => Promise<void>;
|
|
27
|
-
/** Configuration for conditional fields */
|
|
28
|
-
conditionalFieldsConfig?: ConditionalFieldsConfig
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export function CreateEntityModal<
|
|
@@ -42,7 +40,6 @@ export function CreateEntityModal<
|
|
|
42
40
|
idColumnName,
|
|
43
41
|
onCancel,
|
|
44
42
|
onSubmit,
|
|
45
|
-
conditionalFieldsConfig,
|
|
46
43
|
}: CreateEntityModalProps<Entity>) {
|
|
47
44
|
const descriptionsRef = useRef<DescriptionsRefType<Entity>>(null);
|
|
48
45
|
|
|
@@ -82,7 +79,6 @@ export function CreateEntityModal<
|
|
|
82
79
|
editableKeys,
|
|
83
80
|
actionRender: () => [],
|
|
84
81
|
}}
|
|
85
|
-
conditionalFieldsConfig={conditionalFieldsConfig}
|
|
86
82
|
/>
|
|
87
83
|
</Modal>
|
|
88
84
|
);
|
|
@@ -55,7 +55,6 @@ const Table = <Entity extends Record<string | symbol, any>,
|
|
|
55
55
|
columnsState: managedColumnsState,
|
|
56
56
|
columnsSetSelect: managedColumnsSetSelect,
|
|
57
57
|
popupCreation = false,
|
|
58
|
-
conditionalFieldsConfig,
|
|
59
58
|
toolBarRender,
|
|
60
59
|
params,
|
|
61
60
|
editPopupTitle,
|
|
@@ -121,7 +120,6 @@ const Table = <Entity extends Record<string | symbol, any>,
|
|
|
121
120
|
createButtonSize: rest.size,
|
|
122
121
|
popupCreation,
|
|
123
122
|
createNewDefaultParams,
|
|
124
|
-
conditionalFieldsConfig,
|
|
125
123
|
});
|
|
126
124
|
|
|
127
125
|
const { exportButton, importButton, setLastQueryParams } = useImportExport<TPathParams>({
|
|
@@ -6,7 +6,6 @@ import { TColumnsSet } from "./useColumnsSets";
|
|
|
6
6
|
import { ColumnStateType } from "@ant-design/pro-table/es/typing";
|
|
7
7
|
import { RowEditableConfig } from "@ant-design/pro-utils";
|
|
8
8
|
import { ProColumns } from "@ant-design/pro-components";
|
|
9
|
-
import { ConditionalFieldsConfig } from "../Descriptions";
|
|
10
9
|
|
|
11
10
|
export type IWithId = {
|
|
12
11
|
id: string | number,
|
|
@@ -97,7 +96,6 @@ interface BaseProps<Entity,
|
|
|
97
96
|
viewOnly?: boolean;
|
|
98
97
|
columnsSets?: TColumnsSet<Entity>[];
|
|
99
98
|
popupCreation?: boolean;
|
|
100
|
-
conditionalFieldsConfig?: ConditionalFieldsConfig;
|
|
101
99
|
columnsState?: ColumnStateType;
|
|
102
100
|
columnsSetSelect?: () => React.ReactNode;
|
|
103
101
|
editPopupTitle?: string;
|
|
@@ -32,7 +32,6 @@ export function useCreation<Entity, CreateDto, TPathParams = {}>({
|
|
|
32
32
|
createButtonSize,
|
|
33
33
|
popupCreation,
|
|
34
34
|
createNewDefaultParams,
|
|
35
|
-
conditionalFieldsConfig,
|
|
36
35
|
}: {
|
|
37
36
|
actionRef?: MutableRefObject<ActionType | undefined>;
|
|
38
37
|
pathParams: TPathParams;
|
|
@@ -106,7 +105,6 @@ export function useCreation<Entity, CreateDto, TPathParams = {}>({
|
|
|
106
105
|
setCreatePopupData(undefined);
|
|
107
106
|
}}
|
|
108
107
|
onSubmit={onCreateSubmit}
|
|
109
|
-
conditionalFieldsConfig={conditionalFieldsConfig}
|
|
110
108
|
/>;
|
|
111
109
|
|
|
112
110
|
return {
|