Skip to content

Commit

Permalink
Merge branch 'main' into B-21438-MAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryKleinjanCACI authored Feb 18, 2025
2 parents 29892f9 + 7a79a13 commit b8e56df
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/constants/MoveHistory/Database/FieldMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ export default {
approved_at: 'Approved at',
counseling_office_name: 'Counseling office',
assigned_sc: 'Counselor assigned',
assigned_sc_ppm: 'Closeout counselor assigned',
assigned_too: 'Task ordering officer assigned',
assigned_tio: 'Task invoicing officer assigned',
re_assigned_sc: 'Counselor reassigned',
re_assigned_sc_ppm: 'Closeout counselor reassigned',
re_assigned_too: 'Task ordering officer reassigned',
re_assigned_tio: 'Task invoicing officer reassigned',
available_to_prime_at: 'Available to Prime at',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import React from 'react';
import o from 'constants/MoveHistory/UIDisplay/Operations';
import a from 'constants/MoveHistory/Database/Actions';
import t from 'constants/MoveHistory/Database/Tables';
import { MOVE_STATUSES } from 'shared/constants';

export default {
action: a.UPDATE,
eventName: o.deleteAssignedOfficeUser,
tableName: t.moves,
getEventNameDisplay: () => 'Updated move',
getDetails: ({ changedValues }) => {
if (changedValues.sc_assigned_id === null) return <>Counselor unassigned</>;
getDetails: ({ changedValues, oldValues }) => {
if (changedValues.sc_assigned_id === null && oldValues?.status === MOVE_STATUSES.NEEDS_SERVICE_COUNSELING)
return <>Counselor unassigned</>;
if (changedValues.sc_assigned_id === null && oldValues?.status !== MOVE_STATUSES.NEEDS_SERVICE_COUNSELING)
return <>Closeout counselor unassigned</>;
if (changedValues.too_assigned_id === null) return <>Task ordering officer unassigned</>;
if (changedValues.tio_assigned_id === null) return <>Task invoicing officer unassigned</>;
return <>Unassigned</>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { screen, render } from '@testing-library/react';

import e from 'constants/MoveHistory/EventTemplates/UpdateAssignedOfficeUser/DeleteAssignedOfficeUser';
import getTemplate from 'constants/MoveHistory/TemplateManager';
import { MOVE_STATUSES } from 'shared/constants';

describe('When given a move that has been unassigned', () => {
const historyRecord = {
Expand All @@ -26,8 +27,15 @@ describe('When given a move that has been unassigned', () => {
});

describe('displays the proper details for', () => {
it('closeout counselor', () => {
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Closeout counselor unassigned')).toBeInTheDocument();
});
it('services counselor', () => {
const template = getTemplate(historyRecord);
historyRecord.oldValues = { status: MOVE_STATUSES.NEEDS_SERVICE_COUNSELING };

render(template.getDetails(historyRecord));
expect(screen.getByText('Counselor unassigned')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { screen, render } from '@testing-library/react';

import e from 'constants/MoveHistory/EventTemplates/UpdateAssignedOfficeUser/UpdateAssignedOfficeUser';
import getTemplate from 'constants/MoveHistory/TemplateManager';
import { MOVE_STATUSES } from 'shared/constants';

describe('When given a move that has been assigned', () => {
const historyRecord = {
Expand All @@ -13,6 +14,7 @@ describe('When given a move that has been assigned', () => {
},
oldValues: {
sc_assigned_id: null,
status: MOVE_STATUSES.NEEDS_SERVICE_COUNSELING,
},
context: [{ assigned_office_user_last_name: 'Daniels', assigned_office_user_first_name: 'Jayden' }],
};
Expand All @@ -30,14 +32,47 @@ describe('When given a move that has been assigned', () => {
});

describe('displays the proper details for', () => {
it('services counselor', () => {
it('assignment of a services counselor', () => {
const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Counselor assigned')).toBeInTheDocument();
expect(screen.getByText(': Daniels, Jayden')).toBeInTheDocument();
});
it('task ordering officer', () => {
it('reassignment of a services counselor', () => {
const template = getTemplate(historyRecord);
historyRecord.oldValues = {
sc_assigned_id: '759a87ad-dc75-4b34-b551-d31309a79f64',
status: MOVE_STATUSES.NEEDS_SERVICE_COUNSELING,
};

render(template.getDetails(historyRecord));
expect(screen.getByText('Counselor reassigned')).toBeInTheDocument();
expect(screen.getByText(': Daniels, Jayden')).toBeInTheDocument();
});
it('assignment of a closeout counselor', () => {
const template = getTemplate(historyRecord);
historyRecord.oldValues = {
sc_assigned_id: null,
status: MOVE_STATUSES.SERVICE_COUNSELING_COMPLETED,
};

render(template.getDetails(historyRecord));
expect(screen.getByText('Closeout counselor assigned')).toBeInTheDocument();
expect(screen.getByText(': Daniels, Jayden')).toBeInTheDocument();
});
it('reassignment of a closeout counselor', () => {
const template = getTemplate(historyRecord);
historyRecord.oldValues = {
sc_assigned_id: '759a87ad-dc75-4b34-b551-d31309a79f64',
status: MOVE_STATUSES.SERVICE_COUNSELING_COMPLETED,
};

render(template.getDetails(historyRecord));
expect(screen.getByText('Closeout counselor reassigned')).toBeInTheDocument();
expect(screen.getByText(': Daniels, Jayden')).toBeInTheDocument();
});
it('assignment of a task ordering officer', () => {
historyRecord.changedValues = { too_assigned_id: 'fb625e3c-067c-49d7-8fd9-88ef040e6137' };
historyRecord.oldValues = { too_assigned_id: null };
historyRecord.context = [
Expand All @@ -50,7 +85,20 @@ describe('When given a move that has been assigned', () => {
expect(screen.getByText('Task ordering officer assigned')).toBeInTheDocument();
expect(screen.getByText(': Robinson, Brian')).toBeInTheDocument();
});
it('task invoicing officer', () => {
it('reassignment of a task ordering officer', () => {
historyRecord.changedValues = { too_assigned_id: 'fb625e3c-067c-49d7-8fd9-88ef040e6137' };
historyRecord.oldValues = { too_assigned_id: '759a87ad-dc75-4b34-b551-d31309a79f64' };
historyRecord.context = [
{ assigned_office_user_last_name: 'Robinson', assigned_office_user_first_name: 'Brian' },
];

const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Task ordering officer reassigned')).toBeInTheDocument();
expect(screen.getByText(': Robinson, Brian')).toBeInTheDocument();
});
it('assignment of a task invoicing officer', () => {
historyRecord.changedValues = { tio_assigned_id: 'fb625e3c-067c-49d7-8fd9-88ef040e6137' };
historyRecord.oldValues = { tio_assigned_id: null };
historyRecord.context = [{ assigned_office_user_last_name: 'Luvu', assigned_office_user_first_name: 'Frankie' }];
Expand All @@ -61,5 +109,16 @@ describe('When given a move that has been assigned', () => {
expect(screen.getByText('Task invoicing officer assigned')).toBeInTheDocument();
expect(screen.getByText(': Luvu, Frankie')).toBeInTheDocument();
});
it('reassignment of a task invoicing officer', () => {
historyRecord.changedValues = { tio_assigned_id: 'fb625e3c-067c-49d7-8fd9-88ef040e6137' };
historyRecord.oldValues = { tio_assigned_id: '759a87ad-dc75-4b34-b551-d31309a79f64' };
historyRecord.context = [{ assigned_office_user_last_name: 'Luvu', assigned_office_user_first_name: 'Frankie' }];

const template = getTemplate(historyRecord);

render(template.getDetails(historyRecord));
expect(screen.getByText('Task invoicing officer reassigned')).toBeInTheDocument();
expect(screen.getByText(': Luvu, Frankie')).toBeInTheDocument();
});
});
});
110 changes: 80 additions & 30 deletions src/pages/Admin/RequestedOfficeUsers/RequestedOfficeUserList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
TextInput,
TopToolbar,
useRecordContext,
downloadCSV,
useDataProvider,
ExportButton,
useListController,
} from 'react-admin';
import jsonExport from 'jsonexport/dist';

import AdminPagination from 'scenes/SystemAdmin/shared/AdminPagination';

// Overriding the default toolbar
const ListActions = () => {
return <TopToolbar />;
};
const RequestedOfficeUserListFilter = (props) => (
<Filter {...props}>
<TextInput label="Search by Name/Email" source="search" alwaysOn resettable />
Expand All @@ -28,7 +29,7 @@ const RequestedOfficeUserListFilter = (props) => (

const defaultSort = { field: 'createdAt', order: 'DESC' };

const RolesTextField = (user) => {
const UserRolesToString = (user) => {
const { roles } = user;

let roleStr = '';
Expand All @@ -45,32 +46,81 @@ const RolesTextField = (user) => {

const RolesField = () => {
const record = useRecordContext();
return <div>{RolesTextField(record)}</div>;
return <div>{UserRolesToString(record)}</div>;
};

const RequestedOfficeUserList = () => (
<List
pagination={<AdminPagination />}
perPage={25}
sort={defaultSort}
filters={<RequestedOfficeUserListFilter />}
actions={<ListActions />}
>
<Datagrid bulkActionButtons={false} rowClick="show" data-testid="requested-office-user-fields">
<TextField source="id" />
<TextField source="email" />
<TextField source="firstName" />
<TextField source="lastName" />
<ReferenceField label="Transportation Office" source="transportationOfficeId" reference="offices" link={false}>
<TextField source="name" />
</ReferenceField>
<TextField source="status" />
<DateField showTime source="createdAt" label="Requested on" />
<ArrayField source="roles" sortable={false} clickable={false} sort={{ field: 'roleName', order: 'DESC' }}>
<RolesField />
</ArrayField>
</Datagrid>
</List>
);
const ListActions = () => {
const { total, resource, sort, filterValues } = useListController();
const dataProvider = useDataProvider();

const exporter = async (users) => {
const officeObjects = {};
const offices = await dataProvider.getMany('offices');
offices.data.forEach((office) => {
if (!officeObjects[`${office.id}`]) {
officeObjects[`${office.id}`] = office;
}
});

const usersWithTransportationOfficeName = users.map((user) => ({
...user,
transportationOfficeName: officeObjects[user.transportationOfficeId]?.name,
}));

const usersForExport = usersWithTransportationOfficeName.map((user) => {
const { id, email, firstName, lastName, transportationOfficeName, status, createdAt } = user;
const userRoles = UserRolesToString(user);
return {
Id: id,
Email: email,
'First Name': firstName,
'Last Name': lastName,
'Transportation Office': transportationOfficeName,
Status: status,
'Requested On': createdAt,
Roles: userRoles,
};
});

// convert data to csv and download
jsonExport(usersForExport, {}, (err, csv) => {
if (err) throw err;
downloadCSV(csv, 'requested_office_users');
});
};

return (
<TopToolbar>
<ExportButton disabled={total === 0} resource={resource} sort={sort} filter={filterValues} exporter={exporter} />
</TopToolbar>
);
};

const RequestedOfficeUserList = () => {
return (
<List
pagination={<AdminPagination />}
perPage={25}
sort={defaultSort}
filters={<RequestedOfficeUserListFilter />}
actions={<ListActions />}
>
<Datagrid bulkActionButtons={false} rowClick="show" data-testid="requested-office-user-fields">
<TextField source="id" />
<TextField source="email" />
<TextField source="firstName" />
<TextField source="lastName" />
<ReferenceField label="Transportation Office" source="transportationOfficeId" reference="offices" link={false}>
<TextField source="name" />
</ReferenceField>
<TextField source="status" />
<DateField showTime source="createdAt" label="Requested on" />
<ArrayField source="roles" sortable={false} clickable={false} sort={{ field: 'roleName', order: 'DESC' }}>
<RolesField />
</ArrayField>
</Datagrid>
</List>
);
};

export default RequestedOfficeUserList;
11 changes: 8 additions & 3 deletions src/utils/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DEPARTMENT_INDICATOR_OPTIONS } from 'constants/departmentIndicators';
import { SERVICE_MEMBER_AGENCY_LABELS } from 'content/serviceMemberAgencies';
import { ORDERS_TYPE_OPTIONS, ORDERS_TYPE_DETAILS_OPTIONS } from 'constants/orders';
import { PAYMENT_REQUEST_STATUS_LABELS } from 'constants/paymentRequestStatus';
import { DEFAULT_EMPTY_VALUE } from 'shared/constants';
import { DEFAULT_EMPTY_VALUE, MOVE_STATUSES } from 'shared/constants';

/**
* Formats number into a dollar string. Eg. $1,234.12
Expand Down Expand Up @@ -609,8 +609,13 @@ export const formatAssignedOfficeUserFromContext = (historyRecord) => {
const name = `${context[0].assigned_office_user_last_name}, ${context[0].assigned_office_user_first_name}`;

if (changedValues?.sc_assigned_id) {
if (oldValues.sc_assigned_id === null) newValues.assigned_sc = name;
if (oldValues.sc_assigned_id !== null) newValues.re_assigned_sc = name;
if (oldValues.status === MOVE_STATUSES.NEEDS_SERVICE_COUNSELING) {
if (oldValues.sc_assigned_id === null) newValues.assigned_sc = name;
if (oldValues.sc_assigned_id !== null) newValues.re_assigned_sc = name;
} else {
if (oldValues.sc_assigned_id === null) newValues.assigned_sc_ppm = name;
if (oldValues.sc_assigned_id !== null) newValues.re_assigned_sc_ppm = name;
}
}
if (changedValues?.too_assigned_id) {
if (oldValues.too_assigned_id === null) newValues.assigned_too = name;
Expand Down
Loading

0 comments on commit b8e56df

Please sign in to comment.