diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 7647b5231..8ea39882e 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -14,9 +14,6 @@ rules: react/jsx-no-target-blank: 0 react/no-unescaped-entities: 0 parser: babel-eslint -parserOptions: - ecmaFeatures: - legacyDecorators: true plugins: - react diff --git a/source/components/rule/RuleSource.js b/source/components/rule/RuleSource.js index b4874d0d9..98521b2e7 100644 --- a/source/components/rule/RuleSource.js +++ b/source/components/rule/RuleSource.js @@ -1,32 +1,77 @@ import React, { Component, Suspense } from 'react' -import yaml from 'js-yaml' +import { safeDump, safeLoad } from 'js-yaml' import emoji from 'react-easy-emoji' import { buildDottedName } from 'Engine/rules' +import { partition } from 'ramda' let MonacoEditor = React.lazy(() => import('react-monaco-editor')) export default class Source extends Component { - render() { + constructor(props) { + super(props) let { dottedName } = this.props, - source = rawRules.filter(rule => + [rulesNotInScope, rulesInScope] = partition(rule => buildDottedName(rule).includes(dottedName) - ) + )(window.rawRules) + this.rulesNotInScope = rulesNotInScope + this.state = { + code: safeDump(rulesInScope), + PR: null + } + } + submit = () => { + let code = this.refs.monaco.editor.getValue(), + newRulesInScope = safeLoad(code), + newRules = this.rulesNotInScope.concat(newRulesInScope) + + let body = JSON.stringify({ + user: 'laem', + repo: 'publi.codes', + description: "Ceci est une contribution d'un utilisateur", + title: '🔨 Mise à jour des règles', + commit: '🔨 Commit unique', + files: [ + { + path: 'co2.yaml', + content: safeDump(newRules) + } + ] + }) + + let fetchParams = { + method: 'POST', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'cache-control': 'no-cache' + }, + body + } + console.log({ body }) + fetch('http://localhost:3000', fetchParams) + .then(response => response.json()) + .then(json => this.setState({ PR: json })) + } + render() { return (

{emoji('⚙️ ')} Code source
- {dottedName} + {this.props.dottedName}

Chargement du code source...
}> + + {this.state.PR &&
{JSON.stringify(this.state.PR)}
} ) }