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

remaining ember-data 5.3 deprecations #617

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
42 changes: 36 additions & 6 deletions frontend/app/analysis/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ export default class AnalysisEditController extends Controller {
const model = this.store.peekRecord("report-intersection", res.data.id);

if (model.customer) {
this.store.query("project", { customer: model.customer.id });
await this.store.query("project", { customer: model.customer.id });
}

if (model.project) {
this.store.query("task", { project: model.project.id });
await this.store.query("task", { project: model.project.id });
}

return {
Expand Down Expand Up @@ -183,15 +183,45 @@ export default class AnalysisEditController extends Controller {

const queryString = toQueryString(params);

await changeset.execute();
// this is an ugly mess, to get around the changeset using a PromiseProxy
const changes = changeset.get("changes");

const { comment, notBillable, rejected, review, billed, verified } =
changeset;
const _attributes = {
comment,
notBillable,
rejected,
review,
billed,
verified,
};

const [user, customer, project, task] = [
changeset.get("user.id") &&
this.store.peekRecord("user", changeset.get("user.id")),
changeset.get("customer.id") &&
this.store.peekRecord("customer", changeset.get("customer.id")),
changeset.get("project.id") &&
this.store.peekRecord("project", changeset.get("project.id")),
changeset.get("task.id") &&
this.store.peekRecord("task", changeset.get("task.id")),
];
const _relationships = { user, customer, project, task };

const {
data: { attributes, relationships },
} = this.intersectionModel.serialize();
} = this.store
.createRecord("report-intersection", {
..._attributes,
..._relationships,
})
.serialize();

const data = {
type: "report-bulks",
attributes: filterUnchanged(attributes, changeset.get("changes")),
relationships: filterUnchanged(relationships, changeset.get("changes")),
attributes: filterUnchanged(attributes, changes),
relationships: filterUnchanged(relationships, changes),
};

await this.fetch.fetch(`/api/v1/reports/bulk?editable=1&${queryString}`, {
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/analysis/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
{{/unless}}
{{#if
(and
f.model.change.customer
f.model.change.customer.id
(not
(eq f.model.change.customer.id model.customer.id)
)
Expand All @@ -77,7 +77,7 @@
{{/unless}}
{{#if
(and
f.model.change.project
f.model.change.project.id
(not
(eq f.model.change.project.id model.project.id)
)
Expand Down
17 changes: 13 additions & 4 deletions frontend/app/components/task-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { restartableTask, timeout, dropTask } from "ember-concurrency";
import { runTask } from "ember-lifeline";
import { trackedTask } from "reactiveweb/ember-concurrency";
import { trackedFunction } from "reactiveweb/function";
import { resolve } from "rsvp";
import { localCopy } from "tracked-toolbox";

Expand Down Expand Up @@ -62,7 +63,7 @@

if (this.args.liveTracking) {
// we track "_activity" here since we can not track the public getters directly
this.tracking.addObserver(

Check warning on line 66 in frontend/app/components/task-selection.js

View workflow job for this annotation

GitHub Actions / lint (js)

Don't use observers
"_activity",
this.handleTrackingActiveActivityChanged.perform,
);
Expand Down Expand Up @@ -256,16 +257,24 @@
return this._customersAndRecentTasks.value ?? [];
}

get projects() {
return this.customer?.projects
#projects = trackedFunction(this, async () => {
return (await this.customer?.projects)
?.filter(this.filterByArchived)
.toSorted((p) => p.name);
});

get projects() {
return this.#projects.value ?? [];
}

get tasks() {
return this.project?.tasks
#tasks = trackedFunction(this, async () => {
return (await this.project?.tasks)
?.filter(this.filterByArchived)
.toSorted((t) => t.name);
});

get tasks() {
return this.#tasks.value ?? [];
}

@action
Expand Down
16 changes: 16 additions & 0 deletions frontend/app/helpers/conditional-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { helper } from "@ember/component/helper";

/**
* Returns an action if the condition is true; otherwise, returns a no-op function.
*
* @param {[boolean, Function]} args - An array where the first element is a condition (boolean) and the second element is an action (function).
* @returns {Function} The action if the condition is true; otherwise, a no-op function.
*/
export const conditionalAction = ([condition, action]) => {
if (condition) {
return action;
}
return () => {};
};

export default helper(conditionalAction);
7 changes: 4 additions & 3 deletions frontend/app/index/activities/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export default class ActivitiesIndexController extends Controller {

if (!activity.get("date").isSame(moment(), "day")) {
activity = this.store.createRecord("activity", {
...activity.getProperties("task", "comment"),
task: await activity.task,
comment: await activity.comment,
});
}

Expand Down Expand Up @@ -188,7 +189,7 @@ export default class ActivitiesIndexController extends Controller {
const data = {
duration: activity.get("duration"),
date: activity.get("date"),
task: activity.get("task"),
task: await activity.get("task"),
review: activity.get("review"),
notBillable: activity.get("notBillable"),
comment: activity.get("comment").trim(),
Expand All @@ -212,7 +213,7 @@ export default class ActivitiesIndexController extends Controller {
data.duration.add(report.get("duration"));
report.set("duration", data.duration);
} else {
report = this.store.createRecord("report", data);
report = await this.store.createRecord("report", data);
}

activity.set("transferred", true);
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/users/edit/responsibilities/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { action } from "@ember/object";
import { service } from "@ember/service";
import { task } from "ember-concurrency";
import moment from "moment";
import { all } from "rsvp";

export default class UsersEditResponsibilitiesController extends Controller {
@service router;
Expand All @@ -23,6 +22,10 @@ export default class UsersEditResponsibilitiesController extends Controller {
});
});

async getBalance(supervisee) {
return (await supervisee.absenceBalances)[0].balance;
}

supervisees = task(async () => {
const supervisor = this.user?.id;

Expand All @@ -32,7 +35,7 @@ export default class UsersEditResponsibilitiesController extends Controller {
include: "user",
});

return await all(
return await Promise.all(
balances
.map((b) => b.user)
.filter((u) => u.get("isActive"))
Expand Down
5 changes: 2 additions & 3 deletions frontend/app/users/edit/responsibilities/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@
absenceBalances has to be an array but will always only
contain one element. This is why we get the first object here.
}}
<Table::Td>{{get
(object-at 0 supervisee.absenceBalances)
"balance"
<Table::Td>{{await
(this.getBalance supervisee)
}}</Table::Td>
</Table::Tr>
{{/each}}
Expand Down
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"ember-cli-sri": "2.1.1",
"ember-cli-terser": "4.0.2",
"ember-concurrency": "^4.0.2",
"ember-data": "~4.12.8",
"ember-data": "5.3.4",
"ember-decorators": "6.1.1",
"ember-event-helpers": "^0.1.1",
"ember-fetch": "8.1.2",
Expand All @@ -94,7 +94,7 @@
"ember-responsive": "5.0.0",
"ember-shepherd": "^17.0.0",
"ember-simple-auth": "6.0.0",
"ember-simple-auth-oidc": "6.0.1",
"ember-simple-auth-oidc": "7.0.4",
"ember-sinon-qunit": "^6.0.0",
"ember-source": "~5.4.0",
"ember-style-modifier": "^1.0.0",
Expand Down
Loading
Loading