From 50061254831a658eba821238a8a1ae0b7029ab09 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 26 Jan 2024 10:15:41 +0800 Subject: [PATCH] DEV: Rename `Custom_header_links` settings to `custom_header_links` (#45) Why this change? Using uppercase in settings name is not part of our convention so renaming it here. --- .../components/custom-header-links.js | 4 +-- migrations/settings/0001-rename-settings.js | 8 ++++++ settings.yml | 2 +- .../settings/0001-rename-settings-test.js | 25 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 migrations/settings/0001-rename-settings.js create mode 100644 test/unit/migrations/settings/0001-rename-settings-test.js diff --git a/javascripts/discourse/components/custom-header-links.js b/javascripts/discourse/components/custom-header-links.js index 934559f..90b7a2d 100644 --- a/javascripts/discourse/components/custom-header-links.js +++ b/javascripts/discourse/components/custom-header-links.js @@ -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, diff --git a/migrations/settings/0001-rename-settings.js b/migrations/settings/0001-rename-settings.js new file mode 100644 index 0000000..fe5cf67 --- /dev/null +++ b/migrations/settings/0001-rename-settings.js @@ -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; +} diff --git a/settings.yml b/settings.yml index 063d5c7..3c7f568 100644 --- a/settings.yml +++ b/settings.yml @@ -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" diff --git a/test/unit/migrations/settings/0001-rename-settings-test.js b/test/unit/migrations/settings/0001-rename-settings-test.js new file mode 100644 index 0000000..4572b11 --- /dev/null +++ b/test/unit/migrations/settings/0001-rename-settings-test.js @@ -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", + }) + ) + ) + ); + }); +});