Skip to content

Commit

Permalink
DEV: Rename Custom_header_links settings to custom_header_links (#45
Browse files Browse the repository at this point in the history
)

Why this change?

Using uppercase in settings name is not part of our convention so
renaming it here.
  • Loading branch information
tgxworld authored Jan 26, 2024
1 parent 916b1ff commit 5006125
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions javascripts/discourse/components/custom-header-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { dasherize } from "@ember/string";

export default class CustomHeaderLinks extends Component {
get shouldShow() {
return settings.Custom_header_links?.length > 0;
return settings.custom_header_links?.length > 0;
}

get links() {
return settings.Custom_header_links.split("|").reduce((result, item) => {
return settings.custom_header_links.split("|").reduce((result, item) => {
let [
linkText,
linkTitle,
Expand Down
8 changes: 8 additions & 0 deletions migrations/settings/0001-rename-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function migrate(settings) {
if (settings.has("Custom_header_links")) {
settings.set("custom_header_links", settings.get("Custom_header_links"));
settings.delete("Custom_header_links");
}

return settings;
}
2 changes: 1 addition & 1 deletion settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Custom_header_links:
custom_header_links:
type: list
list_type: simple
default: "External link, this link will open in a new tab, https://meta.discourse.org, vdo, blank, remove|Most Liked, Posts with the most amount of likes, /latest/?order=op_likes, vdo, self, keep|Privacy, Our Privacy Policy, /privacy, vdm, self, keep"
Expand Down
25 changes: 25 additions & 0 deletions test/unit/migrations/settings/0001-rename-settings-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { module, test } from "qunit";
import migrate from "../../../../migrations/settings/0001-rename-settings";

module("Unit | Migrations | Settings | 0001-rename-settings", function () {
test("migrate", function (assert) {
const settings = new Map(
Object.entries({
Custom_header_links: "some,links",
})
);

const result = migrate(settings);

assert.deepEqual(
Array.from(result),
Array.from(
new Map(
Object.entries({
custom_header_links: "some,links",
})
)
)
);
});
});

2 comments on commit 5006125

@nolosb
Copy link

@nolosb nolosb commented on 5006125 Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the settings name resets values to defaults. Or rather, which is a bit more confusing: It uses the new default values, but the old ones are still shown on the ui. I had to copy my previous settings, then reset, then paste the previous settings to show it correctly again on the ui.
Maybe add a note on the meta topic about this change?

@damienalexandre
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeaaah same here, header completely destroyed overnight, had to re-enter all the settings manually 🚨 🚨 🚨

Please sign in to comment.