mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:45:18 +00:00
fix(plugin-formula-field): fix component context (#3937)
This commit is contained in:
parent
41321004ca
commit
a08e96adae
@ -1,11 +1,17 @@
|
||||
import { Plugin } from '@nocobase/client';
|
||||
import { FormulaFieldProvider } from './FormulaFieldProvider';
|
||||
import { Formula } from './components';
|
||||
import { renderExpressionDescription } from './scopes';
|
||||
import { FormulaFieldInterface } from './interfaces/formula';
|
||||
import { FormulaComponentFieldSettings } from './FormulaComponentFieldSettings';
|
||||
|
||||
export class FormulaFieldPlugin extends Plugin {
|
||||
async load() {
|
||||
this.app.use(FormulaFieldProvider);
|
||||
this.app.addComponents({
|
||||
Formula,
|
||||
});
|
||||
this.app.addScopes({
|
||||
renderExpressionDescription,
|
||||
});
|
||||
this.app.dataSourceManager.addFieldInterfaces([FormulaFieldInterface]);
|
||||
this.app.schemaSettingsManager.add(FormulaComponentFieldSettings);
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
import { css, i18n, SchemaComponentOptions } from '@nocobase/client';
|
||||
import { css, i18n } from '@nocobase/client';
|
||||
import { Evaluator, evaluators } from '@nocobase/evaluators/client';
|
||||
import { Registry } from '@nocobase/utils/client';
|
||||
import React from 'react';
|
||||
import { Formula } from './components';
|
||||
import { NAMESPACE } from './locale';
|
||||
|
||||
function renderExpressionDescription(key: string) {
|
||||
export function renderExpressionDescription(key: string) {
|
||||
const engine = (evaluators as Registry<Evaluator>).get(key);
|
||||
|
||||
return engine?.link ? (
|
||||
@ -28,20 +27,3 @@ function renderExpressionDescription(key: string) {
|
||||
</>
|
||||
) : null;
|
||||
}
|
||||
|
||||
export const FormulaFieldProvider = React.memo((props) => {
|
||||
return (
|
||||
<SchemaComponentOptions
|
||||
components={{
|
||||
Formula,
|
||||
// DynamicExpression
|
||||
}}
|
||||
scope={{
|
||||
renderExpressionDescription,
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</SchemaComponentOptions>
|
||||
);
|
||||
});
|
||||
FormulaFieldProvider.displayName = 'FormulaFieldProvider';
|
Loading…
Reference in New Issue
Block a user