Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tag search display error #4517

Merged
merged 1 commit into from
Dec 17, 2024
Merged

fix: tag search display error #4517

merged 1 commit into from
Dec 17, 2024

Conversation

fit2bot
Copy link
Contributor

@fit2bot fit2bot commented Dec 17, 2024

fix: tag search display error

@fit2bot fit2bot requested a review from a team December 17, 2024 02:31
if (curChildren.length > 0) {
for (const item of curChildren) {
if (valueDecode === item.value) {
if (valueDecode === String(item.value)) {
searchFieldOption.valueLabel = item.label
break
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There aren't significant differences between the two strings provided here. The second string is simply changed to "String(item.value)", which does not introduce any new errors or inconsistencies. You may continue working on this section without any immediate concerns.

The only issue identified was an incorrect use of decodeURIComponent function for string manipulation in Node.js environment, which should be properly converted using the encodeURIComponent and unescape. This would enhance security while handling untrusted input. I will include it during further review:

searchFieldOption.valueLabel = decodeURI(item.label);

Ensure that you're running your application with Node.js environments that have the correct encoding support enabled and handle JavaScript encoded data correctly for better security. Let's proceed further after these adjustments:

Now update the code snippet accordingly:

      ```typescript
    import { useState } from 'react'
    
    let [items, setItems] = useState([{}])
    const onChangeSearchValue = async(ev => {
         searchFieldOption.setValue(ev.target.value)
        if (ev.key == undefined) {
          debugger;
        }

       // Check if key event type matches 'keydown', meaning user pressed the KeyBoard button.
   const isKeyPressed = ev.key ? true : false;

  // Use filter method to filter items array where their value properties match $valueDecode$ 
    const filteredItems = [...items].filter((item) =>
    Object.keys(valueDecode).some(key => item[key] === decodeURIComponent($query))
);

// If there exists at least one matching item, show relevant info to user
if (filteredItems.length > 0) {
  setValue(filteredItems[0]);
}
} else if (ev.key && ev.keyCode != null &&
           (ev.keyCode >= 65 && ev.keyCode <= 90 || /* alt keys */
            ev.KeyCode >= 37 && ev.KeyCode <= 40 ||
            ev.ControlKey | ev.ShiftKey|/* some control chars etc..*/
            !$(document.activeElement)) ) {

  var lastPosition = $(event.target)

  if ($(lastPosition)[0]){

    if (!isKeyPressd || ev.key.toUpperCase() != "UP" ){
       
         if(isKeyPressd){setIsKeyPressed(false)}
         
      // Handle keyboard navigation up and down keys logic
      if(lastPosition.prev()[offsetParent]){
       const oldVal = eval(lastPosition.prev().textContent.match(/\w+/g));
       const newVal = (oldVal.indexOf(valueDecode)+1);
        
        if(newVal>=current.maxVal){
                  newVal= current.defaultMaxVal;
                }
                
         $('#'+ lastPosition.next()).next().html( newVal );
         $('#'+ lastPosition.next()).prev().text(oldVal[newVal])
          
      }


   setTimeout(()=>{  
         $('#'+lastPosition).toggleClass('active','up');
       },80*$(window).scrollTop());
    }else{
     return;   
      
    }
   
}

    })

    .click(() => {
    searchQuery('');
   });

Note: Ensure all dependencies are included and work as intended.

@feng626 feng626 merged commit c15ba5b into dev Dec 17, 2024
5 of 6 checks passed
@feng626 feng626 deleted the pr@dev@tag_search branch December 17, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants