nocode-js / sequential-workflow-editor

Powerful workflow editor builder for any workflow designer.
https://nocode-js.com/
MIT License
86 stars 8 forks source link

Unstable Sorting in EditorProvider#getToolboxGroups() Function #46

Closed mythsman closed 4 weeks ago

mythsman commented 1 month ago

Although the sorting of EditorProvider#getToolboxGroups itself is stable, when adding steps using DefinitionModelBuilder#steps, the originally ordered steps get regrouped based on model.type . After that, using Object.values(this.definitionModel.steps) does not guarantee the order.

b4rtaz commented 1 month ago

Hello @mythsman,

I'm not sure if I understand correctly. The getToolboxGroups method returns groups and steps in alphabetical order. For that, the localeCompare method is used.

    public getToolboxGroups(): ToolboxGroup[] {
        const stepModels = Object.values(this.definitionModel.steps);
        ...
        categories.forEach((category: string | undefined) => {
            ...
            groupSteps.sort((a, b) => a.name.localeCompare(b.name));
            groups.push({
                name,
                steps: groupSteps
            });
        });
        groups.sort((a, b) => a.name.localeCompare(b.name));
        return groups;
    }

Do you want to keep the order from the model builder?

mythsman commented 1 month ago

@b4rtaz Oh, you know exactly what I want. I have confused 'the order from the model builder' with 'alphabetical order using localCompare' .

There's an issue when using localCompare because the displayed order may differ on machines with different language settings, which made me think it was due to unstable sorting.

So, I think maintaining the order as provided by the model builder might be a better choice.

mythsman commented 1 month ago

And , i am currently facing a scenario related to node definition upgrade. I have designed a node that works perfectly fine. However, as the business grows, the definition of this node needs to be changed. Directly modifying the node definition is not an option since the old workflow definition wouldn't render correctly in the new workflow.

My current solution is to define a new node based on the original one and hide the old one in the getToolboxGroups. This would allow the new workflows to only use the new node while the old workflows can still read from the old node as usual.

Therefore, I believe adding a hidden property or similar in the Step or DefinitionModel, and then filtering it in the getToolboxGroups could be a better choice.

Of course, a custom getToolboxGroups could resolve all these issues as well.

b4rtaz commented 1 month ago

@mythsman please check the 0.14.3 version. I added both features. If you want to keep the default order from the builder, you should use a sorter that does nothing (an empty function).

mythsman commented 4 weeks ago

Thanks for your great work!

mythsman commented 4 weeks ago

image

Oh ,you forgot to export it in index.d.ts 😅

b4rtaz commented 4 weeks ago

@mythsman fixed in 0.14.4. Thanks!