Fix project preselection when project identifier is not defined (#9)

This commit is contained in:
Manuel Bouza 2019-04-01 17:41:54 +02:00 committed by Tobias Miesel
parent 1533c2261f
commit 1d2e336e3d
3 changed files with 14 additions and 7 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "moco-browser-extensions", "name": "moco-browser-extensions",
"description": "Browser plugin for MOCO", "description": "Browser plugin for MOCO",
"version": "1.1.0", "version": "1.1.1",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"start": "yarn start:chrome", "start": "yarn start:chrome",

View File

@ -69,8 +69,9 @@ class App extends Component {
head(projects) head(projects)
const task = const task =
findTask(this.changeset.task_id || service?.taskId || lastTaskId)(project) || findTask(this.changeset.task_id || service?.taskId || lastTaskId)(
head(project?.tasks) project
) || head(project?.tasks)
const defaults = { const defaults = {
remote_service: service?.name, remote_service: service?.name,
@ -111,7 +112,7 @@ class App extends Component {
if (name === "assignment_id") { if (name === "assignment_id") {
const project = findProjectByValue(value)(projects) const project = findProjectByValue(value)(projects)
this.changeset.task_id = head(project?.tasks)?.value this.changeset.task_id = head(project?.tasks)?.value
} }
}; };

View File

@ -21,11 +21,17 @@ export const ERROR_UNKNOWN = "unknown"
export const noop = () => null export const noop = () => null
export const findProjectBy = prop => val => export const findProjectBy = prop => val => projects => {
compose( if (!val) {
return undefined
}
return compose(
find(pathEq(prop, val)), find(pathEq(prop, val)),
flatMap(get("options")) flatMap(get("options"))
) )(projects)
}
export const findProjectByIdentifier = findProjectBy("identifier") export const findProjectByIdentifier = findProjectBy("identifier")
export const findProjectByValue = findProjectBy("value") export const findProjectByValue = findProjectBy("value")