Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Warnings improvements #171

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/js/components/Preview.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class Preview extends React.Component<Props, State> {
};

getTabPanes = () => {
const warningsCount = this.state.warnings.length;
const warningsDisabled = this.state.errorHtml && !this.state.previewHtml;
const previewPane = this.getContentTabPane(
'Preview',
'preview',
Expand All @@ -243,13 +245,16 @@ class Preview extends React.Component<Props, State> {
webview => (this.sourceview = webview)
);
const warningsPane = this.getContentTabPane(
'Warnings',
`Warnings${
!warningsDisabled && warningsCount > 0 ? ` (${warningsCount})` : ''
}`,
'warnings',
() => {},
<Warnings
activeTab={this.state.activeTab}
warningSelector={this.props.editor.warningSelector}
warnings={this.state.warnings}
disabled={!!warningsDisabled}
/>
);
return [previewPane, sourcePane, warningsPane];
Expand Down
7 changes: 5 additions & 2 deletions src/js/components/Warnings.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type WarningProps = {

type Props = {
activeTab: number,
disabled: ?boolean,
warningSelector: ?string,
warnings: WarningProps[],
};
Expand Down Expand Up @@ -64,7 +65,7 @@ class Warnings extends React.Component<Props, State> {
render() {
return (
<div className="warning-tab">
{this.props.warnings.length > 0 ? (
{!this.props.disabled && this.props.warnings.length > 0 ? (
<ul>
{this.props.warnings.map((warning, index) => (
<li
Expand All @@ -89,7 +90,9 @@ class Warnings extends React.Component<Props, State> {
) : (
<div className="message-container">
<p className="message">
No warnings: All fields were successfully connected.
{this.props.disabled
? 'No warnings: Open an article, then connect the required fields in the Article element.'
: 'No warnings: All fields were successfully connected.'}
</p>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion webserver/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function get_instant_article($html_markup, $url, $rules, &$response) {
}
return $warning_obj;
};
$warnings = array_map($warnings_func, $warnings);
$warnings = array_unique(array_map($warnings_func, $warnings), SORT_REGULAR);
$response->warnings = $warnings;

try_set_cached_value($cache_key, $warnings, CACHE_KEY_TYPE_WARNINGS);
Expand Down