fix(plugin-formula-field): fix component context (#3937)

This commit is contained in:
Junyi 2024-04-06 15:30:21 +08:00 committed by GitHub
parent 41321004ca
commit a08e96adae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 22 deletions

View File

@ -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);
}

View File

@ -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';