Skip to content

Commit d8b1039

Browse files
MitanOmarczosel
andauthored
fix(document-card): selected color (#1026)
* fix(document-card): selected color * feat: save the status of documents view in the query parameter * fix(document-view): tests after adding `listView` to query URL * refactor(index-router): don't refresh the modal when `listView` update * chore: refactor tests * fix(document-view-test): remove unused vars --------- Co-authored-by: Christian Zosel <christian@zosel.ch>
1 parent 6dacc65 commit d8b1039

File tree

8 files changed

+19
-27
lines changed

8 files changed

+19
-27
lines changed

addon/components/document-view.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/>
2222

2323
<DocumentViewToggle
24-
@viewList={{this.listView}}
24+
@viewList={{@listView}}
2525
data-test-toggle-side-panel
2626
{{on "click" this.toggleView}}
2727
/>
@@ -45,7 +45,7 @@
4545
{{did-insert (perform this.initialiseDocumentSelection)}}
4646
>
4747
{{! List & Grid View }}
48-
{{#if this.listView}}
48+
{{#if @listView}}
4949
<DocumentList
5050
@columns={{this.tableColumns}}
5151
@loading={{this.fetchedDocuments.isRunning}}

addon/components/document-view.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default class DocumentViewComponent extends Component {
1515

1616
@tracked isDragOver = false;
1717
@tracked dragCounter = 0;
18-
@tracked listView = true;
1918
@tracked sort = "title";
2019
@tracked sortDirection = "";
2120
// Needed for ember-resource
@@ -37,7 +36,9 @@ export default class DocumentViewComponent extends Component {
3736
}
3837

3938
@action toggleView() {
40-
this.listView = !this.listView;
39+
this.router.transitionTo(this.router.currentRouteName, {
40+
queryParams: { listView: !this.args.listView },
41+
});
4142
}
4243

4344
@action setSort(sortAttribute) {

addon/controllers/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class IndexController extends Controller {
1111
"document",
1212
"activeGroup",
1313
"sort",
14+
"listView",
1415
];
1516

1617
@service("alexandria-config") config;
@@ -22,6 +23,7 @@ export default class IndexController extends Controller {
2223
@tracked document;
2324
@tracked activeGroup;
2425
@tracked sort;
26+
@tracked listView = true;
2527

2628
get documentFilters() {
2729
let filters = {

addon/routes/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class IndexRoute extends Route {
1212
search: PARAM_OPTIONS,
1313
document: PARAM_OPTIONS,
1414
activeGroup: PARAM_OPTIONS,
15+
listView: {},
1516
};
1617

1718
@service("alexandria-config") config;

addon/templates/index.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<DocumentView
99
@filters={{this.documentFilters}}
10+
@listView={{this.listView}}
1011
class="uk-border-top"
1112
/>
1213
</section>

app/styles/components/_document-card.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
}
3939

4040
&--selected {
41-
border-color: $global-primary-background;
41+
border-color: $global-primary-background !important;
42+
border-width: 3px !important;
4243
}
4344

4445
.marks {

tests/acceptance/documents-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module("Acceptance | documents", function (hooks) {
7575

7676
assert.strictEqual(
7777
currentURL(),
78-
`/?document=${document.id}`,
78+
`/?document=${document.id}&listView=false`,
7979
"url is set to currently selected document",
8080
);
8181

tests/integration/components/document-view-test.js

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, click } from "@ember/test-helpers";
1+
import { render } from "@ember/test-helpers";
22
import { setupRenderingTest } from "dummy/tests/helpers";
33
import { hbs } from "ember-cli-htmlbars";
44
import { setupMirage } from "ember-cli-mirage/test-support";
@@ -8,25 +8,10 @@ module("Integration | Component | document-view", function (hooks) {
88
setupRenderingTest(hooks);
99
setupMirage(hooks);
1010

11-
test("it renders the documents when in grid view", async function (assert) {
12-
this.server.createList("document", 3);
13-
14-
await render(hbs`<DocumentView />`, { owner: this.engine });
15-
16-
await click("[data-test-toggle]");
17-
18-
assert.dom("[data-test-upload]").exists();
19-
assert.dom("[data-test-empty]").doesNotExist();
20-
21-
assert.dom("[data-test-document]").exists({ count: 3 });
22-
assert
23-
.dom("[data-test-document]")
24-
.doesNotHaveClass("document-card--selected");
25-
});
26-
2711
test("it renders an empty document view", async function (assert) {
28-
await render(hbs`<DocumentView />`, { owner: this.engine });
29-
await click("[data-test-toggle]");
12+
await render(hbs`<DocumentView @listView={{ false }} />`, {
13+
owner: this.engine,
14+
});
3015

3116
assert.dom("[data-test-upload]").exists();
3217
assert.dom("[data-test-empty]").exists();
@@ -38,8 +23,9 @@ module("Integration | Component | document-view", function (hooks) {
3823

3924
docService.selectedDocuments = [documents[0]];
4025

41-
await render(hbs`<DocumentView />`, { owner: this.engine });
42-
await click("[data-test-toggle]");
26+
await render(hbs`<DocumentView @listView={{ false }} />`, {
27+
owner: this.engine,
28+
});
4329

4430
assert.dom("[data-test-empty]").doesNotExist();
4531
assert.dom("[data-test-document]").exists({ count: 3 });

0 commit comments

Comments
 (0)