feat: support filter blocks in select record drawer (#2828)
* feat: support filter blocks in select record drawer * feat: improve UX * chore: add migration
This commit is contained in:
parent
3510506db3
commit
a51df00750
@ -12,6 +12,9 @@ export const useStyles = genStyleHook('nb-action-drawer', (token) => {
|
|||||||
'.ant-drawer-body': { paddingTop: token.paddingContentVerticalLG, backgroundColor: 'var(--colorBgDrawer)' },
|
'.ant-drawer-body': { paddingTop: token.paddingContentVerticalLG, backgroundColor: 'var(--colorBgDrawer)' },
|
||||||
},
|
},
|
||||||
'&.nb-record-picker-selector': {
|
'&.nb-record-picker-selector': {
|
||||||
|
'.ant-drawer-wrapper-body': {
|
||||||
|
backgroundColor: 'var(--colorBgDrawer)',
|
||||||
|
},
|
||||||
'.nb-block-item': {
|
'.nb-block-item': {
|
||||||
marginBottom: token.marginLG,
|
marginBottom: token.marginLG,
|
||||||
'.general-schema-designer': {
|
'.general-schema-designer': {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { SchemaInitializer } from '../..';
|
import { SchemaInitializer, useCollection } from '../..';
|
||||||
import { gridRowColWrap } from '../utils';
|
import { gridRowColWrap } from '../utils';
|
||||||
|
|
||||||
export const TableSelectorInitializers = (props: any) => {
|
export const TableSelectorInitializers = (props: any) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { name } = useCollection();
|
||||||
const { insertPosition, component } = props;
|
const { insertPosition, component } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -17,11 +18,12 @@ export const TableSelectorInitializers = (props: any) => {
|
|||||||
component={component}
|
component={component}
|
||||||
items={[
|
items={[
|
||||||
{
|
{
|
||||||
|
key: 'dataBlocksInTableSelector',
|
||||||
type: 'itemGroup',
|
type: 'itemGroup',
|
||||||
title: t('Selector'),
|
title: t('Selector'),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
key: 'details',
|
key: 'detailsBlockInTableSelector',
|
||||||
type: 'item',
|
type: 'item',
|
||||||
title: 'Table',
|
title: 'Table',
|
||||||
component: 'TableSelectorInitializer',
|
component: 'TableSelectorInitializer',
|
||||||
@ -29,10 +31,33 @@ export const TableSelectorInitializers = (props: any) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
key: 'filterBlocksInTableSelector',
|
||||||
|
type: 'itemGroup',
|
||||||
|
title: '{{t("Filter blocks")}}',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
key: 'filterFormBlockInTableSelector',
|
||||||
|
type: 'item',
|
||||||
|
title: '{{t("Form")}}',
|
||||||
|
component: 'FilterFormBlockInitializer',
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'filterCollapseBlockInTableSelector',
|
||||||
|
type: 'item',
|
||||||
|
title: '{{t("Collapse")}}',
|
||||||
|
component: 'FilterCollapseBlockInitializer',
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'otherBlocksInTableSelector',
|
||||||
type: 'itemGroup',
|
type: 'itemGroup',
|
||||||
title: t('Other blocks'),
|
title: t('Other blocks'),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
key: 'markdownBlockInTableSelector',
|
||||||
type: 'item',
|
type: 'item',
|
||||||
title: t('Add text'),
|
title: t('Add text'),
|
||||||
component: 'BlockInitializer',
|
component: 'BlockInitializer',
|
||||||
|
@ -6,10 +6,20 @@ import { useSchemaTemplateManager } from '../../schema-templates';
|
|||||||
import { useCollectionDataSourceItems } from '../utils';
|
import { useCollectionDataSourceItems } from '../utils';
|
||||||
|
|
||||||
export const DataBlockInitializer = (props) => {
|
export const DataBlockInitializer = (props) => {
|
||||||
const { templateWrap, onCreateBlockSchema, componentType, createBlockSchema, insert, isCusomeizeCreate, ...others } =
|
const {
|
||||||
props;
|
templateWrap,
|
||||||
|
onCreateBlockSchema,
|
||||||
|
componentType,
|
||||||
|
createBlockSchema,
|
||||||
|
insert,
|
||||||
|
isCusomeizeCreate,
|
||||||
|
items,
|
||||||
|
...others
|
||||||
|
} = props;
|
||||||
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
|
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
|
||||||
const { setVisible } = useContext(SchemaInitializerButtonContext);
|
const { setVisible } = useContext(SchemaInitializerButtonContext);
|
||||||
|
const defaultItems = useCollectionDataSourceItems(componentType);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SchemaInitializer.Item
|
<SchemaInitializer.Item
|
||||||
icon={<TableOutlined />}
|
icon={<TableOutlined />}
|
||||||
@ -27,7 +37,7 @@ export const DataBlockInitializer = (props) => {
|
|||||||
}
|
}
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}}
|
}}
|
||||||
items={useCollectionDataSourceItems(componentType)}
|
items={items || defaultItems}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -6,9 +6,10 @@ import { useSchemaTemplateManager } from '../../schema-templates';
|
|||||||
import { useCollectionDataSourceItems } from '../utils';
|
import { useCollectionDataSourceItems } from '../utils';
|
||||||
|
|
||||||
export const FilterBlockInitializer = (props) => {
|
export const FilterBlockInitializer = (props) => {
|
||||||
const { templateWrap, onCreateBlockSchema, componentType, createBlockSchema, insert, ...others } = props;
|
const { templateWrap, onCreateBlockSchema, componentType, createBlockSchema, insert, items, ...others } = props;
|
||||||
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
|
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
|
||||||
const { setVisible } = useContext(SchemaInitializerButtonContext);
|
const { setVisible } = useContext(SchemaInitializerButtonContext);
|
||||||
|
const defaultItems = useCollectionDataSourceItems(componentType);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SchemaInitializer.Item
|
<SchemaInitializer.Item
|
||||||
@ -27,7 +28,7 @@ export const FilterBlockInitializer = (props) => {
|
|||||||
}
|
}
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}}
|
}}
|
||||||
items={useCollectionDataSourceItems(componentType)}
|
items={items || defaultItems}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import React from 'react';
|
|
||||||
import { TableOutlined } from '@ant-design/icons';
|
import { TableOutlined } from '@ant-design/icons';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
import { DataBlockInitializer } from './DataBlockInitializer';
|
|
||||||
import { createCollapseBlockSchema } from '../utils';
|
import { createCollapseBlockSchema } from '../utils';
|
||||||
|
import { DataBlockInitializer } from './DataBlockInitializer';
|
||||||
|
|
||||||
export const FilterCollapseBlockInitializer = (props) => {
|
export const FilterCollapseBlockInitializer = (props) => {
|
||||||
const { insert } = props;
|
const { insert, item } = props;
|
||||||
|
const items = item?.key === 'filterCollapseBlockInTableSelector' && [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataBlockInitializer
|
<DataBlockInitializer
|
||||||
{...props}
|
{...props}
|
||||||
@ -19,6 +21,7 @@ export const FilterCollapseBlockInitializer = (props) => {
|
|||||||
});
|
});
|
||||||
insert(schema);
|
insert(schema);
|
||||||
}}
|
}}
|
||||||
|
items={items}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
import React from 'react';
|
|
||||||
import { FormOutlined } from '@ant-design/icons';
|
import { FormOutlined } from '@ant-design/icons';
|
||||||
|
import React from 'react';
|
||||||
import { createFilterFormBlockSchema } from '../utils';
|
import { createFilterFormBlockSchema } from '../utils';
|
||||||
import { FilterBlockInitializer } from './FilterBlockInitializer';
|
import { FilterBlockInitializer } from './FilterBlockInitializer';
|
||||||
|
|
||||||
export const FilterFormBlockInitializer = (props) => {
|
export const FilterFormBlockInitializer = (props) => {
|
||||||
|
const { item } = props;
|
||||||
|
const items = item?.key === 'filterFormBlockInTableSelector' && [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FilterBlockInitializer
|
<FilterBlockInitializer
|
||||||
{...props}
|
{...props}
|
||||||
@ -20,6 +23,7 @@ export const FilterFormBlockInitializer = (props) => {
|
|||||||
return s;
|
return s;
|
||||||
}}
|
}}
|
||||||
createBlockSchema={createFilterFormBlockSchema}
|
createBlockSchema={createFilterFormBlockSchema}
|
||||||
|
items={items}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,21 +1,18 @@
|
|||||||
import React from 'react';
|
|
||||||
import { FormOutlined } from '@ant-design/icons';
|
import { FormOutlined } from '@ant-design/icons';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
import { useCollection } from '../../collection-manager';
|
import { useCollection } from '../../collection-manager';
|
||||||
import { useSchemaTemplateManager } from '../../schema-templates';
|
|
||||||
import { SchemaInitializer } from '../SchemaInitializer';
|
import { SchemaInitializer } from '../SchemaInitializer';
|
||||||
import { createTableSelectorSchema } from '../utils';
|
import { createTableSelectorSchema } from '../utils';
|
||||||
|
|
||||||
export const TableSelectorInitializer = (props) => {
|
export const TableSelectorInitializer = (props) => {
|
||||||
const { onCreateBlockSchema, componentType, createBlockSchema, insert, ...others } = props;
|
const { onCreateBlockSchema, componentType, createBlockSchema, insert, ...others } = props;
|
||||||
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
|
|
||||||
const collection = useCollection();
|
const collection = useCollection();
|
||||||
return (
|
return (
|
||||||
<SchemaInitializer.Item
|
<SchemaInitializer.Item
|
||||||
icon={<FormOutlined />}
|
icon={<FormOutlined />}
|
||||||
{...others}
|
{...others}
|
||||||
onClick={async ({ item }) => {
|
onClick={async ({ item }) => {
|
||||||
const field = item.field;
|
|
||||||
insert(
|
insert(
|
||||||
createTableSelectorSchema({
|
createTableSelectorSchema({
|
||||||
rowKey: collection.filterTargetKey,
|
rowKey: collection.filterTargetKey,
|
||||||
|
@ -1435,7 +1435,7 @@ export const createTableSelectorSchema = (options) => {
|
|||||||
...others,
|
...others,
|
||||||
},
|
},
|
||||||
'x-designer': 'TableSelectorDesigner',
|
'x-designer': 'TableSelectorDesigner',
|
||||||
'x-component': 'BlockItem',
|
'x-component': 'CardItem',
|
||||||
properties: {
|
properties: {
|
||||||
actions: {
|
actions: {
|
||||||
type: 'void',
|
type: 'void',
|
||||||
@ -1805,7 +1805,7 @@ const getChildren = ({
|
|||||||
}: {
|
}: {
|
||||||
collections: any[];
|
collections: any[];
|
||||||
getCollectionFields: (name: any) => CollectionFieldOptions[];
|
getCollectionFields: (name: any) => CollectionFieldOptions[];
|
||||||
componentName: any;
|
componentName: string;
|
||||||
searchValue: string;
|
searchValue: string;
|
||||||
getTemplatesByCollection: (collectionName: string, resourceName?: string) => any;
|
getTemplatesByCollection: (collectionName: string, resourceName?: string) => any;
|
||||||
t;
|
t;
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
import { Migration } from '@nocobase/server';
|
||||||
|
|
||||||
|
export default class extends Migration {
|
||||||
|
async up() {
|
||||||
|
const result = await this.app.version.satisfies('<=0.14.0-alpha.7');
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const r = this.db.getRepository('uiSchemas');
|
||||||
|
const items = await r.find({
|
||||||
|
filter: {
|
||||||
|
'schema.x-designer': 'TableSelectorDesigner',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await this.db.sequelize.transaction(async (transaction) => {
|
||||||
|
for (const item of items) {
|
||||||
|
const schema = item.schema;
|
||||||
|
// BlockItem -> CardItem
|
||||||
|
schema['x-component'] = 'CardItem';
|
||||||
|
await item.save({ transaction });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user