Skip to content
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
2 changes: 1 addition & 1 deletion assets/dist/roundtable.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/dist/roundtable.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/src/community-app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function CommunityApp() {
</div>
<button class="rt-newtopic-head" type="button" onClick={requestNewTopic}>+ New topic</button>
</div>
{attributionText && <p class="rt-sub rt-attribution">{attributionText}</p>}
{attributionText && <div class="rt-banner rt-banner-info rt-attribution">{attributionText}</div>}
<nav class="rt-tabs" aria-label="Community views">
{TABS.map((tab) => (
<button
Expand Down
1 change: 1 addition & 0 deletions assets/src/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/test/community-app.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ test('CommunityApp shows the chat panel when chatEnabled is true', () => {
assert.match(html, /rt-chat-launch/);
});

test('CommunityApp shows the attribution line under the page header when configured', () => {
test('CommunityApp shows the attribution line as an info notice box under the page header when configured', () => {
globalThis.window = { RoundtableConfig: { agentName: 'Nova', attribution: 'Community powered by Acme' } };
const html = renderToString(h(CommunityApp, {}));
assert.match(html, /rt-attribution[^>]*>Community powered by Acme</);
assert.match(html, /<div class="rt-banner rt-banner-info rt-attribution">Community powered by Acme<\/div>/);
});

test('CommunityApp renders no attribution line when it is not configured', () => {
Expand Down
16 changes: 16 additions & 0 deletions src/Admin/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ public function enqueue( string $hookSuffix ): void {
);
}

/**
* Remove every other plugin's registered admin notices on the Community page only, so they
* don't stack up under our own header. Call on the `in_admin_header` action — the canonical
* point to strip `admin_notices`/`all_admin_notices` before they render, and late enough for
* {@see \get_current_screen()} to be populated. Our own page renders no notices via those
* hooks, so nothing of ours is lost; every other screen is left untouched.
*/
public function suppressAdminNotices(): void {
$screen = \get_current_screen();
if ( ! \str_ends_with( (string) ( $screen->id ?? '' ), '_page_' . self::PAGE_SLUG ) ) {
return;
}
\remove_all_actions( 'admin_notices' );
\remove_all_actions( 'all_admin_notices' );
}

/** Render the admin page: a wrapper and the Preact root container. */
public function render(): void {
echo '<div class="wrap rt-community-wrap"><div id="roundtable-app" data-loading="'
Expand Down
1 change: 1 addition & 0 deletions src/Roundtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function mount( Config $config, string $menuSlug ): void {
$page = new Admin\Page( $config, $menuSlug, $hub );
\add_action( 'admin_menu', array( $page, 'registerMenu' ) );
\add_action( 'admin_enqueue_scripts', array( $page, 'enqueue' ) );
\add_action( 'in_admin_header', array( $page, 'suppressAdminNotices' ) );

$cases = new CasesController( $config, $hub );
$myCases = new MyCasesController( $config, $hub );
Expand Down
25 changes: 25 additions & 0 deletions tests/Admin/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,29 @@ public function test_render_outputs_the_app_container(): void
$html = (string) \ob_get_clean();
self::assertStringContainsString('id="roundtable-app"', $html);
}

public function test_suppress_admin_notices_removes_them_on_our_screen(): void
{
$this->expectNotToPerformAssertions();
Functions\when('get_current_screen')->justReturn((object) ['id' => 'tools_page_roundtable-community']);
Functions\expect('remove_all_actions')->once()->with('admin_notices');
Functions\expect('remove_all_actions')->once()->with('all_admin_notices');
$this->page()->suppressAdminNotices();
}

public function test_suppress_admin_notices_leaves_other_screens_untouched(): void
{
$this->expectNotToPerformAssertions();
Functions\when('get_current_screen')->justReturn((object) ['id' => 'edit-post']);
Functions\expect('remove_all_actions')->never();
$this->page()->suppressAdminNotices();
}

public function test_suppress_admin_notices_does_nothing_without_a_current_screen(): void
{
$this->expectNotToPerformAssertions();
Functions\when('get_current_screen')->justReturn(null);
Functions\expect('remove_all_actions')->never();
$this->page()->suppressAdminNotices();
}
}
1 change: 1 addition & 0 deletions tests/RoundtableMountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function test_mount_registers_admin_and_rest_hooks_when_chat_is_enabled()
$hooks = \array_column( $added, 'hook' );
self::assertContains( 'admin_menu', $hooks );
self::assertContains( 'admin_enqueue_scripts', $hooks );
self::assertContains( 'in_admin_header', $hooks );
self::assertContains( 'rest_api_init', $hooks );

$registered = $this->registeredControllerClasses( $added );
Expand Down
Loading