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

Duplicate/Clone Item #940

Open
davidkong0987 opened this issue Jun 21, 2023 · 1 comment
Open

Duplicate/Clone Item #940

davidkong0987 opened this issue Jun 21, 2023 · 1 comment

Comments

@davidkong0987
Copy link

See clone option here: https://react-querybuilder.js.org/demo/antd#addRuleToNewGroups=false&autoSelectField=true&autoSelectOperator=true&debugMode=false&disabled=false&enableDragAndDrop=false&independentCombinators=false&justifiedLayout=false&listsAsArrays=false&parseNumbers=false&resetOnFieldChange=true&resetOnOperatorChange=false&showBranches=false&showCloneButtons=true&showCombinatorsBetweenRules=false&showLockButtons=false&showNotToggle=false&validateQuery=false

I've been able to create this functionality though it's a little forced:

            renderAfterActions:(props)=><Button className=".rule--header" icon=<CopyOutlined />  onClick={()=>console.log(props)||this.dup(props.id)}/>,
            renderAfterWidget:(props)=><Button  className=".rule--header" icon=<CopyOutlined /> onClick={()=>console.log(props)||this.dup(props.id)}/>,

then something like this

function duplicateById(obj, id) {
    if (obj === null || typeof obj !== 'object') return obj;

    if (Array.isArray(obj)) {
        return obj.reduce((acc, cur) => {
            let dup = duplicateById(cur, id);
            if (cur.id === id) {
                // Copy the duplicated item and assign a new id
                dup = { ...dup, id: Utils.uuid() };
                acc.push(cur, dup);
            } else {
                acc.push(dup);
            }
            return acc;
        }, []);
    }

    return Object.keys(obj).reduce((acc, key) => {
        acc[key] = duplicateById(obj[key], id);
        return acc;
    }, {});
}
@ukrbublik ukrbublik added this to the Improve config milestone Jul 27, 2023
@punto-rojo
Copy link

Hi @ukrbublik, any update on this feature? When can we expect this to be available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants