bugfixing

This commit is contained in:
MuslemRahimi 2024-12-09 13:55:17 +01:00
parent 703d30b6ab
commit 671dcb3258
2 changed files with 27 additions and 17 deletions

View File

@ -330,7 +330,7 @@
return parseValue(a) - parseValue(b);
}
async function handleChangeValue(value) {
async function handleChangeValue(value, { shouldSort = true } = {}) {
// Toggle checkedItems logic
if (checkedItems.has(value)) {
checkedItems.delete(value);
@ -358,8 +358,11 @@
const index = valueMappings[ruleName].indexOf(value);
if (index === -1) {
valueMappings[ruleName].push(value);
// Sort the array when a new value is added
valueMappings[ruleName] = valueMappings[ruleName].sort(customSort);
// Sort the array when a new value is added, respecting shouldSort parameter
if (shouldSort) {
valueMappings[ruleName] = valueMappings[ruleName].sort(customSort);
}
} else {
valueMappings[ruleName].splice(index, 1);
}
@ -371,8 +374,8 @@
} else if (ruleName in valueMappings) {
// For rules that require sorting (like range or numeric values)
if (ruleCondition[ruleName] === "between" && Array.isArray(value)) {
// Sort the array for between conditions
valueMappings[ruleName] = value.sort(customSort);
// Sort the array for between conditions, respecting shouldSort parameter
valueMappings[ruleName] = shouldSort ? value.sort(customSort) : value;
} else {
// Handle non-specific rules as single values
valueMappings[ruleName] = value;
@ -417,7 +420,7 @@
if (ruleCondition[ruleName] === "between") {
const currentValues = valueMappings[ruleName] || ["", ""];
currentValues[index] = newValue;
await handleChangeValue(currentValues);
await handleChangeValue(currentValues, { shouldSort: false });
} else {
await handleChangeValue(newValue);
}

View File

@ -1920,12 +1920,14 @@ const handleKeyDown = (event) => {
return parseValue(a) - parseValue(b);
}
// Main function
async function handleChangeValue(value) {
async function handleChangeValue(value, { shouldSort = true } = {}) {
if (checkedItems.has(ruleName)) {
const itemsSet = checkedItems.get(ruleName);
const sortedValue = Array.isArray(value) ? value.sort(customSort) : value;
// Apply sorting only if shouldSort is true
const sortedValue =
shouldSort && Array.isArray(value) ? value.sort(customSort) : value;
const valueKey = Array.isArray(sortedValue)
? sortedValue.join("-")
: sortedValue;
@ -1936,10 +1938,14 @@ const handleKeyDown = (event) => {
itemsSet?.add(valueKey);
}
} else {
const sortedValue = Array.isArray(value) ? value.sort(customSort) : value;
// Apply sorting only if shouldSort is true
const sortedValue =
shouldSort && Array.isArray(value) ? value.sort(customSort) : value;
const valueKey = Array.isArray(sortedValue)
? sortedValue.join("-")
: sortedValue;
checkedItems?.set(ruleName, new Set([valueKey]));
}
@ -1963,19 +1969,19 @@ const handleKeyDown = (event) => {
]?.includes(ruleName)
) {
searchQuery = "";
if (!Array.isArray(valueMappings[ruleName])) {
valueMappings[ruleName] = [];
}
const sortedValue = Array?.isArray(value)
? value?.sort(customSort)
: value;
// Apply sorting only if shouldSort is true
const sortedValue =
shouldSort && Array?.isArray(value) ? value?.sort(customSort) : value;
const valueKey = Array?.isArray(sortedValue)
? sortedValue.join("-")
: sortedValue;
const index = valueMappings[ruleName].indexOf(valueKey);
const index = valueMappings[ruleName].indexOf(valueKey);
if (index === -1) {
valueMappings[ruleName].push(valueKey);
} else {
@ -1989,7 +1995,8 @@ const handleKeyDown = (event) => {
await updateStockScreenerData();
} else if (ruleName in valueMappings) {
if (ruleCondition[ruleName] === "between" && Array?.isArray(value)) {
valueMappings[ruleName] = value?.sort(customSort);
// Apply sorting only if shouldSort is true
valueMappings[ruleName] = shouldSort ? value?.sort(customSort) : value;
} else {
valueMappings[ruleName] = value;
}
@ -2021,7 +2028,7 @@ const handleKeyDown = (event) => {
if (ruleCondition[ruleName] === "between") {
const currentValues = valueMappings[ruleName] || ["", ""];
currentValues[index] = newValue;
await handleChangeValue(currentValues);
await handleChangeValue(currentValues, { shouldSort: false });
} else {
await handleChangeValue(newValue);
}