diff --git a/assets/css/components.css b/assets/css/components.css index b71302c..0f28a4b 100644 --- a/assets/css/components.css +++ b/assets/css/components.css @@ -541,40 +541,6 @@ footer a { position: relative; } -.chrnx-selected-work__list { - display: grid; - gap: 0; - grid-template-columns: 1fr; - margin: 0; - padding: 0; - border-top: 1px solid var(--chrnx-line); - list-style: none; -} - -.chrnx-selected-work__item { - padding-block: 1.25rem; - border-bottom: 1px solid var(--chrnx-line); -} - -.chrnx-selected-work__title { - margin: 0; - overflow-wrap: anywhere; -} - -.chrnx-selected-work__title a { - color: inherit; - text-decoration: none; -} - -.chrnx-selected-work__title a:hover { - text-decoration: underline; -} - -.chrnx-selected-work__empty { - margin: 0; - color: var(--chrnx-muted); -} - .chrnx-responsive-portrait { display: block; } diff --git a/assets/js/editor-project.js b/assets/js/editor-project.js deleted file mode 100644 index fb14215..0000000 --- a/assets/js/editor-project.js +++ /dev/null @@ -1,111 +0,0 @@ -( function ( factory ) { - if ( typeof module === 'object' && module.exports ) { - module.exports = factory(); - } else { - factory().initialize( window.wp ); - } -} )( function () { - 'use strict'; - - function getTranslator( wp ) { - return wp.i18n && typeof wp.i18n.__ === 'function' - ? wp.i18n.__ - : function ( text ) { - return text; - }; - } - - function updateMeta( editPost, currentMeta, key, value ) { - if ( typeof editPost !== 'function' ) { - return; - } - - editPost( { meta: { ...( currentMeta || {} ), [ key ]: value } } ); - } - - function hasRequiredGlobals( wp ) { - return Boolean( - wp && - wp.components && - wp.components.ToggleControl && - wp.data && - typeof wp.data.useDispatch === 'function' && - typeof wp.data.useSelect === 'function' && - wp.editPost && - wp.editPost.PluginDocumentSettingPanel && - wp.element && - typeof wp.element.createElement === 'function' && - wp.plugins && - typeof wp.plugins.registerPlugin === 'function', - ); - } - - function initialize( wp ) { - if ( ! hasRequiredGlobals( wp ) ) { - return false; - } - - const __ = getTranslator( wp ); - - function ProjectPanel() { - const editorState = wp.data.useSelect( function ( select ) { - if ( typeof select !== 'function' ) { - return null; - } - - const currentEditor = select( 'core/editor' ); - const core = select( 'core' ); - if ( - ! currentEditor || - typeof currentEditor.getCurrentPostType !== 'function' || - typeof currentEditor.getEditedPostAttribute !== 'function' || - ! core || - typeof core.getEntityRecord !== 'function' - ) { - return null; - } - - const topicIds = currentEditor.getEditedPostAttribute( 'topic' ); - return { - meta: currentEditor.getEditedPostAttribute( 'meta' ) || {}, - postType: currentEditor.getCurrentPostType(), - topic: - Array.isArray( topicIds ) && topicIds.length === 1 - ? core.getEntityRecord( 'taxonomy', 'chrnx_topic', topicIds[ 0 ] ) - : null, - }; - }, [] ); - const editorDispatch = wp.data.useDispatch( 'core/editor' ); - if ( ! editorState || editorState.postType !== 'post' || ! editorDispatch?.editPost ) { - return null; - } - - if ( ! editorState.topic || editorState.topic.slug !== 'projects' ) { - return null; - } - - const meta = editorState.meta; - - return wp.element.createElement( - wp.editPost.PluginDocumentSettingPanel, - { name: 'chrnx-project', title: __( 'Project', 'chrnx' ) }, - wp.element.createElement( wp.components.ToggleControl, { - label: __( 'Show in Selected work', 'chrnx' ), - help: __( - 'Selected work lists these first, then fills the rest with the most recent projects.', - 'chrnx', - ), - checked: Boolean( meta.chrnx_project_featured ), - onChange( value ) { - updateMeta( editorDispatch.editPost, meta, 'chrnx_project_featured', Boolean( value ) ); - }, - } ), - ); - } - - wp.plugins.registerPlugin( 'chrnx-project-meta', { render: ProjectPanel } ); - return true; - } - - return { initialize, updateMeta }; -} ); diff --git a/blocks/selected-work/block.json b/blocks/selected-work/block.json deleted file mode 100644 index 19a0deb..0000000 --- a/blocks/selected-work/block.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, - "name": "chrnx/selected-work", - "version": "0.4.4", - "title": "Selected Work", - "category": "theme", - "description": "Hand-picked projects first, then the most recent ones.", - "textdomain": "chrnx", - "attributes": { - "limit": { "type": "integer", "default": 3, "minimum": 1, "maximum": 12 }, - "headingLevel": { "type": "integer", "default": 3, "enum": [2, 3, 4, 5, 6] } - }, - "supports": { "html": false }, - "render": "file:./render.php" -} diff --git a/blocks/selected-work/render.php b/blocks/selected-work/render.php deleted file mode 100644 index 7291587..0000000 --- a/blocks/selected-work/render.php +++ /dev/null @@ -1,26 +0,0 @@ - -
diff --git a/inc/blocks.php b/inc/blocks.php index d0935b5..17793fc 100644 --- a/inc/blocks.php +++ b/inc/blocks.php @@ -232,7 +232,7 @@ function chrnx_get_editorial_card_markup( $post_id, $heading_level = 3, $class_n /** Register all block metadata directories that exist. */ function chrnx_register_editorial_blocks() { - $blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link', 'selected-work', 'release-list', 'release-detail', 'track-meta', 'subscribe-form', 'show-links', 'project-list', 'project-detail' ); + $blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link', 'release-list', 'release-detail', 'track-meta', 'subscribe-form', 'show-links', 'project-list', 'project-detail' ); foreach ( $blocks as $block ) { $name = 'chrnx/' . $block; if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) { diff --git a/inc/editor.php b/inc/editor.php index f185611..4d5c6a3 100644 --- a/inc/editor.php +++ b/inc/editor.php @@ -45,14 +45,6 @@ function chrnx_enqueue_editor_assets() { true ); - wp_enqueue_script( - 'chrnx-editor-project', - get_theme_file_uri( 'assets/js/editor-project.js' ), - array( 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins' ), - CHRNX_VERSION, - true - ); - wp_enqueue_script( 'chrnx-editor-track', get_theme_file_uri( 'assets/js/editor-track.js' ), @@ -63,7 +55,6 @@ function chrnx_enqueue_editor_assets() { wp_set_script_translations( 'chrnx-editor-taxonomies', 'chrnx', get_theme_file_path( 'languages' ) ); wp_set_script_translations( 'chrnx-editor-podcast', 'chrnx', get_theme_file_path( 'languages' ) ); - wp_set_script_translations( 'chrnx-editor-project', 'chrnx', get_theme_file_path( 'languages' ) ); wp_set_script_translations( 'chrnx-editor-track', 'chrnx', get_theme_file_path( 'languages' ) ); } add_action( 'enqueue_block_editor_assets', 'chrnx_enqueue_editor_assets' ); diff --git a/inc/queries.php b/inc/queries.php index 9cbdf65..6b22315 100644 --- a/inc/queries.php +++ b/inc/queries.php @@ -262,59 +262,6 @@ function chrnx_get_featured_story_ids( int $limit = 3 ): array { return $selected; } -/** - * Select projects for the Selected work stage: hand-picked first, then recent. - * - * Sticky already belongs to the home featured stories, so the editorial choice - * lives in its own per-post flag instead of competing for the same signal. - * - * @param int $limit Maximum projects, bounded to 12. - * @return int[] Selected project post IDs. - */ -function chrnx_get_selected_project_ids( int $limit = 3 ): array { - $limit = min( 12, max( 0, $limit ) ); - if ( 0 === $limit ) { - return array(); - } - - $topic_query = array( - array( - 'taxonomy' => 'chrnx_topic', - 'field' => 'slug', - 'terms' => 'projects', - ), - ); - - $selected = chrnx_get_eligible_editorial_post_ids( - array( - 'posts_per_page' => $limit, - 'tax_query' => $topic_query, - 'meta_query' => array( - array( - 'key' => 'chrnx_project_featured', - 'value' => '1', - ), - ), - ) - ); - - $remaining = $limit - count( $selected ); - if ( $remaining > 0 ) { - $selected = array_merge( - $selected, - chrnx_get_eligible_editorial_post_ids( - array( - 'posts_per_page' => $remaining, - 'post__not_in' => $selected, - 'tax_query' => $topic_query, - ) - ) - ); - } - - return $selected; -} - /** * Validate a request taxonomy slug against an existing editorial term. * diff --git a/scripts/seed-test-content.php b/scripts/seed-test-content.php index 2a33069..7175b37 100644 --- a/scripts/seed-test-content.php +++ b/scripts/seed-test-content.php @@ -140,12 +140,9 @@ foreach ( $chrnx_seed_posts as $chrnx_seed_index => $chrnx_seed_post ) { wp_set_object_terms( $chrnx_seed_post_id, array(), 'chrnx_release', false ); } - foreach ( array( 'chrnx_episode_number', 'chrnx_episode_duration', 'canonical_episode_url', 'chrnx_project_featured' ) as $chrnx_seed_meta_key ) { + foreach ( array( 'chrnx_episode_number', 'chrnx_episode_duration', 'canonical_episode_url' ) as $chrnx_seed_meta_key ) { delete_post_meta( $chrnx_seed_post_id, $chrnx_seed_meta_key ); } - if ( ! empty( $chrnx_seed_post['projectFeatured'] ) ) { - update_post_meta( $chrnx_seed_post_id, 'chrnx_project_featured', true ); - } delete_post_meta( $chrnx_seed_post_id, 'chrnx_track_number' ); if ( isset( $chrnx_seed_post['trackNumber'] ) ) { update_post_meta( $chrnx_seed_post_id, 'chrnx_track_number', absint( $chrnx_seed_post['trackNumber'] ) ); diff --git a/tests/e2e/music-podcast-stages.spec.mjs b/tests/e2e/music-podcast-stages.spec.mjs index f129796..3b816ed 100644 --- a/tests/e2e/music-podcast-stages.spec.mjs +++ b/tests/e2e/music-podcast-stages.spec.mjs @@ -557,7 +557,7 @@ const immutableSurfaces = [ 'alter-ego-research-768.webp', 'alter-ego-code-768.webp', ], - // Project names come from chrnx/selected-work: picked projects newest-first, + // Project names come from the project list query: picked projects newest-first, // then the most recent ones. This is the seeded order, not a frozen string. headings: [ 'Selected work', 'Ailed', 'Expressive Tea', 'Published research' ], paragraphs: [], diff --git a/tests/js/editor-project.test.js b/tests/js/editor-project.test.js deleted file mode 100644 index 590d160..0000000 --- a/tests/js/editor-project.test.js +++ /dev/null @@ -1,102 +0,0 @@ -const modulePath = '../../assets/js/editor-project.js'; - -function flatten( node ) { - if ( ! node || typeof node !== 'object' ) { - return []; - } - return [ node ].concat( ( node.children || [] ).flatMap( flatten ) ); -} - -function createWp( topicSlug = 'projects', meta = { unrelated: 'keep' } ) { - const editPost = jest.fn(); - const registerPlugin = jest.fn(); - const state = { meta, topic: [ 12 ] }; - const wp = { - components: { ToggleControl: 'ToggleControl' }, - i18n: { __: jest.fn( ( text ) => text ) }, - data: { - select: ( store ) => { - if ( store === 'core/editor' ) { - return { - getCurrentPostType: () => 'post', - getEditedPostAttribute: ( key ) => state[ key ], - }; - } - return { - getEntityRecord: () => ( topicSlug ? { id: 12, slug: topicSlug } : undefined ), - }; - }, - dispatch: () => ( { editPost } ), - useDispatch: ( store ) => wp.data.dispatch( store ), - useSelect: ( mapper ) => mapper( wp.data.select ), - }, - editPost: { PluginDocumentSettingPanel: 'PluginDocumentSettingPanel' }, - element: { - createElement: ( type, props, ...children ) => ( { type, props: props || {}, children } ), - }, - plugins: { registerPlugin }, - }; - return { wp, editPost, registerPlugin }; -} - -function renderPanel( context ) { - const { initialize } = require( modulePath ); - expect( initialize( context.wp ) ).toBe( true ); - const [ , plugin ] = context.registerPlugin.mock.calls[ 0 ]; - return plugin.render(); -} - -describe( 'project editor panel', () => { - beforeEach( () => { - jest.resetModules(); - } ); - - test( 'refuses to initialize without the required editor globals', () => { - const { initialize } = require( modulePath ); - expect( initialize( undefined ) ).toBe( false ); - expect( initialize( {} ) ).toBe( false ); - } ); - - test( 'renders the Selected work toggle only for the projects topic', () => { - const context = createWp( 'projects' ); - const toggles = flatten( renderPanel( context ) ).filter( - ( node ) => node.type === 'ToggleControl', - ); - expect( toggles ).toHaveLength( 1 ); - expect( toggles[ 0 ].props.checked ).toBe( false ); - } ); - - test.each( [ 'podcasts', 'code', null ] )( 'renders nothing for the %s topic', ( slug ) => { - expect( renderPanel( createWp( slug ) ) ).toBeNull(); - } ); - - test( 'reflects an existing flag and preserves unrelated meta when toggling', () => { - const context = createWp( 'projects', { unrelated: 'keep', chrnx_project_featured: true } ); - const toggle = flatten( renderPanel( context ) ).find( - ( node ) => node.type === 'ToggleControl', - ); - expect( toggle.props.checked ).toBe( true ); - - toggle.props.onChange( false ); - expect( context.editPost ).toHaveBeenCalledWith( { - meta: { unrelated: 'keep', chrnx_project_featured: false }, - } ); - } ); - - test( 'coerces the toggle value to a boolean', () => { - const context = createWp( 'projects' ); - const toggle = flatten( renderPanel( context ) ).find( - ( node ) => node.type === 'ToggleControl', - ); - - toggle.props.onChange( 'yes' ); - expect( context.editPost ).toHaveBeenCalledWith( { - meta: { unrelated: 'keep', chrnx_project_featured: true }, - } ); - } ); - - test( 'updateMeta ignores a missing dispatcher', () => { - const { updateMeta } = require( modulePath ); - expect( () => updateMeta( undefined, {}, 'chrnx_project_featured', true ) ).not.toThrow(); - } ); -} ); diff --git a/tests/php/EditorAssetsTest.php b/tests/php/EditorAssetsTest.php index 2002ca3..b78be22 100644 --- a/tests/php/EditorAssetsTest.php +++ b/tests/php/EditorAssetsTest.php @@ -45,7 +45,7 @@ class EditorAssetsTest extends WP_UnitTestCase { * Clear only the CHRNX editor script state. */ private function reset_editor_scripts() { - foreach ( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-project', 'chrnx-editor-track' ) as $handle ) { + foreach ( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-track' ) as $handle ) { wp_dequeue_script( $handle ); wp_deregister_script( $handle ); } @@ -83,14 +83,13 @@ class EditorAssetsTest extends WP_UnitTestCase { ) ); - $this->assertSame( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-project', 'chrnx-editor-track' ), $handles ); + $this->assertSame( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-track' ), $handles ); $expected_dependencies = array( 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins' ); foreach ( array( 'chrnx-editor-taxonomies' => 'assets/js/editor-taxonomies.js', 'chrnx-editor-podcast' => 'assets/js/editor-podcast.js', - 'chrnx-editor-project' => 'assets/js/editor-project.js', ) as $handle => $asset ) { $this->assertArrayHasKey( $handle, $scripts->registered ); @@ -123,7 +122,6 @@ class EditorAssetsTest extends WP_UnitTestCase { do_action( 'enqueue_block_editor_assets' ); $this->assertFalse( wp_script_is( 'chrnx-editor-taxonomies', 'enqueued' ) ); $this->assertFalse( wp_script_is( 'chrnx-editor-podcast', 'enqueued' ) ); - $this->assertFalse( wp_script_is( 'chrnx-editor-project', 'enqueued' ) ); $this->assertFalse( wp_script_is( 'chrnx-editor-track', 'enqueued' ) ); } } diff --git a/tests/php/PatternsTest.php b/tests/php/PatternsTest.php index c6dc526..bcdc15f 100644 --- a/tests/php/PatternsTest.php +++ b/tests/php/PatternsTest.php @@ -206,7 +206,7 @@ class PatternsTest extends WP_UnitTestCase { $contracts = array( 'home-projects' => array( 'heading' => 'Selected work', - // The project names come from chrnx/selected-work now, not the pattern. + // The project names come from the project list query now, not the pattern. 'order' => array( 'Selected work' ), 'art' => 'alter-ego-code-768.webp', 'art_alt' => '',