From b175945d78a01fb298ece4871143546e28bb034b Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Tue, 26 May 2020 16:12:16 +0200 Subject: [PATCH] :sparkles: ajoute un prototype d'interface pour les warnings du moteur --- mon-entreprise/package.json | 3 +- .../source/sites/publi.codes/Studio.tsx | 30 ++++++++----------- publicodes/package.json | 2 +- publicodes/source/index.ts | 14 +++++++++ 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/mon-entreprise/package.json b/mon-entreprise/package.json index d9ec01e57..2c1d00a01 100644 --- a/mon-entreprise/package.json +++ b/mon-entreprise/package.json @@ -35,7 +35,8 @@ "js-yaml": "^3.13.1", "moo": "^0.5.0", "nearley": "^2.19.0", - "publicodes": "^1.0.0-beta.3", + "publicodes": "^1.0.0-beta.4", + "focus-trap-react": "^3.1.2", "ramda": "^0.27.0", "react": "^16.13.1", "react-color": "^2.14.0", diff --git a/mon-entreprise/source/sites/publi.codes/Studio.tsx b/mon-entreprise/source/sites/publi.codes/Studio.tsx index dae8b26f9..a236600b0 100644 --- a/mon-entreprise/source/sites/publi.codes/Studio.tsx +++ b/mon-entreprise/source/sites/publi.codes/Studio.tsx @@ -132,14 +132,21 @@ export const Results = ({ onClickShare, rules }: ResultsProps) => { setCurrentTarget(last(targets)) } }) - // EN ATTENDANT d'AVOIR une meilleure gestion d'erreur, on va mocker - // console.warn - const warnings: string[] = [] - const originalWarn = console.warn - console.warn = (warning: string) => warnings.push(warning) return ( <> + {engine.getWarnings().map(warning => ( +
+ {nl2br(warning)} +
+ ))}
{
- {warnings.map(warning => ( -
- {nl2br(warning)} -
- ))} + { defaultValues: Situation situation: Situation = {} cache: Cache + warnings: Array = [] cacheWithoutDefault: Cache constructor(rules: string | Rules | ParsedRules) { @@ -81,6 +82,14 @@ export default class Engine { context: string, useDefaultValues = true ): EvaluatedNode { + // EN ATTENDANT d'AVOIR une meilleure gestion d'erreur, on va mocker + // console.warn + const warnings: string[] = [] + const originalWarn = console.warn + console.warn = (warning: string) => { + this.warnings.push(warning) + originalWarn(warning) + } const result = simplifyNodeUnit( evaluateNode( useDefaultValues ? this.cache : this.cacheWithoutDefault, @@ -93,6 +102,7 @@ export default class Engine { )(expression) ) ) + console.warn = originalWarn if (Object.keys(result.defaultValue?.missingVariable ?? {}).length) { throw evaluationError( @@ -161,6 +171,10 @@ export default class Engine { ) } + getWarnings() { + return this.warnings + } + inversionFail(): boolean { return !!this.cache._meta.inversionFail }