Skip to content

Commit

Permalink
NERT-594 changing user roles works, fixed few issues with drafts list… (
Browse files Browse the repository at this point in the history
#185)

Co-authored-by: Oscar Inostroza <[email protected]>
  • Loading branch information
oscar-ip and Oscar Inostroza authored Aug 26, 2024
1 parent 2998f38 commit 560f115
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
10 changes: 7 additions & 3 deletions app/src/features/plans/PlanListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { calculateSelectedProjectsPlans } from 'utils/dataTransfer';
import useProjectPlanTableUtils from 'hooks/useProjectPlanTable';
import PlansTableHead from 'features/plans/components/PlansTableHead';
import PlansTableToolbar from 'features/plans/components/PlansTableToolbar';
import { IGetDraftsListResponse } from 'interfaces/useDraftApi.interface';

const PlanListPage: React.FC<IPlansListProps> = (props) => {
const { plans, drafts, myplan } = props;
Expand All @@ -66,7 +67,10 @@ const PlanListPage: React.FC<IPlansListProps> = (props) => {
const draftCode = getStateCodeFromLabel(states.DRAFT);
const draftStatusStyle = getStatusStyle(draftCode);

function filterPlans(planData: IGetPlanForViewResponse[]): utils.PlanData[] {
function filterPlans(
plans: IGetPlanForViewResponse[],
drafts?: IGetDraftsListResponse[]
): utils.PlanData[] {
let rowsPlanFilterOutArchived = plans;
if (rowsPlanFilterOutArchived && isUserAdmin) {
rowsPlanFilterOutArchived = plans.filter(
Expand Down Expand Up @@ -135,9 +139,9 @@ const PlanListPage: React.FC<IPlansListProps> = (props) => {

// Make sure state is preserved for table component
useEffect(() => {
const filteredPlans = filterPlans(plans);
const filteredPlans = filterPlans(plans, drafts);
setRows(filteredPlans);
}, [plans]);
}, [plans, drafts]);

// Make sure the data download knows what projects are selected.
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/src/features/plans/components/PlansTableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { SYSTEM_ROLE } from 'constants/roles';

function PlansTableHead(props: PlansTableProps) {
const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort, myPlan } = props;

const createSortHandler = (property: keyof PlanData) => (event: React.MouseEvent<unknown>) => {
onRequestSort(event, property);
};
Expand Down Expand Up @@ -99,7 +100,6 @@ function PlansTableHead(props: PlansTableProps) {
{!myPlan ? <></> : <Typography variant="inherit">Delete</Typography>}
</TableCell>
</SystemRoleGuard>

{!myPlan ? (
<TableCell padding="checkbox">
<Tooltip title={PlanTableI18N.exportAllPlans} placement="right">
Expand Down
10 changes: 7 additions & 3 deletions app/src/features/projects/list/ProjectsListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { calculateSelectedProjectsPlans } from 'utils/dataTransfer';
import ProjectsTableHead from 'features/projects/components/ProjectsTableHead';
import useProjectPlanTableUtils from 'hooks/useProjectPlanTable';
import ProjectsTableToolbar from 'features/projects/components/ProjectsTableToolbar';
import { IGetDraftsListResponse } from 'interfaces/useDraftApi.interface';

const ProjectsListPage: React.FC<IProjectsListProps> = (props) => {
const { projects, drafts, myproject } = props;
Expand All @@ -65,7 +66,10 @@ const ProjectsListPage: React.FC<IProjectsListProps> = (props) => {
const draftCode = getStateCodeFromLabel(states.DRAFT);
const draftStatusStyle = getStatusStyle(draftCode);

function filterProjects(projectData: IGetProjectForViewResponse[]): utils.ProjectData[] {
function filterProjects(
projects: IGetProjectForViewResponse[],
drafts?: IGetDraftsListResponse[]
): utils.ProjectData[] {
let rowsProjectFilterOutArchived = projects;
if (rowsProjectFilterOutArchived && isUserAdmin) {
rowsProjectFilterOutArchived = projects.filter(
Expand Down Expand Up @@ -125,9 +129,9 @@ const ProjectsListPage: React.FC<IProjectsListProps> = (props) => {

// Make sure state is preserved for table component
useEffect(() => {
const filteredProjects = filterProjects(projects);
const filteredProjects = filterProjects(projects, drafts);
setRows(filteredProjects);
}, [projects]);
}, [projects, drafts]);

// Make sure the data download knows what projects are selected.
useEffect(() => {
Expand Down
6 changes: 0 additions & 6 deletions app/src/utils/pagedProjectPlanTableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,6 @@ export const planHeadCells: readonly PlanHeadCell[] = [
numeric: false,
disablePadding: false,
label: TableI18N.archive
},
{
id: 'export',
numeric: false,
disablePadding: false,
label: TableI18N.export
}
];

Expand Down

0 comments on commit 560f115

Please sign in to comment.