gentics / mesh-ui

Gentics Mesh UI
https://getmesh.io
Apache License 2.0
23 stars 27 forks source link

Default example for preview URLs is wrong #315

Open deckdom opened 4 years ago

deckdom commented 4 years ago

When Mesh initially creates the mesh-ui2-config.js, it uses a very outdated format which does not work with the UI:

/**
 * Within the node editor in UI the feature "Preview" of a node will open a new tab to a defined frontend app.
 * Here a function can be provided returning the URL which will be called by that component.
 * 
 * @example:
 * ```javascript
 * previewUrls: [
 *    {
 *        label: 'Gentics Mesh Angular Demo',
 *        urlResolver: function (node) { return 'http://test.myapp/category/' + node.uuid + '?preview=true'; }
 *    }
 * ]
 * ```
 */
previewUrls: [
    {
        /** display name to see within preview url selection in frontend */
        label: 'Gentics Mesh Angular Demo',
        /**
         * Function to be called in frontend to get url
         * @param nodeUuid unique Mesh node
         */
        // adopt to angular demo
        urlResolver: function (node) {

            // custom route mapping
            var segmentParent;
            switch (node.schema.name) {
                case 'category':
                    segmentParent = 'category';
                    break;

                case 'vehicle':
                    segmentParent = 'product';
                    break;

                default:
                    throw new Error('No existing app route preview mapping configured for node of schema: ' + node.schema.name);
            }

            // return app preview URL
            return '/demo/' + segmentParent + '/' + node.uuid + '?preview=true';
        }
    }
]

However, the correct format would be like this:

previewUrls: {
    "PROJECT_NAME": [
        {
            label: "Example",
            urlResolver: function(node) {
                return "http://localhost" + node.path;
            }
        }
    ]
}