Skip to content

Commit

Permalink
fixed reset analysis button
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnbanasick committed Aug 6, 2024
1 parent 900af42 commit b7aa467
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 229 deletions.
242 changes: 28 additions & 214 deletions src/renderer/src/Sections/Factors/ResetAnalysisButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,245 +2,59 @@ import { useState } from 'react';
import { Button, Header, Modal } from 'semantic-ui-react';
import GeneralButton from '../../Utils/GeneralButton';
import { useTranslation } from 'react-i18next';
import factorState from '../GlobalState/factorState';
// import factorState from '../GlobalState/factorState';
import projectHistoryState from '../GlobalState/projectHistoryState';
import rotationState from '../GlobalState/rotationState';
import loadingState from '../GlobalState/loadingState';
import outputState from '../GlobalState/outputState';
import appState from '../GlobalState/appState';
import resetManualRotation from '../../Utils/resetManualRotation';
import resetBipolarFactors from '../../Utils/resetBipolarFactors';
import resetAnalysis from '../../Utils/resetAnalysis';
import resetSection3 from '../../Utils/resetSection3';
import resetSection4 from '../../Utils/resetSection4';
import resetSection5 from '../../Utils/resetSection5';
import resetSection6 from '../../Utils/resetSection6';
import resetFacRotSelectButtons from '../../Utils/resetFacRotSelectButtons';

const ResetAnalysisButton = () => {
const { t } = useTranslation();

const [localStore, setLocalStore] = useState({
modalOpen: false,
});
const projectHistoryArray = projectHistoryState((state) => state.projectHistoryArray);
const updateProjectHistoryArray = projectHistoryState((state) => state.updateProjectHistoryArray);

function handleOpen() {
// State
const numFactors = factorState((state) => state.numCentroidFactors);

if (isNaN(numFactors)) {
localStore.modalOpen = true;
} else {
localStore.modalOpen = true;
}
setLocalStore({ modalOpen: true });
}

function handleClose() {
localStore.modalOpen = false;
setLocalStore({ modalOpen: false });
}

function resetAnalysis() {
// getState
const projectHistoryArray = projectHistoryState((state) => state.projectHistoryArray);
const updateShowUnrotatedFactorTable = factorState(
(state) => state.updateShowUnrotatedFactorTable
);
const updateShowEigenValuesTable = factorState((state) => state.updateShowEigenValuesTable);
const updateShowScreePlot = factorState((state) => state.updateShowScreePlot);
const updateDidNotConverge = factorState((state) => state.updateDidNotConverge);
const updateActivePcaButton = factorState((state) => state.updateActivePcaButton);
const updateActiveCentroidRevealButton = factorState(
(state) => state.updateActiveCentroidRevealButton
);
const updateActiveTraditionalCentroidFactorButton = factorState(
(state) => state.updateActiveTraditionalCentroidFactorButton
);
const updateActiveHorst55CentroidButton = factorState(
(state) => state.updateActiveHorst55CentroidButton
);
const updateActiveTuckerMacCallumCentroidButton = factorState(
(state) => state.updateActiveTuckerMacCallumCentroidButton
);
const updateCentroid1FactorsActive = factorState((state) => state.updateCentroid1FactorsActive);
const updateCentroid2FactorsActive = factorState((state) => state.updateCentroid2FactorsActive);
const updateCentroid3FactorsActive = factorState((state) => state.updateCentroid3FactorsActive);
const updateCentroid4FactorsActive = factorState((state) => state.updateCentroid4FactorsActive);
const updateCentroid5FactorsActive = factorState((state) => state.updateCentroid5FactorsActive);
const updateCentroid6FactorsActive = factorState((state) => state.updateCentroid6FactorsActive);
const updateCentroid7FactorsActive = factorState((state) => state.updateCentroid7FactorsActive);
const updateCentroid8FactorsActive = factorState((state) => state.updateCentroid8FactorsActive);

const newProjectHistoryArray = [projectHistoryArray.shift()];
const userSelectedRotFactors = [];
const abFactors = [];

projectHistoryState.projectHistoryArray = newProjectHistoryArray;
// reset num factors kept for rotation - so warning modal triggers on no selected
rotationState.numFactorsKeptForRot = undefined;
function doResetAnalysis() {
// reset Project History
const newProjectHistoryArray = [...projectHistoryArray];
let retainedObject = newProjectHistoryArray[0];
updateProjectHistoryArray([retainedObject]);

// hide section 3
factorState.showUnrotatedFactorTable = false;
factorState.showEigenvaluesTable = false;
factorState.showScreePlot = false;
factorState.didNotConverge = false;

factorState.activePcaButton = false;
factorState.activeCentroidRevealButton = false;
factorState.activeTraditionalCentroidFactorButton = false;
factorState.activeHorst55CentroidButton = false;
factorState.activeTuckerMacCallumCentroidButton = false;

factorState.centroid1FactorsActive = false;
factorState.centroid2FactorsActive = false;
factorState.centroid3FactorsActive = false;
factorState.centroid4FactorsActive = false;
factorState.centroid5FactorsActive = false;
factorState.centroid6FactorsActive = false;
factorState.centroid7FactorsActive = true;
factorState.centroid8FactorsActive = false;

factorState.isPcaButtonDisabled = false;
factorState.isCentroidRevealButtonDisabled = false;
factorState.isTraditionalCentroidDisabled = false;
factorState.isHorst55Disabled = false;
factorState.isTuckerMacCallumCentroidDisabled = false;
factorState.isCentroidFacSelectDisabled = false;
factorState.isCentroidExtractButtonDisabled = false;

factorState.numCentroidFactors = 7;
factorState.showCentroidSelection = false;
factorState.showUseHorstLimit = false;
factorState.showHeywoodCaseNotifications = false;
factorState.heywoodButtonDisabled = false;
factorState.heywoodAdjustButtonActive = false;
factorState.heywoodContinueButtonActive = false;

factorState.horstAutoStopYesActive = false;
factorState.horstAutoStopNoDisabled = false;
factorState.horstAutoStopNoActive = false;
factorState.horstAutoStopYesDisabled = false;
factorState.showUseHorstIterationSetup = false;
factorState.showHorstIterationLimit = false;
factorState.showNumberOfCentroidFacToExtract = false;

factorState.horstExtractActive = false;
factorState.horstExtractDisabled = false;

// pcaButtonText: "Principal Components",
// calculatingPca: false

// set rotation active tab view
rotationState.rotationActiveTabIndex = 0;
// reset centroid factors dropdown

// factor select re-enable
rotationState.isFacSelectDisabled = false;
resetSection3();

// hide section 4
rotationState.shouldDisplayFacKept = false;
rotationState.showKeepFacForRotButton = false;
rotationState.varimaxButtonDisabled = false;
rotationState.varimaxButtonText = 'Varimax Rotation';
rotationState.varimaxButtonActive = false;
resetSection4();

// reset manual rotation
rotationState.shouldShowJudgeRotDiv = false;
rotationState.judgeButtonActive = false;
rotationState.showScatterPlotTableDiv = false;
rotationState.abFactors = abFactors;
rotationState.highlightRotfactor1 = false;
rotationState.highlightRotfactor2 = false;
rotationState.highlightRotfactor3 = false;
rotationState.highlightRotfactor4 = false;
rotationState.highlightRotfactor5 = false;
rotationState.highlightRotfactor6 = false;
rotationState.highlightRotfactor7 = false;
rotationState.highlightRotfactor8 = false;
rotationState.userSelectedRotFactors = userSelectedRotFactors;

rotationState.factor1Active = false;
rotationState.factor2Active = false;
rotationState.factor3Active = false;
rotationState.factor4Active = false;
rotationState.factor5Active = false;
rotationState.factor6Active = false;
rotationState.factor7Active = false;
rotationState.factor8Active = false;

rotationState.variContinueButtonActive = false;
rotationState.variContinueButtonDisabled = false;
rotationState.variAdjustButtonActive = false;
rotationState.variAdjustButtonDisabled = false;
rotationState.variPqmAdjustButtonActive = false;
rotationState.variPqmAdjustButtonDisabled = false;
resetManualRotation();
resetFacRotSelectButtons();

// bipolar
loadingState.bipolarDisabled = false;
loadingState.bipolarSplitCount = 0;
resetBipolarFactors();

// hide section 5
loadingState.showLoadingsTable = false;
loadingState.sendDataToOutputButtonColor = '#d6dbe0';
loadingState.splitFactorsArrayArchive = [];
loadingState.splitFactorsArray = [
{
key: 'factor1',
text: '1',
value: 1,
},
{
key: 'factor2',
text: '2',
value: 2,
},
{
key: 'factor3',
text: '3',
value: 3,
},
{
key: 'factor4',
text: '4',
value: 4,
},
{
key: 'factor5',
text: '5',
value: 5,
},
{
key: 'factor6',
text: '6',
value: 6,
},
{
key: 'factor7',
text: '7',
value: 7,
},
{
key: 'factor8',
text: '8',
value: 8,
},
];
resetSection5();

// hide section 6
outputState.showOutputFactorSelection = false;
outputState.shouldDisplayFactorVizOptions = false;
outputState.showFactorCorrelationsTable = false;
outputState.showStandardErrorsDifferences = false;
outputState.showFactorCharacteristicsTable = false;
outputState.showDownloadOutputButtons = false;
outputState.showTableDataNotSentWarning = true;
outputState.userSelectedFactors = [];
outputState.displayFactorVisualizations = false;
outputState.showDocxOptions = false;
outputState.downloadDocxButtonActive = false;

outputState.thresholdButtonActive = false;
outputState.qSortValueButtonActive = false;
outputState.statementNumButtonActive = true;
outputState.zScoreButtonActive = false;
outputState.distStateListSortKey = 'statementNum';

appState.isLoadingsButtonGreen = false;
appState.isRotationButtonGreen = false;
appState.isFactorsButtonGreen = false;
appState.isOutputButtonGreen = false;

// reset dist statements list button
resetSection6('resetAnalysis');
resetAnalysis();

handleClose();
}
Expand Down Expand Up @@ -279,7 +93,7 @@ const ResetAnalysisButton = () => {
size={'big'}
style={{ alignSelf: 'flexEnd', marginLeft: 220 }}
color="red"
onClick={resetAnalysis}
onClick={doResetAnalysis}
inverted
>
{t('Yes reset the analysis')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ const FactorSelectionForOutputButtons = () => {
updateHighlightFactor7(false);
updateHighlightFactor8(false);

updateOutputFactorSelectButtonsDisabled(false);

// clear visualizations
resetSection6('output');
// reset cache of factor viz data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const FactorSelectButtonModal = () => {
});

const handleOpen = () => {
console.log('clicked');

if (isNaN(numFactorsKept)) {
setLocalStore({ ...localStore, modalOpenSelect: false });
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@ import factorState from '../../GlobalState/factorState';
import coreState from '../../GlobalState/coreState';
import outputState from '../../GlobalState/outputState';

//todo - convert to functional component

const FactorSelectionForOutputButtons = () => {
// componentWillUnmount() {
// // getState
// const isFacSelectDisabled = rotationState.getState().isFacSelectDisabled;
// if (!isFacSelectDisabled) {
// clearAllButtons();
// }
// }

// get state
const updateFactor1Active = rotationState((state) => state.updateFactor1Active);
const updateFactor2Active = rotationState((state) => state.updateFactor2Active);
const updateFactor3Active = rotationState((state) => state.updateFactor3Active);
Expand Down Expand Up @@ -74,7 +63,6 @@ const FactorSelectionForOutputButtons = () => {
// highlight selected button
if (factor === 'factor1') {
updateFactor1Active(true);
console.log('factor1Active', factor1Active);
}
if (factor === 'factor2') {
updateFactor2Active(true);
Expand Down Expand Up @@ -117,7 +105,6 @@ const FactorSelectionForOutputButtons = () => {
resetVarimax();

updateIsRotationButtonGreen(true);
console.log(event.target);
};

const buttonsArray = [];
Expand Down
26 changes: 26 additions & 0 deletions src/renderer/src/Utils/resetAnalysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import outputState from '../Sections/GlobalState/outputState';
import appState from '../Sections/GlobalState/appState';

const resetAnalysis = () => {
outputState.setState({
showOutputFactorSelection: false,
showTableDataNotSentWarning: true,
downloadDocxButtonActive: false,
thresholdButtonActive: false,
qSortValueButtonActive: false,
statementNumButtonActive: true,
zScoreButtonActive: false,
distStateListSortKey: 'statementNum',
});

appState.setState({
isLoadingsButtonGreen: false,
isRotationButtonGreen: false,
isFactorsButtonGreen: false,
isOutputButtonGreen: false,
});

return;
};

export default resetAnalysis;
18 changes: 18 additions & 0 deletions src/renderer/src/Utils/resetFacRotSelectButtons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import rotationState from '../Sections/GlobalState/rotationState';

const resetFacRotSelectButtons = () => {
// reset factor rotation select buttons
rotationState.setState({
factor1Active: false,
factor2Active: false,
factor3Active: false,
factor4Active: false,
factor5Active: false,
factor6Active: false,
factor7Active: false,
factor8Active: false,
});
return;
};

export default resetFacRotSelectButtons;
10 changes: 10 additions & 0 deletions src/renderer/src/Utils/resetManualRotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ const resetManualRotation = () => {
rotationState.setState({ highlightRotfactor7: false });
rotationState.setState({ highlightRotfactor8: false });
rotationState.setState({ userSelectedRotFactors: [] });

rotationState.setState({
variContinueButtonActive: false,
variContinueButtonDisabled: false,
variAdjustButtonActive: false,
variAdjustButtonDisabled: false,
variPqmAdjustButtonActive: false,
variPqmAdjustButtonDisabled: false,
});

return;
};

Expand Down
Loading

0 comments on commit b7aa467

Please sign in to comment.