Skip to content

Commit 203153b

Browse files
committed
Merge branch 'ramps-583-implement-relative-order-column-in-allocations_process_resources' into ramps-100-variable-marketplace
merge ramps-583 to ramps-100-variable-marketplace
2 parents 7403e59 + 4a8f8a7 commit 203153b

11 files changed

+381
-220
lines changed

src/edit-resource/AllocationTypesGrid.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export const AllocationGrid = React.memo(function AllocationGrid({
2323
</div>
2424
</div>
2525
<Grid
26-
classes={style["no-scroll-grid"]}
2726
columns={columns}
2827
rows={rows}
2928
rowClasses={Array(rows.length).fill(style["vertical-align-center"])}
29+
scroll={false}
3030
/>
3131
</div>
3232
);

src/edit-resource/AllocationTypesGrid.module.scss

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
gap: 1rem; /* Space between the buttons */
1111
}
1212

13-
.no-scroll-grid {
14-
overflow: auto; //hidden for no-scroll
15-
height: auto;
16-
}
17-
1813
.allocation-types-grid {
1914
margin-bottom: 0.8rem;
2015
margin-top: 0.8rem;

src/edit-resource/EditResource.jsx

+19-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default function EditResource({
2626
);
2727
const { resourceData, loading, errors, successMessage } = state;
2828
const resourceDetails = resourceData?.resource_details;
29+
const usesExchangeRates = resourceData?.uses_exchange_rates;
2930

3031
const {
3132
allowedActionsOptions,
@@ -51,8 +52,12 @@ export default function EditResource({
5152
handleRequiredResourceChange,
5253
} = useAllocationGrid(resourceData, resourceDetails, dispatch);
5354

54-
const { exchangeRateColumns, exchangeRateRows, handleAddDiscountRate } =
55-
useExchangeRates(resourceData, dispatch);
55+
const {
56+
exchangeRateColumns,
57+
exchangeRateRows,
58+
handleAddDiscountRate,
59+
dateErrors,
60+
} = useExchangeRates(resourceData, dispatch);
5661

5762
const handleSubmit = useResourceSubmit(
5863
resourceDetails,
@@ -65,10 +70,12 @@ export default function EditResource({
6570

6671
// Expose handleSubmit to external Rails template script
6772
useEffect(() => {
68-
if (setExternalSubmit) {
73+
if (setExternalSubmit && dateErrors.length == 0) {
6974
setExternalSubmit(handleSubmit);
75+
} else {
76+
setExternalSubmit(null);
7077
}
71-
}, [handleSubmit, setExternalSubmit]);
78+
}, [handleSubmit, setExternalSubmit, dateErrors]);
7279

7380
const { allocationColumns, allocationRows } = useAllocationRowsAndColumns(
7481
resourceDetails,
@@ -169,11 +176,14 @@ export default function EditResource({
169176
/>
170177
</AddNewModal>
171178

172-
<ExchangeRates
173-
columns={exchangeRateColumns}
174-
rows={exchangeRateRows}
175-
onAddDiscountRate={handleAddDiscountRate}
176-
/>
179+
{usesExchangeRates && (
180+
<ExchangeRates
181+
columns={exchangeRateColumns}
182+
rows={exchangeRateRows}
183+
onAddDiscountRate={handleAddDiscountRate}
184+
dateErrors={dateErrors}
185+
/>
186+
)}
177187
</div>
178188
);
179189
}

src/edit-resource/ExchangeRates.jsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const ExchangeRates = React.memo(function ExchangeRatesGrid({
77
columns,
88
rows,
99
onAddDiscountRate,
10+
dateErrors = [],
1011
}) {
1112
return (
1213
<div className={style["exchange-rates-grid"]}>
@@ -19,11 +20,21 @@ export const ExchangeRates = React.memo(function ExchangeRatesGrid({
1920
</div>
2021
</div>
2122
<Grid
22-
classes={style["no-scroll-grid"]}
2323
columns={columns}
2424
rows={rows}
2525
rowClasses={Array(rows.length).fill(style["vertical-align-center"])}
26+
scroll={false}
2627
/>
28+
{/* Error Summary */}
29+
{dateErrors.length > 0 && (
30+
<div className={style["error-summary"]}>
31+
<ul>
32+
{dateErrors.map((error, index) => (
33+
<li key={index}>{error}</li>
34+
))}
35+
</ul>
36+
</div>
37+
)}
2738
</div>
2839
);
2940
});
@@ -32,4 +43,5 @@ ExchangeRates.propTypes = {
3243
columns: PropTypes.array.isRequired,
3344
rows: PropTypes.array.isRequired,
3445
onAddDiscountRate: PropTypes.func.isRequired,
46+
dateErrors: PropTypes.array,
3547
};

src/edit-resource/ExchangeRatesGrid.module.scss

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.exchange-rates-grid {
2-
margin: 2rem 0;
2+
margin: 0.8rem 0;
3+
border: 0;
34

45
.header-container {
56
display: flex;
@@ -8,11 +9,6 @@
89
margin-bottom: 1rem;
910
}
1011

11-
.header-title {
12-
font-size: 1.25rem;
13-
margin: 0;
14-
}
15-
1612
.header-buttons {
1713
display: flex;
1814
gap: 1rem;
@@ -30,17 +26,6 @@
3026
}
3127
}
3228

33-
// Prevent horizontal scrolling when not needed
34-
.no-scroll-grid {
35-
:global(.table) {
36-
margin-bottom: 0;
37-
}
38-
39-
tbody tr:last-child td {
40-
border-bottom: 1px solid #dee2e6;
41-
}
42-
}
43-
4429
// Style inputs within the grid
4530
:global {
4631
.form-control {
@@ -62,3 +47,21 @@
6247
}
6348
}
6449
}
50+
51+
.error-summary {
52+
margin-top: 1rem;
53+
padding: 1rem;
54+
background-color: #f8d7da;
55+
color: #721c24;
56+
border: 1px solid #f5c6cb;
57+
border-radius: 4px;
58+
59+
ul {
60+
margin: 0;
61+
padding-left: 1.5rem;
62+
}
63+
64+
li {
65+
margin-bottom: 0.25rem;
66+
}
67+
}

src/edit-resource/helpers/hooks.js

+57-77
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useMemo, useReducer, useState } from "react";
1+
import { useCallback, useEffect, useReducer, useState } from "react";
22
import { resources } from "./reducers";
33
import {
44
setLoading,
@@ -54,45 +54,30 @@ export const useResourceData = (resourceId, relativeUrlRoot) => {
5454

5555
export const useResourceOptions = (resourceData) => {
5656
return {
57-
allowedActionsOptions: useMemo(
58-
() =>
59-
resourceData?.resource_state_types_available?.map((state) => ({
60-
value: state.resource_state_type_id,
61-
label: state.display_resource_state_type,
62-
additionalInfo: state.action_types
63-
.map((action) => action.display_action_type)
64-
.join(", "), // Pass action_types as additionalInfo Prop
65-
})) || [],
66-
[resourceData]
67-
),
68-
69-
resourceTypesOptions: useMemo(
70-
() =>
71-
resourceData?.resource_types_available?.map((type) => ({
72-
value: type.resource_type_id,
73-
label: type.display_resource_type,
74-
})) || [],
75-
[resourceData]
76-
),
77-
78-
unitTypesOptions: useMemo(
79-
() =>
80-
resourceData?.unit_types_available?.map((type) => ({
81-
value: type.unit_type_id,
82-
label: type.display_unit_type,
83-
})) || [],
84-
[resourceData]
85-
),
86-
87-
availableResources: useMemo(
88-
() => resourceData?.required_resources_available || [],
89-
[resourceData]
90-
),
91-
92-
availableAllocationTypes: useMemo(
93-
() => resourceData?.unassigned_allocation_types || [],
94-
[resourceData]
95-
),
57+
allowedActionsOptions:
58+
resourceData?.resource_state_types_available?.map((state) => ({
59+
value: state.resource_state_type_id,
60+
label: state.display_resource_state_type,
61+
additionalInfo: state.action_types
62+
.map((action) => action.display_action_type)
63+
.join(", "),
64+
})) || [],
65+
66+
resourceTypesOptions:
67+
resourceData?.resource_types_available?.map((type) => ({
68+
value: type.resource_type_id,
69+
label: type.display_resource_type,
70+
})) || [],
71+
72+
unitTypesOptions:
73+
resourceData?.unit_types_available?.map((type) => ({
74+
value: type.unit_type_id,
75+
label: type.display_unit_type,
76+
})) || [],
77+
78+
availableResources: resourceData?.required_resources_available || [],
79+
80+
availableAllocationTypes: resourceData?.unassigned_allocation_types || [],
9681
};
9782
};
9883

@@ -105,7 +90,7 @@ export const useAllocationRowsAndColumns = (
10590
handleCommentChange,
10691
handleRequiredResourceChange
10792
) => {
108-
const requiredResourcesColumns = useMemo(() => {
93+
const requiredResourcesColumns = () => {
10994
if (!resourceDetails) return [];
11095

11196
const requiredResources = new Set();
@@ -119,36 +104,34 @@ export const useAllocationRowsAndColumns = (
119104
.sort((a, b) => a.localeCompare(b))
120105
.map((resourceName) => ({
121106
key: resourceName,
122-
name: resourceName,
107+
name: `Require ${resourceName}`,
123108
width: 150,
124109
type: "checkbox",
125110
}));
126-
}, [resourceDetails]);
127-
128-
const allocationColumns = useMemo(
129-
() => [
130-
{ key: "display_name", name: "Allocation Type", width: 200 },
131-
{
132-
key: "allowed_actions",
133-
name: "Allowed Actions",
134-
width: 200,
135-
type: "select",
136-
tooltip: "Tooltip text",
137-
},
138-
{
139-
key: "comment",
140-
name: "Descriptive Text",
141-
width: 200,
142-
type: "input",
143-
tooltip:
144-
"Appears below the resource name and allocations description in the form when making a new request",
145-
},
146-
...requiredResourcesColumns,
147-
],
148-
[requiredResourcesColumns]
149-
);
111+
};
112+
113+
const generatedColumns = requiredResourcesColumns();
150114

151-
const allocationRows = useMemo(() => {
115+
const allocationColumns = [
116+
{ key: "display_name", name: "Allocation Type", width: 200 },
117+
{
118+
key: "allowed_actions",
119+
name: "Allowed Actions",
120+
width: 200,
121+
type: "select",
122+
},
123+
{
124+
key: "comment",
125+
name: "Descriptive Text",
126+
width: 200,
127+
type: "input",
128+
tooltip:
129+
"Appears below the resource name and allocations description in the form when making a new request",
130+
},
131+
...generatedColumns,
132+
];
133+
134+
const allocationRows = () => {
152135
if (!resourceDetails?.allocation_types) return [];
153136

154137
return resourceDetails.allocation_types.map((type) => ({
@@ -166,7 +149,7 @@ export const useAllocationRowsAndColumns = (
166149
handleCommentChange(type.allocation_type_id, newValue),
167150
},
168151
...Object.fromEntries(
169-
requiredResourcesColumns.map((column) => [
152+
generatedColumns.map((column) => [
170153
column.key,
171154
{
172155
checked:
@@ -184,16 +167,13 @@ export const useAllocationRowsAndColumns = (
184167
])
185168
),
186169
}));
187-
}, [
188-
resourceDetails,
189-
allowedActionsOptions,
190-
requiredResourcesColumns,
191-
handleAllowedActionChange,
192-
handleCommentChange,
193-
handleRequiredResourceChange,
194-
]);
170+
};
195171

196-
return { allocationColumns, allocationRows, requiredResourcesColumns };
172+
return {
173+
allocationColumns,
174+
allocationRows: allocationRows(),
175+
requiredResourcesColumns: generatedColumns,
176+
};
197177
};
198178

199179
export const useAllocationGrid = (resourceData, resourceDetails, dispatch) => {

0 commit comments

Comments
 (0)