mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 21:28:34 +08:00
fix: subTable
This commit is contained in:
parent
47f4cb4d13
commit
38e9b2c96c
@ -30,12 +30,14 @@ function transform({value, multiple, labelField, valueField = 'id'}) {
|
||||
}
|
||||
|
||||
export function DrawerSelectComponent(props) {
|
||||
const { __parent, size, schema = {}, disabled, viewName, target, multiple, filter, resourceName, associatedKey, labelField, valueField = 'id', value, onChange } = props;
|
||||
const { __parent, size, schema = {}, disabled, viewName, target, multiple, filter, resourceName, associatedKey, valueField = 'id', value, onChange } = props;
|
||||
const labelField = props.labelField || schema.labelField;
|
||||
const [selectedKeys, selectedValue] = transform({value, multiple, labelField, valueField });
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState(multiple ? selectedKeys : [selectedKeys]);
|
||||
const [selectedRows, setSelectedRows] = useState(selectedValue);
|
||||
const [options, setOptions] = useState(selectedValue);
|
||||
const { title = '' } = schema;
|
||||
console.log({schema})
|
||||
return (
|
||||
<>
|
||||
<Select
|
||||
|
@ -25,17 +25,17 @@ export function generateIndex(): string {
|
||||
}
|
||||
|
||||
export default function Table(props: SimpleTableProps) {
|
||||
const { schema = {}, associatedKey, value, onChange, __parent } = props;
|
||||
console.log({props, associatedKey, schema, __parent})
|
||||
const { schema = {}, associatedKey, value, onChange, __index } = props;
|
||||
const { collection_name, name } = schema;
|
||||
const viewName = `${collection_name}.${name}.${schema.viewName||'table'}`;
|
||||
console.log({props, associatedKey, schema, __index, viewName, schema})
|
||||
return (
|
||||
<>
|
||||
<View
|
||||
__parent={__parent}
|
||||
// __parent={__parent}
|
||||
data={value}
|
||||
onChange={onChange}
|
||||
associatedKey={associatedKey}
|
||||
associatedKey={__index}
|
||||
viewName={viewName}
|
||||
type={'subTable'}
|
||||
/>
|
||||
|
@ -121,10 +121,10 @@ export function Form(props: any) {
|
||||
associatedKey,
|
||||
resourceKey,
|
||||
}}
|
||||
effects={($, { setFieldState }) => {
|
||||
effects={($, { setFormState, setFieldState, getFieldState }) => {
|
||||
$(LifeCycleTypes.ON_FORM_INIT).subscribe(() => {
|
||||
setFieldState('*', state => {
|
||||
set(state.props, 'x-component-props.__parent', __parent);
|
||||
set(state.props, 'x-component-props.__index', resourceKey);
|
||||
})
|
||||
})
|
||||
}}
|
||||
|
@ -76,8 +76,8 @@ export function SubTable(props: any) {
|
||||
|
||||
const {
|
||||
fields = [],
|
||||
actions = [],
|
||||
details = [],
|
||||
actions: defaultActions = [],
|
||||
details: defaultDetails = [],
|
||||
paginated = true,
|
||||
defaultPerPage = 10,
|
||||
// rowKey = 'id',
|
||||
@ -90,6 +90,14 @@ export function SubTable(props: any) {
|
||||
filter: schemaFilter = {},
|
||||
} = schema;
|
||||
|
||||
let actions = defaultActions;
|
||||
let details = defaultDetails;
|
||||
|
||||
if (!onChange) {
|
||||
actions = [];
|
||||
details = [];
|
||||
}
|
||||
|
||||
const cloneFields = cloneDeep(fields) as any[];
|
||||
|
||||
let draggable = !!schema.draggable;
|
||||
@ -235,6 +243,16 @@ export function SubTable(props: any) {
|
||||
pagination={false}
|
||||
onChange={(pagination, filters, sorter, extra) => {
|
||||
|
||||
}}
|
||||
components={{
|
||||
body: {
|
||||
row: ({className, ...others}) => {
|
||||
if (!details.length) {
|
||||
return <tr className={className} {...others}/>
|
||||
}
|
||||
return <tr className={className ? `${className} row-clickable` : 'row-clickable'} {...others}/>
|
||||
},
|
||||
}
|
||||
}}
|
||||
expandable={expandable}
|
||||
onRow={(data, index) => ({
|
||||
@ -248,6 +266,9 @@ export function SubTable(props: any) {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (!details.length) {
|
||||
return;
|
||||
}
|
||||
Drawer.open({
|
||||
title: details.length > 1 ? undefined : data[labelField],
|
||||
bodyStyle: {
|
||||
@ -261,12 +282,14 @@ export function SubTable(props: any) {
|
||||
resourceName={resourceName}
|
||||
onFinish={async (values) => {
|
||||
let data = [...dataSource];
|
||||
console.log({values});
|
||||
data[index] = values;
|
||||
data = data.map((v: any, i) => {
|
||||
return {...v, [sortField]: i};
|
||||
});
|
||||
mutate(data);
|
||||
onChange && await onChange(data);
|
||||
console.log({values, data});
|
||||
resolve();
|
||||
}}
|
||||
onReset={resolve}
|
||||
|
@ -219,14 +219,23 @@ export function RealtionField(props: any) {
|
||||
}
|
||||
|
||||
export function SubTableField(props: any) {
|
||||
const { schema: { children }, value } = props;
|
||||
console.log(value);
|
||||
const { data, schema, schema: { name, children, collection_name }, value } = props;
|
||||
if (!Array.isArray(value)) {
|
||||
return null;
|
||||
}
|
||||
const viewName = `${collection_name}.${name}.${schema.viewName||'table'}`;
|
||||
console.log({value, viewName, schema});
|
||||
return (
|
||||
<div className={'sub-table-field'}>
|
||||
<Table size={'small'} columns={fields2columns(children)} dataSource={value} pagination={false}/>
|
||||
<View
|
||||
// __parent={__parent}
|
||||
data={value}
|
||||
// onChange={onChange}
|
||||
associatedKey={data.id}
|
||||
viewName={viewName}
|
||||
type={'subTable'}
|
||||
/>
|
||||
{/* <Table size={'small'} columns={fields2columns(children)} dataSource={value} pagination={false}/> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -247,8 +256,8 @@ export function LinkToField(props: any) {
|
||||
}
|
||||
|
||||
export function LinkToFieldLink(props) {
|
||||
const { isArr, itemIndex, ctx, parent, schema, schema: { title, labelField, viewName, name, target, collection_name } } = props;
|
||||
const [data, setData] = useState(props.data||{});
|
||||
const { data, isArr, itemIndex, ctx, parent, schema, schema: { title, labelField, viewName, name, target, collection_name } } = props;
|
||||
// const [data, setData] = useState(props.data||{});
|
||||
return (
|
||||
<span className={'link-to-field-tag'}>
|
||||
<a onClick={(e) => {
|
||||
@ -270,7 +279,7 @@ export function LinkToFieldLink(props) {
|
||||
const parentData = {...parent};
|
||||
set(parentData, isArr ? [name, itemIndex] : [name], values);
|
||||
items[index] = parentData;
|
||||
setData(values);
|
||||
// setData(values);
|
||||
mutate(items);
|
||||
onChange(items);
|
||||
resolve();
|
||||
|
Loading…
Reference in New Issue
Block a user