A platform for community discussion. Free, open, simple.
UX: Update blog editor to match admin UI guidelines (#45233)
David Battersbya9ffbd78aa6e
diff --git a/plugins/blog/README.md b/plugins/blog/README.mdindex 77e4c3797d6..b393d7a4083 100644--- a/plugins/blog/README.md+++ b/plugins/blog/README.md@@ -9,7 +9,7 @@ a deferred, interactive Discourse discussion below each article.- Exactly one configured public Blog category; subcategories are not included.- Separate editorial-only drafts category and native Discourse composer autosave.- Editorial dashboard with server-side status filtering, title/path search, and- explicit 30-item Load more pagination.+ pages of 20 that load as you scroll.- An editor-only publication panel on the article's own topic: state, one-clickpublish or correction, an inline summary and diff of pending changes, inlinearticle settings, and scheduling, approval, and withdrawal behind a menu.@@ -445,16 +445,17 @@ style `.blog-post-summary` without reaching into cooked article content.## Finding articles in the editor-`/blog-editor` does not infinitely scroll or download the whole library. It fetches-up to 30 results and offers **Load more** only while another page exists.+`/blog-editor` does not download the whole library. It fetches 20 results at a+time and loads the next page as you scroll near the end of the list, while another+page exists.The All articles, Drafts, Published, and Not on the blog filters run on the serverbefore pagination. Not on the blog means discussions in the public publicationcategory which are not currently live articles; private drafts have their ownfilter. Search matches titles, slugs, and stored article paths case-insensitively,across the entire authorized editorial collection, not just downloaded entries.-Search and status remain active for Load more and Refresh; changing either starts-at the first page. Search input is bounded to 100 characters and SQL wildcards are+Search and status apply to every page that loads and are kept in the URL, so a+filtered view survives a reload; changing either starts at the first page. Search input is bounded to 100 characters and SQL wildcards areescaped. Ordering uses update time and ID, with duplicate rows suppressed whenappending pages if entries move between requests.diff --git a/plugins/blog/admin/assets/javascripts/discourse/components/modal/blog-theme-preview.gjs b/plugins/blog/admin/assets/javascripts/discourse/components/modal/blog-theme-preview.gjsindex bc9bc57cbb9..c270ffb41be 100644--- a/plugins/blog/admin/assets/javascripts/discourse/components/modal/blog-theme-preview.gjs+++ b/plugins/blog/admin/assets/javascripts/discourse/components/modal/blog-theme-preview.gjs@@ -39,15 +39,23 @@ const BlogThemePreview = <template>"blog.admin.template_not_found"}}</select.Option></DNativeSelect>- <DNativeSelect- aria-label={{i18n "blog.admin.sample_article"}}- @includeNone={{false}}- @onChange={{editor.selectPreviewArticle}}- @value={{editor.selectedArticle}}- as |select|- >{{#each editor.articleOptions as |article|}}<select.Option- @value={{article.id}}- >{{article.title}}</select.Option>{{/each}}</DNativeSelect>+ {{#if (eq editor.previewPage "article")}}+ <DNativeSelect+ aria-label={{i18n "blog.admin.sample_article"}}+ disabled={{not editor.articleOptions.length}}+ @includeNone={{not editor.articleOptions.length}}+ @nonePlaceholder={{i18n "blog.admin.no_published_articles"}}+ @onChange={{editor.selectPreviewArticle}}+ @value={{editor.selectedArticle}}+ as |select|+ >+ {{#each editor.articleOptions as |article|}}+ <select.Option @value={{article.id}}>+ {{article.title}}+ </select.Option>+ {{/each}}+ </DNativeSelect>+ {{/if}}<DNativeSelectaria-label={{i18n "blog.admin.preview_size"}}@includeNone={{false}}diff --git a/plugins/blog/app/controllers/blog/editor_controller.rb b/plugins/blog/app/controllers/blog/editor_controller.rbindex ce50ec3dc05..70809483def 100644--- a/plugins/blog/app/controllers/blog/editor_controller.rb+++ b/plugins/blog/app/controllers/blog/editor_controller.rb@@ -2,6 +2,8 @@module ::Blogclass EditorController < ::ApplicationController+ PAGE_SIZE = 20+helper Blog::BlogHelperrequires_plugin PLUGIN_NAMErequires_login except: [:index]@@ -22,7 +24,12 @@ module ::Blogquery: params[:q] || "",)@page = [params[:page].to_i, 0].max- selected = topics.offset(@page * 30).limit(31).includes(:first_post, :category).to_a+ selected =+ topics+ .offset(@page * PAGE_SIZE)+ .limit(PAGE_SIZE + 1)+ .includes(:first_post, :category)+ .to_apublications =Publication.where(topic_id: selected.map(&:id))@@ -40,10 +47,10 @@ module ::Blogrender json: {error: Configuration.error,blog_url: Configuration.base_url,- more: selected.size > 30,+ more: selected.size > PAGE_SIZE,topics:selected- .first(30)+ .first(PAGE_SIZE).map { |topic|entry(topic,diff --git a/plugins/blog/assets/javascripts/discourse/components/blog-admin-plugin-actions.gjs b/plugins/blog/assets/javascripts/discourse/components/blog-admin-plugin-actions.gjsnew file mode 100644index 00000000000..168afa36602--- /dev/null+++ b/plugins/blog/assets/javascripts/discourse/components/blog-admin-plugin-actions.gjs@@ -0,0 +1,7 @@+export default <template>+ <@actions.Primary+ ...attributes+ @label="blog.admin.go_to_editor"+ @route="blog-editor"+ />+</template>diff --git a/plugins/blog/assets/javascripts/discourse/components/blog-dashboard.gjs b/plugins/blog/assets/javascripts/discourse/components/blog-dashboard.gjsindex 66ef0221b96..5b968b20c5a 100644--- a/plugins/blog/assets/javascripts/discourse/components/blog-dashboard.gjs+++ b/plugins/blog/assets/javascripts/discourse/components/blog-dashboard.gjs@@ -3,34 +3,65 @@ import { tracked } from "@glimmer/tracking";import { fn } from "@ember/helper";import { action } from "@ember/object";import { service } from "@ember/service";-import Form from "discourse/components/form";+import DMenu from "discourse/float-kit/components/d-menu";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";-import DiscourseURL from "discourse/lib/url";+import discourseDebounce from "discourse/lib/debounce";+import { INPUT_DELAY } from "discourse/lib/environment";+import DiscourseURL, { searchParamsFromPath } from "discourse/lib/url";import Category from "discourse/models/category";import DButton from "discourse/ui-kit/d-button";+import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner";+import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";import DEmptyState from "discourse/ui-kit/d-empty-state";+import DFilterControls from "discourse/ui-kit/d-filter-controls";import DFlashMessage from "discourse/ui-kit/d-flash-message";+import DLoadMore from "discourse/ui-kit/d-load-more";import DPageHeader from "discourse/ui-kit/d-page-header";+import dAgeWithTooltip from "discourse/ui-kit/helpers/d-age-with-tooltip";+import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";import { i18n } from "discourse-i18n";+import {+ editorFilters,+ STATUS_OPTIONS,+} from "discourse/plugins/blog/discourse/lib/blog-editor-filters";export default class BlogDashboard extends Component {@service composer;@service currentUser;+ @service router;@service siteSettings;- @tracked filter = "all";+ @tracked filter;@tracked loading = false;+ @tracked loadingMore = false;@tracked page = 0;- @tracked query = "";+ @tracked query;+ // Lets a newer filter change discard responses to older ones.+ #requestId = 0;+@tracked _data;+ constructor() {+ super(...arguments);+ const { filter, q } = editorFilters(+ Object.fromEntries(searchParamsFromPath(this.router.currentURL))+ );+ this.filter = filter;+ this.query = q;+ }+get data() {return this._data || this.args.model;}- get searchData() {- return { q: this.query };+ get showEmptyState() {+ return (+ !this.topics.length &&+ !this.loading &&+ this.filter === "all" &&+ !this.query+ );}get topics() {@@ -44,59 +75,38 @@ export default class BlogDashboard extends Component {}@action- async setFilter(filter) {- if (this.loading) {- return;- }- const previousFilter = this.filter;- this.filter = filter;- if (!(await this.refresh())) {- this.filter = previousFilter;- }+ onQueryChange(event) {+ this.query = editorFilters({ q: event.target.value }).q;+ discourseDebounce(this, this.#load, INPUT_DELAY);}@action- async search(data) {- if (this.loading) {- return;- }- const previousQuery = this.query;- this.query = data.q?.trim() || "";- if (!(await this.refresh())) {- this.query = previousQuery;- }+ onStatusFilterChange(filter) {+ this.filter = filter;+ this.#load();}@action- async refresh() {- if (this.loading) {- return;- }- this.loading = true;- try {- this._data = await ajax("/blog-editor.json", {- data: { filter: this.filter, q: this.query },- });- this.page = 0;- return true;- } catch (error) {- popupAjaxError(error);- return false;- } finally {- this.loading = false;- }+ async onResetFilters() {+ this.filter = "all";+ this.query = "";+ await this.#load();}@actionasync loadMore() {- if (this.loading) {+ if (this.loading || this.loadingMore || !this.data.more) {return;}- this.loading = true;+ const requestId = this.#requestId;+ this.loadingMore = true;try {const data = await ajax("/blog-editor.json", {data: { page: this.page + 1, filter: this.filter, q: this.query },});+ if (requestId !== this.#requestId) {+ return;+ }this.page += 1;this._data = {...data,@@ -110,9 +120,11 @@ export default class BlogDashboard extends Component {],};} catch (error) {- popupAjaxError(error);+ if (requestId === this.#requestId) {+ popupAjaxError(error);+ }} finally {- this.loading = false;+ this.loadingMore = false;}}@@ -129,175 +141,302 @@ export default class BlogDashboard extends Component {}}+ async #load() {+ const requestId = ++this.#requestId;+ this.loading = true;+ try {+ const data = await ajax("/blog-editor.json", {+ data: { filter: this.filter, q: this.query },+ });+ if (requestId === this.#requestId) {+ this._data = data;+ this.page = 0;+ }+ } catch (error) {+ if (requestId === this.#requestId) {+ popupAjaxError(error);+ }+ } finally {+ if (requestId === this.#requestId) {+ this.loading = false;+ }+ }+ }+<template><div class="blog-dashboard" ...attributes><DPageHeader@collapseActionsOnMobile={{false}}@descriptionLabel={{i18n "blog.editor_description"}}+ @hideTabs={{true}}@titleLabel={{i18n "blog.editor_title"}}>- <:actions>- <DButton- class="btn-primary"+ <:actions as |actions|>+ <actions.Primary@action={{this.newDraft}}@disabled={{this.data.error}}@icon="pen-to-square"@label="blog.new_draft"/>+ <actions.Wrapped>+ <DMenu+ @icon="ellipsis-vertical"+ @identifier="blog-dashboard-page-actions"+ @placement="bottom-end"+ @title={{i18n "blog.editor_table.more_actions"}}+ @triggerClass="btn-default btn-small blog-dashboard__page-actions"+ >+ <:content>+ <DDropdownMenu as |dropdown|>+ <dropdown.item>+ <DButton+ class="btn-transparent blog-dashboard__visit-blog"+ rel="noopener noreferrer"+ target="_blank"+ @href={{this.data.blog_url}}+ @icon="up-right-from-square"+ @label="blog.visit_blog"+ />+ </dropdown.item>+ {{#if this.currentUser.admin}}+ <dropdown.item>+ <DButton+ class="btn-transparent blog-dashboard__appearance"+ @icon="palette"+ @label="blog.appearance_link"+ @route="adminPlugins.show.discourse-blog-themes"+ @routeModels="blog"+ />+ </dropdown.item>+ {{/if}}+ </DDropdownMenu>+ </:content>+ </DMenu>+ </actions.Wrapped></:actions></DPageHeader>{{#if this.data.error}}<DFlashMessage @flash={{this.data.error}} @type="warning" />- <a href="/admin/site_settings/category/plugins?filter=blog_">{{i18n+ <a href="/admin/plugins/blog/settings?filter=category">{{i18n"blog.settings"}}</a>{{/if}}- <div class="blog-dashboard__toolbar">- <div class="blog-dashboard__filters">- <DButton- class="btn-default"- @action={{fn this.setFilter "all"}}- @ariaPressed={{eq this.filter "all"}}- @disabled={{this.loading}}- @label="blog.all"- />- <DButton- class="btn-default"- @action={{fn this.setFilter "drafts"}}- @ariaPressed={{eq this.filter "drafts"}}- @disabled={{this.loading}}- @label="blog.drafts"- />- <DButton- class="btn-default"- @action={{fn this.setFilter "published"}}- @ariaPressed={{eq this.filter "published"}}- @disabled={{this.loading}}- @label="blog.published"- />- <DButton- class="btn-default"- @action={{fn this.setFilter "unpublished"}}- @ariaPressed={{eq this.filter "unpublished"}}- @disabled={{this.loading}}- @label="blog.not_published"- />- </div>- <div class="blog-dashboard__links">- {{#if this.currentUser.admin}}<a- href="/admin/plugins/blog/themes"- >{{i18n "blog.appearance_link"}}</a>{{/if}}- <a- href={{this.data.blog_url}}- rel="noopener noreferrer"- target="_blank"- >{{i18n "blog.visit_blog"}} ↗</a>- <DButton- class="btn-flat"- @action={{this.refresh}}- @disabled={{this.loading}}- @icon="arrows-rotate"- @title="blog.refresh"- />- </div>- </div>- <Form- class="blog-dashboard__search"- @data={{this.searchData}}- @onSubmit={{this.search}}- as |form|+ <DFilterControls+ @array={{this.topics}}+ @dropdownFilterQueryParam="status"+ @dropdownOptions={{STATUS_OPTIONS}}+ @dropdownValue={{this.filter}}+ @initialTextFilter={{this.query}}+ @inputPlaceholder={{i18n "blog.editor_search_hint"}}+ @loading={{this.loading}}+ @noResultsMessage={{i18n "blog.editor_no_results"}}+ @onDropdownFilterChange={{this.onStatusFilterChange}}+ @onResetFilters={{this.onResetFilters}}+ @onTextFilterChange={{this.onQueryChange}}+ @textFilterQueryParam="q">- <form.Field- @format="full"- @name="q"- @showOptional={{false}}- @title={{i18n "blog.editor_search"}}- @type="input"- as |field|- >- <field.Control- maxlength="100"- placeholder={{i18n "blog.editor_search_hint"}}- @type="search"- />- </form.Field>- <form.Actions>- <form.Submit- @disabled={{this.loading}}- @label="blog.search_articles"- />- </form.Actions>- </Form>- <p class="blog-dashboard__hint">{{i18n "blog.editor_pagination_hint"}}</p>- <p class="blog-dashboard__hint">{{i18n "blog.drafts_hint"}}</p>- {{#each this.topics as |topic|}}- <article class="blog-dashboard__entry" data-topic-id={{topic.id}}>- <div class="blog-dashboard__entry-content">- <div class="blog-dashboard__statuses">- <span class="blog-dashboard__status">{{#if topic.draft}}{{i18n- "blog.private_draft"- }}{{else if topic.live}}{{i18n- "blog.published"- }}{{else}}{{i18n "blog.not_published"}}{{/if}}</span>- {{#if topic.draft_correction}}<span- class="blog-dashboard__correction"- >{{i18n "blog.draft_correction"}}</span>{{/if}}- </div>- {{#if topic.live}}- <h2><a href={{topic.url}}>{{or- topic.public_title- topic.title- }}</a></h2>- {{#if topic.public_excerpt}}<p>{{topic.public_excerpt}}</p>{{/if}}- <span class="blog-dashboard__path">{{or- topic.public_path- topic.path- }}</span>- {{else}}- <h2><a href={{topic.topic_url}}>{{topic.title}}</a></h2>- {{#if topic.excerpt}}<p>{{topic.excerpt}}</p>{{/if}}- <span class="blog-dashboard__path">{{topic.path}}</span>- {{/if}}- </div>- <div class="blog-dashboard__entry-actions">- {{#if topic.live}}- <a href={{topic.discussion_url}}>{{i18n- "blog.public_discussion"- }}</a>- {{else}}- <a- href={{topic.preview_url}}- rel="noopener noreferrer"- target="_blank"- >{{i18n "blog.preview"}}</a>- {{/if}}- {{#if topic.source_url}}- <a- class="btn btn-default blog-dashboard__edit-private"- href={{topic.source_url}}- >{{i18n "blog.open_draft"}}</a>- {{else}}- <DButton- class="blog-dashboard__edit-private btn-default"- @action={{fn this.editPrivately topic}}- @label="blog.edit_privately"- />- {{/if}}- </div>- </article>- {{else}}+ <:content>+ <DLoadMore+ class="blog-dashboard__load-more"+ @action={{this.loadMore}}+ @enabled={{this.data.more}}+ @isLoading={{this.loadingMore}}+ @rootMargin="0px 0px 250px 0px"+ >+ <table class="d-table blog-dashboard__table">+ <thead class="d-table__header">+ <tr class="d-table__row">+ <th class="d-table__header-cell">{{i18n+ "blog.editor_table.article"+ }}</th>+ <th class="d-table__header-cell">{{i18n+ "blog.editor_table.status"+ }}</th>+ <th class="d-table__header-cell">{{i18n+ "blog.editor_table.published"+ }}</th>+ <th class="d-table__header-cell">{{i18n+ "blog.editor_table.replies"+ }}</th>+ <th class="d-table__header-cell"></th>+ </tr>+ </thead>+ <tbody class="d-table__body">+ {{#each this.topics as |topic|}}+ <tr+ class="d-table__row blog-dashboard__row"+ data-topic-id={{topic.id}}+ >+ <td class="d-table__cell --overview">+ {{#if topic.live}}+ <a+ class="d-table__overview-link"+ href={{or topic.discussion_url topic.url}}+ >+ <div class="d-table__overview-name">{{or+ topic.public_title+ topic.title+ }}</div>+ </a>+ {{#if topic.public_excerpt}}+ <p+ class="blog-dashboard__excerpt"+ >{{topic.public_excerpt}}</p>+ {{/if}}+ {{else}}+ <a+ class="d-table__overview-link"+ href={{topic.topic_url}}+ >+ <div+ class="d-table__overview-name"+ >{{topic.title}}</div>+ </a>+ {{#if topic.excerpt}}+ <p+ class="blog-dashboard__excerpt"+ >{{topic.excerpt}}</p>+ {{/if}}+ {{/if}}+ </td>+ <td class="d-table__cell --detail">+ <div class="d-table__mobile-label">{{i18n+ "blog.editor_table.status"+ }}</div>+ <div class="blog-dashboard__statuses">+ <div+ class={{dConcatClass+ "status-label"+ "blog-dashboard__status"+ (if topic.live "--success")+ (unless (or topic.live topic.draft) "--inactive")+ }}+ >+ <div class="status-label-indicator"></div>+ <div class="status-label-text">{{#if+ topic.draft+ }}{{i18n "blog.private_draft"}}{{else if+ topic.live+ }}{{i18n "blog.published"}}{{else}}{{i18n+ "blog.not_published"+ }}{{/if}}</div>+ </div>+ {{#if topic.scheduled_at}}+ <span class="blog-dashboard__scheduled">{{i18n+ "blog.editor_table.scheduled"+ }}</span>+ {{/if}}+ {{#if topic.draft_correction}}+ <span class="blog-dashboard__correction">{{i18n+ "blog.draft_correction"+ }}</span>+ {{/if}}+ </div>+ </td>+ <td+ class="d-table__cell --detail blog-dashboard__published"+ >+ <div class="d-table__mobile-label">{{i18n+ "blog.editor_table.published"+ }}</div>+ {{#if topic.published}}+ {{dAgeWithTooltip topic.published_at format="medium"}}+ {{else}}+ —+ {{/if}}+ </td>+ <td class="d-table__cell --detail blog-dashboard__replies">+ <div class="d-table__mobile-label">{{i18n+ "blog.editor_table.replies"+ }}</div>+ {{#if+ topic.discussion_url+ }}{{topic.replies}}{{else}}—{{/if}}+ </td>+ <td class="d-table__cell --controls">+ <div class="d-table__cell-actions">+ {{#if topic.source_url}}+ <DButton+ class="btn-default btn-small blog-dashboard__edit-private"+ @href={{topic.source_url}}+ @label="blog.editor_table.edit"+ />+ {{else}}+ <DButton+ class="btn-default btn-small blog-dashboard__edit-private"+ @action={{fn this.editPrivately topic}}+ @label="blog.editor_table.edit"+ />+ {{/if}}+ <DMenu+ @icon="ellipsis-vertical"+ @identifier="blog-dashboard-actions"+ @title={{i18n "blog.editor_table.more_actions"}}+ @triggerClass="btn-default btn-small blog-dashboard__more-actions"+ >+ <:content>+ <DDropdownMenu as |dropdown|>+ {{#if+ (or topic.draft_correction (not topic.live))+ }}+ <dropdown.item>+ <DButton+ class="btn-transparent blog-dashboard__preview"+ rel="noopener noreferrer"+ target="_blank"+ @href={{topic.preview_url}}+ @icon="far-eye"+ @label={{if+ topic.live+ "blog.editor_table.preview_changes"+ "blog.preview"+ }}+ />+ </dropdown.item>+ {{/if}}+ {{#if topic.live}}+ <dropdown.item>+ <DButton+ class="btn-transparent blog-dashboard__view-live"+ rel="noopener noreferrer"+ target="_blank"+ @href={{topic.url}}+ @icon="up-right-from-square"+ @label="blog.editor_table.view_on_blog"+ />+ </dropdown.item>+ {{/if}}+ {{#if+ (and topic.discussion_url (not topic.live))+ }}+ <dropdown.item>+ <DButton+ class="btn-transparent blog-dashboard__discussion"+ @href={{topic.discussion_url}}+ @icon="comments"+ @label="blog.public_discussion"+ />+ </dropdown.item>+ {{/if}}+ </DDropdownMenu>+ </:content>+ </DMenu>+ </div>+ </td>+ </tr>+ {{/each}}+ </tbody>+ </table>+ </DLoadMore>+ <DConditionalLoadingSpinner @condition={{this.loadingMore}} />+ </:content>+ </DFilterControls>+ {{#if this.showEmptyState}}<DEmptyState@body={{i18n "blog.editor_no_results_hint"}}@title={{i18n "blog.editor_no_results"}}/>- {{/each}}- {{#if this.data.more}}<DButton- class="btn-default"- data-blog-load-more- @action={{this.loadMore}}- @disabled={{this.loading}}- @label="blog.load_more"- />{{/if}}+ {{/if}}</div></template>}diff --git a/plugins/blog/assets/javascripts/discourse/components/blog-publication-panel.gjs b/plugins/blog/assets/javascripts/discourse/components/blog-publication-panel.gjsindex dc8e2bb275b..58778d5a600 100644--- a/plugins/blog/assets/javascripts/discourse/components/blog-publication-panel.gjs+++ b/plugins/blog/assets/javascripts/discourse/components/blog-publication-panel.gjs@@ -592,7 +592,7 @@ export default class BlogPublicationPanel extends Component {>{{i18n "blog.panel.preview"}}</a>{{#if this.publication.source_topic_id}}<DButton- class="btn-default blog-publication-panel__reviews"+ class="btn-default blog-publication-panel__share-for-review"@action={{this.shareForReview}}@disabled={{this.busy}}@label="blog.panel.share_for_review"diff --git a/plugins/blog/assets/javascripts/discourse/initializers/admin-blog-navigation.js b/plugins/blog/assets/javascripts/discourse/initializers/admin-blog-navigation.jsindex 6ef08a44436..b2ee85b18be 100644--- a/plugins/blog/assets/javascripts/discourse/initializers/admin-blog-navigation.js+++ b/plugins/blog/assets/javascripts/discourse/initializers/admin-blog-navigation.js@@ -1,4 +1,5 @@import { withPluginApi } from "discourse/lib/plugin-api";+import BlogAdminPluginActions from "../components/blog-admin-plugin-actions.gjs";export default {name: "discourse-blog-admin-navigation",@@ -9,6 +10,7 @@ export default {}withPluginApi((api) => {api.setAdminPluginIcon("blog", "pen-to-square");+ api.registerPluginHeaderActionComponent("blog", BlogAdminPluginActions);api.addAdminPluginConfigurationNav("blog", [{label: "blog.admin.themes",diff --git a/plugins/blog/assets/javascripts/discourse/lib/blog-editor-filters.js b/plugins/blog/assets/javascripts/discourse/lib/blog-editor-filters.jsnew file mode 100644index 00000000000..f7a2613de30--- /dev/null+++ b/plugins/blog/assets/javascripts/discourse/lib/blog-editor-filters.js@@ -0,0 +1,20 @@+import { i18n } from "discourse-i18n";++export const STATUS_OPTIONS = [+ { value: "all", label: i18n("blog.all") },+ { value: "drafts", label: i18n("blog.drafts") },+ { value: "published", label: i18n("blog.published") },+ { value: "unpublished", label: i18n("blog.not_published") },+];++// The server rejects longer queries.+const MAX_QUERY_LENGTH = 100;++export function editorFilters({ status, q } = {}) {+ return {+ filter: STATUS_OPTIONS.some((option) => option.value === status)+ ? status+ : "all",+ q: (q || "").trim().slice(0, MAX_QUERY_LENGTH),+ };+}diff --git a/plugins/blog/assets/javascripts/discourse/routes/blog-editor.js b/plugins/blog/assets/javascripts/discourse/routes/blog-editor.jsindex 9b93ace7494..9a160e79a59 100644--- a/plugins/blog/assets/javascripts/discourse/routes/blog-editor.js+++ b/plugins/blog/assets/javascripts/discourse/routes/blog-editor.js@@ -1,6 +1,7 @@import { service } from "@ember/service";import { ajax } from "discourse/lib/ajax";import DiscourseRoute from "discourse/routes/discourse";+import { editorFilters } from "discourse/plugins/blog/discourse/lib/blog-editor-filters";export default class BlogEditorRoute extends DiscourseRoute {@service currentUser;@@ -16,9 +17,11 @@ export default class BlogEditorRoute extends DiscourseRoute {}}- model() {+ model(params, transition) {if (this.currentUser?.can_blog_edit ?? this.currentUser?.staff) {- return ajax("/blog-editor.json");+ return ajax("/blog-editor.json", {+ data: editorFilters(transition.to.queryParams),+ });}}}diff --git a/plugins/blog/assets/stylesheets/blog-editor.scss b/plugins/blog/assets/stylesheets/blog-editor.scssindex 136ad1b046f..feacdec2e43 100644--- a/plugins/blog/assets/stylesheets/blog-editor.scss+++ b/plugins/blog/assets/stylesheets/blog-editor.scss@@ -4,57 +4,39 @@margin-inline: auto;padding-block: 2em;- &__toolbar,- &__filters,- &__links,- &__entry-actions,- &__statuses {- display: flex;- align-items: center;- gap: 0.75em;- flex-wrap: wrap;+ // An icon-only trigger is shorter than a labelled button, so size the+ // header actions to their tallest button and stretch the rest to match.+ .d-page-header__actions {+ align-self: center;+ align-items: stretch;}- &__toolbar {- justify-content: space-between;- margin-block: 2em 1em;- }-- &__filters .btn[aria-pressed="true"] {- color: var(--tertiary);- background: var(--tertiary-low);+ .d-page-action-wrapped-button {+ display: flex;}- &__correction,- &__hint,- &__path {- color: var(--primary-high);- font-size: var(--font-down-1);+ .d-filter-controls {+ margin-block: var(--space-4);}- &__entry {+ &__statuses {display: flex;- justify-content: space-between;- align-items: center;- gap: 1.5em;flex-wrap: wrap;- padding-block: 1.5em;- border-bottom: 1px solid var(--primary-low);+ align-items: center;+ gap: 0.25em 0.75em;}- &__entry-content {- min-width: 0;- flex: 1 1 300px;-- h2 {- margin-block: 0.5em;- font-size: var(--font-up-2);- }+ &__correction,+ &__excerpt,+ &__published,+ &__replies,+ &__scheduled {+ color: var(--primary-high);+ font-size: var(--font-down-1);}- &__status {- color: var(--tertiary);- font-size: var(--font-down-1);- font-weight: 600;+ &__excerpt {+ @include line-clamp(2);+ margin-block: 0.25em 0;}}diff --git a/plugins/blog/config/locales/client.en.yml b/plugins/blog/config/locales/client.en.ymlindex ab412937f5f..ffabff19b9d 100644--- a/plugins/blog/config/locales/client.en.yml+++ b/plugins/blog/config/locales/client.en.yml@@ -18,6 +18,7 @@ en:blog:admin:title: Blog+ go_to_editor: Go to editoropen_blog: Open blogsafe_mode: Open without custom codeidentity: Blog identity@@ -40,6 +41,7 @@ en:no_variables: No variables match that search.insert: Insertsample_article: Sample published article+ no_published_articles: No published articlesarray_value: Listtrusted_html: Trusted HTMLescaped_text: Escaped value@@ -255,29 +257,29 @@ en:read: Read the articleexpand: Expand article herecollapse: Collapse article- editor_pagination_hint: Search and status filters apply to all articles. Load more adds up to 30 results.- editor_search: Search articleseditor_search_hint: Search by title or article path- search_articles: Searcheditor_no_results: No matching articleseditor_no_results_hint: Try another search or status filter, or start a new draft.editor_title: Blog editor- editor_description:- Draft in private. Publish with intention. Keep the conversation- going.+ editor_description: Drafts stay private until you publish them. Edit an article to publish, schedule, or correct it.+ editor_table:+ article: Article+ edit: Edit+ status: Status+ published: Published+ replies: Replies+ scheduled: Scheduled+ more_actions: More actions+ preview_changes: Preview changes+ view_on_blog: View on blognew_draft: New draftsettings: Configure blog settingsall: All articlesdrafts: Draftspublished: Publishedvisit_blog: Visit blog- refresh: Refresh articles- drafts_hint:- Published titles open the live blog article. Open a draft to publish, schedule, or correct it from its topic. Editorial working copies remain private after publication; public discussions stay in the Blog category.private_draft: Draftdraft_correction: Draft correction- edit_privately: Edit privately- open_draft: Open draftpublic_discussion: Public discussionnot_published: Not on the blogpreview: Previewdiff --git a/plugins/blog/spec/requests/editor_filtering_spec.rb b/plugins/blog/spec/requests/editor_filtering_spec.rbindex ac81272c879..b1eb6920b2f 100644--- a/plugins/blog/spec/requests/editor_filtering_spec.rb+++ b/plugins/blog/spec/requests/editor_filtering_spec.rb@@ -26,7 +26,7 @@ RSpec.describe "Blog editor filtering", type: :request doit "filters the entire collection before applying the page limit" dopublished_topic.update_column(:updated_at, 3.days.ago)- Fabricate.times(31, :topic, category: drafts)+ Fabricate.times(Blog::EditorController::PAGE_SIZE + 1, :topic, category: drafts)get "/blog-editor.json", params: { filter: "published" }@@ -37,7 +37,9 @@ RSpec.describe "Blog editor filtering", type: :request doit "paginates search results in a stable order within the selected status" domatching =- 31.times.map { |index| Fabricate(:topic, category: drafts, title: "Needle article #{index}") }+ (Blog::EditorController::PAGE_SIZE + 1).times.map do |index|+ Fabricate(:topic, category: drafts, title: "Needle article #{index}")+ endTopic.where(id: matching.map(&:id)).update_all(updated_at: 1.day.ago)Fabricate(:topic, category: drafts, title: "Unrelated newer draft")Fabricate(:topic, title: "Needle outside editorial categories")@@ -45,7 +47,7 @@ RSpec.describe "Blog editor filtering", type: :request doget "/blog-editor.json", params: { filter: "drafts", q: "NEEDLE" }expect(response.status).to eq(200)expect(response.parsed_body["topics"].map { |entry| entry["id"] }).to eq(- matching.reverse.first(30).map(&:id),+ matching.reverse.first(Blog::EditorController::PAGE_SIZE).map(&:id),)expect(response.parsed_body["more"]).to eq(true)diff --git a/plugins/blog/test/javascripts/acceptance/blog-editor-test.js b/plugins/blog/test/javascripts/acceptance/blog-editor-test.jsindex c9a54cc2a79..c0c56a3479a 100644--- a/plugins/blog/test/javascripts/acceptance/blog-editor-test.js+++ b/plugins/blog/test/javascripts/acceptance/blog-editor-test.js@@ -1,8 +1,19 @@-import { click, currentURL, visit } from "@ember/test-helpers";+import {+ click,+ currentURL,+ fillIn,+ select,+ visit,+ waitUntil,+} from "@ember/test-helpers";import { test } from "qunit";import pretender, { response } from "discourse/tests/helpers/create-pretender";-import formKit from "discourse/tests/helpers/form-kit-helper";import { acceptance } from "discourse/tests/helpers/qunit-helpers";+import stubIntersectionObserver from "discourse/tests/helpers/stub-intersection-observer";+import {+ disableLoadMoreObserver,+ enableLoadMoreObserver,+} from "discourse/ui-kit/d-load-more";acceptance("Blog editor", function (needs) {needs.user({ admin: true, moderator: false });@@ -61,22 +72,35 @@ acceptance("Blog editor", function (needs) {test("filters private drafts and published articles", async function (assert) {await visit("/blog-editor");assert- .dom(".blog-dashboard__entry")+ .dom(".blog-dashboard__row").exists({ count: 2 }, "both editorial states are listed");- await click(".blog-dashboard__filters button:nth-child(2)");+ await select(".d-filter-controls__dropdown", "drafts");assert.dom('[data-topic-id="123"]').exists("private drafts are shown");assert.dom('[data-topic-id="124"]').doesNotExist("published articles are filtered out");- await click(".blog-dashboard__filters button:nth-child(3)");+ await select(".d-filter-controls__dropdown", "published");assert.dom('[data-topic-id="124"]').exists("published articles are shown");assert.dom('[data-topic-id="123"]').doesNotExist("private drafts are filtered out");- await click(".blog-dashboard__filters button:nth-child(4)");+ await select(".d-filter-controls__dropdown", "unpublished");assert- .dom(".blog-dashboard__entry")+ .dom(".blog-dashboard__row").doesNotExist("unpublished filtering can return an empty result");+ assert+ .dom(".d-filter-controls__no-results")+ .includesText(+ "No matching articles",+ "filtered lists explain the result"+ );+ assert+ .dom(".empty-state")+ .doesNotExist("the no-articles state is only for an empty blog");+ await click(".d-filter-controls__no-results .btn");+ assert+ .dom(".blog-dashboard__row")+ .exists({ count: 2 }, "resetting the filters lists everything again");});test("separates published articles from private correction work", async function (assert) {@@ -93,17 +117,17 @@ acceptance("Blog editor", function (needs) {};await visit("/blog-editor");assert- .dom('[data-topic-id="124"] h2 a')+ .dom('[data-topic-id="124"] .d-table__overview-link').hasText("The live article title","published entries use the live title rather than the working copy");assert- .dom('[data-topic-id="124"] h2 a')+ .dom('[data-topic-id="124"] .d-table__overview-link').hasAttribute("href",- published.url,- "the main link opens the actual blog article"+ "/t/live-article/200",+ "the main link opens the public discussion");assert.dom('[data-topic-id="124"] .blog-dashboard__edit-private')@@ -113,11 +137,25 @@ acceptance("Blog editor", function (needs) {"the working copy is where publishing happens");assert- .dom('[data-topic-id="124"] a[href="/t/live-article/200"]')+ .dom('[data-topic-id="124"] .blog-dashboard__edit-private')+ .hasText("Edit", "live articles are edited through their working copy");+ assert+ .dom('[data-topic-id="123"] .blog-dashboard__edit-private')+ .hasText("Edit", "drafts use the same edit action");+ await click('[data-topic-id="124"] .blog-dashboard__more-actions');+ assert+ .dom(".blog-dashboard__discussion")+ .doesNotExist("the title already opens the public discussion");+ assert+ .dom(".blog-dashboard__view-live")+ .hasAttribute("href", published.url, "live articles link to the blog");+ assert+ .dom(".blog-dashboard__preview").hasText(- "Public discussion",- "the public forum topic is separately accessible"+ "Preview changes",+ "live articles with a correction preview the working copy");+ await click('[data-topic-id="124"] .blog-dashboard__more-actions');assert.dom('[data-topic-id="124"] .blog-dashboard__status').hasText(@@ -130,11 +168,79 @@ acceptance("Blog editor", function (needs) {assert.dom('[data-topic-id="123"] .blog-dashboard__status').hasText("Draft", "never-published articles are drafts");+ assert+ .dom('[data-topic-id="124"] .blog-dashboard__status')+ .hasClass("--success", "live articles use the success status style");+ assert+ .dom('[data-topic-id="123"] .blog-dashboard__status')+ .doesNotHaveClass("--success", "drafts use the neutral status style");assert.dom('[data-topic-id="123"] .blog-dashboard__correction').doesNotExist("new drafts are not corrections");});+ test("lists status, publication date, replies, and row actions", async function (assert) {+ published = {+ ...published,+ discussion_url: "/t/live-article/200",+ scheduled_at: "2026-10-01T10:00:00.000Z",+ };+ await visit("/blog-editor");+ assert+ .dom('[data-topic-id="124"] .blog-dashboard__scheduled')+ .hasText("Scheduled", "scheduled releases are identified");+ assert+ .dom('[data-topic-id="124"] .blog-dashboard__published .relative-date')+ .exists("published articles show when they went live");+ assert+ .dom('[data-topic-id="123"] .blog-dashboard__published .relative-date')+ .doesNotExist("drafts have no publication date");+ assert+ .dom('[data-topic-id="124"] .blog-dashboard__replies')+ .includesText("2", "published articles show their reply count");+ assert+ .dom('[data-topic-id="123"] .blog-dashboard__published')+ .includesText("—", "drafts show a placeholder for the publication date");+ assert+ .dom('[data-topic-id="123"] .blog-dashboard__replies')+ .includesText("—", "drafts without a discussion show a placeholder");++ await click('[data-topic-id="123"] .blog-dashboard__more-actions');+ assert+ .dom(".blog-dashboard__preview")+ .hasAttribute("href", draft.preview_url, "drafts can be previewed");+ assert+ .dom(".blog-dashboard__view-live")+ .doesNotExist("drafts have no live article to open");++ await click('[data-topic-id="123"] .blog-dashboard__more-actions');+ await click('[data-topic-id="124"] .blog-dashboard__more-actions');+ assert+ .dom(".blog-dashboard__preview")+ .doesNotExist("live articles without changes have nothing to preview");+ assert+ .dom(".blog-dashboard__view-live")+ .exists("live articles can be opened on the blog");+ });++ test("keeps the discussion reachable for unpublished articles", async function (assert) {+ draft = {+ ...draft,+ draft: false,+ published: false,+ discussion_url: "/t/withdrawn-story/300",+ };+ await visit("/blog-editor");+ await click('[data-topic-id="123"] .blog-dashboard__more-actions');+ assert+ .dom(".blog-dashboard__discussion")+ .hasAttribute(+ "href",+ "/t/withdrawn-story/300",+ "withdrawn articles still link to their public discussion"+ );+ });+test("creates a private working copy for articles without one", async function (assert) {published = { ...published, source_url: null, source_topic_id: null };pretender.post("/blog-editor/publications/124/prepare.json", () => {@@ -145,6 +251,9 @@ acceptance("Blog editor", function (needs) {});});await visit("/blog-editor");+ assert+ .dom('[data-topic-id="124"] .blog-dashboard__edit-private')+ .hasText("Edit", "creating a working copy uses the same edit action");await click('[data-topic-id="124"] .blog-dashboard__edit-private');assert.verifySteps(["prepare"], "a working copy is created on demand");assert.strictEqual(@@ -154,34 +263,63 @@ acceptance("Blog editor", function (needs) {);});- test("marks exactly one article filter as selected", async function (assert) {+ test("offers page actions in the header", async function (assert) {await visit("/blog-editor");- const filters = ".blog-dashboard__filters";- assert- .dom(`${filters} button[aria-pressed="true"]`)- .hasText("All articles", "all articles is selected initially");-- for (const [index, label] of [- "Drafts",- "Published",- "Not on the blog",- "All articles",- ].entries()) {- const position = index === 3 ? 1 : index + 2;- await click(`${filters} button:nth-child(${position})`);- assert- .dom(`${filters} button[aria-pressed="true"]`)- .exists({ count: 1 }, "exactly one filter is selected");- assert- .dom(`${filters} button[aria-pressed="true"]`)- .hasText(label, "the clicked filter stays selected");- assert- .dom(`${filters} button[aria-pressed="false"]`)- .exists({ count: 3 }, "the other filters are explicitly unselected");- }+ assert+ .dom(".d-page-header__actions .btn-primary")+ .hasText("New draft", "starting a draft is the primary action");+ await click(".blog-dashboard__page-actions");+ assert+ .dom(".blog-dashboard__visit-blog")+ .hasAttribute("href", "https://blog.example.com", "the blog is linked");+ assert+ .dom(".blog-dashboard__appearance")+ .exists("admins can reach the blog appearance settings");+ });++ test("keeps filters in the URL and restores them on reload", async function (assert) {+ const requests = [];+ pretender.get("/blog-editor.json", (request) => {+ requests.push({ ...request.queryParams });+ return response({ topics: [draft] });+ });+ await visit("/blog-editor?status=published&q=story");+ assert.deepEqual(+ requests[0],+ { filter: "published", q: "story" },+ "the first request uses the filters from the URL"+ );+ assert+ .dom(".d-filter-controls__dropdown")+ .hasValue("published", "the status filter is restored");+ assert+ .dom(".d-filter-controls__input")+ .hasValue("story", "the search is restored");++ await select(".d-filter-controls__dropdown", "drafts");+ assert.strictEqual(+ currentURL(),+ "/blog-editor?status=drafts&q=story",+ "changing the status updates the URL"+ );+ });++ test("ignores an unknown status in the URL", async function (assert) {+ const requests = [];+ pretender.get("/blog-editor.json", (request) => {+ requests.push({ ...request.queryParams });+ return response({ topics: [draft] });+ });+ await visit("/blog-editor?status=banana");+ assert.strictEqual(+ requests[0].filter,+ "all",+ "an unknown status falls back to all articles"+ );+ assert.dom(".d-filter-controls__dropdown").hasValue("all");});- test("searches the server and preserves filters through load more and refresh", async function (assert) {+ test("searches the server and preserves filters through load more", async function (assert) {const requests = [];pretender.get("/blog-editor.json", (request) => {requests.push({ ...request.queryParams });@@ -195,35 +333,54 @@ acceptance("Blog editor", function (needs) {request.queryParams.page !== "1",});});+ enableLoadMoreObserver();+ const observations = stubIntersectionObserver();+ const scrollToEnd = () =>+ observations+ .findLast(({ element }) =>+ element.closest(".blog-dashboard__load-more")+ )+ .trigger();++ try {+ await visit("/blog-editor");+ await select(".d-filter-controls__dropdown", "drafts");+ await fillIn(".d-filter-controls__input", "workflow");+ assert.deepEqual(+ requests.at(-1),+ { filter: "drafts", q: "workflow" },+ "search is combined with the server-side status filter"+ );++ await scrollToEnd();+ await waitUntil(() => requests.some((request) => request.page === "1"));+ assert.deepEqual(+ requests.at(-1),+ { filter: "drafts", q: "workflow", page: "1" },+ "scrolling to the end loads the next page with the entire query"+ );+ assert+ .dom(".blog-dashboard__row")+ .exists({ count: 2 }, "additional matching entries are appended");++ const requestCount = requests.length;+ await scrollToEnd();+ assert.strictEqual(+ requests.length,+ requestCount,+ "loading stops when there are no more matches"+ );+ } finally {+ disableLoadMoreObserver();+ }+ });++ test("shows an empty state when there are no articles at all", async function (assert) {+ pretender.get("/blog-editor.json", () => response({ topics: [] }));await visit("/blog-editor");- await click(".blog-dashboard__filters button:nth-child(2)");- await formKit(".blog-dashboard__search").field("q").fillIn("workflow");- await formKit(".blog-dashboard__search").submit();- assert.deepEqual(- requests.at(-1),- { filter: "drafts", q: "workflow" },- "search is combined with the server-side status filter"- );- await click("[data-blog-load-more]");- assert.deepEqual(- requests.at(-1),- { filter: "drafts", q: "workflow", page: "1" },- "load more preserves the entire query"- );- assert- .dom(".blog-dashboard__entry")- .exists({ count: 2 }, "additional matching entries are appended");- assert- .dom("[data-blog-load-more]")- .doesNotExist("loading stops when there are no more matches");- await click(".blog-dashboard__links button");- assert.deepEqual(- requests.at(-1),- { filter: "drafts", q: "workflow" },- "refresh keeps filters and returns to the first page"- );+ assert.dom(".empty-state").exists("an empty blog explains itself");assert- .dom(".blog-dashboard__entry")- .exists({ count: 1 }, "refresh replaces previous pages");+ .dom(".d-filter-controls__no-results")+ .doesNotExist("there is nothing to reset");});});diff --git a/plugins/blog/test/javascripts/acceptance/blog-reviews-management-test.js b/plugins/blog/test/javascripts/acceptance/blog-reviews-management-test.jsindex 84b3e669da2..490c3fd44e1 100644--- a/plugins/blog/test/javascripts/acceptance/blog-reviews-management-test.js+++ b/plugins/blog/test/javascripts/acceptance/blog-reviews-management-test.js@@ -87,7 +87,7 @@ acceptance("Blog review management", function (needs) {return response(204);});await visit(TOPIC_URL);- await click(".blog-publication-panel__reviews");+ await click(".blog-publication-panel__share-for-review");assert.dom(".blog-reviews").includesText(@@ -141,7 +141,7 @@ acceptance("Blog review management", function (needs) {await formKit(".blog-publication-panel__form").field("excerpt").fillIn("Unsaved publication excerpt");- await click(".blog-publication-panel__reviews");+ await click(".blog-publication-panel__share-for-review");assert.dom(".dialog-body").includesText(diff --git a/plugins/blog/test/javascripts/acceptance/blog-themes-test.js b/plugins/blog/test/javascripts/acceptance/blog-themes-test.jsindex 394195ddfad..1c66c500093 100644--- a/plugins/blog/test/javascripts/acceptance/blog-themes-test.js+++ b/plugins/blog/test/javascripts/acceptance/blog-themes-test.js@@ -336,6 +336,11 @@ acceptance("Blog themes and identity", function (needs) {"<h1>Unsaved preview</h1>");await click(".blog-theme-editor__preview-draft");+ assert+ .dom('select[aria-label="Sample published article"]')+ .doesNotExist(+ "the sample article selector is hidden for homepage previews"+ );assert.dom(".blog-theme-preview__frame").hasAttribute(@@ -348,6 +353,9 @@ acceptance("Blog themes and identity", function (needs) {.isDisabled("previewing does not commit unsaved changes");await fillControl('select[aria-label="Page to preview"]', "article");+ assert+ .dom('select[aria-label="Sample published article"]')+ .hasValue("1", "article previews select the available published article");assert.dom(".blog-theme-preview__frame").hasAttribute(@@ -399,8 +407,22 @@ acceptance("Blog themes and identity", function (needs) {assert.dom(".blog-theme-preview__frame").exists("without a published article the homepage stands in");+ assert+ .dom('select[aria-label="Sample published article"]')+ .doesNotExist("homepage previews do not need a sample article");await fillControl('select[aria-label="Page to preview"]', "article");+ assert+ .dom('select[aria-label="Sample published article"]')+ .isDisabled(+ "the selector is disabled when there are no published articles"+ );+ assert+ .dom('select[aria-label="Sample published article"] option:checked')+ .hasText(+ "No published articles",+ "the empty selector explains why it is unavailable"+ );assert.dom(".blog-theme-preview__empty").includesText(@@ -408,6 +430,11 @@ acceptance("Blog themes and identity", function (needs) {"the article page explains what it needs");assert.strictEqual(previews, 1, "no preview is requested for that page");++ await fillControl('select[aria-label="Page to preview"]', "index");+ assert+ .dom('select[aria-label="Sample published article"]')+ .doesNotExist("the article selector is hidden again on the homepage");});test("marks customized templates on their tab and names the state above the editor", async function (assert) {