mirror of
https://github.com/discourse/discourse.git
synced 2025-01-16 06:32:42 +08:00
UX: Conditionally render permalinks filter (#30633)
This commit is contained in:
parent
6330e6ceae
commit
9779cc9d5e
|
@ -87,7 +87,9 @@ export default class AdminFlagsForm extends Component {
|
||||||
permalink_type: data.permalinkType,
|
permalink_type: data.permalinkType,
|
||||||
permalink_type_value: this.valueForPermalinkType(data),
|
permalink_type_value: this.valueForPermalinkType(data),
|
||||||
});
|
});
|
||||||
this.adminPermalinks.model.unshift(Permalink.create(result.payload));
|
this.adminPermalinks.model.allLinks.unshift(
|
||||||
|
Permalink.create(result.payload)
|
||||||
|
);
|
||||||
this.router.transitionTo("adminPermalinks");
|
this.router.transitionTo("adminPermalinks");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
popupAjaxError(error);
|
popupAjaxError(error);
|
||||||
|
@ -106,10 +108,12 @@ export default class AdminFlagsForm extends Component {
|
||||||
permalink_type_value: this.valueForPermalinkType(data),
|
permalink_type_value: this.valueForPermalinkType(data),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const index = this.adminPermalinks.model.findIndex(
|
const index = this.adminPermalinks.model.allLinks.findIndex(
|
||||||
(permalink) => permalink.id === this.args.permalink.id
|
(permalink) => permalink.id === this.args.permalink.id
|
||||||
);
|
);
|
||||||
this.adminPermalinks.model[index] = Permalink.create(result.payload);
|
this.adminPermalinks.model.allLinks[index] = Permalink.create(
|
||||||
|
result.payload
|
||||||
|
);
|
||||||
this.router.transitionTo("adminPermalinks");
|
this.router.transitionTo("adminPermalinks");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
popupAjaxError(error);
|
popupAjaxError(error);
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default class AdminPermalinksIndexController extends Controller {
|
||||||
didConfirm: async () => {
|
didConfirm: async () => {
|
||||||
try {
|
try {
|
||||||
await this.store.destroyRecord("permalink", permalink);
|
await this.store.destroyRecord("permalink", permalink);
|
||||||
this.model.removeObject(permalink);
|
this.model.allLinks.removeObject(permalink);
|
||||||
} catch {
|
} catch {
|
||||||
this.dialog.alert(i18n("generic_error"));
|
this.dialog.alert(i18n("generic_error"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,16 @@ import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
export default class Permalink extends RestModel {
|
export default class Permalink extends RestModel {
|
||||||
static findAll(filter) {
|
static findAll(filter) {
|
||||||
return ajax("/admin/permalinks.json", { data: { filter } }).then(function (
|
return ajax("/admin/permalinks.json").then(function (permalinks) {
|
||||||
permalinks
|
let allLinks = permalinks.map((p) => Permalink.create(p));
|
||||||
) {
|
|
||||||
return permalinks.map((p) => Permalink.create(p));
|
let filteredLinks = filter
|
||||||
|
? allLinks.filter(
|
||||||
|
(p) => p.url.includes(filter) || p.external_url?.includes(filter)
|
||||||
|
)
|
||||||
|
: allLinks;
|
||||||
|
|
||||||
|
return { allLinks, filteredLinks };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
<ConditionalLoadingSpinner @condition={{this.loading}}>
|
<ConditionalLoadingSpinner @condition={{this.loading}}>
|
||||||
<div class="d-admin-filter">
|
{{#if this.model.allLinks.length}}
|
||||||
<div class="admin-filter__input-container permalink-search">
|
<div class="d-admin-filter">
|
||||||
<TextField
|
<div class="admin-filter__input-container permalink-search">
|
||||||
@value={{this.filter}}
|
<TextField
|
||||||
@placeholderKey="admin.permalink.form.filter"
|
@value={{this.filter}}
|
||||||
@autocorrect="off"
|
@placeholderKey="admin.permalink.form.filter"
|
||||||
@autocapitalize="off"
|
@autocorrect="off"
|
||||||
class="admin-filter__input"
|
@autocapitalize="off"
|
||||||
/>
|
class="admin-filter__input"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{{/if}}
|
||||||
|
|
||||||
<div class="permalink-results">
|
<div class="permalink-results">
|
||||||
{{#if this.model.length}}
|
{{#if this.model.filteredLinks.length}}
|
||||||
<table class="d-admin-table permalinks">
|
<table class="d-admin-table permalinks">
|
||||||
<thead>
|
<thead>
|
||||||
<th>{{i18n "admin.permalink.url"}}</th>
|
<th>{{i18n "admin.permalink.url"}}</th>
|
||||||
<th>{{i18n "admin.permalink.destination"}}</th>
|
<th>{{i18n "admin.permalink.destination"}}</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#each this.model as |pl|}}
|
{{#each this.model.filteredLinks as |pl|}}
|
||||||
<tr
|
<tr
|
||||||
class={{concat-class
|
class={{concat-class
|
||||||
"admin-permalink-item d-admin-row__content"
|
"admin-permalink-item d-admin-row__content"
|
||||||
|
|
|
@ -26,10 +26,8 @@ acceptance("Admin - Permalinks", function (needs) {
|
||||||
|
|
||||||
needs.user();
|
needs.user();
|
||||||
needs.pretender((server, helper) => {
|
needs.pretender((server, helper) => {
|
||||||
server.get("/admin/permalinks.json", (response) => {
|
server.get("/admin/permalinks.json", () => {
|
||||||
const result =
|
return helper.response(200, startingData);
|
||||||
response.queryParams.filter !== "feature" ? [] : startingData;
|
|
||||||
return helper.response(200, result);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ describe "Admin Permalinks Page", type: :system do
|
||||||
|
|
||||||
it "allows admin to create, edit, and destroy permalink" do
|
it "allows admin to create, edit, and destroy permalink" do
|
||||||
admin_permalinks_page.visit
|
admin_permalinks_page.visit
|
||||||
|
expect(admin_permalinks_page).to have_no_filter
|
||||||
|
|
||||||
admin_permalinks_page.click_add_permalink
|
admin_permalinks_page.click_add_permalink
|
||||||
admin_permalink_form_page
|
admin_permalink_form_page
|
||||||
.fill_in_url("test")
|
.fill_in_url("test")
|
||||||
|
@ -18,6 +20,13 @@ describe "Admin Permalinks Page", type: :system do
|
||||||
.fill_in_category("1")
|
.fill_in_category("1")
|
||||||
.click_save
|
.click_save
|
||||||
expect(admin_permalinks_page).to have_permalinks("test")
|
expect(admin_permalinks_page).to have_permalinks("test")
|
||||||
|
expect(admin_permalinks_page).to have_filter
|
||||||
|
|
||||||
|
admin_permalinks_page.filter("no results")
|
||||||
|
expect(admin_permalinks_page).to have_no_results
|
||||||
|
expect(admin_permalinks_page).to have_filter
|
||||||
|
|
||||||
|
admin_permalinks_page.filter("")
|
||||||
|
|
||||||
admin_permalinks_page.click_edit_permalink("test")
|
admin_permalinks_page.click_edit_permalink("test")
|
||||||
admin_permalink_form_page.fill_in_url("test2").click_save
|
admin_permalink_form_page.fill_in_url("test2").click_save
|
||||||
|
|
|
@ -41,6 +41,22 @@ module PageObjects
|
||||||
has_no_css?(".admin-permalink-item__url")
|
has_no_css?(".admin-permalink-item__url")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_no_filter?
|
||||||
|
has_no_css?(".permalink-search")
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_filter?
|
||||||
|
has_css?(".permalink-search")
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter(text)
|
||||||
|
find(".permalink-search").fill_in with: text
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_no_results?
|
||||||
|
has_css?(".permalink-results__no-result")
|
||||||
|
end
|
||||||
|
|
||||||
def open_permalink_menu(url)
|
def open_permalink_menu(url)
|
||||||
find("tr.#{url} .permalink-menu-trigger").click
|
find("tr.#{url} .permalink-menu-trigger").click
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in New Issue
Block a user