DEV: Update linting (#22)

* drop jQ

* qunit-dom

* convert the button to gjs

* use the store

---------

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
David Taylor 2024-03-28 10:12:48 +00:00 committed by GitHub
parent d0c50fcbaa
commit 1902277ff0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 1394 additions and 744 deletions

View File

@ -1,8 +0,0 @@
{
"extends": "eslint-config-discourse",
"ignorePatterns": ["javascripts/vendor/*"],
"globals": {
"settings": "readonly",
"themePrefix": "readonly"
}
}

1
.eslintrc.cjs Normal file
View File

@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/eslint-theme");

View File

@ -1 +0,0 @@
{}

1
.prettierrc.cjs Normal file
View File

@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/prettier");

1
.template-lintrc.cjs Normal file
View File

@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/template-lint");

View File

@ -1,4 +0,0 @@
module.exports = {
plugins: ["ember-template-lint-plugin-discourse"],
extends: "discourse:recommended",
};

View File

@ -0,0 +1,32 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
export default class UserCardDirectoryToggle extends Component {
@service router;
get showingCards() {
const { cards } = this.router.currentRoute.queryParams;
return (
cards === "yes" ||
(cards === undefined && settings.default_view === "cards")
);
}
@action
toggleCards() {
const newValue = this.showingCards ? "no" : "yes";
this.router.transitionTo({ queryParams: { cards: newValue } });
}
<template>
<DButton
@action={{this.toggleCards}}
@icon={{if this.showingCards "th-list" "id-card"}}
@title={{themePrefix (if this.showingCards "show_table" "show_cards")}}
class="btn-default open-edit-columns-btn toggle-cards-button"
/>
</template>
}

View File

@ -1,6 +0,0 @@
{{d-button
icon=(if showingCards "th-list" "id-card")
action=(action "toggleCards")
title=(theme-prefix (if showingCards "show_table" "show_cards"))
class="btn-default open-edit-columns-btn toggle-cards-button"
}}

View File

@ -1,23 +0,0 @@
import Component from "@ember/component";
import { inject as service } from "@ember/service";
import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({
router: service("router"),
tagName: "",
@discourseComputed("router.currentRoute.queryParams.cards")
showingCards(cardsParam) {
return (
cardsParam === "yes" ||
(cardsParam === undefined && settings.default_view === "cards")
);
},
actions: {
toggleCards() {
const newValue = this.showingCards ? "no" : "yes";
this.router.transitionTo({ queryParams: { cards: newValue } });
},
},
});

View File

@ -1,12 +1,14 @@
import UserCardContents from "discourse/components/user-card-contents";
import { action } from "@ember/object"; import { action } from "@ember/object";
import UserCardContents from "discourse/components/user-card-contents";
export default UserCardContents.extend({ export default UserCardContents.extend({
layoutName: "components/user-card-contents", layoutName: "components/user-card-contents",
elementId: null, elementId: null,
// Overriding functions which cause the user card to show/hide based on mouse/keyboard events: // Overriding functions which cause the user card to show/hide based on mouse/keyboard events:
cleanUp() {}, cleanUp() {},
// eslint-disable-next-line ember/require-super-in-lifecycle-hooks
didInsertElement() {}, didInsertElement() {},
// eslint-disable-next-line ember/require-super-in-lifecycle-hooks
willDestroyElement() {}, willDestroyElement() {},
keyUp() {}, keyUp() {},

View File

@ -1,9 +1,8 @@
import { withPluginApi } from "discourse/lib/plugin-api";
import discourseComputed from "discourse-common/utils/decorators";
import User from "discourse/models/user";
import EmberObject, { action } from "@ember/object"; import EmberObject, { action } from "@ember/object";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { withPluginApi } from "discourse/lib/plugin-api";
import DiscourseURL, { userPath } from "discourse/lib/url"; import DiscourseURL, { userPath } from "discourse/lib/url";
import discourseComputed from "discourse-common/utils/decorators";
export default { export default {
name: "user-card-directory", name: "user-card-directory",
@ -67,7 +66,7 @@ export default {
const userCardInfo = (this.cachedUserCardInfo[u.id] = const userCardInfo = (this.cachedUserCardInfo[u.id] =
EmberObject.create({ EmberObject.create({
user: User.create(u.user), user: this.store.createRecord("user", u.user),
directoryItem: u, directoryItem: u,
loading: true, loading: true,
})); }));

View File

@ -1,4 +1,5 @@
{{#d-section pageClass="users"}} {{body-class "users-page"}}
<section>
{{#load-more {{#load-more
selector=".user-card-directory .user-card-container" selector=".user-card-directory .user-card-container"
action=(action "loadMore") action=(action "loadMore")
@ -32,7 +33,7 @@
</label> </label>
<Input <Input
@value={{readonly emailInput}} @value={{readonly emailInput}}
placeholder={{I18n "directory.filter_name"}} placeholder={{i18n "directory.filter_name"}}
class="filter-name no-blur" class="filter-name no-blur"
{{on {{on
"input" "input"
@ -126,4 +127,4 @@
</div> </div>
</div> </div>
{{/load-more}} {{/load-more}}
{{/d-section}} </section>

View File

@ -1,10 +1,9 @@
{ {
"name": "discourse-user-card-directory", "private": true,
"version": "1.0.0",
"repository": "https://github.com/discourse/discourse-user-card-directory",
"author": "Discourse",
"license": "MIT",
"devDependencies": { "devDependencies": {
"eslint-config-discourse": "^3.2.0" "@discourse/lint-configs": "^1.3.7",
"ember-template-lint": "^5.13.0",
"eslint": "^8.56.0",
"prettier": "^2.8.8"
} }
} }

View File

@ -1,6 +1,6 @@
import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("User Card Directory", function (needs) { acceptance("User Card Directory", function (needs) {
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
@ -132,33 +132,31 @@ acceptance("User Card Directory", function (needs) {
test("Displays table when cards=no", async function (assert) { test("Displays table when cards=no", async function (assert) {
await visit("/u?cards=no"); await visit("/u?cards=no");
assert.ok($("body.users-page").length, "has the body class"); assert.dom(document.body).hasClass(/users-page/);
assert.equal( assert
count(".directory .directory-table__row"), .dom(".directory .directory-table__row")
2, .exists({ count: 2 }, "has a list of users");
"has a list of users"
);
}); });
test("Displays cards when cards=yes", async function (assert) { test("Displays cards when cards=yes", async function (assert) {
await visit("/u?cards=yes"); await visit("/u?cards=yes");
assert.equal(count(".user-card-avatar"), 2, "has two cards showing"); assert
.dom(".user-card-avatar")
.exists({ count: 2 }, "has two cards showing");
}); });
test("Can toggle between views", async function (assert) { test("Can toggle between views", async function (assert) {
await visit("/u?cards=no"); await visit("/u?cards=no");
assert.equal( assert
count(".directory .directory-table__row"), .dom(".directory .directory-table__row")
2, .exists({ count: 2 }, "has two table rows");
"has two table rows"
);
await click(".toggle-cards-button"); await click(".toggle-cards-button");
assert.equal(count(".user-card-avatar"), 2, "has two cards"); assert.dom(".user-card-avatar").exists({ count: 2 }, "has two cards");
await click(".toggle-cards-button"); await click(".toggle-cards-button");
assert.equal( assert
count(".directory .directory-table__row"), .dom(".directory .directory-table__row")
2, .exists({ count: 2 }, "has two table rows");
"has two table rows"
);
}); });
}); });

1994
yarn.lock

File diff suppressed because it is too large Load Diff