From 043d11a040ecec518301e61ed2c15c1e6ad7ef52 Mon Sep 17 00:00:00 2001 From: Manuel Bouza Date: Mon, 1 Apr 2019 17:35:19 +0200 Subject: [PATCH] Fix project preselection when project identifier is not defined --- package.json | 2 +- src/js/components/App.js | 7 ++++--- src/js/utils/index.js | 12 +++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 37051df..051ad7b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "moco-browser-extensions", "description": "Browser plugin for MOCO", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "scripts": { "start": "yarn start:chrome", diff --git a/src/js/components/App.js b/src/js/components/App.js index ce1dae8..3e2dab5 100644 --- a/src/js/components/App.js +++ b/src/js/components/App.js @@ -69,8 +69,9 @@ class App extends Component { head(projects) const task = - findTask(this.changeset.task_id || service?.taskId || lastTaskId)(project) || - head(project?.tasks) + findTask(this.changeset.task_id || service?.taskId || lastTaskId)( + project + ) || head(project?.tasks) const defaults = { remote_service: service?.name, @@ -111,7 +112,7 @@ class App extends Component { if (name === "assignment_id") { const project = findProjectByValue(value)(projects) - this.changeset.task_id = head(project?.tasks)?.value + this.changeset.task_id = head(project?.tasks)?.value } }; diff --git a/src/js/utils/index.js b/src/js/utils/index.js index b2523ce..d0d0379 100644 --- a/src/js/utils/index.js +++ b/src/js/utils/index.js @@ -21,11 +21,17 @@ export const ERROR_UNKNOWN = "unknown" export const noop = () => null -export const findProjectBy = prop => val => - compose( +export const findProjectBy = prop => val => projects => { + if (!val) { + return undefined + } + + return compose( find(pathEq(prop, val)), flatMap(get("options")) - ) + )(projects) +} + export const findProjectByIdentifier = findProjectBy("identifier") export const findProjectByValue = findProjectBy("value")