diff --git a/src/domain/usecases/SaveConfigAnalysisUseCase.ts b/src/domain/usecases/SaveConfigAnalysisUseCase.ts index 814746a..2230e03 100644 --- a/src/domain/usecases/SaveConfigAnalysisUseCase.ts +++ b/src/domain/usecases/SaveConfigAnalysisUseCase.ts @@ -1,17 +1,26 @@ +import { Id } from "$/domain/entities/Ref"; import { FutureData } from "../../data/api-futures"; import { QualityAnalysis } from "../entities/QualityAnalysis"; -import { Future } from "../entities/generic/Future"; import { QualityAnalysisRepository } from "../repositories/QualityAnalysisRepository"; export class SaveConfigAnalysisUseCase { constructor(private qualityAnalysisRepository: QualityAnalysisRepository) {} execute(options: SaveQualityAnalysisOptions): FutureData { - if (QualityAnalysis.hasExecutedSections(options.qualityAnalysis)) { - return Future.error(new Error("Cannot change analysis with executed sections")); - } - const qualityAnalysisToSave = QualityAnalysis.build(options.qualityAnalysis).get(); - return this.qualityAnalysisRepository.save([qualityAnalysisToSave]); + return this.getAnalysis(options.qualityAnalysis.id).flatMap(analysis => { + const wasExecuted = QualityAnalysis.hasExecutedSections(analysis); + const qualityAnalysisToSave = wasExecuted + ? QualityAnalysis.build({ + ...analysis, + name: options.qualityAnalysis.name, + }).get() + : QualityAnalysis.build(options.qualityAnalysis).get(); + return this.qualityAnalysisRepository.save([qualityAnalysisToSave]); + }); + } + + private getAnalysis(id: Id): FutureData { + return this.qualityAnalysisRepository.getById(id); } } diff --git a/src/webapp/components/configuration-form/ConfigurationForm.tsx b/src/webapp/components/configuration-form/ConfigurationForm.tsx index 74ed456..b4e7a17 100644 --- a/src/webapp/components/configuration-form/ConfigurationForm.tsx +++ b/src/webapp/components/configuration-form/ConfigurationForm.tsx @@ -109,7 +109,8 @@ export const ConfigurationForm: React.FC = React.memo(pr setSelectedOrgUnits(value); }; - const canBeUpdated = QualityAnalysis.hasExecutedSections(formData); + const disableSave = QualityAnalysis.hasExecutedSections(formData); + const selectorClass = disableSave ? "config-form-selector disabled" : "config-form-selector"; return (
@@ -122,7 +123,7 @@ export const ConfigurationForm: React.FC = React.memo(pr /> = React.memo(pr /> onChangePeriod(value, "startDate")} @@ -140,7 +141,7 @@ export const ConfigurationForm: React.FC = React.memo(pr /> onChangePeriod(value, "endDate")} @@ -150,7 +151,7 @@ export const ConfigurationForm: React.FC = React.memo(pr {initialCountries.length > 0 && ( - + = React.memo(pr )} - @@ -184,8 +185,10 @@ const FormControlsContainer = styled.div` gap: 1em; `; -const OrgUnitContainer = styled.div` +const OrgUnitContainer = styled.div<{ $disabled?: boolean }>` padding: 0; + pointer-events: ${props => (props.$disabled ? "none" : "auto")}; + opacity: ${props => (props.$disabled ? "0.7" : "1")}; `; const ActionsContainer = styled.div` diff --git a/src/webapp/pages/app/App.css b/src/webapp/pages/app/App.css index bc7e841..cfdb46c 100644 --- a/src/webapp/pages/app/App.css +++ b/src/webapp/pages/app/App.css @@ -15,3 +15,9 @@ li { .config-form-selector > div { min-height: 40px !important; } + +.config-form-selector.disabled > div { + cursor: none; + opacity: 0.7; + pointer-events: none !important; +}