Skip to content
Snippets Groups Projects
Commit e96dfa0a authored by Jean Valverde's avatar Jean Valverde :construction_site: Committed by Pierre Dureau
Browse files

Issue #3469805 by mogtofu33, pdureau, kristen pol: Some UX tweaks in Component validator

parent eb18e501
Branches
Tags
1 merge request!203Issue #3469805 by pdureau, kristen pol: [2.0.0-beta2] Some UX tweaks in Component validator
Pipeline #281173 passed with warnings
......@@ -38,14 +38,9 @@ final class ComponentValidatorOverview extends ControllerBase {
private array $componentHasCritical = [];
/**
* Current minimum severity.
* Current severity to show.
*/
private int $minimumSeverity = RfcLogLevel::NOTICE;
/**
* Flag if current component has messages in current level or more.
*/
private bool $hasMessagesSeverity = FALSE;
private array $levels = [];
/**
* Flag if current component is viewed on a single page.
......@@ -118,6 +113,11 @@ final class ComponentValidatorOverview extends ControllerBase {
$build['summary'] = $this->buildMessagesSummary();
$empty = $this->t('No messages found.');
if (!empty($this->levels) && count(array_filter($this->levels)) < 4) {
$empty = $this->t('No messages found for this severity, check filter in this form.');
}
$header = [
$this->t('Component'),
$this->t('Severity'),
......@@ -131,6 +131,7 @@ final class ComponentValidatorOverview extends ControllerBase {
'#responsive' => TRUE,
'#header' => $header,
'#rows' => $rows,
'#empty' => $empty,
];
return $build;
......@@ -241,13 +242,9 @@ final class ComponentValidatorOverview extends ControllerBase {
];
}
if (!$this->hasMessagesSeverity) {
if ($this->singleDisplay) {
$build['details'] = [
'#markup' => $this->t('Nothing to show at this minimum severity level.'),
];
}
return $build;
$empty = $this->t('No messages found.');
if (!empty($this->levels) && count(array_filter($this->levels)) < 4) {
$empty = $this->t('No messages found for this severity, check filter in this form.');
}
$header = [
......@@ -262,6 +259,7 @@ final class ComponentValidatorOverview extends ControllerBase {
'#responsive' => TRUE,
'#header' => $header,
'#rows' => $rows,
'#empty' => $empty,
'#weight' => -1,
];
......@@ -286,10 +284,10 @@ final class ComponentValidatorOverview extends ControllerBase {
*/
private function buildOnMessageRows(array $messages, string $component_id, bool $with_name = FALSE): array {
$levels = RfcLogLevel::getLevels();
$this->hasMessagesSeverity = FALSE;
$default = [RfcLogLevel::WARNING, RfcLogLevel::ERROR, RfcLogLevel::CRITICAL, RfcLogLevel::NOTICE];
// @phpstan-ignore-next-line
$this->minimumSeverity = (int) $this->state()->get('ui_patterns_devel_overview_severity', RfcLogLevel::WARNING);
$this->levels = $this->state()->get('ui_patterns_devel_overview_severity', $default);
$rows = [];
foreach ($messages as $message) {
......@@ -306,12 +304,10 @@ final class ComponentValidatorOverview extends ControllerBase {
$this->componentHasCritical[$component_id] = TRUE;
}
if ($message->level() > $this->minimumSeverity) {
if (!in_array($message->level(), $this->levels)) {
continue;
}
$this->hasMessagesSeverity = TRUE;
$line = (0 === $message->line()) ? '-' : $message->line();
$source = new FormattableMarkup('<pre><code>@code</code></pre>', ['@code' => $message->getSourceCode()]);
$data = [];
......@@ -391,6 +387,11 @@ final class ComponentValidatorOverview extends ControllerBase {
$notice = $this->t('No notice.');
}
$open = FALSE;
if (!empty($this->levels) && count(array_filter($this->levels)) < 4) {
$open = TRUE;
}
return [
'report' => [
'#theme' => 'status_report_page',
......@@ -420,8 +421,8 @@ final class ComponentValidatorOverview extends ControllerBase {
],
'form' => [
'#type' => 'details',
'#title' => $this->t('Filter messages'),
'#open' => $this->minimumSeverity < RfcLogLevel::NOTICE ? TRUE : FALSE,
'#title' => $this->t('Filter by severity'),
'#open' => $open,
'form' => $form,
],
'#weight' => -1,
......@@ -451,7 +452,7 @@ final class ComponentValidatorOverview extends ControllerBase {
$build['schema'] = [
'#type' => 'details',
'#title' => $this->t('YAML schema'),
'#title' => $this->t('Definition YAML'),
'#description' => $definition['_discovered_file_path'] ?? '',
'#open' => FALSE,
'#weight' => 2,
......@@ -460,8 +461,8 @@ final class ComponentValidatorOverview extends ControllerBase {
$build['schema_full'] = [
'#type' => 'details',
'#title' => $this->t('Schema full'),
'#description' => $this->t('Discovered definition'),
'#title' => $this->t('Definition discovered'),
'#description' => $this->t('Definition processed by the code before rendering.'),
'#open' => FALSE,
'#weight' => 3,
['#markup' => '<pre><code>' . \htmlentities((string) Yaml::dump($component->getPluginDefinition(), 10, 2)) . '</code></pre>'],
......@@ -494,14 +495,13 @@ final class ComponentValidatorOverview extends ControllerBase {
$build = [];
$definition = $component->getPluginDefinition();
// @phpstan-ignore-next-line
if (!isset($definition['stories']) && empty($definition['stories'])) {
return ['#markup' => $this->t('<small><i>Note</i>: Add `stories` to this component to enable render preview.</small>')];
return ['#markup' => $this->t('<i>Note</i>: No preview available for this component, add <code>stories</code> value to this component definition YAML to enable preview.')];
}
if (isset($this->componentHasCritical[$component_id])) {
return ['#markup' => $this->t('<small><b>Error</b>: No render available as there is a Runtime error with this component, see critical above!</small>')];
return ['#markup' => $this->t('<b>Error</b>: No render available as there is a Runtime error with this component, see critical above!')];
}
foreach (\array_keys($definition['stories']) as $story_id) {
......
......@@ -59,13 +59,15 @@ final class OverviewForm extends FormBase {
}
krsort($options);
$value = $this->state->get('ui_patterns_devel_overview_severity', RfcLogLevel::NOTICE);
$form['severity'] = [
'#type' => 'select',
'#title' => $this->t('Show only messages with minimum severity'),
$values = $this->state->get('ui_patterns_devel_overview_severity', array_keys($options));
$form['levels'] = [
'#type' => 'checkboxes',
'#title' => $this->t('By severity'),
'#options' => $options,
'#default_value' => $value,
'#required' => TRUE,
'#multiple' => TRUE,
'#default_value' => $values,
];
$form['actions'] = [
......@@ -78,15 +80,6 @@ final class OverviewForm extends FormBase {
],
];
if ($value !== 5) {
$form['actions']['reset'] = [
'#type' => 'submit',
'#name' => 'reset',
'#value' => $this->t('Reset'),
'#button_type' => 'secondary',
];
}
return $form;
}
......@@ -94,12 +87,7 @@ final class OverviewForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
if ($form_state->getTriggeringElement()['#name'] === 'reset') {
$this->state->set('ui_patterns_devel_overview_severity', NULL);
}
else {
$this->state->set('ui_patterns_devel_overview_severity', $form_state->getValue('severity'));
}
$this->state->set('ui_patterns_devel_overview_severity', $form_state->getValue('levels'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment