From 4ec56feb0aaa67320241e37d1776a3e3c10d05b0 Mon Sep 17 00:00:00 2001 From: Mael Date: Mon, 17 Dec 2018 19:08:51 +0100 Subject: [PATCH] WIP collaboration PR Utiliser PRB0t --- .eslintrc.yaml | 3 -- source/components/rule/RuleSource.js | 57 +++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 9 deletions(-) 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)}
} ) }