Skip to content
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

Fix various bugs #648

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/components/tag-filter.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class="uk-border uk-padding-small uk-width-expand uk-flex uk-flex-wrap uk-flex-middle"
...attributes
>
{{#each this.marks.marks.records as |mark|}}
{{#each this.activeMarks.value as |mark|}}
<button
type="button"
class="tag uk-text-small
Expand Down
21 changes: 21 additions & 0 deletions addon/components/tag-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class TagFilterComponent extends Component {
@service router;
@service tags;
@service marks;
@service store;

get parsedSelected() {
const parse = (str) => (str ? str.split(",") : []);
Expand All @@ -20,6 +21,26 @@ export default class TagFilterComponent extends Component {
return this.tags.fetchSearchTags.perform(this.args.category);
});

activeMarks = trackedFunction(this, async () => {
const activeMarks = await this.store
.peekAll("document")
.reduce(async (acc, doc) => {
const marks = await doc.marks;
acc = await acc;
if (
(this.args.category === undefined ||
(await doc.category) === this.args.category) &&
marks.length > 0
) {
marks.forEach((mark) => acc.add(mark.id));
}

return acc;
}, new Set());

return this.marks.marks.records?.filter((mark) => activeMarks.has(mark.id));
});

@action toggle(type, value) {
const queryParams = {};
const currentParams = this.parsedSelected[type];
Expand Down
16 changes: 16 additions & 0 deletions addon/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class ApplicationRoute extends Route {
queryParams = {
category: PARAM_OPTIONS,
tags: PARAM_OPTIONS,
marks: PARAM_OPTIONS,
search: PARAM_OPTIONS,
document: PARAM_OPTIONS,
activeGroup: PARAM_OPTIONS,
Expand All @@ -30,4 +31,19 @@ export default class ApplicationRoute extends Route {
this.config.alexandriaQueryParams = transition.to.parent.params;
this.config.activeGroup = transition.to.queryParams.activeGroup;
}

resetController(controller, isExiting) {
// isExiting would be false if only the route's model was changing
if (isExiting) {
controller.setProperties({
category: undefined,
tags: [],
marks: [],
search: undefined,
document: undefined,
activeGroup: undefined,
sort: undefined,
});
}
}
}
2 changes: 1 addition & 1 deletion tests/integration/components/document-card-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Service from "@ember/service";
import { render, click } from "@ember/test-helpers";
import { setupRenderingTest } from "dummy/tests/helpers";
import { hbs } from "ember-cli-htmlbars";
import fileSaver from "file-saver";
import * as fileSaver from "file-saver";
Copy link
Contributor

Choose a reason for hiding this comment

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

was this broken before?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

current test failures on master are from this

import { module, test } from "qunit";
import sinon from "sinon";

Expand Down
12 changes: 11 additions & 1 deletion tests/integration/components/tag-filter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ module("Integration | Component | tag-filter", function (hooks) {
setupMirage(hooks);

hooks.beforeEach(function () {
this.server.create("mark");
this.mark = this.server.create("mark");
this.server.createList("tag", 2);
});

test("it renders", async function (assert) {
await render(hbs`<TagFilter />`);

assert.dom("button").exists({ count: 2 });
});

test("it renders mark filter", async function (assert) {
this.server.create("document", {
marks: [this.mark],
});

await render(hbs`<TagFilter />`);

assert.dom("button").exists({ count: 3 });
});
});
Loading