Skip to content

A platform for community discussion. Free, open, simple.

UX: wider inputs, centered form, and footer controls for simplified category creation (#37964)

Krise2dcaf5b01da
diff --git a/app/assets/stylesheets/common/base/uc-simplified-category-setup-edit-categories.scss b/app/assets/stylesheets/common/base/uc-simplified-category-setup-edit-categories.scss
index 76e08a7282b..db40725be97 100644
--- a/app/assets/stylesheets/common/base/uc-simplified-category-setup-edit-categories.scss
+++ b/app/assets/stylesheets/common/base/uc-simplified-category-setup-edit-categories.scss
@@ -1,16 +1,86 @@
@use "lib/viewport";
.uc-enable-simplified-category-creation {
- .select-kit.multi-select.group-chooser {
- width: var(--form-kit-large-input);
+ .edit-category-tab-security {
+ .alert {
+ --permission-table-max-width: var(--form-kit-max-input);
+ }
+ }
- @include viewport.until(sm) {
- width: 100%;
+ .form-kit__container-content {
+ width: 100%;
+ }
+
+ .edit-category-tab:not(.edit-category-tab-general) {
+ .form-kit__container-optional {
+ display: none;
}
}
+ .category-permissions-table {
+ --permission-table-max-width: var(--form-kit-max-input);
+ width: 100%;
+ }
+
div.edit-category {
display: block;
+ max-width: 75ch;
+ width: 100%;
+ margin: 0 auto;
+
+ .form-kit {
+ padding-bottom: 6em; // space for save footer
+ }
+
+ .form-kit__field-toggle {
+ flex-direction: column;
+ width: 100%;
+ gap: 0.5em;
+ align-items: start;
+
+ .form-kit__container-content {
+ align-items: flex-start;
+ }
+ }
+
+ .form-kit__conditional-display-content {
+ // prevent content shift when changing style options
+ min-height: 2.8em;
+
+ &:has(.badge-category__wrapper) {
+ justify-content: center;
+ }
+ }
+
+ .--radio-cards {
+ width: var(--form-kit-max-input);
+
+ .form-kit__container-title {
+ max-width: var(--form-kit-max-input);
+ width: 100%;
+ }
+
+ .form-kit__conditional-display-content {
+ .form-kit__container {
+ flex-direction: column;
+ }
+ }
+ }
+
+ .select-kit.multi-select.group-chooser {
+ max-width: var(--form-kit-max-input);
+ width: 100%;
+ }
+
+ .edit-category-tab-settings label,
+ .edit-category-tab-tags label,
+ .edit-category-tab-settings input[type="text"],
+ .edit-category-tab-settings .select-kit,
+ .edit-category-tab-tags input[type="text"],
+ .edit-category-tab-tags .select-kit {
+ width: 100%;
+ max-width: var(--form-kit-max-input);
+ }
.add-required-tag-group {
align-self: start;
@@ -69,12 +139,6 @@
}
}
- .edit-category-tab-security {
- .form-kit__container-content {
- width: 100%;
- }
- }
-
.edit-category-title-text {
display: flex;
flex-direction: column;
@@ -98,11 +162,9 @@
}
}
- .category-permissions-table {
- width: 100%;
- }
-
.form-kit__errors-summary {
+ width: 100%;
+ max-width: var(--form-kit-max-input);
margin-top: var(--space-4);
+ .form-kit__section.edit-category-content {
@@ -111,11 +173,6 @@
}
.form-kit__conditional-display {
- .badge-category__wrapper {
- min-height: 2.6em;
- top: var(--space-1);
- }
-
.form-kit__container-content:has(.is-disabled) {
// select-kit has pointer-events disabled, so we need to style the parent
cursor: not-allowed;
@@ -126,4 +183,25 @@
padding: 0;
margin-bottom: var(--space-4);
}
+
+ .edit-category-tab-localizations {
+ .btn-default {
+ align-self: start;
+ }
+ }
+
+ #main-outlet:has(.edit-category) + .powered-by-discourse {
+ display: none; // hide for now due to alignment
+ }
+
+ .admin-changes-banner {
+ max-width: var(--form-kit-max-input);
+ flex-direction: row-reverse;
+ align-items: center;
+
+ .controls {
+ flex-direction: row-reverse;
+ margin-right: auto;
+ }
+ }
}
diff --git a/app/assets/stylesheets/common/base/upload.scss b/app/assets/stylesheets/common/base/upload.scss
index 2b1d6a41c4b..bfbcd05969d 100644
--- a/app/assets/stylesheets/common/base/upload.scss
+++ b/app/assets/stylesheets/common/base/upload.scss
@@ -12,12 +12,16 @@
position: relative;
max-width: 400px;
width: 100%;
- height: 80px;
+ height: 125px;
box-sizing: border-box;
border-radius: var(--d-input-border-radius);
background-origin: content-box;
background-clip: content-box;
+ &:has(.lightbox) {
+ height: 85px; // ~125px with controls visible to match above height
+ }
+
&:focus,
&:focus-within {
border-color: var(--tertiary);
diff --git a/app/assets/stylesheets/common/form-kit/_conditional-display.scss b/app/assets/stylesheets/common/form-kit/_conditional-display.scss
index 8aca24a9b36..0160c3b23d6 100644
--- a/app/assets/stylesheets/common/form-kit/_conditional-display.scss
+++ b/app/assets/stylesheets/common/form-kit/_conditional-display.scss
@@ -13,7 +13,7 @@
}
.--radio-cards {
- width: var(--form-kit-large-input);
+ width: var(--form-kit-max-input);
@include viewport.until(sm) {
width: 100%;
diff --git a/app/assets/stylesheets/common/form-kit/_container.scss b/app/assets/stylesheets/common/form-kit/_container.scss
index 0d4004763da..c45bd06dc9a 100644
--- a/app/assets/stylesheets/common/form-kit/_container.scss
+++ b/app/assets/stylesheets/common/form-kit/_container.scss
@@ -59,6 +59,11 @@
width: var(--form-kit-large-input);
}
+ &.--max {
+ max-width: var(--form-kit-max-input);
+ width: 100%;
+ }
+
&.--full {
width: 100% !important;
}
diff --git a/app/assets/stylesheets/common/form-kit/_field.scss b/app/assets/stylesheets/common/form-kit/_field.scss
index 58484bcdda0..670b6f3cc6c 100644
--- a/app/assets/stylesheets/common/form-kit/_field.scss
+++ b/app/assets/stylesheets/common/form-kit/_field.scss
@@ -64,6 +64,11 @@
width: var(--form-kit-large-input);
}
+ &.--max {
+ max-width: var(--form-kit-max-input);
+ width: 100%;
+ }
+
&.--full {
width: 100% !important;
}
diff --git a/app/assets/stylesheets/common/form-kit/_form-kit.scss b/app/assets/stylesheets/common/form-kit/_form-kit.scss
index 05b02fe40af..ce91b8d087e 100644
--- a/app/assets/stylesheets/common/form-kit/_form-kit.scss
+++ b/app/assets/stylesheets/common/form-kit/_form-kit.scss
@@ -3,4 +3,9 @@
flex-direction: column;
gap: 1.5em;
align-items: flex-start;
+
+ .alert {
+ // we space elements with gap, so don't need the margin
+ margin-bottom: 0;
+ }
}
diff --git a/app/assets/stylesheets/common/form-kit/_variables.scss b/app/assets/stylesheets/common/form-kit/_variables.scss
index 5ebf9285873..08dbe6f70dc 100644
--- a/app/assets/stylesheets/common/form-kit/_variables.scss
+++ b/app/assets/stylesheets/common/form-kit/_variables.scss
@@ -1,6 +1,7 @@
:root {
--form-kit-gutter-x: 1rem;
--form-kit-gutter-y: 1rem;
+ --form-kit-max-input: 75ch;
--form-kit-large-input: 325px;
--form-kit-medium-input: 200px;
--form-kit-small-input: 75px;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index ad2b4a71795..563acd0179d 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4662,11 +4662,15 @@ en:
delete: "Delete"
add: "Add required tag group"
placeholder: "Select tag group…"
+ min_count: "Tag count"
+ tag_group: "Tag group"
topic_featured_link_allowed: "Allow featured links in this category"
delete: "Delete category"
create: "New category"
create_long: "Create a new category"
+ create_category: "Create category"
save: "Save category"
+ unsaved_changes: "You have unsaved changes"
slug: "Category slug"
parent: "Parent category"
slug_placeholder: "(Optional) dashed-words for url"
diff --git a/frontend/discourse/admin/components/changes-banner.gjs b/frontend/discourse/admin/components/changes-banner.gjs
index 35657107050..8ae8a91cd38 100644
--- a/frontend/discourse/admin/components/changes-banner.gjs
+++ b/frontend/discourse/admin/components/changes-banner.gjs
@@ -43,7 +43,7 @@ export default class ChangesBanner extends Component {
}}</span>
<div class="controls">
<DButton
- class="btn-secondary btn-small"
+ class="btn-default btn-secondary btn-small"
@action={{@discard}}
@disabled={{this.isSaving}}
@translatedLabel={{@discardLabel}}
diff --git a/frontend/discourse/admin/components/edit-category-localizations.gjs b/frontend/discourse/admin/components/edit-category-localizations.gjs
index dc089cc1d89..df890b03071 100644
--- a/frontend/discourse/admin/components/edit-category-localizations.gjs
+++ b/frontend/discourse/admin/components/edit-category-localizations.gjs
@@ -33,16 +33,6 @@ export default class EditCategoryLocalizations extends buildCategoryPanel(
{{/if}}
<@form.Collection @name="localizations" as |collection index|>
- <collection.Field
- @name="category_id"
- @title="category_id"
- @showTitle={{false}}
- @disabled={{true}}
- as |field|
- >
- <field.Input @value={{this.category.id}} @type="hidden" />
- </collection.Field>
-
<@form.Row as |row|>
<row.Col @size={{2}}>
<collection.Field
@@ -99,7 +89,7 @@ export default class EditCategoryLocalizations extends buildCategoryPanel(
</@form.Collection>
<@form.Button
- class="add-localization"
+ class="btn-default add-localization"
@icon="plus"
@label="category.localization.add"
@action={{fn
diff --git a/frontend/discourse/admin/components/upsert-category/appearance.gjs b/frontend/discourse/admin/components/upsert-category/appearance.gjs
index e40315f2cc8..f06be41947d 100644
--- a/frontend/discourse/admin/components/upsert-category/appearance.gjs
+++ b/frontend/discourse/admin/components/upsert-category/appearance.gjs
@@ -210,7 +210,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="text_color"
@title={{i18n "category.foreground_color"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Color @colors={{CATEGORY_TEXT_COLORS}} />
@@ -219,7 +219,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="default_view"
@title={{i18n "category.default_view"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Custom>
@@ -237,7 +237,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="default_top_period"
@title={{i18n "category.default_top_period"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Custom>
@@ -255,7 +255,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="sort_order"
@title={{i18n "category.sort_order"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Custom>
@@ -284,7 +284,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="default_list_filter"
@title={{i18n "category.default_list_filter"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Custom>
@@ -303,7 +303,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="show_subcategory_list"
@title={{i18n "category.show_subcategory_list"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -313,7 +313,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="subcategory_list_style"
@title={{i18n "category.subcategory_list_style"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Custom>
@@ -332,7 +332,7 @@ export default class UpsertCategoryAppearance extends Component {
<@form.Field
@name="read_only_banner"
@title={{i18n "category.read_only_banner"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Input @maxlength="255" />
diff --git a/frontend/discourse/admin/components/upsert-category/general.gjs b/frontend/discourse/admin/components/upsert-category/general.gjs
index c6fe4fecab2..d2db4bec9df 100644
--- a/frontend/discourse/admin/components/upsert-category/general.gjs
+++ b/frontend/discourse/admin/components/upsert-category/general.gjs
@@ -1,5 +1,4 @@
import Component from "@glimmer/component";
-import { tracked } from "@glimmer/tracking";
import { concat, hash } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
@@ -26,8 +25,6 @@ export default class UpsertCategoryGeneral extends Component {
@service site;
@service siteSettings;
- @tracked categoryVisibilityState = null;
-
uncategorizedSiteSettingLink = getURL(
"/admin/site_settings/category/all_results?filter=allow_uncategorized_topics"
);
@@ -147,9 +144,9 @@ export default class UpsertCategoryGeneral extends Component {
}
get categoryVisibility() {
- const state = this.categoryVisibilityState;
- if (state && state.categoryId === this.args.category.id) {
- return state.value;
+ const visibility = this.args.transientData?.visibility;
+ if (visibility) {
+ return visibility;
}
if (this.isParentRestricted) {
@@ -196,16 +193,14 @@ export default class UpsertCategoryGeneral extends Component {
}));
}
- this.categoryVisibilityState = {
- categoryId: this.args.category.id,
- value,
- };
+ this.args.form.set("visibility", value);
if (value === "public") {
this.#setFormPermissions([this.#everyoneFullPermission]);
} else if (value === "group_restricted") {
if (this.#previousPermissions?.length) {
this.#setFormPermissions(this.#previousPermissions);
+ this.#previousPermissions = null;
} else {
this.#setFormPermissions([]);
}
@@ -215,7 +210,7 @@ export default class UpsertCategoryGeneral extends Component {
@action
async onParentCategoryChange(parentCategoryId) {
if (!parentCategoryId) {
- this.categoryVisibilityState = null;
+ this.args.form.set("visibility", null);
this.#setFormPermissions([this.#everyoneFullPermission]);
return;
}
@@ -231,7 +226,7 @@ export default class UpsertCategoryGeneral extends Component {
);
if (!hasEveryone) {
- this.categoryVisibilityState = null;
+ this.args.form.set("visibility", null);
const newPermissions = parentCategory.permissions.map((p) => ({
group_name: p.group_name,
@@ -347,7 +342,7 @@ export default class UpsertCategoryGeneral extends Component {
<@form.Field
@name="name"
@title={{i18n "category.name"}}
- @format="large"
+ @format="max"
@validation="required"
as |field|
>
@@ -363,7 +358,7 @@ export default class UpsertCategoryGeneral extends Component {
<@form.Field
@name="color"
@title={{i18n "category.background_color"}}
- @format="large"
+ @format="max"
@validation="required"
@onSet={{this.onBackgroundColorSet}}
as |field|
@@ -380,7 +375,7 @@ export default class UpsertCategoryGeneral extends Component {
<@form.Field
@name="style_type"
@title={{i18n "category.style"}}
- @format="large"
+ @format="max"
as |styleField|
>
<styleField.Custom>
@@ -407,7 +402,7 @@ export default class UpsertCategoryGeneral extends Component {
@name="icon"
@title={{i18n "category.icon"}}
@showTitle={{false}}
- @format="large"
+ @format="max"
@validate={{this.validateIcon}}
as |field|
>
@@ -437,7 +432,7 @@ export default class UpsertCategoryGeneral extends Component {
@name="emoji"
@title={{i18n "category.emoji"}}
@showTitle={{false}}
- @format="large"
+ @format="max"
@validate={{this.validateEmoji}}
as |field|
>
@@ -472,7 +467,7 @@ export default class UpsertCategoryGeneral extends Component {
<@form.Field
@name="parent_category_id"
@title={{i18n "category.subcategory_of"}}
- @format="large"
+ @format="max"
@onSet={{this.onParentCategorySet}}
as |field|
>
@@ -499,7 +494,7 @@ export default class UpsertCategoryGeneral extends Component {
<@form.Container
@title={{i18n "category.visibility.title"}}
class="--radio-cards"
- @format="large"
+ @format="max"
>
<@form.ConditionalContent
@activeName={{this.categoryVisibility}}
@@ -534,7 +529,7 @@ export default class UpsertCategoryGeneral extends Component {
<Content @name="group_restricted">
<@form.Container
@title={{i18n "category.visibility.which_groups_can_access"}}
- @format="large"
+ @format="max"
>
<GroupChooser
@content={{this.availableAccessGroups}}
diff --git a/frontend/discourse/admin/components/upsert-category/security.gjs b/frontend/discourse/admin/components/upsert-category/security.gjs
index 269397c7d55..c08dc4a75a3 100644
--- a/frontend/discourse/admin/components/upsert-category/security.gjs
+++ b/frontend/discourse/admin/components/upsert-category/security.gjs
@@ -160,6 +160,7 @@ export default class UpsertCategorySecurity extends Component {
(if (eq @selectedTab "security") "active")
}}
>
+
{{#if @category.is_special}}
{{#if @category.isUncategorizedCategory}}
<@form.Alert @type="warning">
@@ -172,6 +173,23 @@ export default class UpsertCategorySecurity extends Component {
{{/if}}
{{/if}}
+ {{#if this.allParentGroupsUsed}}
+ <@form.Alert @type="warning">
+ {{i18n "category.permissions.all_parent_groups_used"}}
+ </@form.Alert>
+ {{/if}}
+
+ <@form.Alert @type="warning">
+ {{#if this.everyonePermission}}
+ {{i18n
+ this.everyoneAccessMessageKey
+ everyone_group=this.everyonePermission.group_name
+ }}
+ {{else}}
+ {{i18n "category.permissions.specific_groups_have_access"}}
+ {{/if}}
+ </@form.Alert>
+
{{#unless @category.is_special}}
<@form.Container>
<div class="category-permissions-table">
@@ -231,22 +249,6 @@ export default class UpsertCategorySecurity extends Component {
{{/if}}
</div>
- {{#if this.allParentGroupsUsed}}
- <@form.Alert @type="warning">
- {{i18n "category.permissions.all_parent_groups_used"}}
- </@form.Alert>
- {{/if}}
-
- <@form.Alert @type="warning">
- {{#if this.everyonePermission}}
- {{i18n
- this.everyoneAccessMessageKey
- everyone_group=this.everyonePermission.group_name
- }}
- {{else}}
- {{i18n "category.permissions.specific_groups_have_access"}}
- {{/if}}
- </@form.Alert>
</@form.Container>
{{/unless}}
diff --git a/frontend/discourse/admin/components/upsert-category/settings.gjs b/frontend/discourse/admin/components/upsert-category/settings.gjs
index 56814809de8..8306907df76 100644
--- a/frontend/discourse/admin/components/upsert-category/settings.gjs
+++ b/frontend/discourse/admin/components/upsert-category/settings.gjs
@@ -64,18 +64,6 @@ export default class UpsertCategorySettings extends Component {
return this.args.transientData?.category_setting;
}
- get requireTopicApproval() {
- return this.categorySetting?.require_topic_approval;
- }
-
- get requireReplyApproval() {
- return this.categorySetting?.require_reply_approval;
- }
-
- get autoCloseBasedOnLastPost() {
- return this.args.transientData?.auto_close_based_on_last_post;
- }
-
get numAutoBumpDaily() {
return this.categorySetting?.num_auto_bump_daily;
}
@@ -108,21 +96,6 @@ export default class UpsertCategorySettings extends Component {
this.args.form.set("moderating_group_ids", groupIds);
}
- @action
- onRequireTopicApprovalChange(event) {
- this.#updateCategorySetting("require_topic_approval", event.target.checked);
- }
-
- @action
- onRequireReplyApprovalChange(event) {
- this.#updateCategorySetting("require_reply_approval", event.target.checked);
- }
-
- @action
- onAutoCloseBasedOnLastPostChange(event) {
- this.args.form.set("auto_close_based_on_last_post", event.target.checked);
- }
-
@action
onNumAutoBumpDailyChange(value) {
this.#updateCategorySetting("num_auto_bump_daily", value);
@@ -144,7 +117,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="slug"
@title={{i18n "category.slug"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Input
@@ -157,7 +130,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="position"
@title={{i18n "category.position"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Input type="number" min="0" />
@@ -171,7 +144,7 @@ export default class UpsertCategorySettings extends Component {
(i18n "category.subcategory_num_featured_topics")
(i18n "category.num_featured_topics")
}}
- @format="large"
+ @format="max"
as |field|
>
<field.Input type="number" min="1" />
@@ -180,7 +153,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="search_priority"
@title={{i18n "category.search_priority.label"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Custom>
@@ -199,7 +172,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="allow_badges"
@title={{i18n "category.allow_badges_label"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -210,7 +183,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="topic_featured_link_allowed"
@title={{i18n "category.topic_featured_link_allowed"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -220,7 +193,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="navigate_to_first_post_after_read"
@title={{i18n "category.navigate_to_first_post_after_read"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -229,7 +202,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="all_topics_wiki"
@title={{i18n "category.all_topics_wiki"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -238,7 +211,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="allow_unlimited_owner_edits_on_first_post"
@title={{i18n "category.allow_unlimited_owner_edits_on_first_post"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -255,27 +228,23 @@ export default class UpsertCategorySettings extends Component {
</@form.Container>
{{/if}}
- <@form.Container>
- <label class="checkbox-label">
- <input
- type="checkbox"
- checked={{this.requireTopicApproval}}
- {{on "change" this.onRequireTopicApprovalChange}}
- />
- {{i18n "category.require_topic_approval"}}
- </label>
- </@form.Container>
+ <@form.Object @name="category_setting" as |object|>
+ <object.Field
+ @name="require_topic_approval"
+ @title={{i18n "category.require_topic_approval"}}
+ as |field|
+ >
+ <field.Checkbox />
+ </object.Field>
- <@form.Container>
- <label class="checkbox-label">
- <input
- type="checkbox"
- checked={{this.requireReplyApproval}}
- {{on "change" this.onRequireReplyApprovalChange}}
- />
- {{i18n "category.require_reply_approval"}}
- </label>
- </@form.Container>
+ <object.Field
+ @name="require_reply_approval"
+ @title={{i18n "category.require_reply_approval"}}
+ as |field|
+ >
+ <field.Checkbox />
+ </object.Field>
+ </@form.Object>
<@form.Container @title={{i18n "category.default_slow_mode"}}>
<RelativeTimePicker
@@ -292,16 +261,16 @@ export default class UpsertCategorySettings extends Component {
@hiddenIntervals={{this.hiddenRelativeIntervals}}
@onChange={{this.onAutoCloseDurationChange}}
/>
- <label class="checkbox-label">
- <input
- type="checkbox"
- checked={{this.autoCloseBasedOnLastPost}}
- {{on "change" this.onAutoCloseBasedOnLastPostChange}}
- />
- {{i18n "topic.auto_close.based_on_last_post"}}
- </label>
</@form.Container>
+ <@form.Field
+ @name="auto_close_based_on_last_post"
+ @title={{i18n "topic.auto_close.based_on_last_post"}}
+ as |field|
+ >
+ <field.Checkbox />
+ </@form.Field>
+
<@form.Container @title={{i18n "category.num_auto_bump_daily"}}>
<input
{{on "input" (withEventValue this.onNumAutoBumpDailyChange)}}
@@ -328,7 +297,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="email_in"
@title={{i18n "category.email_in"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Input @maxlength="255" />
@@ -337,7 +306,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="email_in_allow_strangers"
@title={{i18n "category.email_in_allow_strangers"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -346,7 +315,7 @@ export default class UpsertCategorySettings extends Component {
<@form.Field
@name="mailinglist_mirror"
@title={{i18n "category.mailinglist_mirror"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Checkbox />
@@ -373,7 +342,11 @@ export default class UpsertCategorySettings extends Component {
<PluginOutlet
@name="category-custom-settings"
- @outletArgs={{lazyHash category=@category form=@form}}
+ @outletArgs={{lazyHash
+ category=@category
+ form=@form
+ transientData=@transientData
+ }}
/>
</@form.Section>
</template>
diff --git a/frontend/discourse/admin/components/upsert-category/tags.gjs b/frontend/discourse/admin/components/upsert-category/tags.gjs
index a0939bde6d4..26d29feec9b 100644
--- a/frontend/discourse/admin/components/upsert-category/tags.gjs
+++ b/frontend/discourse/admin/components/upsert-category/tags.gjs
@@ -1,11 +1,8 @@
import Component from "@glimmer/component";
import { array, fn, hash } from "@ember/helper";
-import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { LinkTo } from "@ember/routing";
-import DButton from "discourse/components/d-button";
import concatClass from "discourse/helpers/concat-class";
-import withEventValue from "discourse/helpers/with-event-value";
import TagGroupChooser from "discourse/select-kit/components/tag-group-chooser";
import { eq } from "discourse/truth-helpers";
import { i18n } from "discourse-i18n";
@@ -19,10 +16,6 @@ export default class UpsertCategoryTags extends Component {
return this.args.transientData?.allowed_tag_groups;
}
- get requiredTagGroups() {
- return this.args.transientData?.required_tag_groups ?? [];
- }
-
get disableAllowGlobalTags() {
const allowedTagsEmpty = !this.allowedTags || this.allowedTags.length === 0;
const allowedTagGroupsEmpty =
@@ -36,36 +29,8 @@ export default class UpsertCategoryTags extends Component {
}
@action
- onTagGroupChange(rtgIndex, valueArray) {
- // A little strange, but we're using a multi-select component
- // to select a single tag group. This action takes the array
- // and extracts the first value in it.
- const newRequiredTagGroups = this.requiredTagGroups.map((rtg, idx) =>
- idx === rtgIndex ? { ...rtg, name: valueArray[0] } : rtg
- );
- this.args.form.set("required_tag_groups", newRequiredTagGroups);
- }
-
- @action
- onMinCountChange(rtgIndex, value) {
- const newRequiredTagGroups = this.requiredTagGroups.map((rtg, idx) =>
- idx === rtgIndex ? { ...rtg, min_count: value } : rtg
- );
- this.args.form.set("required_tag_groups", newRequiredTagGroups);
- }
-
- @action
- addRequiredTagGroup() {
- const newRequiredTagGroups = [...this.requiredTagGroups, { min_count: 1 }];
- this.args.form.set("required_tag_groups", newRequiredTagGroups);
- }
-
- @action
- deleteRequiredTagGroup(rtgIndex) {
- const newRequiredTagGroups = this.requiredTagGroups.filter(
- (_, idx) => idx !== rtgIndex
- );
- this.args.form.set("required_tag_groups", newRequiredTagGroups);
+ onTagGroupFieldChange(field, valueArray) {
+ field.set(valueArray[0]);
}
<template>
@@ -79,7 +44,7 @@ export default class UpsertCategoryTags extends Component {
<@form.Field
@name="minimum_required_tags"
@title={{i18n "category.minimum_required_tags"}}
- @format="large"
+ @format="max"
as |field|
>
<field.Input type="number" min="0" id="category-minimum-tags" />
@@ -92,7 +57,7 @@ export default class UpsertCategoryTags extends Component {
(i18n "category.tags_allowed_tags" [email protected])
(i18n "category.tags_allowed_tags_new_category")
}}
- @format="large"
+ @format="max"
as |field|
>
<field.TagChooser
@@ -125,7 +90,7 @@ export default class UpsertCategoryTags extends Component {
<@form.Field
@name="allow_global_tags"
@title={{i18n "category.allow_global_tags_label"}}
- @format="large"
+ @format="max"
@disabled={{this.disableAllowGlobalTags}}
as |field|
>
@@ -137,35 +102,59 @@ export default class UpsertCategoryTags extends Component {
</@form.Alert>
<@form.Section @title={{i18n "category.required_tag_group.description"}}>
- {{#each this.requiredTagGroups as |rtg index|}}
- <div class="required-tag-group-row">
- <input
- type="number"
- min="1"
- value={{rtg.min_count}}
- {{on "input" (withEventValue (fn this.onMinCountChange index))}}
- />
- <TagGroupChooser
- @tagGroups={{if rtg.name (array rtg.name) (array)}}
- @onChange={{fn this.onTagGroupChange index}}
- @options={{hash
- maximum=1
- filterPlaceholder="category.required_tag_group.placeholder"
- }}
- />
- <DButton
- @label="category.required_tag_group.delete"
- @action={{fn this.deleteRequiredTagGroup index}}
- @icon="trash-can"
- class="delete-required-tag-group"
- />
- </div>
- {{/each}}
- <DButton
- @label="category.required_tag_group.add"
- @action={{this.addRequiredTagGroup}}
- @icon="plus"
+ <@form.Collection @name="required_tag_groups" as |collection index|>
+ <@form.Row as |row|>
+ <row.Col @size={{2}}>
+ <collection.Field
+ @name="min_count"
+ @title={{i18n "category.required_tag_group.min_count"}}
+ @validation="required"
+ as |field|
+ >
+ <field.Input @type="number" min="1" />
+ </collection.Field>
+ </row.Col>
+
+ <row.Col @size={{9}}>
+ <collection.Field
+ @name="name"
+ @title={{i18n "category.required_tag_group.tag_group"}}
+ @validation="required"
+ as |field|
+ >
+ <field.Custom>
+ <TagGroupChooser
+ @tagGroups={{if field.value (array field.value) (array)}}
+ @onChange={{fn this.onTagGroupFieldChange field}}
+ @options={{hash
+ maximum=1
+ filterPlaceholder="category.required_tag_group.placeholder"
+ }}
+ />
+ </field.Custom>
+ </collection.Field>
+ </row.Col>
+
+ <row.Col @size={{1}}>
+ <@form.Button
+ class="btn-danger delete-required-tag-group"
+ @icon="trash-can"
+ @title="category.required_tag_group.delete"
+ @action={{fn collection.remove index}}
+ />
+ </row.Col>
+ </@form.Row>
+ </@form.Collection>
+
+ <@form.Button
class="btn-default add-required-tag-group"
+ @icon="plus"
+ @label="category.required_tag_group.add"
+ @action={{fn
+ @form.addItemToCollection
+ "required_tag_groups"
+ (hash min_count=1)
+ }}
/>
</@form.Section>
</@form.Section>
diff --git a/frontend/discourse/admin/controllers/edit-category/tabs.js b/frontend/discourse/admin/controllers/edit-category/tabs.js
index a88a6617ae4..57467aad6ed 100644
--- a/frontend/discourse/admin/controllers/edit-category/tabs.js
+++ b/frontend/discourse/admin/controllers/edit-category/tabs.js
@@ -44,18 +44,30 @@ const FIELD_LIST = [
"subcategory_list_style",
"read_only_banner",
"email_in",
+ "email_in_enabled",
"email_in_allow_strangers",
"mailinglist_mirror",
"allowed_tag_groups",
"allowed_tags",
];
+// Additional fields managed through FormKit in the simplified creation flow.
+// The legacy edit-category components manage these directly on the model.
+const SIMPLIFIED_FIELD_LIST = [
+ ...FIELD_LIST,
+ "required_tag_groups",
+ "minimum_required_tags",
+ "allow_global_tags",
+ "default_slow_mode_seconds",
+];
+
const SHOW_ADVANCED_TABS_KEY = "category_edit_show_advanced_tabs";
export default class EditCategoryTabsController extends Controller {
@service currentUser;
@service dialog;
@service site;
+ @service siteSettings;
@service router;
@service keyValueStore;
@service toasts;
@@ -65,6 +77,7 @@ export default class EditCategoryTabsController extends Controller {
showAdvancedTabs =
this.keyValueStore.getItem(SHOW_ADVANCED_TABS_KEY) === "true";
@tracked selectedTab = "general";
+ @tracked formApi = null;
@trackedArray panels = [];
saving = false;
deleting = false;
@@ -78,12 +91,25 @@ export default class EditCategoryTabsController extends Controller {
@and("showTooltip", "model.cannot_delete_reason") showDeleteReason;
get formData() {
- const data = getProperties(this.model, ...FIELD_LIST);
+ const simplified = this.siteSettings.enable_simplified_category_creation;
+ const data = getProperties(
+ this.model,
+ ...(simplified ? SIMPLIFIED_FIELD_LIST : FIELD_LIST)
+ );
- if (!this.model.styleType) {
+ if (simplified && !this.model.styleType) {
data.style_type = "icon";
}
+ if (simplified) {
+ data.required_tag_groups = Array.from(
+ data.required_tag_groups ?? [],
+ (rtg) => ({ ...rtg })
+ );
+ data.category_setting = { ...(this.model.category_setting ?? {}) };
+ data.custom_fields = { ...(this.model.custom_fields ?? {}) };
+ }
+
return data;
}
@@ -103,7 +129,7 @@ export default class EditCategoryTabsController extends Controller {
if (saving) {
return "saving";
}
- return id ? "category.save" : "category.create";
+ return id ? "category.save" : "category.create_category";
}
get baseTitle() {
@@ -116,6 +142,15 @@ export default class EditCategoryTabsController extends Controller {
return i18n("category.create");
}
+ get isFormDirty() {
+ return this.formApi?.isDirty ?? false;
+ }
+
+ @action
+ onRegisterFormApi(api) {
+ this.formApi = api;
+ }
+
@action
setSelectedTab(tab) {
this.selectedTab = tab;
@@ -124,6 +159,10 @@ export default class EditCategoryTabsController extends Controller {
@action
validateForm(data, { addError }) {
+ if (!this.siteSettings.enable_simplified_category_creation) {
+ return;
+ }
+
if (this.selectedTab === "general") {
return;
}
@@ -193,7 +232,9 @@ export default class EditCategoryTabsController extends Controller {
return;
}
- this.model.setProperties(data);
+ // eslint-disable-next-line no-unused-vars
+ const { visibility, ...categoryData } = data;
+ this.model.setProperties(categoryData);
// If permissions is empty or not set, ensure it's an empty array (public category)
if (!this.model.permissions || this.model.permissions.length === 0) {
diff --git a/frontend/discourse/admin/templates/edit-category/tabs.gjs b/frontend/discourse/admin/templates/edit-category/tabs.gjs
index f156ed64aa8..68e6c7ee725 100644
--- a/frontend/discourse/admin/templates/edit-category/tabs.gjs
+++ b/frontend/discourse/admin/templates/edit-category/tabs.gjs
@@ -1,5 +1,6 @@
import { concat } from "@ember/helper";
import { htmlSafe } from "@ember/template";
+import ChangesBanner from "discourse/admin/components/changes-banner";
import EditCategoryGeneral from "discourse/admin/components/edit-category-general";
import EditCategoryImages from "discourse/admin/components/edit-category-images";
import EditCategoryLocalizations from "discourse/admin/components/edit-category-localizations";
@@ -16,6 +17,8 @@ import EditCategoryTabsHorizontal from "discourse/admin/templates/edit-category/
import EditCategoryTabsVertical from "discourse/admin/templates/edit-category/tabs-vertical";
import Form from "discourse/components/form";
import { registeredEditCategoryTabs } from "discourse/lib/edit-category-tabs";
+import { or } from "discourse/truth-helpers";
+import { i18n } from "discourse-i18n";
const TAB_COMPONENTS = {
general: EditCategoryGeneral,
@@ -67,6 +70,7 @@ export default <template>
@onDirtyCheck={{@controller.isLeavingForm}}
@onSubmit={{@controller.saveCategory}}
@validate={{@controller.validateForm}}
+ @onRegisterApi={{@controller.onRegisterFormApi}}
as |form transientData|
>
<form.Section
@@ -116,27 +120,67 @@ export default <template>
</form.Alert>
{{/if}}
- <form.Actions class="edit-category-footer">
- <form.Submit @label={{@controller.saveLabel}} id="save-category" />
-
- {{#if @controller.model.can_delete}}
- <form.Button
- @disabled={{@controller.deleteDisabled}}
- @action={{@controller.deleteCategory}}
- @icon="trash-can"
- @label="category.delete"
- class="btn-danger"
- />
- {{else if @controller.model.id}}
- <form.Button
- @disabled={{@controller.deleteDisabled}}
- @action={{@controller.toggleDeleteTooltip}}
- @icon="circle-question"
- @label="category.delete"
- class="btn-default"
- />
+ {{#if @controller.siteSettings.enable_simplified_category_creation}}
+ {{#if (or @controller.model.can_delete @controller.model.id)}}
+ <form.Actions class="edit-category-footer">
+ {{#if @controller.model.can_delete}}
+ <form.Button
+ @disabled={{@controller.deleteDisabled}}
+ @action={{@controller.deleteCategory}}
+ @icon="trash-can"
+ @label="category.delete"
+ class="btn-danger"
+ />
+ {{else}}
+ <form.Button
+ @disabled={{@controller.deleteDisabled}}
+ @action={{@controller.toggleDeleteTooltip}}
+ @icon="circle-question"
+ @label="category.delete"
+ class="btn-default"
+ />
+ {{/if}}
+ </form.Actions>
{{/if}}
- </form.Actions>
+ {{else}}
+ <form.Actions class="edit-category-footer">
+ <form.Submit @label={{@controller.saveLabel}} id="save-category" />
+
+ {{#if @controller.model.can_delete}}
+ <form.Button
+ @disabled={{@controller.deleteDisabled}}
+ @action={{@controller.deleteCategory}}
+ @icon="trash-can"
+ @label="category.delete"
+ class="btn-danger"
+ />
+ {{else if @controller.model.id}}
+ <form.Button
+ @disabled={{@controller.deleteDisabled}}
+ @action={{@controller.toggleDeleteTooltip}}
+ @icon="circle-question"
+ @label="category.delete"
+ class="btn-default"
+ />
+ {{/if}}
+ </form.Actions>
+ {{/if}}
</Form>
+
+ {{#if @controller.siteSettings.enable_simplified_category_creation}}
+ {{#if @controller.isFormDirty}}
+ <ChangesBanner
+ @bannerLabel={{i18n "category.unsaved_changes"}}
+ @saveLabel={{if
+ @controller.model.id
+ (i18n "category.save")
+ (i18n "category.create_category")
+ }}
+ @discardLabel={{i18n "form_kit.reset"}}
+ @save={{@controller.formApi.submit}}
+ @discard={{@controller.formApi.reset}}
+ />
+ {{/if}}
+ {{/if}}
</div>
</template>
diff --git a/frontend/discourse/app/form-kit/components/fk/collection.gjs b/frontend/discourse/app/form-kit/components/fk/collection.gjs
index a5498b7f691..bdfaa516206 100644
--- a/frontend/discourse/app/form-kit/components/fk/collection.gjs
+++ b/frontend/discourse/app/form-kit/components/fk/collection.gjs
@@ -61,21 +61,23 @@ export default class FKCollection extends Component {
}
<template>
- {{#let (element this.tagName) as |Wrapper|}}
- <Wrapper class="form-kit__collection">
- {{#each this.collectionData key="identifier" as |data index|}}
- {{yield
- (hash
- Field=(this.componentFor FKField index)
- Object=(this.componentFor FKObject index)
- Collection=(this.componentFor FKCollection index)
- remove=this.remove
- )
- index
- data.item
- }}
- {{/each}}
- </Wrapper>
- {{/let}}
+ {{#if this.collectionData.length}}
+ {{#let (element this.tagName) as |Wrapper|}}
+ <Wrapper class="form-kit__collection">
+ {{#each this.collectionData key="identifier" as |data index|}}
+ {{yield
+ (hash
+ Field=(this.componentFor FKField index)
+ Object=(this.componentFor FKObject index)
+ Collection=(this.componentFor FKCollection index)
+ remove=this.remove
+ )
+ index
+ data.item
+ }}
+ {{/each}}
+ </Wrapper>
+ {{/let}}
+ {{/if}}
</template>
}
diff --git a/frontend/discourse/app/form-kit/components/fk/form.gjs b/frontend/discourse/app/form-kit/components/fk/form.gjs
index a655f2850c7..855afa8146c 100644
--- a/frontend/discourse/app/form-kit/components/fk/form.gjs
+++ b/frontend/discourse/app/form-kit/components/fk/form.gjs
@@ -42,6 +42,7 @@ class FKForm extends Component {
constructor() {
super(...arguments);
+ const instance = this;
this.args.onRegisterApi?.({
set: this.set,
setProperties: this.setProperties,
@@ -51,6 +52,9 @@ class FKForm extends Component {
addError: this.addError,
removeError: this.removeError,
removeErrors: this.removeErrors,
+ get isDirty() {
+ return instance.formData.isDirty;
+ },
});
this.router.on("routeWillChange", this.checkIsDirty);
diff --git a/frontend/discourse/app/form-kit/lib/fk-form-data.js b/frontend/discourse/app/form-kit/lib/fk-form-data.js
index dde9381a030..09020d009da 100644
--- a/frontend/discourse/app/form-kit/lib/fk-form-data.js
+++ b/frontend/discourse/app/form-kit/lib/fk-form-data.js
@@ -30,13 +30,13 @@ export default class FKFormData {
* The patches to be applied.
* @type {Array}
*/
- patches = [];
+ @tracked patches = [];
/**
* The inverse patches to be applied, useful for rollback.
* @type {Array}
*/
- inversePatches = [];
+ @tracked inversePatches = [];
/**
* Creates an instance of Changeset.
@@ -113,9 +113,9 @@ export default class FKFormData {
*/
async rollback() {
while (this.inversePatches.length > 0) {
- this.draftData = applyPatches(this.draftData, [
- this.inversePatches.pop(),
- ]);
+ const patch = this.inversePatches[this.inversePatches.length - 1];
+ this.draftData = applyPatches(this.draftData, [patch]);
+ this.inversePatches = this.inversePatches.slice(0, -1);
}
this.resetPatches();
@@ -191,8 +191,8 @@ export default class FKFormData {
target[parts[0]] = value;
},
(patches, inversePatches) => {
- this.patches.push(...patches);
- this.inversePatches.push(...inversePatches);
+ this.patches = [...this.patches, ...patches];
+ this.inversePatches = [...this.inversePatches, ...inversePatches];
}
);
}
diff --git a/frontend/discourse/tests/integration/components/form-kit/collection-test.gjs b/frontend/discourse/tests/integration/components/form-kit/collection-test.gjs
index 9a997b982be..7a819aa39ab 100644
--- a/frontend/discourse/tests/integration/components/form-kit/collection-test.gjs
+++ b/frontend/discourse/tests/integration/components/form-kit/collection-test.gjs
@@ -176,6 +176,22 @@ module("Integration | Component | FormKit | Collection", function (hooks) {
assert.form().field("one.0.two.0.three.0.foo").hasValue("2");
});
+ test("renders nothing when collection is empty", async function (assert) {
+ await render(
+ <template>
+ <Form @data={{hash foo=(array)}} as |form|>
+ <form.Collection @name="foo" @tagName="ul" as |collection|>
+ <collection.Field @title="Bar" as |field|>
+ <field.Input />
+ </collection.Field>
+ </form.Collection>
+ </Form>
+ </template>
+ );
+
+ assert.dom("ul.form-kit__collection").doesNotExist();
+ });
+
test("emptying a collection field", async function (assert) {
const onSubmit = (data) => {
assert.deepEqual(
diff --git a/frontend/discourse/tests/integration/components/form-kit/form-test.gjs b/frontend/discourse/tests/integration/components/form-kit/form-test.gjs
index b5a1f649543..d06bbb1ff6d 100644
--- a/frontend/discourse/tests/integration/components/form-kit/form-test.gjs
+++ b/frontend/discourse/tests/integration/components/form-kit/form-test.gjs
@@ -179,6 +179,32 @@ module("Integration | Component | FormKit | Form", function (hooks) {
}, 0);
});
+ test("@onRegisterApi - isDirty", async function (assert) {
+ let formApi;
+ const model = { foo: 1 };
+ const registerApi = (api) => (formApi = api);
+
+ await render(
+ <template>
+ <Form @data={{model}} @onRegisterApi={{registerApi}} as |form|>
+ <form.Field @name="foo" @title="Foo" as |field|>
+ <field.Input />
+ </form.Field>
+ </Form>
+ </template>
+ );
+
+ assert.false(formApi.isDirty, "form is not dirty initially");
+
+ await formKit().field("foo").fillIn("2");
+
+ assert.true(formApi.isDirty, "form is dirty after a change");
+
+ await formApi.reset();
+
+ assert.false(formApi.isDirty, "form is not dirty after reset");
+ });
+
test("@data", async function (assert) {
await render(
<template>
diff --git a/plugins/discourse-assign/assets/javascripts/discourse/connectors/category-custom-settings/assign-settings-upsert.gjs b/plugins/discourse-assign/assets/javascripts/discourse/connectors/category-custom-settings/assign-settings-upsert.gjs
new file mode 100644
index 00000000000..348353108b0
--- /dev/null
+++ b/plugins/discourse-assign/assets/javascripts/discourse/connectors/category-custom-settings/assign-settings-upsert.gjs
@@ -0,0 +1,38 @@
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
+import { i18n } from "discourse-i18n";
+
+export default class AssignSettingsUpsert extends Component {
+ static shouldRender(args, context) {
+ return context.siteSettings.enable_simplified_category_creation;
+ }
+
+ get enableUnassignedFilter() {
+ const value =
+ this.args.outletArgs.transientData?.custom_fields
+ ?.enable_unassigned_filter;
+ return value?.toString() === "true";
+ }
+
+ @action
+ async onToggleUnassignedFilter(_, { set, name }) {
+ await set(name, this.enableUnassignedFilter ? "false" : "true");
+ }
+
+ <template>
+ {{#let @outletArgs.form as |form|}}
+ <form.Section @title={{i18n "discourse_assign.assign.title"}}>
+ <form.Object @name="custom_fields" as |customFields|>
+ <customFields.Field
+ @name="enable_unassigned_filter"
+ @title={{i18n "discourse_assign.add_unassigned_filter"}}
+ @onSet={{this.onToggleUnassignedFilter}}
+ as |field|
+ >
+ <field.Checkbox checked={{this.enableUnassignedFilter}} />
+ </customFields.Field>
+ </form.Object>
+ </form.Section>
+ {{/let}}
+ </template>
+}
diff --git a/plugins/discourse-assign/assets/javascripts/discourse/connectors/category-custom-settings/assign-settings.gjs b/plugins/discourse-assign/assets/javascripts/discourse/connectors/category-custom-settings/assign-settings.gjs
index d7f42f3f6a7..001818d388c 100644
--- a/plugins/discourse-assign/assets/javascripts/discourse/connectors/category-custom-settings/assign-settings.gjs
+++ b/plugins/discourse-assign/assets/javascripts/discourse/connectors/category-custom-settings/assign-settings.gjs
@@ -7,6 +7,10 @@ import { i18n } from "discourse-i18n";
@tagName("")
export default class AssignSettings extends Component {
+ static shouldRender(args, context) {
+ return !context.siteSettings.enable_simplified_category_creation;
+ }
+
@action
onChangeSetting(event) {
this.set(
diff --git a/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings-upsert.gjs b/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings-upsert.gjs
new file mode 100644
index 00000000000..dabba0231b7
--- /dev/null
+++ b/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings-upsert.gjs
@@ -0,0 +1,51 @@
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import { i18n } from "discourse-i18n";
+
+export default class SolvedSettingsUpsert extends Component {
+ static shouldRender(args, context) {
+ return context.siteSettings.enable_simplified_category_creation;
+ }
+
+ @service siteSettings;
+
+ get enableAcceptedAnswers() {
+ const value =
+ this.args.outletArgs.transientData?.custom_fields
+ ?.enable_accepted_answers;
+ return value?.toString() === "true";
+ }
+
+ @action
+ async onToggleAcceptedAnswers(_, { set, name }) {
+ await set(name, this.enableAcceptedAnswers ? "false" : "true");
+ }
+
+ <template>
+ {{#let @outletArgs.form as |form|}}
+ <form.Section @title={{i18n "solved.title"}}>
+ <form.Object @name="custom_fields" as |customFields|>
+ {{#unless this.siteSettings.allow_solved_on_all_topics}}
+ <customFields.Field
+ @name="enable_accepted_answers"
+ @title={{i18n "solved.allow_accepted_answers"}}
+ @onSet={{this.onToggleAcceptedAnswers}}
+ as |field|
+ >
+ <field.Checkbox checked={{this.enableAcceptedAnswers}} />
+ </customFields.Field>
+ {{/unless}}
+
+ <customFields.Field
+ @name="solved_topics_auto_close_hours"
+ @title={{i18n "solved.solved_topics_auto_close_hours"}}
+ as |field|
+ >
+ <field.Input @type="number" min="0" />
+ </customFields.Field>
+ </form.Object>
+ </form.Section>
+ {{/let}}
+ </template>
+}
diff --git a/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.gjs b/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.gjs
index 775f197e652..9196d31f985 100644
--- a/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.gjs
+++ b/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.gjs
@@ -7,6 +7,10 @@ import withEventValue from "discourse/helpers/with-event-value";
import { i18n } from "discourse-i18n";
export default class SolvedSettings extends Component {
+ static shouldRender(args, context) {
+ return !context.siteSettings.enable_simplified_category_creation;
+ }
+
@service siteSettings;
@tracked
diff --git a/plugins/discourse-solved/spec/system/simplified_category_settings_spec.rb b/plugins/discourse-solved/spec/system/simplified_category_settings_spec.rb
new file mode 100644
index 00000000000..e1328374930
--- /dev/null
+++ b/plugins/discourse-solved/spec/system/simplified_category_settings_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+describe "Solved - Simplified Category Settings", type: :system do
+ fab!(:admin)
+ fab!(:category)
+
+ let(:category_page) { PageObjects::Pages::Category.new }
+ let(:form) { PageObjects::Components::FormKit.new(".form-kit") }
+
+ before do
+ SiteSetting.enable_simplified_category_creation = true
+ SiteSetting.solved_enabled = true
+ sign_in(admin)
+ end
+
+ describe "enable_accepted_answers" do
+ it "saves 'true' when enabling accepted answers" do
+ category_page.visit_settings(category)
+ form.field("custom_fields.enable_accepted_answers").toggle
+ category_page.save_settings
+
+ expect(category.reload.custom_fields["enable_accepted_answers"]).to eq("true")
+ end
+
+ it "saves 'false' when disabling accepted answers" do
+ category.upsert_custom_fields("enable_accepted_answers" => "true")
+
+ category_page.visit_settings(category)
+ form.field("custom_fields.enable_accepted_answers").toggle
+ category_page.save_settings
+
+ expect(category.reload.custom_fields["enable_accepted_answers"]).to eq("false")
+ end
+ end
+end
diff --git a/plugins/discourse-topic-voting/assets/javascripts/discourse/connectors/category-custom-settings/feature-voting-settings-upsert.gjs b/plugins/discourse-topic-voting/assets/javascripts/discourse/connectors/category-custom-settings/feature-voting-settings-upsert.gjs
new file mode 100644
index 00000000000..8b528c63237
--- /dev/null
+++ b/plugins/discourse-topic-voting/assets/javascripts/discourse/connectors/category-custom-settings/feature-voting-settings-upsert.gjs
@@ -0,0 +1,37 @@
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
+import { i18n } from "discourse-i18n";
+
+export default class FeatureVotingSettingsUpsert extends Component {
+ static shouldRender(args, context) {
+ return context.siteSettings.enable_simplified_category_creation;
+ }
+
+ get enableTopicVoting() {
+ const value =
+ this.args.outletArgs.transientData?.custom_fields?.enable_topic_voting;
+ return value?.toString() === "true";
+ }
+
+ @action
+ async onToggleTopicVoting(_, { set, name }) {
+ await set(name, this.enableTopicVoting ? "false" : "true");
+ }
+
+ <template>
+ {{#let @outletArgs.form as |form|}}
+ <form.Section @title={{i18n "topic_voting.title"}}>
+ <form.Object @name="custom_fields" as |customFields|>
+ <customFields.Field
+ @name="enable_topic_voting"
+ @title={{i18n "topic_voting.allow_topic_voting"}}
+ @onSet={{this.onToggleTopicVoting}}
+ as |field|
+ >
+ <field.Checkbox checked={{this.enableTopicVoting}} />
+ </customFields.Field>
+ </form.Object>
+ </form.Section>
+ {{/let}}
+ </template>
+}
diff --git a/plugins/discourse-topic-voting/assets/javascripts/discourse/connectors/category-custom-settings/feature-voting-settings.gjs b/plugins/discourse-topic-voting/assets/javascripts/discourse/connectors/category-custom-settings/feature-voting-settings.gjs
index 13cf7963f71..4644f133563 100644
--- a/plugins/discourse-topic-voting/assets/javascripts/discourse/connectors/category-custom-settings/feature-voting-settings.gjs
+++ b/plugins/discourse-topic-voting/assets/javascripts/discourse/connectors/category-custom-settings/feature-voting-settings.gjs
@@ -1,17 +1,24 @@
+import Component from "@glimmer/component";
import { Input } from "@ember/component";
import { i18n } from "discourse-i18n";
-<template>
- <section class="field">
- <h3>{{i18n "topic_voting.title"}}</h3>
- <div class="enable-topic-voting">
- <label class="checkbox-label">
- <Input
- @type="checkbox"
- @checked={{@outletArgs.category.custom_fields.enable_topic_voting}}
- />
- {{i18n "topic_voting.allow_topic_voting"}}
- </label>
- </div>
- </section>
-</template>
+export default class FeatureVotingSettings extends Component {
+ static shouldRender(args, context) {
+ return !context.siteSettings.enable_simplified_category_creation;
+ }
+
+ <template>
+ <section class="field">
+ <h3>{{i18n "topic_voting.title"}}</h3>
+ <div class="enable-topic-voting">
+ <label class="checkbox-label">
+ <Input
+ @type="checkbox"
+ @checked={{@outletArgs.category.custom_fields.enable_topic_voting}}
+ />
+ {{i18n "topic_voting.allow_topic_voting"}}
+ </label>
+ </div>
+ </section>
+ </template>
+}
diff --git a/spec/system/page_objects/pages/category.rb b/spec/system/page_objects/pages/category.rb
index fd06bbe7a9e..2c6e362cd90 100644
--- a/spec/system/page_objects/pages/category.rb
+++ b/spec/system/page_objects/pages/category.rb
@@ -64,7 +64,11 @@ module PageObjects
end
def save_settings
- find("#save-category").click
+ if page.has_css?(".admin-changes-banner", wait: 0)
+ find(".admin-changes-banner .btn-primary").click
+ else
+ find("#save-category").click
+ end
self
end
@@ -106,6 +110,11 @@ module PageObjects
self
end
+ def toggle_form_container(title)
+ find(".form-kit__container", text: title).find("label.d-toggle-switch__label").click
+ self
+ end
+
def select_form_template(template_name)
find(".select-category-template").click
find(".select-kit-collection .select-kit-row", text: template_name).click
diff --git a/spec/system/simplified_category_creation_spec.rb b/spec/system/simplified_category_creation_spec.rb
index 6cfb0e22f4d..534ee805ee4 100644
--- a/spec/system/simplified_category_creation_spec.rb
+++ b/spec/system/simplified_category_creation_spec.rb
@@ -167,7 +167,7 @@ describe "Simplified Category Creation" do
it "enables topic approval requirement" do
category_page.visit_settings(category)
- category_page.toggle_checkbox(I18n.t("js.category.require_topic_approval"))
+ form.field("category_setting.require_topic_approval").toggle
category_page.save_settings
expect(category.reload.require_topic_approval?).to eq(true)