WIP collaboration PR

Utiliser PRB0t
publicodes
Mael 2018-12-17 19:08:51 +01:00
parent 398595b8cc
commit 4ec56feb0a
2 changed files with 51 additions and 9 deletions

View File

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

View File

@ -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 (
<div id="Source" className="ui__ container">
<h2>
{emoji('⚙️ ')}
Code source <br />
<code>{dottedName}</code>
<code>{this.props.dottedName}</code>
</h2>
<Suspense fallback={<div>Chargement du code source...</div>}>
<MonacoEditor
ref="monaco"
height="800"
width="1000"
language={'yaml'}
value={yaml.safeDump(source)}
value={this.state.code}
onChange={this.onChange}
/>
<button onClick={this.submit}>Soumettre mes changements</button>
</Suspense>
{this.state.PR && <div>{JSON.stringify(this.state.PR)}</div>}
</div>
)
}