Skip to content

Commit

Permalink
APPEALS-34350 fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
amybids committed Dec 22, 2023
2 parents 0ca82c4 + aa3c157 commit 32dd0a6
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const AffinityDays = (props) => {
<div>
<label className={lever.is_disabled ? styles.leverDisabled : styles.leverActive}
htmlFor={`${lever.item}-${option.item}`}>
{`${option.text} ${option.data_type === 'number' ? `${option.value } ${ option.unit}` : ''}`}
{`${option.text} ${option.data_type === 'number' ? `${option.value} ${option.unit}` : ''}`}
</label>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React from 'react';
import StaticLeversWrapper from './StaticLeversWrapper';
import InteractableLeverWrapper from './InteractableLeversWrapper';
import LeverHistory from './LeverHistory';
Expand Down Expand Up @@ -58,7 +58,7 @@ const CaseflowDistributionContent = ({
</h2>
<div {...sectionSegmentStyling}>
<p className="cf-lead-paragraph">{COPY.CASE_DISTRIBUTION_HISTORY_DESCRIPTION}</p>
<LeverHistory historyData={formattedHistory} leverStore={leverStore}/>
<LeverHistory historyData={formattedHistory} leverStore={leverStore} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import styles from 'app/styles/caseDistribution/InteractableLevers.module.scss';

Expand Down
26 changes: 9 additions & 17 deletions client/app/caseflowDistribution/components/LeverButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,39 @@ import PropTypes from 'prop-types';
import * as Constants from 'app/caseflowDistribution/reducers/Levers/leversActionTypes';
import Button from 'app/components/Button';

function CancelLeverChanges(leverStore) {
function CancelLeverChanges(leverStore) {
leverStore.dispatch({
type: Constants.REVERT_LEVERS,
});
};
}

function RefreshLevers () {
window.location.reload(false); //PLACEHOLDER
// Find levers div
// refresh levers div
};
window.location.reload(false);
}

function DisplayButtonLeverAlert(alert) {
console.log("alert", alert)
//show small banner displaying the alert
};

function DisableSaveButton() {
document.getElementById("SaveLeversButton").disabled = true;
console.log('alert', alert);
}

export function LeverCancelButton({leverStore}) {
export function LeverCancelButton({ leverStore }) {
const CancelButtonActions = (leverStore) => {
CancelLeverChanges(leverStore);
RefreshLevers();
DisplayButtonLeverAlert("Cancelled")
DisplayButtonLeverAlert('Cancelled');
};

return (
<Button
style={{"background": "none", "color": "blue", "font-weight": "300"}}
style={{ background: 'none', color: 'blue', 'font-weight': '300' }}
id="CancelLeversButton"
classNames={['cf-btn-link']}
onClick={() => CancelButtonActions(leverStore)}>
Cancel
</Button>
);
};
}

LeverCancelButton.propTypes = {
leverStore: PropTypes.any
};


99 changes: 52 additions & 47 deletions client/app/caseflowDistribution/components/LeverModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@ import COPY from '../../../COPY';
import styles from 'app/styles/caseDistribution/InteractableLevers.module.scss';
import moment from 'moment';

function changedOptionValue(changedLever, currentLever) {
if (changedLever.data_type === 'radio' || changedLever.data_type === 'radio') {
const changedOptionValue = changedLever.options.find((option) => option.item === changedLever.value).value;
const currentOptionValue = currentLever.options.find((option) => option.item === currentLever.value)?.value;

return changedOptionValue !== currentOptionValue;
}

return false;

}

function GenerateLeverUpdateData(leverStore) {
const levers = leverStore.getState().levers;
const initialLevers = leverStore.getState().initial_levers;
const filteredLevers = levers.filter((lever, i) => lever.value !== initialLevers[i].value || changedOptionValue(lever, initialLevers[i]));
const filteredInitialLevers = initialLevers.filter((lever, i) => initialLevers[i].value !== levers[i].value || changedOptionValue(initialLevers[i], levers[i]));
const filteredLevers = levers.filter((lever, i) =>
lever.value !== initialLevers[i].value || changedOptionValue(lever, initialLevers[i])
);

return ([filteredLevers, filteredInitialLevers])
const filteredInitialLevers = initialLevers.filter((lever, i) =>
initialLevers[i].value !== levers[i].value || changedOptionValue(initialLevers[i], levers[i])
);

return ([filteredLevers, filteredInitialLevers]);
}

function GenerateLeverHistory(filteredLevers, filteredInitialLevers) {
Expand All @@ -27,8 +44,8 @@ function GenerateLeverHistory(filteredLevers, filteredInitialLevers) {
let todaysDate = moment(today).format('ddd MMM DD hh:mm:ss YYYY');

if (doesDatatypeRequireComplexLogic) {
const selectedOption = lever.options.find(option => option.item === lever.value);
const previousSelectedOption = filteredInitialLevers[index].options.find(option => option.item === filteredInitialLevers[index].value);
const selectedOption = lever.options.find((option) => option.item === lever.value);
const previousSelectedOption = filteredInitialLevers[index].options.find((option) => option.item === filteredInitialLevers[index].value);
const isSelectedOptionANumber = selectedOption.data_type === 'number';
const isPreviouslySelectedOptionANumber = previousSelectedOption.data_type === 'number';

Expand All @@ -40,7 +57,7 @@ function GenerateLeverHistory(filteredLevers, filteredInitialLevers) {
current_value: isSelectedOptionANumber ? selectedOption.value : selectedOption.text,
unit: lever.unit
}
)
);
} else {
history.push(
{
Expand All @@ -50,14 +67,15 @@ function GenerateLeverHistory(filteredLevers, filteredInitialLevers) {
current_value: lever.value,
unit: lever.unit
}
)
);
}
})
});

return history
return history;
}
function UpdateLeverHistory(leverStore) {
let [filteredLevers, filteredInitialLevers] = GenerateLeverUpdateData(leverStore)
let [filteredLevers, filteredInitialLevers] = GenerateLeverUpdateData(leverStore);

leverStore.dispatch({
type: Constants.FORMAT_LEVER_HISTORY,
history: GenerateLeverHistory(filteredLevers, filteredInitialLevers)
Expand All @@ -72,14 +90,14 @@ function setShowSuccessBanner(leverStore) {
leverStore.dispatch({
type: Constants.HIDE_SUCCESS_BANNER,
});
}, 10000)
}, 10000);
}

function leverValueDisplay(lever, isPreviousValue) {
const doesDatatypeRequireComplexLogic = lever.data_type === 'radio' || lever.data_type === 'combination';

if (doesDatatypeRequireComplexLogic) {
const selectedOption = lever.options.find(option => option.item === lever.value);
const selectedOption = lever.options.find((option) => option.item === lever.value);
const isSelectedOptionANumber = selectedOption.data_type === 'number';

return isSelectedOptionANumber ? selectedOption.value : selectedOption.text;
Expand All @@ -88,21 +106,20 @@ function leverValueDisplay(lever, isPreviousValue) {
return isPreviousValue ? lever.value : <strong>{lever.value}</strong>;
}

function SaveLeverChanges(leverStore) {
function SaveLeverChanges(leverStore) {
leverStore.dispatch({
type: Constants.SAVE_LEVERS,
saveChangesActivated: true,
});
}

function ShowSuccessBanner(shouldShowSuccessBanner) {
function ShowSuccessBanner(shouldShowSuccessBanner) {
leverStore.dispatch({
type: Constants.SHOW_SUCCESS_BANNER,
showSuccessBanner: shouldShowSuccessBanner,
});
}


function SaveLeversToDB(leverStore) {
const leversData = leverStore.getState().levers;

Expand All @@ -112,28 +129,19 @@ function SaveLeversToDB(leverStore) {
const postData = {
current_levers: leversData,
audit_lever_entries: auditData
}
return ApiUtil.post('/case_distribution_levers/update_levers_and_history', { data: postData })
.then(() => {
};

return ApiUtil.post('/case_distribution_levers/update_levers_and_history', { data: postData }).
then(() => {
SaveLeverChanges(leverStore);
})
.catch((error) => {
if(error.response) {
}).
catch((error) => {
if (error.response) {
console.error('Error:', error);
}
});
}

function changedOptionValue(changedLever, currentLever) {
if (changedLever.data_type === 'radio' || changedLever.data_type === 'radio') {
const changedOptionValue = changedLever.options.find(option => option.item === changedLever.value).value
const currentOptionValue = currentLever.options.find(option => option.item === currentLever.value)?.value
return changedOptionValue !== currentOptionValue
} else {
return false
}
}

function leverList(leverStore) {
const levers = leverStore.getState().levers;
const initialLevers = leverStore.getState().initial_levers;
Expand Down Expand Up @@ -173,7 +181,6 @@ function leverList(leverStore) {
export function LeverSaveButton({ leverStore }) {
const [showModal, setShowModal] = useState(false);
const [changesOccurred, setChangesOccurred] = useState(false);
const [saveButtonDisabled, setSaveButtonDisabled] = useState(false);

useEffect(() => {
const unsubscribe = leverStore.subscribe(() => {
Expand All @@ -192,7 +199,6 @@ export function LeverSaveButton({ leverStore }) {
};
}, [leverStore]);


const handleSaveButton = () => {
if (changesOccurred) {
setShowModal(true);
Expand All @@ -201,11 +207,10 @@ export function LeverSaveButton({ leverStore }) {

const handleConfirmButton = async () => {
await SaveLeversToDB(leverStore);
setShowSuccessBanner(leverStore)
setShowSuccessBanner(leverStore);
setShowModal(false);
setSaveButtonDisabled(true);
ShowSuccessBanner(true);
}
};

return (
<>
Expand All @@ -217,17 +222,17 @@ export function LeverSaveButton({ leverStore }) {
Save
</Button>
{showModal &&
<Modal
isOpen={showModal}
onClose={() => setShowModal(false)}
title={COPY.CASE_DISTRIBUTION_MODAL_TITLE}
confirmButton={<Button onClick={handleConfirmButton}>{COPY.MODAL_CONFIRM_BUTTON}</Button>}
cancelButton={<Button onClick={() => setShowModal(false)}>{COPY.MODAL_CANCEL_BUTTON}</Button>}
className={styles.updatedModalStyling}
>
<p>{COPY.CASE_DISTRIBUTION_MODAL_DESCRIPTION}</p>
{leverList(leverStore)}
</Modal>
<Modal
isOpen={showModal}
onClose={() => setShowModal(false)}
title={COPY.CASE_DISTRIBUTION_MODAL_TITLE}
confirmButton={<Button onClick={handleConfirmButton}>{COPY.MODAL_CONFIRM_BUTTON}</Button>}
cancelButton={<Button onClick={() => setShowModal(false)}>{COPY.MODAL_CANCEL_BUTTON}</Button>}
className={styles.updatedModalStyling}
>
<p>{COPY.CASE_DISTRIBUTION_MODAL_DESCRIPTION}</p>
{leverList(leverStore)}
</Modal>
}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion client/app/caseflowDistribution/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/prop-types */

import React, { useState, useEffect } from 'react';
import React from 'react';
import ReduxBase from '../components/ReduxBase';
import NavigationBar from '../components/NavigationBar';
import { BrowserRouter } from 'react-router-dom';
Expand Down
Loading

0 comments on commit 32dd0a6

Please sign in to comment.