Skip to content

Commit

Permalink
Fix issue creating a new widget from admin #581
Browse files Browse the repository at this point in the history
  • Loading branch information
treoden committed Aug 23, 2024
1 parent 7a41e63 commit d932525
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const isErrorHandlerTriggered = require('@evershop/evershop/src/lib/middleware/isErrorHandlerTriggered');
const { render } = require('@evershop/evershop/src/lib/response/render');
const { get } = require('@evershop/evershop/src/lib/util/get');
const { v4: uuidv4 } = require('uuid');
const isDevelopmentMode = require('@evershop/evershop/src/lib/util/isDevelopmentMode');
const {
loadWidgetInstances
Expand Down Expand Up @@ -68,7 +69,9 @@ module.exports = async (request, response, delegate, next) => {
areaId: widget.areaId,
type: widget.type
};
newWidget.id = `e${widget.uuid.replace(/-/g, '')}`;
newWidget.id = widget.uuid
? `e${widget.uuid.replace(/-/g, '')}`
: `e${uuidv4().replace(/-/g, '')}`;
if (route.isAdmin) {
newWidget.areaId = 'widget_setting_form';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ module.exports = {
'&lt;': '<',
'&gt;': '>'
};
const jsonText = text.replace(
/&lt;|&gt;/g,
(match) => replacements[match]
);
const jsonText = text
? text.replace(/&lt;|&gt;/g, (match) => replacements[match])
: '[]';
return { text: JSON.parse(jsonText), className };
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ exports.loadWidgetInstances = async function loadWidgetInstances(request) {
.map((widget) => ({
type: widget.type,
areaId: 'widget_setting_form',
props: widget.default_settings || {},
sortOrder: 0
}))
.filter((widget) => widget.type === type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = async (request, response, delegate, next) => {
if (currentRoute?.isAdmin) {
if (currentRoute?.id === 'widgetNew') {
const currentWidget = enabledWidgets.find(
(widget) => widget.type === currentRoute?.params?.type
(widget) => widget.type === request.params?.type
);
applicableWidgets = [
{
Expand Down

0 comments on commit d932525

Please sign in to comment.