Skip to content

Commit e82eed7

Browse files
committed
chnages to render group based on advanced query - part 1
1 parent 78373d7 commit e82eed7

File tree

1 file changed

+126
-2
lines changed

1 file changed

+126
-2
lines changed

UI/web-app/src/components/HRQuerySource/HRQuerySource.base.tsx

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,61 @@ export const HRQuerySourceBase: React.FunctionComponent<HRQuerySourceProps> = (p
221221
};
222222
}
223223

224+
225+
function findPartsOfString(string: string, substringArray: { currentSegment: string, start: number; end: number }[]): { currentSegment: string, start: number; end: number, andOr: string }[] {
226+
const output: { currentSegment: string, start: number; end: number, andOr: "" }[] = [];
227+
let lastEnd = 0;
228+
229+
for (const substringInfo of substringArray) {
230+
const { currentSegment, start, end } = substringInfo;
231+
232+
// Add the segment between the end of the previous segment and the start of the current segment
233+
if (start > lastEnd) {
234+
output.push({
235+
currentSegment: string.substring(lastEnd, start),
236+
start: lastEnd,
237+
end: start - 1,
238+
andOr: ""
239+
});
240+
}
241+
242+
// Add the current segment
243+
output.push({ currentSegment, start, end, andOr: "" });
244+
245+
// Update lastEnd
246+
lastEnd = end + 1;
247+
}
248+
249+
// Add the remaining part of the string after the last segment
250+
if (lastEnd < string.length) {
251+
output.push({
252+
currentSegment: string.substring(lastEnd),
253+
start: lastEnd,
254+
end: string.length - 1,
255+
andOr: ""
256+
});
257+
}
258+
259+
return output;
260+
}
261+
224262

225263
function parseGroup(input: string): Group[] {
226264
const groups: Group[] = [];
265+
const subStrings: string[] = [];
266+
let subStringsWithMoreDetails: { currentSegment: string, start: number; end: number}[] = [];
227267
let depth = 0;
228268
let currentSegment = '';
269+
// let start: number;
270+
// let end: number;
229271
let operators: string[] = [];
230272

231273
input = input.trim();
274+
let start: number = 0;
275+
let end: number = input.length - 1;
276+
console.log("start", start);
277+
console.log("end", end);
278+
232279
for (let i = 0; i < input.length; i++) {
233280
const char = input[i];
234281

@@ -237,10 +284,15 @@ export const HRQuerySourceBase: React.FunctionComponent<HRQuerySourceProps> = (p
237284
currentSegment += char;
238285
}
239286
depth++;
287+
if (depth === 1) start = i;
240288
} else if (char === ')') {
241289
depth--;
242290
if (depth === 0) {
243-
groups.push(parseSegment(currentSegment));
291+
end = i;
292+
//groups.push(parseSegment(currentSegment));
293+
subStrings.push(currentSegment);
294+
// const index: number = input.indexOf(currentSegment);
295+
subStringsWithMoreDetails.push({ currentSegment, start, end});
244296
currentSegment = '';
245297
} else {
246298
currentSegment += char;
@@ -253,10 +305,82 @@ export const HRQuerySourceBase: React.FunctionComponent<HRQuerySourceProps> = (p
253305
}
254306
}
255307

308+
// for (let i = 0; i < groups.length - 1; i++) {
309+
// groups[i].andOr = operators[i] || '';
310+
// }
311+
312+
// console.log("subStrings", subStrings);
313+
// console.log("subStringsWithMoreDetails", subStringsWithMoreDetails);
314+
// console.log("NEW", input.substr(63, 140));
315+
var a = findPartsOfString(input, subStringsWithMoreDetails);
316+
// console.log("a", a);
317+
// console.log("operators", operators);
318+
319+
320+
a.forEach((segment, index) => {
321+
let modifiedSegment = segment.currentSegment.trim();
322+
console.log(`Modified Segment before: ${modifiedSegment}`);
323+
let startWord = '';
324+
let endWord = '';
325+
326+
const lowerCaseSegment = modifiedSegment.toLowerCase();
327+
328+
if (lowerCaseSegment.startsWith('and ')) {
329+
startWord = 'And';
330+
modifiedSegment = modifiedSegment.substring(4).trim();
331+
} else if (lowerCaseSegment.startsWith('or ')) {
332+
startWord = 'Or';
333+
modifiedSegment = modifiedSegment.substring(3).trim();
334+
}
335+
336+
if (lowerCaseSegment.endsWith(' and')) {
337+
endWord = 'And';
338+
modifiedSegment = modifiedSegment.substring(0, modifiedSegment.length - 4).trim();
339+
} else if (lowerCaseSegment.endsWith(' or')) {
340+
endWord = 'Or';
341+
modifiedSegment = modifiedSegment.substring(0, modifiedSegment.length - 3).trim();
342+
}
343+
344+
if (lowerCaseSegment === 'and') { // Additional condition for exact match
345+
startWord = 'And';
346+
modifiedSegment = '';
347+
} else if (lowerCaseSegment === 'or') { // Additional condition for exact match
348+
startWord = 'Or';
349+
modifiedSegment = '';
350+
}
351+
352+
if (startWord !== '') {
353+
console.log(`Start word: ${startWord}`);
354+
a[index-1].andOr = startWord;
355+
}
356+
if (endWord !== '') {
357+
console.log(`End word: ${endWord}`);
358+
a[index].andOr = endWord;
359+
}
360+
361+
console.log(`Modified Segment after: ${modifiedSegment}`);
362+
a[index].currentSegment = modifiedSegment;
363+
364+
if (modifiedSegment === '') {
365+
a.splice(index, 1);
366+
} else {
367+
a[index].currentSegment = modifiedSegment;
368+
}
369+
370+
});
371+
372+
// console.log("A", a);
373+
374+
a.forEach((currentSegment) => {
375+
groups.push(parseSegment(currentSegment.currentSegment));
376+
});
377+
256378
for (let i = 0; i < groups.length - 1; i++) {
257-
groups[i].andOr = operators[i] || '';
379+
groups[i].andOr = a[i].andOr || '';
258380
}
259381

382+
console.log("groups", groups);
383+
260384
return groups;
261385
}
262386

0 commit comments

Comments
 (0)