abzubarev / web-developer-form-filler-ext

This extension is used by developers to make it easy to fill forms
MIT License
113 stars 54 forks source link

added support for importing arrays #34

Open AviFix opened 1 year ago

abzubarev commented 1 year ago

Hey Thanks for the pull requests The changes file is very hard to read since it's full of changes in code formatting.

Can you elaborate on what kind of change is it? Maybe provide some examples

AviFix commented 1 year ago

Hey, sorry, I can't seem to get the formatting right.

on line 144 i added the following function:

 function validateImportedItems(items) {
    items.forEach(item => {
        if (!item.url || !item.content || !item.name) {
           throw new Error("Invalid JSON format");
        }
    })
}

i changed the $("#btnImportSave").click() callback to this: $("#btnImportSave").click(function () { var json = $('#txtImportFormJson').val();

    try {
        var importedForm = JSON.parse(json);

        if (!Array.isArray(importedForm)) {
            importedForm = [importedForm]
        }

        validateImportedItems(importedForm)

        importedForm.forEach(item => {
            if (item.url === '*') {
                item.name += '-global';
            }

            var key = getRandomStorageId();
            localStorage.setItem(key, JSON.stringify(item));
        })
    } catch (err) {
        alert('Got an error: ' + err.message);
    }

    refreshSetsList(tab_url);
    $('#importBlock').hide();
});

Sorry for the inconvenience

John-Fratila commented 11 months ago

@abzubarev, @AviFix, any news on this pull request? I came here to propose adding exactly the functionality that @AviFix has already added in this pull request, it would be nice to move it forward. I haven't reviewed the code in detail, but it looks like it supports importing an array of sets. Maybe a way to export all the sets as a JSON array would be cool as well.

kanielrkirby commented 8 months ago

Would be very useful to our team as well to be able to use JSON array import/export functionality.

If there's any code that needs to be rewritten, added to, etc., I'm happy to help. Just ping me if this is something that would be helpful.