ToolJet / ToolJet

Low-code platform for building business applications. Connect to databases, cloud storages, GraphQL, API endpoints, Airtable, Google sheets, OpenAI, etc and build apps using drag and drop application builder. Built using JavaScript/TypeScript. 🚀
https://tooljet.com
GNU Affero General Public License v3.0
28.71k stars 3.55k forks source link

setTab does not switch to tab 0 if tabIndex is passed as number 0 #10332

Open johnsoncherian opened 2 months ago

johnsoncherian commented 2 months ago

What is the expected behaviour?

In the setTab function should switch to 0th tab regardless of if value is passed as integer 0 or string '0'

What is the current behaviour?

If the tabindex is passed as number type 0 setTab ignore the value and tab is not switched to 0th tab

https://github.com/ToolJet/ToolJet/assets/57667706/942c4a83-77d3-4386-9d3d-f185208a8198

Apetun commented 2 months ago

Hey just wanted to know if im getting this right the function rn is

    const exposedVariables = {
      setTab: async function (id) {
        if (id) {
          setCurrentTab(id);
          setExposedVariable('currentTab', id);
          fireEvent('onTabSwitch');
        }
      },
      currentTab: currentTab,
    };
    setExposedVariables(exposedVariables);

    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [setCurrentTab, currentTab]);

the id is being checked and when string is passed its giving a truthy value and when 0 is passed it gives a falsy value

So something like:

if (id !== undefined) { // Check if id is not undefined
          const tabId = Number(id); // Convert id to number if it's a string
          setCurrentTab(tabId);
          setExposedVariable('currentTab', tabId);
          fireEvent('onTabSwitch')

Should fix it right?

PriteshKiri commented 1 month ago

@Apetun, please ensure the issue is assigned to you before you start working on it. Let me know if you would like me to assign it to you. Once it's assigned, you can create a PR, and we can then evaluate and discuss the best possible solution in the PR discussion.

Apetun commented 1 month ago

Ok sure please assign the issue to me.

CuriousCoder00 commented 1 month ago

I would like to work on it.... If this isn't assigned to someone else or not planning to assign to someone else..!!

PriteshKiri commented 1 month ago

@Apetun assigned it to you! Happy coding :)

PriteshKiri commented 1 month ago

@CuriousCoder00 this issue has been assigned. Can you please check other community issues? Just search for other community contribution lable

CuriousCoder00 commented 1 month ago

@PriteshKiri Yeah.. I looked at a few issues.. i'd love to work on em

Apetun commented 1 month ago

I have made the required changes

PriteshKiri commented 1 month ago

Thanks for your contribution @Apetun. Moving the issue to the review