Ju99ernaut / grapesjs-template-manager

Template and page manager for grapesjs
MIT License
79 stars 35 forks source link

The template manager uses a hardcoded(?) ID prefix #13

Closed Biont closed 2 years ago

Biont commented 2 years ago

I wanted to get rid of the gjs--prefix in the payloads, so I set up my storage manager like this:

{
        storageManager: {
            id: '',
            type: 'rest-api',
            stepsBeforeSave: 3,
            urlStore: 'api/grapesjs',
            urlLoad: 'api/grapesjs',
            urlDelete: 'api/grapesjs',
        },
}

If I save a document like this and then open the template manager modal, I see the following error:

Error SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at grapesjs-project-manager.min.js:2
    at Array.map (<anonymous>)
    at n.value (grapesjs-project-manager.min.js:2)
    at n.value (grapesjs-project-manager.min.js:2)
    at n.value (grapesjs-project-manager.min.js:2)
    at grapesjs-project-manager.min.js:2
    at r.onResponse (grapes.min.js:2)
    at grapes.min.js:2

That's because it is still trying to access the "pages" property using the "gjs-" prefix:

screenshot_2021-09-06-123032

I would expect this to respect the prefix I configured in the storeManager. Did I miss something here?

I am using the latest releases of everything:

    "dependencies": {
        "@fortawesome/fontawesome-free": "^5.15.4",
        "grapesjs": "^0.17.25",
        "grapesjs-preset-webpage": "^0.1.11",
        "grapesjs-project-manager": "^1.0.9"
    },
Ju99ernaut commented 2 years ago

Good catch, the prefix isn't hardcoded but it defaults to gjs- since an empty string is falsy. Should be matter of properly handling the assignment of this.id. https://github.com/Ju99ernaut/grapesjs-template-manager/blob/11a7190177ecf3f98ec31e59422c58e01087b374/src/utils/ui.js#L6 I'll work on a fix for this but a PR is also welcome.

Ju99ernaut commented 2 years ago

Probably there's no need to add || 'gjs-', it can just be:

this.id = editor.Storage.getConfig().id;