Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add csv seed comments #1545

Draft
wants to merge 8 commits into
base: edge
Choose a base branch
from
2 changes: 1 addition & 1 deletion client-admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Gulp v3 stops us from upgrading beyond Node v11
FROM docker.io/node:11.15.0-alpine
FROM docker.io/node:18.9.0-alpine

WORKDIR /app

Expand Down
22,663 changes: 10,363 additions & 12,300 deletions client-admin/package-lock.json

Large diffs are not rendered by default.

63 changes: 47 additions & 16 deletions client-admin/src/components/conversation-admin/seed-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,40 @@ class ModerateCommentsSeed extends React.Component {
this.props.dispatch(handleSeedCommentSubmit(comment))
}

handleTextareaChange(e) {
this.props.dispatch(seedCommentChanged(e.target.value))
handleCsvSeed() {
document.getElementById('file-upload').click()
}

getButtonText() {
let text = 'Submit'

if (this.props.success) {
text = 'Success!'
}

if (this.props.loading) {
text = 'Saving...'
handleFileUpload(e) {
console.log(e.target.files[0])
let file = e.target.files[0]
if (file) {
if (file.type !== 'text/csv') {
alert('File must be in csv format')
return
}
let fr = new FileReader()
fr.onload = (e) => {
let commentTexts = fr.result.split(/\r?\n/);
console.log(commentTexts);
commentTexts.forEach(commentText => {
const comment = {
txt: commentText,
pid: 'mypid',
conversation_id: this.props.params.conversation_id,
// vote: 0,
is_seed: true
}
this.props.dispatch(handleSeedCommentSubmit(comment))
// TODO: why does it always fail for one random row?
});
}
fr.readAsText(file);
}
}

return text
handleTextareaChange(e) {
this.props.dispatch(seedCommentChanged(e.target.value))
}

render() {
Expand All @@ -56,7 +74,8 @@ class ModerateCommentsSeed extends React.Component {
<Link target="_blank" href="https://compdemocracy.org/seed-comments">
seed comments
</Link>{' '}
for participants to vote on:
for participants to vote on. For CSV uploads, please ensure that each
comment is in its own row and does not contain any newline characters.
</Text>
<Box sx={{ mb: [2] }}>
<textarea
Expand All @@ -79,10 +98,22 @@ class ModerateCommentsSeed extends React.Component {
/>
</Box>
<Box>
<Button onClick={this.handleSubmitSeed.bind(this)}>
{this.getButtonText()}
<Button onClick={this.handleSubmitSeed.bind(this)} sx={{ mb: [2] }}>
Submit
</Button>
<Button onClick={this.handleCsvSeed} sx={{ ml: [2] }}>
Upload from CSV
</Button>
{this.props.error ? <Text>{strings(this.props.error)}</Text> : null}
<input id="file-upload" type="file" onChange={this.handleFileUpload.bind(this)} sx={{ display: 'none' }}/>
{
this.props.error ?
<Text>{strings(this.props.error)}</Text> :
this.props.loading ?
<Text>Saving...</Text> :
this.props.success ?
<Text>Success!</Text> :
null
}
</Box>
</Box>
)
Expand Down
2 changes: 1 addition & 1 deletion client-report/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Gulp v3 stops us from upgrading beyond Node v11
FROM docker.io/node:11.15.0-alpine
FROM docker.io/node:18.9.0-alpine

WORKDIR /app

Expand Down
43 changes: 36 additions & 7 deletions client-report/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client-report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"hull.js": "^0.2.10",
"jquery": "^2.1.4",
"lodash": "4.17.21",
"moment": "^2.14.1",
"moment": "^2.29.4",
"moment-range": "^2.2.0",
"prop-types": "^15.5.10",
"query-string": "^4.2.3",
Expand Down
Loading