Skip to content

Commit 497d4aa

Browse files
Merge pull request #4344 from OneCommunityGlobal/julia-integrate-frontend-with-backend-for-material-graph
Julia - Integrate the Frontend with Backend for Material Graph
2 parents a0ccf72 + e1add6a commit 497d4aa

6 files changed

Lines changed: 39 additions & 31 deletions

File tree

src/components/BMDashboard/WeeklyProjectSummary/TotalMaterialCostPerProject/TotalMaterialCostPerProject.jsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ function TotalMaterialCostPerProject() {
8383
const fetchData = async () => {
8484
setDataLoaded(false);
8585
try {
86-
const projectsResponse = await axios.get(ENDPOINTS.BM_PROJECTS_LIST_FOR_MATERIALS_COST);
86+
const projectsResponse = await axios.get(ENDPOINTS.BM_PROJECTS);
8787
if (projectsResponse.status < 200 || projectsResponse.status >= 300) {
8888
throw new Error(
8989
`API request to get projects list failed with status ${projectsResponse.status}`,
9090
);
9191
}
9292
const projectsFilteredData = projectsResponse.data.map(project => ({
93-
value: project.projectId,
94-
label: project.projectName,
93+
value: project._id,
94+
label: project.name,
9595
}));
9696
setSelectedProjects(projectsFilteredData);
9797
setAllProjects(projectsFilteredData);
@@ -103,7 +103,7 @@ function TotalMaterialCostPerProject() {
103103
);
104104
}
105105
const projectCostsData = costResponse.data.reduce((acc, item) => {
106-
acc[item.projectId] = item.totalCostK;
106+
acc[item.project] = item.totalCostK;
107107
return acc;
108108
}, {});
109109
setProjectCosts(projectCostsData);
@@ -145,6 +145,8 @@ function TotalMaterialCostPerProject() {
145145
minHeight: 38,
146146
boxShadow: 'none',
147147
borderRadius: 8,
148+
overflowX: 'auto',
149+
whiteSpace: 'nowrap',
148150
}),
149151
menu: base => ({
150152
...base,
@@ -165,14 +167,12 @@ function TotalMaterialCostPerProject() {
165167
}),
166168
option: (base, state) => ({
167169
...base,
168-
backgroundColor: state.isSelected
169-
? '#0d55b3'
170-
: state.isFocused
171-
? '#0d55b3'
172-
: darkMode
173-
? '#22272e'
174-
: '#fff',
170+
backgroundColor: state.isSelected ? '#0d55b3' : darkMode ? '#22272e' : '#fff',
175171
color: state.isSelected ? '#fff' : darkMode ? '#fff' : '#232323',
172+
':hover': {
173+
color: '#fff',
174+
backgroundColor: '#0d55b3',
175+
},
176176
fontSize: 13,
177177
padding: '10px 16px',
178178
cursor: 'pointer',
@@ -183,6 +183,8 @@ function TotalMaterialCostPerProject() {
183183
borderRadius: 6,
184184
fontSize: 12,
185185
marginRight: 4,
186+
maxWidth: 'none',
187+
flexShrink: 0,
186188
}),
187189
multiValueLabel: base => ({
188190
...base,
@@ -200,6 +202,18 @@ function TotalMaterialCostPerProject() {
200202
borderRadius: 4,
201203
padding: 2,
202204
}),
205+
valueContainer: provided => ({
206+
...provided,
207+
overflowX: 'auto',
208+
flexWrap: 'nowrap',
209+
display: 'flex',
210+
alignItems: 'center',
211+
justifyContent: 'flex-start',
212+
whiteSpace: 'nowrap',
213+
maxWidth: '100%',
214+
position: 'relative',
215+
scrollbarWidth: 'none',
216+
}),
203217
}),
204218
[darkMode],
205219
);
@@ -219,7 +233,6 @@ function TotalMaterialCostPerProject() {
219233
value={selectedProjects}
220234
onChange={setSelectedProjects}
221235
classNamePrefix="select"
222-
className={styles.selectValueContainer}
223236
styles={selectStyles}
224237
menuPortalTarget={document.body}
225238
menuPosition="fixed"

src/components/BMDashboard/WeeklyProjectSummary/TotalMaterialCostPerProject/TotalMaterialCostPerProject.module.css

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
color: var(--text-color, #ffffff);
1010
}
1111

12-
.selectValueContainer {
13-
display: flex;
14-
align-items: center;
15-
justify-content: flex-start;
16-
overflow-x: auto;
17-
white-space: nowrap;
18-
flex-wrap: nowrap;
19-
max-width: 100%;
20-
position: relative;
21-
}
22-
2312

2413
.selectValueContainerDark {
2514
background-color: var(--section-bg);

src/components/BMDashboard/WeeklyProjectSummary/TotalMaterialCostPerProject/__tests__/TotalMaterialCostPerProject.test.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const store = mockStore({
3232
});
3333

3434
const mockProjects = [
35-
{ projectId: 1, projectName: 'Project A' },
36-
{ projectId: 2, projectName: 'Project B' },
35+
{ _id: 1, name: 'Project A' },
36+
{ _id: 2, name: 'Project B' },
3737
];
3838

3939
const mockCosts = [
@@ -44,7 +44,7 @@ const mockCosts = [
4444
describe('TotalMaterialCostPerProject', () => {
4545
beforeEach(() => {
4646
axios.get.mockImplementation(url => {
47-
if (url.includes('/totalProjects')) {
47+
if (url.includes('/bm/projects')) {
4848
return Promise.resolve({ data: mockProjects });
4949
}
5050
if (url.includes('/material-costs')) {
@@ -129,7 +129,7 @@ describe('TotalMaterialCostPerProject', () => {
129129

130130
it('shows error toast when failed to load projects from api', async () => {
131131
axios.get.mockImplementation(url => {
132-
if (url.includes('/totalProjects')) {
132+
if (url.includes('/bm/projects')) {
133133
return Promise.reject(new Error('API error'));
134134
}
135135
if (url.includes('/material-costs')) {
@@ -147,7 +147,7 @@ describe('TotalMaterialCostPerProject', () => {
147147

148148
it('shows error toast when failed to load projects cost from api', async () => {
149149
axios.get.mockImplementation(url => {
150-
if (url.includes('/totalProjects')) {
150+
if (url.includes('/bm/projects')) {
151151
return Promise.resolve({ data: mockProjects });
152152
}
153153
if (url.includes('/material-costs')) {

src/components/BMDashboard/WeeklyProjectSummary/WeeklyProjectSummary.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function WeeklyProjectSummary() {
249249
{
250250
title: 'Material Consumption',
251251
key: 'Material Consumption',
252-
className: 'large',
252+
className: 'full',
253253
content: [1, 2, 3].map((_, index) => {
254254
let content;
255255
if (index === 1) {

src/components/BMDashboard/WeeklyProjectSummary/WeeklyProjectSummary.module.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
.weeklyProjectSummaryDashboardCategoryContent {
220220
padding: 15px;
221221
display: grid;
222-
grid-template-columns: repeat(4, 1fr);
222+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
223223
gap: 20px;
224224
border-top: 1px solid var(--card-shadow);
225225
animation: fadeIn 0.3s ease-in-out;
@@ -406,6 +406,12 @@
406406
max-width: 1600px;
407407
margin: auto;
408408
}
409+
/* .projectStatusGrid {
410+
display: grid;
411+
grid-template-columns: repeat(6, 1fr);
412+
grid-template-rows: repeat(2, auto);
413+
gap: 10px;
414+
} */
409415

410416
/* ---------------- OVAL STATUS BUTTON ---------------- */
411417
.weeklyStatusButton {

src/utils/URL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export const ENDPOINTS = {
289289
BM_PROJECTS_WITH_LOCATION: `${APIEndpoint}/bm/projects/location`,
290290
BM_PROJECT_EXPENSE_BY_ID: projectId => `${APIEndpoint}/bm/project/${projectId}/expenses`,
291291
BM_PROJECT_BY_ID: projectId => `${APIEndpoint}/bm/project/${projectId}`,
292-
BM_PROJECTS_LIST_FOR_MATERIALS_COST: `${APIEndpoint}/totalProjects `,
292+
293293
BM_PROJECT_MATERIALS_COST: `${APIEndpoint}/material-costs`,
294294
BM_UPDATE_MATERIAL: `${APIEndpoint}/bm/updateMaterialRecord`,
295295
BM_UPDATE_MATERIAL_BULK: `${APIEndpoint}/bm/updateMaterialRecordBulk`,

0 commit comments

Comments
 (0)