Allow to set tag in description
This commit is contained in:
parent
f49c0bdc3d
commit
1b1fae6f7a
@ -10,6 +10,7 @@ import {
|
|||||||
ERROR_UNKNOWN,
|
ERROR_UNKNOWN,
|
||||||
ERROR_UNAUTHORIZED,
|
ERROR_UNAUTHORIZED,
|
||||||
ERROR_UPGRADE_REQUIRED,
|
ERROR_UPGRADE_REQUIRED,
|
||||||
|
extractAndSetTag,
|
||||||
findProjectByValue,
|
findProjectByValue,
|
||||||
findProjectByIdentifier,
|
findProjectByIdentifier,
|
||||||
findTask,
|
findTask,
|
||||||
@ -80,13 +81,11 @@ class App extends Component {
|
|||||||
seconds:
|
seconds:
|
||||||
this.changeset.hours &&
|
this.changeset.hours &&
|
||||||
new TimeInputParser(this.changeset.hours).parseSeconds(),
|
new TimeInputParser(this.changeset.hours).parseSeconds(),
|
||||||
description: service?.description
|
description: service?.description,
|
||||||
|
tag: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return { ...defaults, ...this.changeset }
|
||||||
...defaults,
|
|
||||||
...this.changeset
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -124,7 +123,7 @@ class App extends Component {
|
|||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
type: "createActivity",
|
type: "createActivity",
|
||||||
payload: {
|
payload: {
|
||||||
activity: this.changesetWithDefaults,
|
activity: extractAndSetTag(this.changesetWithDefaults),
|
||||||
service
|
service
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -86,3 +86,16 @@ export const formatDate = date => format(date, "YYYY-MM-DD")
|
|||||||
|
|
||||||
export const extensionSettingsUrl = () =>
|
export const extensionSettingsUrl = () =>
|
||||||
`chrome://extensions/?id=${chrome.runtime.id}`
|
`chrome://extensions/?id=${chrome.runtime.id}`
|
||||||
|
|
||||||
|
export const extractAndSetTag = changeset => {
|
||||||
|
let { description } = changeset
|
||||||
|
const match = description.match(/^#(\S+)/)
|
||||||
|
if (!match) {
|
||||||
|
return changeset
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...changeset,
|
||||||
|
description: description.replace(/^#\S+\s/, ""),
|
||||||
|
tag: match[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,8 @@ import {
|
|||||||
findProjectByValue,
|
findProjectByValue,
|
||||||
findProjectByIdentifier,
|
findProjectByIdentifier,
|
||||||
findTask,
|
findTask,
|
||||||
groupedProjectOptions
|
groupedProjectOptions,
|
||||||
|
extractAndSetTag
|
||||||
} from "../../src/js/utils"
|
} from "../../src/js/utils"
|
||||||
import { map } from "lodash/fp"
|
import { map } from "lodash/fp"
|
||||||
|
|
||||||
@ -86,4 +87,36 @@ describe("utils", () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("extractAndSetTag", () => {
|
||||||
|
it("sets the correct tag and updates description", () => {
|
||||||
|
const changeset = {
|
||||||
|
description: "#meeting Lorem ipsum",
|
||||||
|
tag: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(extractAndSetTag(changeset)).toEqual({
|
||||||
|
description: "Lorem ipsum",
|
||||||
|
tag: "meeting"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("only matches tag at the beginning", () => {
|
||||||
|
const changeset = {
|
||||||
|
description: "Lorem #meeting ipsum",
|
||||||
|
tag: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(extractAndSetTag(changeset)).toEqual(changeset)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the changeset if not tag is set", () => {
|
||||||
|
const changeset = {
|
||||||
|
description: "Without tag",
|
||||||
|
tag: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(extractAndSetTag(changeset)).toEqual(changeset)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user