tachybase_todo/packages/plugins/@nocobase/plugin-map/src/client/index.tsx
Zeke Zhang 74051ff0a5
refactor(DataBlock): kanban and gantt and map and calendar (#3792)
* refactor: kanban

* refactor: gantt

* refactor: map

* refactor: calendar

* refactor: compat

* refactor: rename to createKanbanBlockUISchema

* refactor(kanban): use x-use-component-props instead of useProps

* refactor(Gantt): rename to createGanttBlockUISchema

* refactor: use x-use-component-props instead of useProps

* refactor: rename

* refactor(Map): use x-use-component-props instead of useProps

* refactor(Calendar): rename

* refactor(Calendar): should not get collection on getting association in UISchema

* refactor(Calendar): use x-use-component-props instead of useProps

* chore: add comment

* chore: fix unit test

* fix: add scopes to fix e2e

* fix(Calendar): add association property to CalendarBlockProvider decorator

* test: add e2e for Calenndar
2024-03-27 18:06:28 +08:00

56 lines
1.8 KiB
TypeScript

import { CurrentAppInfoProvider, Plugin, SchemaComponentOptions } from '@nocobase/client';
import React from 'react';
import { MapBlockOptions } from './block';
import { mapActionInitializers, mapActionInitializers_deprecated } from './block/MapActionInitializers';
import { mapBlockSettings } from './block/MapBlock.Settings';
import { Configuration, Map } from './components';
import { fields } from './fields';
import { NAMESPACE, generateNTemplate } from './locale';
import { useMapBlockProps } from './block/MapBlockProvider';
const MapProvider = React.memo((props) => {
return (
<CurrentAppInfoProvider>
<SchemaComponentOptions components={{ Map }}>
<MapBlockOptions>{props.children}</MapBlockOptions>
</SchemaComponentOptions>
</CurrentAppInfoProvider>
);
});
MapProvider.displayName = 'MapProvider';
export class MapPlugin extends Plugin {
async load() {
this.app.use(MapProvider);
this.app.dataSourceManager.addFieldInterfaces(fields);
this.app.dataSourceManager.addFieldInterfaceGroups({
map: {
label: generateNTemplate('Map-based geometry'),
order: 51,
},
});
this.app.schemaInitializerManager.add(mapActionInitializers_deprecated);
this.app.schemaInitializerManager.add(mapActionInitializers);
this.schemaSettingsManager.add(mapBlockSettings);
const blockInitializers = this.app.schemaInitializerManager.get('page:addBlock');
blockInitializers?.add('dataBlocks.map', {
title: generateNTemplate('Map'),
Component: 'MapBlockInitializer',
});
this.app.pluginSettingsManager.add(NAMESPACE, {
title: `{{t("Map Manager", { ns: "${NAMESPACE}" })}}`,
icon: 'EnvironmentOutlined',
Component: Configuration,
aclSnippet: 'pm.map.configuration',
});
this.app.addScopes({
useMapBlockProps,
});
}
}
export default MapPlugin;