Skip to content

Conversation

@YvetteNikolov
Copy link
Contributor

@YvetteNikolov YvetteNikolov commented Feb 26, 2025

Brave components package

In overleg met Simon deze components package gecreëerd. We merkten dat best wat logica-heavy componenten gekopieerd worden van project naar project, zoals de Back Button. Met deze package is het beter te maintainen

Back Button

Zoals jullie die kennen. Er komt een PR in Brave aan van dit:

<x-back-button>

naar dit

<x-brave-back-button>

Pattern Content (nieuw)

Met dit component kun je gemakkelijk gesynchroniseerde patroon content ophalen en tonen op basis van de slug. Dit gebruiken we zodat klanten stukken kan bewerken die normaal in de code staan. Zoals de footer, of een info blok op een single vacature die buiten de content staat.

Voorbeeld:

<footer class="footer">
    <x-brave-pattern-content slug="footer" />
    <div class="footer-bottom">
        // Rest van de footer
    </div>
</footer>

Daarnaast kun je via de config instellen of een patroon in de admin vergrendeld moet worden en een custom label moet krijgen. Default:

return [
	'hooks' => [
		'pattern_content' => [
			'enabled' => true,
			'patterns' => [
				'footer' => [
					'save_as_draft' => true, // Removes the pattern from the pattern-inserter
					'disable_deletion' => true,
					'custom_label' => 'Vergrendeld',
				],
				// Add more patterns as needed
			],
		],
	],
];

En wat het doet:
footer

@github-actions
Copy link

Composer package changes
Prod Packages Operation Base Target
yard/wp-hook-registrar New - v1.0.2

@github-actions
Copy link

github-actions bot commented Feb 26, 2025

Coverage report for commit: c3bc844
File: coverage.xml

Cover ┌─────────────────────────┐ Freq.
   0% │ ███████████████████████ │ 100.0%
  10% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  20% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  30% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  40% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  50% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  60% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  70% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  80% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  90% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
 100% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
      └─────────────────────────┘
 *Legend:* █ = Current Distribution 
Summary - Lines: - | Methods: -
FilesLinesMethodsBranches
src/Components
   BackButton.php--100.00%
   PatternContent.php--100.00%
src
   ComponentsServiceProvider.php--100.00%
src/Hooks
   PatternContent.php--100.00%

🤖 comment via lucassabreu/comment-coverage-clover

->name('components')
->hasConfigFile()
->hasViews('brave')
->hasViewComponent('brave', PatternContent::class)
Copy link
Contributor

Choose a reason for hiding this comment

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

hasViewComponents('brave', [PatternContent::class, BackButton::class]

Copy link
Contributor

@laravdiemen laravdiemen left a comment

Choose a reason for hiding this comment

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

Ziet er vet uit! De inhoudelijke review laat ik aan backend over ;)


class BackButton extends Component
{
public string $link = 'javascript:history.back();';
Copy link
Contributor

Choose a reason for hiding this comment

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

Deze kunnen toch gewoon naar de constructor?

Copy link
Contributor Author

@YvetteNikolov YvetteNikolov Feb 26, 2025

Choose a reason for hiding this comment

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

Nee, kreeg de error Typed property App\View\Components\BackButton:: must not be accessed before initialization.

Het gebeurde (volgens mij) als ik een terugknop blok op een pagina zetten, en dat hij geen parent page had.

Simon heeft hier een fix doorgevoerd https://github.com/yardinternet/brave/pull/121/files en heb die file gekopieerd (+ verbeterd om PHPStan tevreden te stellen)

Copy link
Contributor

Choose a reason for hiding this comment

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

Weird, ik zou denken dat ze met een default waarde wel voldoende geinitialiseerd waren

@ictbeheer
Copy link
Contributor

Meer packages = meer beter 🥳

Comment on lines 31 to 35
$patternConfig = $this->patterns[$post['post_name']] ?? null;

if ($patternConfig && ! empty($patternConfig['save_as_draft'])) {
$data['post_status'] = 'draft';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

Suggested change
$patternConfig = $this->patterns[$post['post_name']] ?? null;
if ($patternConfig && ! empty($patternConfig['save_as_draft'])) {
$data['post_status'] = 'draft';
}
$patternConfig = $this->patterns[$post['post_name']] ?? [];
if ($patternConfig['save_as_draft'] ?? false ) {
$data['post_status'] = 'draft';
}

Zo ben je meteen die sloppy empty() kwijt en is je type safety stukken beter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Beter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants