Skip to content

Commit

Permalink
KAAV-1473 make it possible to remove princebles timeline first phase
Browse files Browse the repository at this point in the history
  • Loading branch information
henrihaapalasiili committed Aug 27, 2024
1 parent 0fafa54 commit 3e07b32
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
37 changes: 30 additions & 7 deletions src/components/ProjectTimeline/VisTimelineGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const VisTimelineGroup = forwardRef(({ groups, items, deadlines, visValues, dead
if(attributeLautakuntaanKeys.length === 0 || phase === "tarkistettu_ehdotus"){
lautakuntaCount += 1
}
lautakuntaCount = phase === "ehdotus" ? lautakuntaCount : lautakuntaCount + 1;
lautakuntaCount = phase === "ehdotus" || phase === "luonnos" || phase === "periaatteet" ? lautakuntaCount : lautakuntaCount + 1;
canAddLautakunta = lautakuntaCount <= deadlineLautakuntakertaKeys;
const nextLautakuntaStr = canAddLautakunta ? `${phase}_lautakuntaan_${lautakuntaCount}$` : false;
nextLautakuntaClean = nextLautakuntaStr ? nextLautakuntaStr.replace(/[/$]/g, '') : nextLautakuntaStr;
Expand Down Expand Up @@ -155,7 +155,7 @@ const VisTimelineGroup = forwardRef(({ groups, items, deadlines, visValues, dead
if(phase === "luonnos"){
lautakuntaConfirmed = Object.prototype.hasOwnProperty.call(visValRef, `vahvista_kaavaluonnos_lautakunnassa${lautakuntaCount}`) && visValRef[`vahvista_kaavaluonnos_lautakunnassa${lautakuntaCount}`] === true;
}
if(phase === "periaatteet" && !(phase + "_lautakuntaan_1" in visValRef)|| phase === "luonnos" && !(phase + "_lautakuntaan_1")){
if(phase === "periaatteet" && !(phase + "_lautakuntaan_1" in visValRef) || phase === "periaatteet" && visValRef["periaatteet_lautakuntaan_1"] || phase === "luonnos" && !(phase + "_lautakuntaan_1") || phase === "luonnos" && visValRef["kaavaluonnos_lautakuntaan_1"] === false){
lautakuntaConfirmed = true
}
if(phase === "luonnos" && !("jarjestetaan_" + phase + "_esillaolo_1" in visValRef) || phase === "periaatteet" && !("jarjestetaan_"+phase+"_esillaolo_1" in visValRef)){
Expand Down Expand Up @@ -188,6 +188,11 @@ const VisTimelineGroup = forwardRef(({ groups, items, deadlines, visValues, dead
canAddLautakunta = false
}

/* TODO if(visValRef["kaavaluonnos_lautakuntaan_1"] === false){
//adds second one althou when false needs to just show first one if deleted once
canAddLautakunta = true
} */

return [canAddEsillaolo, nextEsillaoloClean, canAddLautakunta, nextLautakuntaClean, esillaoloReason, lautakuntaReason];
};

Expand Down Expand Up @@ -220,7 +225,8 @@ const VisTimelineGroup = forwardRef(({ groups, items, deadlines, visValues, dead
//TODO review logic and split this to smaller functions
let removeFromTimeline = dataToRemove?.deadlinegroup
let phase = dataToRemove?.nestedInGroup.toLowerCase()
let esillaolo = dataToRemove?.content?.includes("Esilläolo") ? true : false
const esillaolo = dataToRemove?.content?.includes("Esilläolo") ? true : false
const luonnos = dataToRemove?.content?.includes("Lautakunta") ? true : false

let toRemoveFromCalendar = dataToRemove?.nestedInGroup?.toLowerCase() + "_" + dataToRemove?.content?.toLowerCase().replace(/[äöå]/g, match => {
switch (match) {
Expand All @@ -237,10 +243,27 @@ const VisTimelineGroup = forwardRef(({ groups, items, deadlines, visValues, dead
//remove from attribute data/calendar
for (const key in visValues) {
if (Object.prototype.hasOwnProperty.call(visValues, key)) {
if (key.includes(toRemoveFromCalendar) && key.includes(index) || esillaolo && key.includes("mielipiteet_"+phase+index)) {
keysToRemove.push(key)
// Filter out the matching deadline from deadlines
dispatch(change(EDIT_PROJECT_TIMETABLE_FORM, key, null));
if (
(key.includes(toRemoveFromCalendar) && key.includes(index)) ||
(esillaolo && key.includes("mielipiteet_" + phase + index)) ||
(luonnos && key.includes("kaavaluonnos_") || luonnos && key.includes("periaatteet_lautakuntaan"))
)
{
if(luonnos && index === "_1" || esillaolo && index === "_1"){
if(!(key.includes("_2") || key.includes("_3") || key.includes("_4"))){
keysToRemove.push(key)
}
}
else{
keysToRemove.push(key)
}
// Filter out the matching deadline from deadlines
let deleteValue = null
if(key.includes("kaavaluonnos_lautakuntaan_") || key.includes("jarjestetaan_luonnos_esillaolo_") || key.includes("periaatteet_lautakuntaan_") || key.includes("jarjestetaan_periaatteet_esillaolo_")){
deleteValue = false
}
console.log("dispatch",key,deleteValue)
dispatch(change(EDIT_PROJECT_TIMETABLE_FORM, key, deleteValue));
}
}
}
Expand Down
22 changes: 16 additions & 6 deletions src/components/project/EditProjectTimetableModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,22 @@ class EditProjectTimeTableModal extends Component {
numberOfPhases++
}
else if(milestone && innerStart && innerEnd || innerStart && innerEnd){
let subgroup2 = this.addSubgroup(deadlines, i, numberOfPhases, innerStart, innerEnd, innerStyle, phaseData, deadLineGroups, nestedDeadlines, milestone);
[phaseData, deadLineGroups, nestedDeadlines] = subgroup2;
innerStart = false
innerEnd = false
milestone = false
numberOfPhases++
if (
!(
(deadlines[i].deadline.deadlinegroup === "luonnos_lautakuntakerta_1" && formValues && formValues["kaavaluonnos_lautakuntaan_1"] === false) ||
(deadlines[i].deadline.deadlinegroup === "luonnos_esillaolokerta_1" && formValues && formValues["jarjestetaan_luonnos_esillaolo_1"] === false) ||
(deadlines[i].deadline.deadlinegroup === "periaatteet_lautakuntakerta_1" && formValues && formValues["periaatteet_lautakuntaan_1"] === false) ||
(deadlines[i].deadline.deadlinegroup === "periaatteet_esillaolokerta_1" && formValues && formValues["jarjestetaan_periaatteet_esillaolo_1"] === false)
)
) {
let subgroup2 = this.addSubgroup(deadlines, i, numberOfPhases, innerStart, innerEnd, innerStyle, phaseData, deadLineGroups, nestedDeadlines, milestone);
[phaseData, deadLineGroups, nestedDeadlines] = subgroup2;
innerStart = false;
innerEnd = false;
milestone = false;
numberOfPhases++;
}

}
}

Expand Down

0 comments on commit 3e07b32

Please sign in to comment.