Skip to content

Commit

Permalink
add ranked responses component, styling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen authored and Amy Chen committed May 1, 2024
1 parent 8a554cf commit 631ca5f
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 22 deletions.
12 changes: 12 additions & 0 deletions src/components/CopyButton.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
addButtonErrorStateTransition,
Expand Down Expand Up @@ -98,3 +99,14 @@ export default class CopyButton extends Component {
);
}
}

CopyButton.propTypes = {
elementToCopy: PropTypes.object, // element to be copied
buildElementForCopy: PropTypes.func, // function for building element(s) to be copied
buttonTitle: PropTypes.string,
buttonStyle: PropTypes.object,
disableFrame: PropTypes.bool,
beforeCopy: PropTypes.func, // function to execute before copy
afterCopy: PropTypes.func, // function to execute after copy
options: PropTypes.object // copy options
};
2 changes: 1 addition & 1 deletion src/components/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Report extends Component {

renderSectionHeader(section) {
return (
<h2 id={`${section.dataKey}_section`} className="section__header">
<h2 id={`${section.dataKey}_section`} className={`section__header ${section.showHeaderInPrint?"print-header":""}`}>
<div className="section__header-title">
{section.icon && <span title={section.title}>{section.icon()}</span>}
<span className="title-text-container">
Expand Down
1 change: 1 addition & 0 deletions src/components/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ export default class Summary extends Component {
<ScoringSummary
summary={surveyData}
title={panel.title}
readOnly={true}
></ScoringSummary>
}
</div>
Expand Down
294 changes: 294 additions & 0 deletions src/components/report/RankedResponses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
import React, { Component } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
//import PropTypes from "prop-types";

export default class RankedResponses extends Component {
constructor() {
super(...arguments);
this.state = {
dates: ["4/1/2004", "3/1/2004", "2/1/2004"],
data: [],
selectedIndex: 0,
};
this.handleClickNextButton = this.handleClickNextButton.bind(this);
this.handleClickPrevButton = this.handleClickPrevButton.bind(this);
this.handleSetFirst = this.handleSetFirst.bind(this);
this.handleSetLast = this.handleSetLast.bind(this);

//consts
const BORDER_COLOR = "#777";
const HEADER_BORDER_COLOR = "#217684";
this.tableStyle = {
borderCollapse: "collapse",
border: `1px solid ${BORDER_COLOR}`,
};
this.cellStyle = {
borderRight: `1px solid ${BORDER_COLOR}`,
borderLeft: `1px solid ${BORDER_COLOR}`,
borderBottom: `1px solid ${BORDER_COLOR}`,
padding: "12px 16px",
};
this.headerCellStyle = {
borderTop: `1px solid ${BORDER_COLOR}`,
borderRight: `1px solid ${BORDER_COLOR}`,
borderLeft: `1px solid ${BORDER_COLOR}`,
borderBottom: `2px solid ${HEADER_BORDER_COLOR}`,
padding: "8px 16px",
};
}
handleSetFirst() {
if (this.state.selectedIndex === 0) return;
this.setState({
selectedIndex: 0,
selectedDate: this.state.dates[0],
});
}
handleSetLast() {
const lastIndex = this.state.dates.length - 1;
if (this.state.selectedIndex === lastIndex) return;
this.setState({
selectedIndex: lastIndex,
selectedDate: this.state.dates[lastIndex],
});
}
handleClickPrevButton() {
const prevIndex = this.state.selectedIndex - 1;
// console.log("Prev Index ", prevIndex);
if (prevIndex < 0) return;
this.setState({
selectedIndex: prevIndex,
selectedDate: this.state.dates[prevIndex],
});
}
handleClickNextButton() {
const nextIndex = this.state.selectedIndex + 1;
if (nextIndex > this.state.dates.length - 1) return;
this.setState({
selectedIndex: nextIndex,
selectedDate: this.state.dates[nextIndex],
});
}
renderNavTitle() {
const titleContainerStyle = {
color: "#777",
fontSize: "0.85em",
textAlign: "left",
width: "100%",
marginBottom: "8px",
};
return <div style={titleContainerStyle}>Responses</div>;
}
renderNavButtons() {
// const iconStyle = {
// borderWidth: "1px",
// borderStyle: "solid",
// padding: "8px",
// width: "22px",
// height: "22px",
// borderRadius: "100vmax",
// cursor: "pointer",
// position: "relative",
// zIndex: 10,
// };
const buttonStyle = {
borderWidth: "2px",
borderStyle: "solid",
padding: "8px 16px",
borderRadius: "100vmax",
fontWeight: 600,
cursor: "pointer",
position: "relative",
zIndex: 10,
backgroundColor: "#FFF",
backgroundImage: "none",
};
if (
!this.state.dates ||
!this.state.dates.length ||
this.state.dates.length < 2
)
return null;
return (
<div className="flex flex-gap-1 icons-container exclude-from-copy">
{/* <FontAwesomeIcon
icon="angle-double-left"
title="First"
style={iconStyle}
onClick={this.handleSetFirst}
className={this.state.selectedIndex <= 0 ? "disabled" : ""}
></FontAwesomeIcon> */}
<button
style={buttonStyle}
onClick={this.handleClickPrevButton}
className={this.state.selectedIndex <= 0 ? "disabled" : ""}
>
<FontAwesomeIcon
icon="chevron-left"
title="Less"
style={{ marginRight: "4px" }}
></FontAwesomeIcon>
Less
</button>
<button
style={buttonStyle}
onClick={this.handleClickNextButton}
className={
this.state.selectedIndex >= this.state.dates.length - 1
? "disabled"
: ""
}
>
More
<FontAwesomeIcon
icon="chevron-right"
title="Next"
style={{ marginLeft: "4px" }}
></FontAwesomeIcon>
</button>
{/* <FontAwesomeIcon
icon="angle-double-right"
title="Last"
style={iconStyle}
onClick={this.handleSetLast}
className={
this.state.selectedIndex >= this.state.dates.length - 1
? "disabled"
: ""
}
></FontAwesomeIcon> */}
</div>
);
}
renderDots() {
if (!this.state.dates) return null;
if (this.state.dates.length < 2) return null;
return (
<div className="exclude-from-copy dots-container print-hidden">
{this.state.dates.map((item, index) => {
return (
<div
className={`dot ${
index === this.state.selectedIndex ? "active" : ""
}`}
key={`dot_${index}`}
title={`${item}`}
></div>
);
})}
</div>
);
}
renderTableHeader() {
return (
<thead>
<th style={this.headerCellStyle}>Rank</th>
{this.state.dates.map((date, index) => {
return (
<th
style={{
...this.headerCellStyle,
...{
display:
index <= this.state.selectedIndex ? "table-cell" : "none",
},
}}
className={`${index > 0 ? "exclude-from-copy print-hidden" : ""}`}
>
Goals {date}
</th>
);
})}
</thead>
);
}
renderTableBody() {
return (
<tbody>
<tr>
<td style={this.cellStyle}>1st</td>
{this.state.dates.map((date, index) => {
return (
<td
style={{
...this.cellStyle,
...{
display:
index <= this.state.selectedIndex ? "table-cell" : "none",
},
}}
className={`${
index > 0 ? "exclude-from-copy print-hidden" : ""
}`}
>
{/* TODO: display ranked response */}
Test
</td>
);
})}
</tr>
<tr>
<td style={this.cellStyle}>2nd</td>
{this.state.dates.map((date, index) => {
return (
<td
style={{
...this.cellStyle,
...{
display:
index <= this.state.selectedIndex ? "table-cell" : "none",
},
}}
className={`${
index > 0 ? "exclude-from-copy print-hidden" : ""
}`}
>
{/* TODO: display ranked response */}
Test
</td>
);
})}
</tr>
<tr>
<td style={this.cellStyle}>3rd</td>
{this.state.dates.map((date, index) => {
return (
<td
style={{
...this.cellStyle,
...{
display:
index <= this.state.selectedIndex ? "table-cell" : "none",
},
}}
className={`${
index > 0 ? "exclude-from-copy print-hidden" : ""
}`}
>
{/* TODO: display ranked response */}
Test
</td>
);
})}
</tr>
</tbody>
);
}
render() {
return (
<div
class="flex flex-column flex-gap-2 flex-align-start"
style={{ padding: "16px 24px" }}
>
<table style={this.tableStyle}>
{this.renderTableHeader()}
{this.renderTableBody()}
</table>
<div className="flex flex-column">
{this.renderNavTitle()}
{this.renderNavButtons()}
<div>{this.renderDots()}</div>
</div>
</div>
);
}
}
4 changes: 3 additions & 1 deletion src/components/report/ScoringSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export default class ScoringSummary extends Component {
render() {
const { summary, showAnchorLinks } = this.props;
const noSummaryData = this.hasNoSummaryData(summary);
const readOnly = this.props.readOnly;
return (
<React.Fragment>
<table
Expand All @@ -330,7 +331,7 @@ export default class ScoringSummary extends Component {
<div style={this.captionRowStyle}>
{this.renderTitle()}
<div style={{ textAlign: "right" }}>
{!noSummaryData && this.renderCopyButton()}
{!noSummaryData && !readOnly && this.renderCopyButton()}
</div>
</div>
</caption>
Expand All @@ -349,4 +350,5 @@ ScoringSummary.propTypes = {
title: PropTypes.string,
summary: PropTypes.array,
showAnchorLinks: PropTypes.bool,
readOnly: PropTypes.bool
};
Loading

0 comments on commit 631ca5f

Please sign in to comment.