-
Notifications
You must be signed in to change notification settings - Fork 16
DEV: migratre to objects setting, fix mobile CSS #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| en: | ||
| theme_metadata: | ||
| settings: | ||
| nav_links: | ||
| description: Custom links to display in the topic list navigation | ||
| schema: | ||
| properties: | ||
| display_name: | ||
| label: Display name | ||
| description: The text that shows on the menu | ||
| title: | ||
| label: Title | ||
| description: The text that shows on hover | ||
| url: | ||
| label: URL | ||
| description: The link (e.g., /latest or https://discourse.org) |
|
awesomerobot marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| export default function migrate(settings) { | ||
| if (!settings.has("Nav_links")) { | ||
| return settings; | ||
| } | ||
|
|
||
| const oldValue = settings.get("Nav_links"); | ||
| settings.delete("Nav_links"); | ||
|
|
||
| if (Array.isArray(oldValue)) { | ||
| settings.set("nav_links", oldValue); | ||
| return settings; | ||
| } | ||
|
|
||
| if (typeof oldValue === "string") { | ||
| const newLinks = []; | ||
|
|
||
| oldValue.split("|").forEach((link) => { | ||
| const [displayName, title, url] = link | ||
| .split(";") | ||
| .map((section) => section.trim()); | ||
|
|
||
| if (displayName && url) { | ||
| const newLink = { display_name: displayName, url }; | ||
|
|
||
| if (title) { | ||
| newLink.title = title; | ||
| } | ||
|
|
||
| newLinks.push(newLink); | ||
| } | ||
| }); | ||
|
|
||
| settings.set("nav_links", newLinks); | ||
| } | ||
|
|
||
| return settings; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
test/unit/migrations/settings/0001-migrate-nav-links-to-objects-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { module, test } from "qunit"; | ||
| import migrate from "../../../../migrations/settings/0001-migrate-nav-links-to-objects"; | ||
|
|
||
| module( | ||
| "Custom Top Navigation Links | Migrations | Settings | 0001-migrate-nav-links-to-objects", | ||
| function () { | ||
| test("does nothing when the old setting is not present", function (assert) { | ||
| const settings = new Map(Object.entries({ Hide_dropdowns: true })); | ||
|
|
||
| const result = migrate(settings); | ||
|
|
||
| assert.deepEqual( | ||
| Object.fromEntries(result.entries()), | ||
| Object.fromEntries(new Map(Object.entries({ Hide_dropdowns: true }))) | ||
| ); | ||
| }); | ||
|
|
||
| test("migrate when value of setting is already an array", function (assert) { | ||
| const links = [ | ||
| { | ||
| display_name: "Latest", | ||
| title: "topics with recent posts", | ||
| url: "/latest", | ||
| }, | ||
| ]; | ||
| const settings = new Map(Object.entries({ Nav_links: links })); | ||
|
|
||
| const result = migrate(settings); | ||
|
|
||
| assert.deepEqual( | ||
| Object.fromEntries(result.entries()), | ||
| Object.fromEntries(new Map(Object.entries({ nav_links: links }))) | ||
| ); | ||
| }); | ||
|
|
||
| test("migrate when old setting value is an empty string", function (assert) { | ||
| const settings = new Map(Object.entries({ Nav_links: "" })); | ||
|
|
||
| const result = migrate(settings); | ||
|
|
||
| assert.deepEqual( | ||
| Object.fromEntries(result.entries()), | ||
| Object.fromEntries(new Map(Object.entries({ nav_links: [] }))) | ||
| ); | ||
| }); | ||
|
|
||
| test("migrate when old setting value is invalid", function (assert) { | ||
| const settings = new Map( | ||
| Object.entries({ | ||
| Nav_links: "Missing URL|Missing URL 2;some title|;;/no-name", | ||
| }) | ||
| ); | ||
|
|
||
| const result = migrate(settings); | ||
|
|
||
| assert.deepEqual( | ||
| Object.fromEntries(result.entries()), | ||
| Object.fromEntries(new Map(Object.entries({ nav_links: [] }))) | ||
| ); | ||
| }); | ||
|
|
||
| test("migrate when title is not provided", function (assert) { | ||
| const settings = new Map( | ||
| Object.entries({ | ||
| Nav_links: "External link;;https://meta.discourse.org", | ||
| }) | ||
| ); | ||
|
|
||
| const result = migrate(settings); | ||
|
|
||
| assert.deepEqual( | ||
| Object.fromEntries(result.entries()), | ||
| Object.fromEntries( | ||
| new Map( | ||
| Object.entries({ | ||
| nav_links: [ | ||
| { | ||
| display_name: "External link", | ||
| url: "https://meta.discourse.org", | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ) | ||
| ); | ||
| }); | ||
|
|
||
| test("migrate", function (assert) { | ||
| const settings = new Map( | ||
| Object.entries({ | ||
| Nav_links: | ||
| "Latest;topics with recent posts;/latest|Categories;all topics grouped by category;/categories|Top;the most active topics in the last year, month, week or day;/top", | ||
| }) | ||
| ); | ||
|
|
||
| const result = migrate(settings); | ||
|
|
||
| assert.deepEqual( | ||
| Object.fromEntries(result.entries()), | ||
| Object.fromEntries( | ||
| new Map( | ||
| Object.entries({ | ||
| nav_links: [ | ||
| { | ||
| display_name: "Latest", | ||
| title: "topics with recent posts", | ||
| url: "/latest", | ||
| }, | ||
| { | ||
| display_name: "Categories", | ||
| title: "all topics grouped by category", | ||
| url: "/categories", | ||
| }, | ||
| { | ||
| display_name: "Top", | ||
| title: | ||
| "the most active topics in the last year, month, week or day", | ||
| url: "/top", | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ) | ||
| ); | ||
| }); | ||
| } | ||
| ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great