FIX: Permalinks issues (#18939)

This commit is contained in:
Keegan George 2022-11-09 11:23:08 -08:00 committed by GitHub
parent 4dad7816b2
commit 4ae288367e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 114 additions and 48 deletions

View File

@ -6,11 +6,13 @@ import discourseDebounce from "discourse-common/lib/debounce";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
import { clipboardCopy } from "discourse/lib/utilities"; import { clipboardCopy } from "discourse/lib/utilities";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import { or } from "@ember/object/computed";
export default Controller.extend({ export default Controller.extend({
dialog: service(), dialog: service(),
loading: false, loading: false,
filter: null, filter: null,
showSearch: or("model.length", "filter"),
_debouncedShow() { _debouncedShow() {
Permalink.findAll(this.filter).then((result) => { Permalink.findAll(this.filter).then((result) => {

View File

@ -6,8 +6,8 @@
<ComboBox @content={{this.permalinkTypes}} @value={{this.permalinkType}} @onChange={{action (mut this.permalinkType)}} @class="permalink-type" /> <ComboBox @content={{this.permalinkTypes}} @value={{this.permalinkType}} @onChange={{action (mut this.permalinkType)}} @class="permalink-type" />
<TextField @value={{this.permalinkTypeValue}} @disabled={{this.formSubmitted}} @placeholderKey={{this.permalinkTypePlaceholder}} @autocorrect="off" @autocapitalize="off" @keyDown={{action "submitFormOnEnter"}} /> <TextField @value={{this.permalinkTypeValue}} @disabled={{this.formSubmitted}} @class="permalink-destination" @placeholderKey={{this.permalinkTypePlaceholder}} @autocorrect="off" @autocapitalize="off" @keyDown={{action "submitFormOnEnter"}} />
<DButton @action={{action "onSubmit"}} @disabled={{this.formSubmitted}} @label="admin.permalink.form.add" /> <DButton @action={{action "onSubmit"}} @disabled={{this.formSubmitted}} @class="permalink-add" @label="admin.permalink.form.add" />
</div> </div>
</div> </div>

View File

@ -6,51 +6,58 @@
<PermalinkForm @action={{action "recordAdded"}} /> <PermalinkForm @action={{action "recordAdded"}} />
<ConditionalLoadingSpinner @condition={{this.loading}}> <ConditionalLoadingSpinner @condition={{this.loading}}>
{{#if this.model.length}} <div class="permalink-search">
<div class="permalink-search"> <TextField @value={{this.filter}} @class="url-input" @placeholderKey="admin.permalink.form.filter" @autocorrect="off" @autocapitalize="off" />
<TextField @value={{this.filter}} @class="url-input" @placeholderKey="admin.permalink.form.filter" @autocorrect="off" @autocapitalize="off" /> </div>
</div>
<table class="admin-logs-table permalinks grid"> <div class="permalink-results">
<thead class="heading-container"> {{#if this.model.length}}
<th class="col heading first url">{{i18n "admin.permalink.url"}}</th> <table class="admin-logs-table permalinks grid">
<th class="col heading destination">{{i18n "admin.permalink.destination"}}</th> <thead class="heading-container">
<th class="col heading actions"></th> <th class="col heading first url">{{i18n "admin.permalink.url"}}</th>
</thead> <th class="col heading destination">{{i18n "admin.permalink.destination"}}</th>
<tbody> <th class="col heading actions"></th>
{{#each this.model as |pl|}} </thead>
<tr class="admin-list-item"> <tbody>
<td class="col first url"> {{#each this.model as |pl|}}
<FlatButton @title="admin.permalink.copy_to_clipboard" @icon="far-clipboard" @action={{action "copyUrl" pl}} /> <tr class="admin-list-item">
<span id="admin-permalink-{{pl.id}}" title={{pl.url}}>{{pl.url}}</span> <td class="col first url">
</td> <FlatButton @title="admin.permalink.copy_to_clipboard" @icon="far-clipboard" @action={{action "copyUrl" pl}} />
<td class="col destination"> <span id="admin-permalink-{{pl.id}}" title={{pl.url}}>{{pl.url}}</span>
{{#if pl.topic_id}} </td>
<a href={{pl.topic_url}}>{{pl.topic_title}}</a> <td class="col destination">
{{/if}} {{#if pl.topic_id}}
{{#if pl.post_id}} <a href={{pl.topic_url}}>{{pl.topic_title}}</a>
<a href={{pl.post_url}}>{{pl.post_topic_title}} #{{pl.post_number}}</a>
{{/if}}
{{#if pl.category_id}}
{{category-link pl.category}}
{{/if}}
{{#if pl.tag_id}}
<a href={{pl.tag_url}}>{{pl.tag_name}}</a>
{{/if}}
{{#if pl.external_url}}
{{#if pl.linkIsExternal}}
{{d-icon "external-link-alt"}}
{{/if}} {{/if}}
<a href={{pl.external_url}}>{{pl.external_url}}</a> {{#if pl.post_id}}
{{/if}} <a href={{pl.post_url}}>{{pl.post_topic_title}} #{{pl.post_number}}</a>
</td> {{/if}}
<td class="col action" style="text-align: right;"> {{#if pl.category_id}}
<DButton @action={{action "destroy"}} @actionParam={{pl}} @icon="far-trash-alt" @class="btn-danger" /> {{category-link pl.category}}
</td> {{/if}}
</tr> {{#if pl.tag_id}}
{{/each}} <a href={{pl.tag_url}}>{{pl.tag_name}}</a>
</tbody> {{/if}}
</table> {{#if pl.external_url}}
{{else}} {{#if pl.linkIsExternal}}
{{i18n "search.no_results"}} {{d-icon "external-link-alt"}}
{{/if}} {{/if}}
<a href={{pl.external_url}}>{{pl.external_url}}</a>
{{/if}}
</td>
<td class="col action" style="text-align: right;">
<DButton @action={{action "destroy"}} @actionParam={{pl}} @icon="far-trash-alt" @class="btn-danger" />
</td>
</tr>
{{/each}}
</tbody>
</table>
{{else}}
{{#if this.filter}}
<p class="permalink-results__no-result">{{i18n "search.no_results"}}</p>
{{else}}
<p class="permalink-results__no-permalinks">{{i18n "admin.permalink.no_permalinks"}}</p>
{{/if}}
{{/if}}
</div>
</ConditionalLoadingSpinner> </ConditionalLoadingSpinner>

View File

@ -0,0 +1,56 @@
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
acceptance("Admin - Permalinks", function (needs) {
const startingData = [
{
id: 38,
url: "c/feature/announcements",
topic_id: null,
topic_title: null,
topic_url: null,
post_id: null,
post_url: null,
post_number: null,
post_topic_title: null,
category_id: 67,
category_name: "announcements",
category_url: "/c/announcements/67",
external_url: null,
tag_id: null,
tag_name: null,
tag_url: null,
},
];
needs.user();
needs.pretender((server, helper) => {
server.get("/admin/permalinks.json", (response) => {
const result =
response.queryParams.filter !== "feature" ? [] : startingData;
return helper.response(200, result);
});
});
test("search permalinks with result", async function (assert) {
await visit("/admin/customize/permalinks");
await fillIn(".permalink-search input", "feature");
assert.ok(
exists(".permalink-results span[title='c/feature/announcements']"),
"permalink is found after search"
);
});
test("search permalinks without results", async function (assert) {
await visit("/admin/customize/permalinks");
await fillIn(".permalink-search input", "garboogle");
assert.ok(
exists(".permalink-results__no-result"),
"no results message shown"
);
assert.ok(exists(".permalink-search"), "search input still visible");
});
});

View File

@ -5839,6 +5839,7 @@ en:
destination: "Destination" destination: "Destination"
copy_to_clipboard: "Copy Permalink to Clipboard" copy_to_clipboard: "Copy Permalink to Clipboard"
delete_confirm: Are you sure you want to delete this permalink? delete_confirm: Are you sure you want to delete this permalink?
no_permalinks: "You don't have any permalinks yet. Create a new permalink above to begin seeing a list of your permalinks here."
form: form:
label: "New:" label: "New:"
add: "Add" add: "Add"