Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/hackforla/tdm-calculator
Browse files Browse the repository at this point in the history
…into 1649-modify-searchby-text-box
  • Loading branch information
roslynwythe committed Sep 25, 2024
2 parents 4fc8fe5 + ebaccd2 commit 0e752ff
Show file tree
Hide file tree
Showing 12 changed files with 857 additions and 308 deletions.
413 changes: 287 additions & 126 deletions client/package-lock.json

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions client/src/components/Projects/ColumnHeaderPopups/MultiSelectText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import SearchIcon from "../../../images/search.png";
import { createUseStyles } from "react-jss";

const useStyles = createUseStyles({
searchBarWrapper: {
position: "relative",
alignSelf: "center",
marginBottom: "0.5rem"
},
searchBar: {
maxWidth: "100%",
width: "20em",
padding: "12px 12px 12px 48px",
marginRight: "0.5rem"
},
searchIcon: {
position: "absolute",
left: "16px",
top: "14px"
},
listItem: {
display: "flex",
flexDirection: "row",
alignItems: "center",
height: "2rem",
"&:hover": {
backgroundColor: "lightblue"
}
}
});

const MultiSelectText = ({ options, selectedOptions, setSelectedOptions }) => {
const classes = useStyles();
const [searchString, setSearchString] = useState("");
const [selectedListItems, setSelectedListItems] = useState([
...selectedOptions
]);

const filteredOptions = options
.filter(o => !!o)
.filter(opt => opt.toLowerCase().includes(searchString.toLowerCase()));

const onChangeSearchString = e => {
setSearchString(e.target.value);
};

const handleCheckboxChange = e => {
const optionValue = e.target.name;
if (selectedListItems.find(so => so.value == optionValue)) {
const newSelectedListItems = selectedListItems.filter(
selectedOption => selectedOption.value !== optionValue
);
setSelectedListItems(newSelectedListItems);
setSelectedOptions(newSelectedListItems);
} else {
const newSelectedListItems = [
...selectedListItems,
{ value: optionValue, label: optionValue }
];
setSelectedListItems(newSelectedListItems);
setSelectedOptions(newSelectedListItems);
}
};

const isChecked = optionValue => {
const checked = selectedListItems.find(
option => option.value == optionValue
);
return !!checked;
};

return (
<>
<div className={classes.searchBarWrapper}>
<input
type="text"
value={searchString}
onChange={onChangeSearchString}
placeholder="Search"
className={classes.searchBar}
/>
<img
className={classes.searchIcon}
src={SearchIcon}
alt="Search Icon"
/>
</div>

<div style={{ overflow: "scroll", maxHeight: "15rem" }}>
<pre>{JSON.stringify(selectedOptions, null, 2)}</pre>
{/* <pre>{JSON.stringify(options, null, 2)}</pre> */}

{filteredOptions.map(o => (
<div key={o} className={classes.listItem}>
<input
style={{ height: "1.5rem" }}
type="checkbox"
name={o}
checked={isChecked(o)}
onChange={handleCheckboxChange}
/>
<span>{o}</span>
</div>
))}
</div>
</>
);
};

MultiSelectText.propTypes = {
options: PropTypes.any,
selectedOptions: PropTypes.any,
setSelectedOptions: PropTypes.func
};

export default MultiSelectText;
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from "react";
import PropTypes from "prop-types";
import "react-datepicker/dist/react-datepicker.css";
import { MdFilterAlt } from "react-icons/md";
import { MdFilterAlt, MdFilterList } from "react-icons/md";
import Popup from "reactjs-popup";
import DatePopup from "./DatePopup";
import TextPopup from "./TextPopup";
import VisibilityPopup from "./VisibilityPopup";
import StatusPopup from "./StatusPopup";
import { useTheme } from "react-jss";

const ProjectTableColumnHeader = ({
uniqueValues,
projects,
filter,
header,
criteria,
setCriteria,
Expand All @@ -19,10 +21,36 @@ const ProjectTableColumnHeader = ({
setCheckedProjectIds,
setSelectAllChecked
}) => {
const theme = useTheme();

// Filter is considered Applied if it is not set
// to the default criteria values.
const isFilterApplied = () => {
let propertyName = header.id;
if (header.popupType === "text") {
propertyName += "List";
return criteria[propertyName].length > 0;
}
if (header.popupType === "datetime") {
return (
criteria[header.startDatePropertyName] ||
criteria[header.endDatePropertyName]
);
}
if (header.id === "dateHidden") {
return criteria.visibility !== "visible";
}
if (header.id === "dateSnapshotted") {
return criteria.type !== "all" || criteria.status !== "active";
}
return false;
};

return (
<div style={{ width: "100%", height: "100%" }}>
{header.id !== "checkAllProjects" && header.id !== "contextMenu" ? (
<Popup
lockScroll={true}
trigger={
<div
style={{
Expand All @@ -31,14 +59,25 @@ const ProjectTableColumnHeader = ({
}}
>
<span>{header.label}</span>
<MdFilterAlt
style={{
backgroundColor: "transparent",
color: "white",
marginLeft: "0.5rem"
}}
alt={`Show column filter and sort popup`}
/>
{isFilterApplied() ? (
<MdFilterAlt
style={{
backgroundColor: "transparent",
color: "white",
marginLeft: "0.5rem"
}}
alt={`Show column filter and sort popup`}
/>
) : (
<MdFilterList
style={{
backgroundColor: "transparent",
color: theme.colorLightGray,
marginLeft: "0.5rem"
}}
alt={`Show column filter and sort popup`}
/>
)}
{/* <FontAwesomeIcon
style={{
backgroundColor: "transparent",
Expand Down Expand Up @@ -71,7 +110,6 @@ const ProjectTableColumnHeader = ({
/>
) : header.popupType === "text" ? (
<TextPopup
selectOptions={uniqueValues}
close={close}
header={header}
criteria={criteria}
Expand All @@ -81,6 +119,8 @@ const ProjectTableColumnHeader = ({
setSort={setSort}
setCheckedProjectIds={setCheckedProjectIds}
setSelectAllChecked={setSelectAllChecked}
projects={projects}
filter={filter}
/>
) : header.popupType === "visibility" ? (
<VisibilityPopup
Expand Down Expand Up @@ -117,7 +157,8 @@ const ProjectTableColumnHeader = ({
};

ProjectTableColumnHeader.propTypes = {
uniqueValues: PropTypes.any,
projects: PropTypes.any,
filter: PropTypes.func,
header: PropTypes.any,
criteria: PropTypes.any,
setCriteria: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const StatusPopup = ({
// TODO More state variables for status filtering go here

const setDefault = () => {
setTypeSetting("all");
setShowDeleted(false);
setCriteria({
...criteria,
status: showDeleted ? "all" : "active",
Expand Down
Loading

0 comments on commit 0e752ff

Please sign in to comment.