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

Fix unexpected preview crash with adding preview condition #656

Merged
merged 3 commits into from
Jan 19, 2024

Conversation

Prokyonn
Copy link
Member

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets fixes #issuenum
Related issues/PRs #issuenum
License MIT

What's in this PR?

Fixes the preview when the locale is switched to a non existing one in the article detail view.

@@ -260,6 +260,8 @@ function(Localization $localization) {
];
}

$previewCondition = 'route != null';
Copy link
Member Author

@Prokyonn Prokyonn Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-schranz @wachterjohannes that was the best solution I was able to find for the preview condition 😅 it is working but somehow feels a bit wrong, do you have any better suggestion?

@Prokyonn Prokyonn marked this pull request as ready for review December 21, 2023 13:59
@Prokyonn Prokyonn force-pushed the bugfix/article-preview branch from a79ecee to ec269aa Compare December 21, 2023 23:20
@@ -260,6 +260,7 @@ function(Localization $localization) {
];
}

$previewCondition = "locale in availableLocales";
Copy link
Member Author

@Prokyonn Prokyonn Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wachterjohannes Checking the locale is only possible, when we also update the PreviewForm.js in sulu/sulu like this:

-    const enablePreview = !previewCondition || jexl.evalSync(previewCondition, this.resourceFormStore.data);
+    const previewData = {
+        ...this.props.router.attributes,
+        ...toJS(this.resourceFormStore.data)
+    };
+    const enablePreview = !previewCondition || jexl.evalSync(previewCondition, previewData);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there not a locale and originalLocale returned by the JSON response?
When we add router attributes to the conditoin we maybe should prefix it with __ like we did it with __parent or __webspaces already. So maybe __routeAttributes.

Copy link
Member Author

@Prokyonn Prokyonn Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response json

image

Unfortunately we do not have a locale or originalLocale only the ghostLocale and this is not helpful.

So should we go with __routeAttributes ?

@Prokyonn Prokyonn force-pushed the bugfix/article-preview branch from 382fc39 to fa9b82f Compare January 12, 2024 10:18
@alexander-schranz alexander-schranz merged commit 387625a into sulu:2.5 Jan 19, 2024
7 checks passed
@alexander-schranz alexander-schranz added the bug Error or unexpected behavior of already existing functionality label Jan 19, 2024
@alexander-schranz alexander-schranz changed the title Add preview condition Fix unexpected preview crash with adding preview condition Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Error or unexpected behavior of already existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants