Skip to content

Commit

Permalink
Merged fix to 1651 with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
entrotech committed Dec 5, 2024
1 parent ed25bf9 commit 2a14821
Showing 1 changed file with 48 additions and 32 deletions.
80 changes: 48 additions & 32 deletions client/src/components/Projects/ProjectsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ const ProjectsPage = ({ contentContainerRef }) => {
const projectsPerPage = perPage;
const isAdmin = userContext.account?.isAdmin || false;

const enhancedProjects = projects
? projects.map(project => {
const droName =
droOptions.find(dro => dro.id === project.droId)?.name || "";
return {
...project,
droName: droName,
adminNotes: project.adminNotes || ""
};
})
: [];

useEffect(() => {
const fetchDroOptions = async () => {
try {
Expand Down Expand Up @@ -608,16 +620,6 @@ const ProjectsPage = ({ contentContainerRef }) => {
return new Date(dateOnly);
};

const enhancedProjects = projects.map(project => {
const droName =
droOptions.find(dro => dro.id === project.droId)?.name || "";
return {
...project,
droName: droName,
adminNotes: project.adminNotes || ""
};
});

const filter = (p, criteria) => {
if (criteria.type === "draft" && p.dateSnapshotted) return false;
if (criteria.type === "snapshot" && !p.dateSnapshotted) return false;
Expand Down Expand Up @@ -714,6 +716,7 @@ const ProjectsPage = ({ contentContainerRef }) => {
) {
return false;
}

if (criteria.droList.length > 0) {
const droNames = criteria.droList.map(n => n.toLowerCase());
const projectDroName = (p.droName || "").toLowerCase();
Expand All @@ -723,27 +726,38 @@ const ProjectsPage = ({ contentContainerRef }) => {
}
}

if (userContext.account?.isAdmin) {
const projectAdminNotes = (p.adminNotes || "").toLowerCase().trim();
const criteriaAdminNotes = criteria.adminNotes.toLowerCase().trim();

if (
criteriaAdminNotes &&
!projectAdminNotes.includes(criteriaAdminNotes)
) {
return false;
}

if (
criteria.adminNotesList.length > 0 &&
!criteria.adminNotesList
.map(n => n.toLowerCase())
.includes((p.adminNotes || "").toLowerCase())
) {
return false;
}
if (
criteria.adminNotesList.length > 0 &&
!criteria.adminNotesList
.map(n => n.toLowerCase())
.includes(
p.adminNotes ? p.adminNotes.toLowerCase() : "eowurqoieuroiwutposi"
)
) {
return false;
}

// if (userContext.account?.isAdmin) {
// const projectAdminNotes = (p.adminNotes || "").toLowerCase().trim();
// const criteriaAdminNotes = criteria.adminNotes.toLowerCase().trim();

// if (
// criteriaAdminNotes &&
// !projectAdminNotes.includes(criteriaAdminNotes)
// ) {
// return false;
// }

// if (
// criteria.adminNotesList.length > 0 &&
// !criteria.adminNotesList
// .map(n => n.toLowerCase())
// .includes((p.adminNotes || "").toLowerCase())
// ) {
// return false;
// }
// }

if (
criteria.startDateModifiedAdmin &&
getDateOnly(p.dateModifiedAdmin) <
Expand Down Expand Up @@ -857,7 +871,7 @@ const ProjectsPage = ({ contentContainerRef }) => {

const indexOfLastPost = currentPage * projectsPerPage;
const indexOfFirstPost = indexOfLastPost - projectsPerPage;
let sortedProjects = projects.filter(p => filter(p, filterCriteria));
let sortedProjects = enhancedProjects.filter(p => filter(p, filterCriteria));
for (let i = 0; i < sortCriteria.length; i++) {
sortedProjects.sort(
getComparator(sortCriteria[i].direction, sortCriteria[i].field)
Expand Down Expand Up @@ -972,8 +986,8 @@ const ProjectsPage = ({ contentContainerRef }) => {
</tr>
</thead>
<tbody className={classes.tbody}>
{enhancedProjects?.length ? (
enhancedProjects.map(project => (
{enhancedProjects.length ? (
currentProjects.map(project => (
<ProjectTableRow
key={project.id}
project={project}
Expand Down Expand Up @@ -1030,6 +1044,7 @@ const ProjectsPage = ({ contentContainerRef }) => {
<span className={classes.itemsPerPage}>Items per page</span>
</div>
{/* <pre>{JSON.stringify(sortCriteria, null, 2)}</pre> */}
{/* <pre>{JSON.stringify(filterCriteria, null, 2)}</pre> */}
{(selectedProject || checkedProjectsStatusData) && (
<>
<CsvModal
Expand Down Expand Up @@ -1070,6 +1085,7 @@ const ProjectsPage = ({ contentContainerRef }) => {
</div>
</div>
</div>
``
</div>
</ContentContainerNoSidebar>
);
Expand Down

0 comments on commit 2a14821

Please sign in to comment.