* test(e2e): better locators for designer buttons * fix: make test passing * refactor: remove DesignerControl * chore: better locators * fix: should not disable add-menu-item * chore: better test id for block * chore: optimize Action * chore: remove role in BlockItem * feat: improve locators * chore: menu & add block * chore: initializer * chore: testid -> aria label * chore: tabs * chore: designers * refactor: optimize schemaInitializer * refactor: rename * chore: add collectionName * chore: block item * chore: action * fix: avoid crashting * chore(e2e): add __E2E__ * chore: all dialog * chore: add aria-label for block menu * Revert "chore: add aria-label for block menu" This reverts commit 6a840ef816ee1095484dc268b5dfa1bbe6cd8cbe. * chore: optimize aria-label of Action * chore: schema-initializer * chore(e2e): increase timeout * chore: schema settings * chore: optimize table * chore: workflow * chore: plugin manager * chore: collection manager and workflow * chore: details of workflow * chore: remove testid of Select * test: fix unit-tests * test: fix unit-tests * test(e2e): passing tests * test: fix unit test * chore: should use hover * test: passing tests * chore: passing tests * chore: fix CI * chore: fix CI * chore: increase timeout in CI --------- Co-authored-by: chenos <chenlinxh@gmail.com>
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
import { LineChartOutlined } from '@ant-design/icons';
|
|
import { ISchema } from '@formily/react';
|
|
import { uid } from '@formily/shared';
|
|
import { SchemaInitializer, useACLRoleContext, useCollectionDataSourceItems } from '@nocobase/client';
|
|
import React, { useContext } from 'react';
|
|
import { ChartConfigContext } from '../configure/ChartConfigure';
|
|
import { useChartsTranslation } from '../locale';
|
|
|
|
const itemWrap = SchemaInitializer.itemWrap;
|
|
const ConfigureButton = itemWrap((props) => {
|
|
const { setVisible, setCurrent } = useContext(ChartConfigContext);
|
|
return (
|
|
<SchemaInitializer.Item
|
|
{...props}
|
|
onClick={() => {
|
|
setCurrent({ schema: {}, field: null, collection: props.item?.name, service: null, data: undefined });
|
|
setVisible(true);
|
|
}}
|
|
/>
|
|
);
|
|
});
|
|
|
|
export const ChartInitializers = () => {
|
|
const { t } = useChartsTranslation();
|
|
const collections = useCollectionDataSourceItems('Chart');
|
|
const { allowAll, parseAction } = useACLRoleContext();
|
|
|
|
if (collections[0].loadChildren) {
|
|
const originalLoadChildren = collections[0].loadChildren;
|
|
collections[0].loadChildren = ({ searchValue }) => {
|
|
const children = originalLoadChildren({ searchValue });
|
|
const result = children
|
|
.filter((item) => {
|
|
if (allowAll) {
|
|
return true;
|
|
}
|
|
const params = parseAction(`${item.name}:list`);
|
|
return params;
|
|
})
|
|
.map((item) => ({
|
|
...item,
|
|
component: ConfigureButton,
|
|
}));
|
|
|
|
return result;
|
|
};
|
|
}
|
|
|
|
return (
|
|
<SchemaInitializer.Button
|
|
icon={'PlusOutlined'}
|
|
items={collections as any}
|
|
dropdown={{
|
|
placement: 'bottomLeft',
|
|
}}
|
|
>
|
|
{t('Add chart')}
|
|
</SchemaInitializer.Button>
|
|
);
|
|
};
|
|
|
|
export const ChartV2BlockInitializer: React.FC<{
|
|
insert: (s: ISchema) => void;
|
|
}> = (props) => {
|
|
const { insert } = props;
|
|
return (
|
|
<SchemaInitializer.Item
|
|
{...props}
|
|
icon={<LineChartOutlined />}
|
|
onClick={() => {
|
|
insert({
|
|
type: 'void',
|
|
'x-component': 'CardItem',
|
|
'x-component-props': {
|
|
name: 'charts',
|
|
},
|
|
'x-designer': 'ChartV2BlockDesigner',
|
|
properties: {
|
|
[uid()]: {
|
|
type: 'void',
|
|
'x-component': 'Grid',
|
|
'x-decorator': 'ChartV2Block',
|
|
'x-initializer': 'ChartInitializers',
|
|
},
|
|
},
|
|
});
|
|
}}
|
|
/>
|
|
);
|
|
};
|