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

Sriram- add special toggles for weekly summary reports #3024

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/components/WeeklySummariesReport/FormattedReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function FormattedReport({
canSeeBioHighlight,
darkMode,
handleTeamCodeChange,
handleSpecialColorDotClick,
selectedSpecialColorsMap,
}) {
const loggedInUserEmail = auth?.user?.email ? auth.user.email : '';

Expand All @@ -93,6 +95,8 @@ function FormattedReport({
darkMode={darkMode}
handleTeamCodeChange={handleTeamCodeChange}
auth={auth}
handleSpecialColorDotClick={handleSpecialColorDotClick}
selectedSpecialColorsMap={selectedSpecialColorsMap}
/>
))}
</ListGroup>
Expand Down Expand Up @@ -207,6 +211,8 @@ function ReportDetails({
darkMode,
handleTeamCodeChange,
auth,
handleSpecialColorDotClick,
selectedSpecialColorsMap,
}) {
const [filteredBadges, setFilteredBadges] = useState([]);
const ref = useRef(null);
Expand All @@ -227,7 +233,14 @@ function ReportDetails({
<li className={`list-group-item px-0 ${darkMode ? 'bg-yinmn-blue' : ''}`} ref={ref}>
<ListGroup className="px-0" flush>
<ListGroupItem darkMode={darkMode}>
<Index summary={summary} weekIndex={weekIndex} allRoleInfo={allRoleInfo} auth={auth} />
<Index
summary={summary}
weekIndex={weekIndex}
allRoleInfo={allRoleInfo}
auth={auth}
handleSpecialColorDotClick={handleSpecialColorDotClick}
selectedSpecialColorsMap={selectedSpecialColorsMap}
/>
</ListGroupItem>
<Row className="flex-nowrap">
<Col xs="6" className="flex-grow-0">
Expand Down Expand Up @@ -632,9 +645,17 @@ function WeeklyBadge({ summary, weekIndex, badges }) {
);
}

function Index({ summary, weekIndex, allRoleInfo, auth }) {
function Index({
summary,
weekIndex,
allRoleInfo,
auth,
handleSpecialColorDotClick,
selectedSpecialColorsMap,
}) {
const hoursLogged = (summary.totalSeconds[weekIndex] || 0) / 3600;
const currentDate = moment.tz('America/Los_Angeles').startOf('day');
const colors = ['purple', 'green', 'navy'];

const googleDocLink = summary.adminLinks?.reduce((targetLink, currentElement) => {
if (currentElement.Name === 'Google Doc') {
Expand Down Expand Up @@ -677,6 +698,27 @@ function Index({ summary, weekIndex, allRoleInfo, auth }) {
</div>
</div>

<div style={{ display: 'inline-block', marginLeft: '10px' }}>
{colors.map(color => (
<span
key={color}
onClick={() => handleSpecialColorDotClick(summary._id, color)}
style={{
display: 'inline-block',
width: '15px',
height: '15px',
margin: '0 5px',
borderRadius: '50%',
backgroundColor: selectedSpecialColorsMap[color].includes(summary._id)
? color
: 'transparent',
border: `3px solid ${color}`,
cursor: 'pointer',
}}
/>
))}
</div>

{showStar(hoursLogged, summary.promisedHoursByWeek[weekIndex]) && (
<i
className="fa fa-star"
Expand Down
25 changes: 25 additions & 0 deletions src/components/WeeklySummariesReport/WeeklySummariesReport.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@
color: red;
}

/* Colored knobs for each toggle */
#purple-toggle + .switch-toggle-label .switch-toggle-switch {
background-color: purple;
}

#green-toggle + .switch-toggle-label .switch-toggle-switch {
background-color: green;
}

#navy-toggle + .switch-toggle-label .switch-toggle-switch {
background-color: navy;
}

#purple-toggle:checked + .switch-toggle-label .switch-toggle-inner:before {
background-color: rgba(223, 57, 231);
}

#green-toggle:checked + .switch-toggle-label .switch-toggle-inner:before {
background-color: rgba(55, 223, 55);
}

#navy-toggle:checked + .switch-toggle-label .switch-toggle-inner:before {
background-color: rgb(83, 83, 223);
}

@media screen and (max-width: 544px) {
.responsive-font-size {
font-size: 0.75rem !important;
Expand Down
93 changes: 93 additions & 0 deletions src/components/WeeklySummariesReport/WeeklySummariesReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ export class WeeklySummariesReport extends Component {
replaceCodeError: null,
replaceCodeLoading: false,
// weeklyRecipientAuthPass: '',
selectedSpecialColorsMap: {
purple: [],
green: [],
navy: [],
},
selectedSpecialColors: {
purple: false,
green: false,
navy: false,
},
};
}

Expand Down Expand Up @@ -389,6 +399,8 @@ export class WeeklySummariesReport extends Component {
selectedBioStatus,
tableData,
COLORS,
selectedSpecialColorsMap,
selectedSpecialColors,
} = this.state;
const chartData = [];
let temptotal = 0;
Expand All @@ -397,6 +409,12 @@ export class WeeklySummariesReport extends Component {
const selectedCodesArray = selectedCodes.map(e => e.value);
const selectedColorsArray = selectedColors.map(e => e.value);

const selectedUserIds = new Set(
Object.entries(selectedSpecialColors)
.filter(([, isSelected]) => isSelected) // Include only active colors
.flatMap(([color]) => selectedSpecialColorsMap[color]), // Get users for active colors
);

const temp = summaries.filter(summary => {
const { activeTab } = this.state;
const hoursLogged = (summary.totalSeconds[navItems.indexOf(activeTab)] || 0) / 3600;
Expand All @@ -412,10 +430,12 @@ export class WeeklySummariesReport extends Component {
hoursLogged > 0 &&
hoursLogged >= summary.promisedHoursByWeek[navItems.indexOf(activeTab)] * 1.25);

const matchesSelectedUsers = selectedUserIds.size === 0 || selectedUserIds.has(summary._id);
return (
(selectedCodesArray.length === 0 || selectedCodesArray.includes(summary.teamCode)) &&
(selectedColorsArray.length === 0 ||
selectedColorsArray.includes(summary.weeklySummaryOption)) &&
matchesSelectedUsers &&
isOverHours &&
isBio
);
Expand Down Expand Up @@ -532,6 +552,36 @@ export class WeeklySummariesReport extends Component {
);
};

handleSpecialColorToggleChange = event => {
const { id, checked } = event.target;
const color = id.split('-')[0];

this.setState(
prevState => ({
selectedSpecialColors: {
...prevState.selectedSpecialColors,
[color]: checked,
},
}),
this.filterWeeklySummaries,
);
};

handleSpecialColorDotClick = (userId, color) => {
this.setState(prevState => {
const updatedMap = { ...prevState.selectedSpecialColorsMap };
// Remove user from all color lists
Object.keys(updatedMap).forEach(col => {
updatedMap[col] = updatedMap[col].filter(id => id !== userId);
});
// Add user to the selected color list
if (color) {
updatedMap[color].push(userId);
}
return { selectedSpecialColorsMap: updatedMap };
});
};

handleTeamCodeChange = (oldTeamCode, newTeamCode, userIdObj) => {
try {
this.setState(prevState => {
Expand Down Expand Up @@ -826,6 +876,47 @@ export class WeeklySummariesReport extends Component {
<Row style={{ marginBottom: '10px' }}>
<Col lg={{ size: 10, offset: 1 }} xs={{ size: 8, offset: 4 }}>
<div className="filter-container">
{hasPermissionToFilter && (
<div className="filter-style margin-right">
<span>Filter by Special</span>
<div className="switch-toggle-control">
<input
type="checkbox"
className="switch-toggle"
id="purple-toggle"
onChange={this.handleSpecialColorToggleChange}
/>
<label className="switch-toggle-label" htmlFor="purple-toggle">
<span className="switch-toggle-inner" />
<span className="switch-toggle-switch" />
</label>
</div>
<div className="switch-toggle-control">
<input
type="checkbox"
className="switch-toggle"
id="green-toggle"
onChange={this.handleSpecialColorToggleChange}
/>
<label className="switch-toggle-label" htmlFor="green-toggle">
<span className="switch-toggle-inner" />
<span className="switch-toggle-switch" />
</label>
</div>
<div className="switch-toggle-control">
<input
type="checkbox"
className="switch-toggle"
id="navy-toggle"
onChange={this.handleSpecialColorToggleChange}
/>
<label className="switch-toggle-label" htmlFor="navy-toggle">
<span className="switch-toggle-inner" />
<span className="switch-toggle-switch" />
</label>
</div>
</div>
)}
{(hasPermissionToFilter || this.canSeeBioHighlight) && (
<div className="filter-style margin-right">
<span>Filter by Bio Status</span>
Expand Down Expand Up @@ -977,6 +1068,8 @@ export class WeeklySummariesReport extends Component {
canSeeBioHighlight={this.canSeeBioHighlight}
darkMode={darkMode}
handleTeamCodeChange={this.handleTeamCodeChange}
handleSpecialColorDotClick={this.handleSpecialColorDotClick}
selectedSpecialColorsMap={this.state.selectedSpecialColorsMap}
/>
</Col>
</Row>
Expand Down
Loading