Skip to content

Commit

Permalink
KAAV-1473 add to timeline logic changed and distances between phases …
Browse files Browse the repository at this point in the history
…from data
  • Loading branch information
henrihaapalasiili committed Aug 28, 2024
1 parent c91d620 commit d5b6dd8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/ProjectTimeline/TimelineModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EDIT_PROJECT_TIMETABLE_FORM } from '../../constants'
import FormField from '../input/FormField'
import { isArray } from 'lodash'
import { showField } from '../../utils/projectVisibilityUtils'
import scandicUtil from '../../utils/scandicUtil'
import textUtil from '../../utils/textUtil'
import PropTypes from 'prop-types'
import './VisTimeline.css'

Expand Down Expand Up @@ -110,7 +110,7 @@ const TimelineModal = ({ open,group,content,deadlinegroup,deadlines,openDialog,v
const splitTitle = title.split('-').map(part => part.toLowerCase())
splitTitle[1] = splitTitle[1] === "1" ? "" : "_"+splitTitle[1]
let confirmedValue = "vahvista_"+group.toLowerCase()+"_"+splitTitle[0]+"_alkaa"+splitTitle[1]
confirmedValue = scandicUtil.replaceScandics(confirmedValue)
confirmedValue = textUtil.replaceScandics(confirmedValue)
if(group === "Ehdotus" && splitTitle[0] === "nahtavillaolo"){
splitTitle[0] = "esillaolo"
confirmedValue = "vahvista_"+group.toLowerCase()+"_"+splitTitle[0]+splitTitle[1]
Expand Down
20 changes: 17 additions & 3 deletions src/components/ProjectTimeline/VisTimelineGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,27 @@ const VisTimelineGroup = forwardRef(({ groups, items, deadlines, visValues, dead
let lautakuntaReason = !lautakuntaConfirmed ? "noconfirmation" : "";
if (esillaoloConfirmed) {
const deadlineEsillaolokertaKeys = data.maxEsillaolo
const esillaoloRegex = new RegExp(`${phase}_esillaolo_\\d+$`);
const esillaoloRegex = new RegExp(`jarjestetaan_${phase}_esillaolo_\\d+$`);
const attributeEsillaoloKeys = Object.keys(visValRef).filter(key => esillaoloRegex.test(key));
let esillaoloCount = attributeEsillaoloKeys.length
if(attributeEsillaoloKeys.length === 0 || data.content === "OAS" || data.content === "Ehdotus"){
let largestIndex = 0;
//find largest index
attributeEsillaoloKeys.forEach(key => {
const match = key.match(/_(\d+)$/);
if (match) {
const number = parseInt(match[1], 10);
if (number > largestIndex) {
largestIndex = number;
}
}
});

let esillaoloCount = largestIndex
//If no index found add one
if(esillaoloCount === 0){
esillaoloCount += 1
}
esillaoloCount = esillaoloCount + 1;

canAddEsillaolo = esillaoloCount <= deadlineEsillaolokertaKeys;
const nextEsillaoloStr = canAddEsillaolo ? `jarjestetaan_${phase}_esillaolo_${esillaoloCount}$` : false;
nextEsillaoloClean = nextEsillaoloStr ? nextEsillaoloStr.replace(/[/$]/g, '') : nextEsillaoloStr;
Expand Down
27 changes: 22 additions & 5 deletions src/components/project/EditProjectTimetableModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,18 +542,35 @@ class EditProjectTimeTableModal extends Component {
}
};

processValuesSequentially = async (matchingValues) => {
processValuesSequentially = async (matchingValues,index,phase) => {
const validValues = [];
let foundItem = matchingValues.find(item => item?.key?.includes("_paattyy")) || matchingValues[0].value;
// Replace all underscores with spaces
let phaseNormalized = phase.replace(/_/g, ' ');
// Trim leading and trailing spaces just in case
phaseNormalized = phaseNormalized.trim();
// Capitalize the first character and concatenate with the rest of the string
phaseNormalized = phaseNormalized.charAt(0).toUpperCase() + phaseNormalized.slice(1);
console.log(matchingValues)
let distanceArray = []
for (let i = 0; i < this.props.deadlineSections.length; i++) {
if(this.props.deadlineSections[i].title === phaseNormalized){
const sections = this.props.deadlineSections[i].sections[0].attributes
for (let x = 0; x < sections.length; x++) {
distanceArray.push({"name":sections[x].name,"distance":sections[x].distance_from_previous})
console.log(sections[x].name,sections[x]?.distance_from_previous)
}
}
}

for (const { key } of matchingValues) {
try {
let valueToCheck
//Add required range between dates
let newDate = new Date(foundItem.value ? foundItem.value : foundItem);
//TODO Oikeat etäisyydet tuoda excel->backend->frontend esilläolo/lautakunta +vaihe. date_types. dateTypes
let daysToAdd = key.includes("_maaraaika") ? 15 : 30; //Replace with excel info later
daysToAdd = key.includes("_paattyy") || key.includes("viimeistaan_lausunnot") ? daysToAdd + 30 : daysToAdd;
let matchingSection = distanceArray.find(section => section.name === key)
let daysToAdd = matchingSection.distance

while (daysToAdd > 0) {
newDate.setDate(newDate.getDate() + 1);
const dateStr = newDate.toISOString().split('T')[0];
Expand Down Expand Up @@ -716,7 +733,7 @@ class EditProjectTimeTableModal extends Component {
}
// Process the values sequentially and return new validated values from backend
// waits for all values to be ready so vis does not give error if missing start or end date
this.processValuesSequentially(matchingValues, index).then(validValues => {
this.processValuesSequentially(matchingValues, index, phase).then(validValues => {
if (validValues.length >= 2) {
let newIndex
let indexString
Expand Down
12 changes: 12 additions & 0 deletions src/utils/scandicUtil.js → src/utils/textUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ const replaceScandics = (str) => {
});
}

const capitalizeAndRemoveUnderscores = (str) => {
// Replace all underscores with spaces
let formattedStr = str.replace(/_/g, ' ');
// Trim leading and trailing spaces just in case
formattedStr = formattedStr.trim();
// Capitalize the first character and concatenate with the rest of the string
formattedStr = formattedStr.charAt(0).toUpperCase() + formattedStr.slice(1);

return formattedStr;
}

export default {
replaceScandics,
capitalizeAndRemoveUnderscores
}

0 comments on commit d5b6dd8

Please sign in to comment.