diff --git a/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts b/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts index 94b46535ea..1adb70f9e7 100644 --- a/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts +++ b/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts @@ -377,6 +377,38 @@ export class ExperimentDesignStepperService { return tableData; } + editFactorialConditionTableData( + designData: ExperimentFactorialDesignData, + oldTableData: FactorialConditionTableRowData[] + ): FactorialConditionTableRowData[] { + const tableData: FactorialConditionTableRowData[] = []; + const requiredFactorialTableData = this.factorDataToConditions(designData.factors); + + requiredFactorialTableData.map((conditionData) => { + const conditionLevelsData = this.filterLevelsData(conditionData); + const conditionstring = this.createConditionString(conditionData); + const condition = oldTableData.filter((conditionData) => { + return conditionData.condition === conditionstring; + }); + + if (condition.length) { + tableData.push({ ...condition[0], id: uuidv4() }); + } else { + const tableRow: FactorialConditionTableRowData = { + id: uuidv4(), // TODO: maybe not the right place? + levels: conditionLevelsData, + condition: conditionstring, + payload: conditionstring, + weight: '0.0', + include: true, + }; + tableData.push(tableRow); + } + }); + + return tableData; + } + factorDataToConditions(factorsData: ExperimentFactorData[], levelsCombinationData: FactorLevelData[] = []) { // return if no data in factors if (factorsData.length === 0) { @@ -485,7 +517,7 @@ export class ExperimentDesignStepperService { let conditionIndex = 1; tableData.forEach((factorialConditionTableRow) => { factorialConditionsRequestObject.push({ - id: factorialConditionTableRow.id, + id: factorialConditionTableRow.id || uuidv4(), name: factorialConditionTableRow.condition, conditionCode: factorialConditionTableRow.condition, assignmentWeight: parseFloat(factorialConditionTableRow.weight), diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html index b9be5a051e..7115679be2 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html @@ -152,8 +152,8 @@ >
- {{ conditionweightSumError }} - {{ conditionnegativeweightError }} + {{ conditionWeightSumError }} + {{ conditionNegativeWeightError }}
diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts index 39d5fd2b45..6926a07104 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts @@ -17,7 +17,6 @@ import { ExperimentVM } from '../../../../../../core/experiments/store/experimen }) export class ConditionsTableComponent implements OnInit, OnDestroy { @Input() experimentInfo: ExperimentVM; - @Input() isAnyRowRemoved: boolean; @Input() isExperimentEditable: boolean; subscriptions: Subscription; @@ -35,8 +34,8 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { useEllipsis = false; // Condition Errors - conditionweightSumError: string = null; - conditionnegativeweightError: string = null; + conditionWeightSumError: string = null; + conditionNegativeWeightError: string = null; constructor( private experimentDesignStepperService: ExperimentDesignStepperService, @@ -98,15 +97,15 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { } handleDesignDataChanges(designData: ExperimentFactorialDesignData) { - if (this.experimentInfo?.partitions.length && !this.formInitialized && !this.isAnyRowRemoved) { + const isDesignDataValid = this.checkDesignDataValidity(designData); + if (this.experimentInfo?.partitions.length && (!this.formInitialized || !isDesignDataValid)) { this.handleInitializeExistingTableData(); - } else if (!this.experimentInfo && this.formInitialized && !this.isAnyRowRemoved) { + } else if (!this.experimentInfo && (!this.formInitialized || !isDesignDataValid)) { this.handleInitializeNewNewTableData(designData); } else { // if new exp and form initialized and you move back and forth // if edit exp and form already initialized - this.handleInitializeNewNewTableData(designData); // <---- be careful doing this! if you see bugs, it may be because this is not the intended place for this function - // this.handleUpdateDesignDataTableChanges(designData); + this.handleUpdateDesignDataTableChanges(designData); } } @@ -125,9 +124,25 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { this.initializeForm(newTableData); } - // handleUpdateDesignDataTableChanges(designData: ExperimentFactorialDesignData) { - // // TODO: intelligently handle updates to design data without triggering complete table re-creation - // } + handleUpdateDesignDataTableChanges(designData: ExperimentFactorialDesignData) { + const newTableData = this.experimentDesignStepperService.editFactorialConditionTableData( + designData, + this.tableData$.value + ); + this.initializeForm(newTableData); + } + + checkDesignDataValidity(designData: ExperimentFactorialDesignData) { + let isDesignDataValid = true; + if (designData.factors.length > 1) { + designData.factors.forEach((factor) => { + if (!factor.levels[0].name) { + isDesignDataValid = false; + } + }); + } + return isDesignDataValid; + } initializeForm(tableData: FactorialConditionTableRowData[]) { this.createFormControls(tableData); @@ -171,18 +186,18 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { factorialConditions.forEach((condition) => (sumOfAssignmentWeights += parseFloat(condition.weight))); // checking if sum is not equal to 100 if (Math.round(sumOfAssignmentWeights) !== 100.0) { - this.conditionweightSumError = weightSumNot100ErrorMsg; + this.conditionWeightSumError = weightSumNot100ErrorMsg; } else { - this.conditionweightSumError = null; + this.conditionWeightSumError = null; } } validateWeightsNotNegative(factorialConditions: FactorialConditionTableRowData[]) { - this.conditionnegativeweightError = null; - const negativeweightErrorMsg = this.translate.instant('home.new-experiment.design.assignment-weight-negative.text'); + this.conditionNegativeWeightError = null; + const negativeWeightErrorMsg = this.translate.instant('home.new-experiment.design.assignment-weight-negative.text'); // handling sum of decimal values for assignment weights: factorialConditions.forEach((condition) => - parseFloat(condition.weight) < 0 ? (this.conditionnegativeweightError = negativeweightErrorMsg) : null + parseFloat(condition.weight) < 0 ? (this.conditionNegativeWeightError = negativeWeightErrorMsg) : null ); } @@ -198,7 +213,7 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { this.equalWeightFlag = !this.equalWeightFlag; if (this.equalWeightFlag) { - const newTableData = this.applyEqualWeights(); + const newTableData = this.applyEqualWeights(this.factorialConditionTableForm.value.factorialConditions); this.experimentDesignStepperService.updateFactorialConditionTableData(newTableData); } } diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html index 5d23edf2f8..60fde75126 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html @@ -772,7 +772,6 @@

diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts index f91b81a89a..5349dadda1 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts @@ -97,7 +97,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On conditionTableDataUpToDate = true; isExperimentEditable = true; - isAnyRowRemoved = false; // common lock variable for all tables: isFormLockedForEdit$ = this.experimentDesignStepperService.isFormLockedForEdit$; @@ -370,7 +369,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On removeFactor(groupIndex: number) { this.factor.removeAt(groupIndex); this.handleConditionsButtonClick(); - this.isAnyRowRemoved = true; this.experimentDesignStepperService.experimentStepperDataChanged(); this.experimentDesignStepperService.clearFactorialFactorTableEditModeDetails(); this.updateView('factorTable'); @@ -382,7 +380,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On removeLevel(factorIndex: number, levelIndex: number) { this.getFactorialLevelsAt(factorIndex).removeAt(levelIndex); this.handleConditionsButtonClick(); - this.isAnyRowRemoved = true; this.experimentDesignStepperService.experimentStepperDataChanged(); this.experimentDesignStepperService.clearFactorialLevelTableEditModeDetails(); this.updateView('levelTable'); @@ -777,7 +774,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On if (eventType == NewExperimentDialogEvents.SAVE_DATA) { this.experimentDesignStepperService.experimentStepperDataReset(); - this.isAnyRowRemoved = false; this.factorialExperimentDesignForm.markAsPristine(); } }