UX: redesign admin permalinks page (#29634)

Redesign the permalinks page to follow the UX guide. In addition, the ability to edit permalinks was added.

This change includes:
- move to RestModel
- added Validations
- update endpoint and clear old values after the update
- system specs and improvements for unit tests
This commit is contained in:
Krzysztof Kotlarek
2024-11-14 10:03:58 +11:00
committed by GitHub
parent b37f6f1edb
commit 42b1ca8f78
29 changed files with 924 additions and 239 deletions

View File

@ -10,10 +10,20 @@ RSpec.describe Admin::PermalinksController do
before { sign_in(admin) }
it "filters url" do
Fabricate(:permalink, url: "/forum/23")
Fabricate(:permalink, url: "/forum/98")
Fabricate(:permalink, url: "/discuss/topic/45")
Fabricate(:permalink, url: "/discuss/topic/76")
Fabricate(:permalink, url: "/forum/23", permalink_type_value: "1", permalink_type: "topic")
Fabricate(:permalink, url: "/forum/98", permalink_type_value: "1", permalink_type: "topic")
Fabricate(
:permalink,
url: "/discuss/topic/45",
permalink_type_value: "1",
permalink_type: "topic",
)
Fabricate(
:permalink,
url: "/discuss/topic/76",
permalink_type_value: "1",
permalink_type: "topic",
)
get "/admin/permalinks.json", params: { filter: "topic" }
@ -23,10 +33,26 @@ RSpec.describe Admin::PermalinksController do
end
it "filters external url" do
Fabricate(:permalink, external_url: "http://google.com")
Fabricate(:permalink, external_url: "http://wikipedia.org")
Fabricate(:permalink, external_url: "http://www.discourse.org")
Fabricate(:permalink, external_url: "http://try.discourse.org")
Fabricate(
:permalink,
permalink_type_value: "http://google.com",
permalink_type: "external_url",
)
Fabricate(
:permalink,
permalink_type_value: "http://wikipedia.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
permalink_type_value: "http://www.discourse.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
permalink_type_value: "http://try.discourse.org",
permalink_type: "external_url",
)
get "/admin/permalinks.json", params: { filter: "discourse" }
@ -36,10 +62,30 @@ RSpec.describe Admin::PermalinksController do
end
it "filters url and external url both" do
Fabricate(:permalink, url: "/forum/23", external_url: "http://google.com")
Fabricate(:permalink, url: "/discourse/98", external_url: "http://wikipedia.org")
Fabricate(:permalink, url: "/discuss/topic/45", external_url: "http://discourse.org")
Fabricate(:permalink, url: "/discuss/topic/76", external_url: "http://try.discourse.org")
Fabricate(
:permalink,
url: "/forum/23",
permalink_type_value: "http://google.com",
permalink_type: "external_url",
)
Fabricate(
:permalink,
url: "/discourse/98",
permalink_type_value: "http://wikipedia.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
url: "/discuss/topic/45",
permalink_type_value: "http://discourse.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
url: "/discuss/topic/76",
permalink_type_value: "http://try.discourse.org",
permalink_type: "external_url",
)
get "/admin/permalinks.json", params: { filter: "discourse" }
@ -80,9 +126,11 @@ RSpec.describe Admin::PermalinksController do
post "/admin/permalinks.json",
params: {
url: "/topics/771",
permalink_type: "topic_id",
permalink_type_value: topic.id,
permalink: {
url: "/topics/771",
permalink_type: "topic",
permalink_type_value: topic.id,
},
}
expect(response.status).to eq(200)
@ -102,9 +150,11 @@ RSpec.describe Admin::PermalinksController do
post "/admin/permalinks.json",
params: {
url: "/topics/771/8291",
permalink_type: "post_id",
permalink_type_value: some_post.id,
permalink: {
url: "/topics/771/8291",
permalink_type: "post",
permalink_type_value: some_post.id,
},
}
expect(response.status).to eq(200)
@ -124,9 +174,11 @@ RSpec.describe Admin::PermalinksController do
post "/admin/permalinks.json",
params: {
url: "/forums/11",
permalink_type: "category_id",
permalink_type_value: category.id,
permalink: {
url: "/forums/11",
permalink_type: "category",
permalink_type_value: category.id,
},
}
expect(response.status).to eq(200)
@ -146,9 +198,11 @@ RSpec.describe Admin::PermalinksController do
post "/admin/permalinks.json",
params: {
url: "/forums/12",
permalink_type: "tag_name",
permalink_type_value: tag.name,
permalink: {
url: "/forums/12",
permalink_type: "tag",
permalink_type_value: tag.name,
},
}
expect(response.status).to eq(200)
@ -168,9 +222,11 @@ RSpec.describe Admin::PermalinksController do
post "/admin/permalinks.json",
params: {
url: "/people/42",
permalink_type: "user_id",
permalink_type_value: user.id,
permalink: {
url: "/people/42",
permalink_type: "user",
permalink_type_value: user.id,
},
}
expect(response.status).to eq(200)
@ -193,9 +249,11 @@ RSpec.describe Admin::PermalinksController do
expect do
post "/admin/permalinks.json",
params: {
url: "/topics/771",
permalink_type: "topic_id",
permalink_type_value: topic.id,
permalink: {
url: "/topics/771",
permalink_type: "topic",
permalink_type_value: topic.id,
},
}
end.not_to change { Permalink.count }