Skip to content

Commit

Permalink
refactor commentList
Browse files Browse the repository at this point in the history
  • Loading branch information
tevko committed Dec 13, 2024
1 parent c2be9a2 commit c7bc94d
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 65 deletions.
2 changes: 1 addition & 1 deletion client-report/src/components/beeswarm/beeswarm.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import React, { useState, useEffect } from "react";
import CommentList from "../lists/commentList";
import CommentList from "../lists/commentList.jsx";
import * as globals from "../globals";
import _ from "lodash";
// import Flex from "../framework/flex"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import React, { useState } from "react";
import CommentList from "./commentList";
import CommentList from "./commentList.jsx";
import * as globals from "../globals";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import AllCommentsModeratedIn from './allCommentsModeratedIn.jsx';
import CommentList from './commentList.js';
import CommentList from './commentList.jsx';

jest.mock('./commentList', () => ({
__esModule: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import React from "react";
import _ from "lodash";
import * as globals from "../globals";

const BarChartCompact = ({ comment, voteCounts, nMembers, voteColors }) => {
Expand Down Expand Up @@ -82,17 +81,17 @@ const CommentRow = ({ comment, groups, voteColors }) => {
console.error("WHY IS THERE NO COMMENT 3452354235", comment);
return null;
}
// const percentAgreed = Math.floor(groupVotesForThisGroup.votes[comment.tid].A / groupVotesForThisGroup.votes[comment.tid].S * 100);

let BarCharts = [];
let totalMembers = 0;

// groups
_.forEach(groups, (g, i) => {
let nMembers = g["n-members"];
Object.entries(groups).forEach(([key, g]) => {
const i = parseInt(key, 10); // Parse the key to an integer
const nMembers = g["n-members"];
totalMembers += nMembers;
let gVotes = g.votes[comment.tid];

const gVotes = g.votes[comment.tid];
BarCharts.push(
<BarChartCompact
key={i}
Expand All @@ -105,12 +104,6 @@ const CommentRow = ({ comment, groups, voteColors }) => {
);
});

// totals column
// let globalCounts = {
// A: comment.agreed,
// D: comment.disagreed,
// S: comment.saw,
// };
BarCharts.unshift(
<BarChartCompact
key={99}
Expand Down Expand Up @@ -159,11 +152,9 @@ const CommentRow = ({ comment, groups, voteColors }) => {
);
};

class CommentList extends React.Component {
constructor(props) {
super(props)
}
getGroupLabels() {
const CommentList = ({ comments, math, ptptCount, tidsToRender, voteColors }) => {

const getGroupLabels = () => {
function makeLabel(key, label, numMembers) {
return (
<span
Expand Down Expand Up @@ -191,57 +182,59 @@ class CommentList extends React.Component {
let labels = [];

// totals
labels.push(makeLabel(99, "Overall", this.props.ptptCount));
labels.push(makeLabel(99, "Overall", ptptCount));

_.each(this.props.math["group-votes"], (g, i) => {
Object.entries(math["group-votes"]).forEach(([key, g]) => {
const i = parseInt(key, 10);
labels.push(makeLabel(i, globals.groupLabels[i], g["n-members"]));
});

return labels;
}

render() {
const comments = _.keyBy(this.props.comments, "tid");
const cs = comments.reduce((acc, comment) => {
acc[comment.tid] = comment;
return acc;
}, {});

return (
<div>
<div
return (
<div>
<div
style={{
marginBottom: 1,
borderBottom: "2px solid black",
position: "relative",
}}
>
<span
style={{
marginBottom: 1,
borderBottom: "2px solid black",
position: "relative",
minWidth: 200,
marginRight:
50 + 10 + 33 /* the 10 in padding from the cells, the 33 for offset group labels */,
display: "inline-block",
fontWeight: 700,
fontSize: 14,
textTransform: "uppercase",
}}
>
<span
style={{
minWidth: 200,
marginRight:
50 + 10 + 33 /* the 10 in padding from the cells, the 33 for offset group labels */,
display: "inline-block",
fontWeight: 700,
fontSize: 14,
textTransform: "uppercase",
}}
>
Statement
</span>
Statement
</span>

{this.getGroupLabels()}
</div>
{this.props.tidsToRender.map((tid, i) => {
return (
<CommentRow
key={i}
index={i}
groups={this.props.math["group-votes"]}
comment={comments[tid]}
voteColors={this.props.voteColors}
/>
);
})}
{getGroupLabels()}
</div>
);
}
{tidsToRender.map((tid, i) => {
return (
<CommentRow
key={i}
index={i}
groups={math["group-votes"]}
comment={cs[tid]}
voteColors={voteColors}
/>
);
})}
</div>
);
}

export default CommentList;
2 changes: 1 addition & 1 deletion client-report/src/components/lists/consensusNarrative.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import * as globals from "../globals";
import Narrative from "../narrative";
import CommentList from "./commentList";
import CommentList from "./commentList.jsx";
const ConsensusNarrative = ({
math,
comments,
Expand Down
2 changes: 1 addition & 1 deletion client-report/src/components/lists/majorityStrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React from "react";
import * as globals from "../globals";
import CommentList from "./commentList";
import CommentList from "./commentList.jsx";
import Legend from "../framework/legend.jsx";

const MajorityStrict = ({
Expand Down
2 changes: 1 addition & 1 deletion client-report/src/components/lists/metadata.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import React from "react";
import CommentList from "./commentList";
import CommentList from "./commentList.jsx";
import * as globals from "../globals";

const Metadata = ({ conversation, comments, ptptCount, formatTid, math, voteColors }) => {
Expand Down
2 changes: 1 addition & 1 deletion client-report/src/components/lists/participantGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import * as globals from "../globals";
// import Flex from "../framework/flex"
// import style from "../../util/style";
import CommentList from "./commentList";
import CommentList from "./commentList.jsx";

const ParticipantGroup = ({
gid,
Expand Down
2 changes: 1 addition & 1 deletion client-report/src/components/lists/uncertainty.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import React from "react";
import CommentList from "./commentList";
import CommentList from "./commentList.jsx";
import * as globals from "../globals";
// import style from "../../util/style";
import Narrative from "../narrative";
Expand Down
2 changes: 1 addition & 1 deletion client-report/src/components/lists/uncertaintyNarrative.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import React from "react";
import CommentList from "./commentList";
import CommentList from "./commentList.jsx";
import * as globals from "../globals";
// import style from "../../util/style";
import Narrative from "../narrative";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as d3chromatic from "d3-scale-chromatic";
// import GroupLabels from "./groupLabels";
import Comments from "../commentsGraph/comments.jsx";
import Hull from "./hull";
import CommentList from "../lists/commentList";
import CommentList from "../lists/commentList.jsx";

const pointsPerSquarePixelMax = 0.0017; /* choose dynamically ? */
const contourBandwidth = 20;
Expand Down

0 comments on commit c7bc94d

Please sign in to comment.