review changes
This commit is contained in:
@@ -4,8 +4,7 @@ import { observer } from "mobx-react"
|
||||
import { isChrome, getSettings, setStorage } from "utils/browser"
|
||||
import ApiClient from "api/Client"
|
||||
import remoteServices from "../remoteServices"
|
||||
import { map, sortedUniqBy, filter } from "lodash"
|
||||
import { getHostOverridesFromSettings } from "../utils/settings"
|
||||
import { pipe, prop, map, sortedUniqBy, filter } from "lodash/fp"
|
||||
|
||||
@observer
|
||||
class Options extends Component {
|
||||
@@ -18,25 +17,19 @@ class Options extends Component {
|
||||
@observable showHostOverrideOptions = false
|
||||
|
||||
componentDidMount() {
|
||||
this.servicesHostOverrideList = sortedUniqBy(
|
||||
map(
|
||||
filter(remoteServices, (remoteService) => {
|
||||
return remoteService.allowHostOverride
|
||||
}),
|
||||
(remoteService) => {
|
||||
return {
|
||||
name: remoteService.name,
|
||||
host: remoteService.host,
|
||||
}
|
||||
},
|
||||
),
|
||||
"name",
|
||||
)
|
||||
this.servicesHostOverrideList = pipe(
|
||||
filter(prop("allowHostOverride")),
|
||||
map((remoteService) => ({
|
||||
name: remoteService.name,
|
||||
host: remoteService.host,
|
||||
})),
|
||||
sortedUniqBy("name"),
|
||||
)(remoteServices)
|
||||
|
||||
getSettings(false).then((storeData) => {
|
||||
this.subdomain = storeData.subdomain || ""
|
||||
this.apiKey = storeData.apiKey || ""
|
||||
this.hostOverrides = getHostOverridesFromSettings(storeData) || {}
|
||||
this.hostOverrides = storeData.hostOverrides || {}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,7 +42,7 @@ class Options extends Component {
|
||||
this.hostOverrides[event.target.name] = this.removePathFromUrl(event.target.value.trim())
|
||||
}
|
||||
|
||||
toggleHostOverrideOptions = (event) => {
|
||||
toggleHostOverrideOptions = () => {
|
||||
this.showHostOverrideOptions = !this.showHostOverrideOptions
|
||||
}
|
||||
|
||||
@@ -61,7 +54,7 @@ class Options extends Component {
|
||||
subdomain: this.subdomain,
|
||||
apiKey: this.apiKey,
|
||||
settingTimeTrackingHHMM: false,
|
||||
...this.hostOverrides,
|
||||
hostOverrides: this.hostOverrides,
|
||||
}).then(() => {
|
||||
const { version } = chrome.runtime.getManifest()
|
||||
const apiClient = new ApiClient({
|
||||
@@ -142,8 +135,8 @@ class Options extends Component {
|
||||
<label>Host URL: {remoteService.name}</label>
|
||||
<input
|
||||
type="text"
|
||||
name={`hostOverrides:${remoteService.name}`}
|
||||
value={this.hostOverrides[`hostOverrides:${remoteService.name}`]}
|
||||
name={remoteService.name}
|
||||
value={this.hostOverrides[remoteService.name] || ""}
|
||||
placeholder={remoteService.host}
|
||||
onKeyDown={this.handleInputKeyDown}
|
||||
onChange={this.onChangeHostOverrides}
|
||||
|
||||
@@ -8,14 +8,12 @@ import remoteServices from "./remoteServices"
|
||||
import { ContentMessenger } from "utils/messaging"
|
||||
import "../css/content.scss"
|
||||
import { getSettings } from "./utils/browser"
|
||||
import { getHostOverridesFromSettings } from "./utils/settings"
|
||||
|
||||
const popupRef = createRef()
|
||||
|
||||
let findService
|
||||
getSettings().then((settings) => {
|
||||
const hostOverrides = getHostOverridesFromSettings(settings, true)
|
||||
findService = createServiceFinder(remoteServices, hostOverrides)(document)
|
||||
findService = createServiceFinder(remoteServices, settings.hostOverrides)(document)
|
||||
})
|
||||
|
||||
chrome.runtime.onConnect.addListener(function (port) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { head } from "lodash/fp"
|
||||
import remoteServices from "../remoteServices"
|
||||
|
||||
export const isChrome = () => typeof browser === "undefined" && chrome
|
||||
export const isFirefox = () => typeof browser !== "undefined" && chrome
|
||||
@@ -7,8 +6,7 @@ export const isFirefox = () => typeof browser !== "undefined" && chrome
|
||||
const DEFAULT_SUBDOMAIN = "unset"
|
||||
|
||||
export const getSettings = (withDefaultSubdomain = true) => {
|
||||
const keys = ["subdomain", "apiKey", "settingTimeTrackingHHMM",
|
||||
...Object.values(remoteServices).map(remoteService => `hostOverrides:${remoteService.name}`)]
|
||||
const keys = ["subdomain", "apiKey", "settingTimeTrackingHHMM", "hostOverrides"]
|
||||
const { version } = chrome.runtime.getManifest()
|
||||
if (isChrome()) {
|
||||
return new Promise(resolve => {
|
||||
|
||||
@@ -11,13 +11,11 @@ import { get, forEach, reject, isNil } from "lodash/fp"
|
||||
import { createMatcher } from "utils/urlMatcher"
|
||||
import remoteServices from "remoteServices"
|
||||
import { queryTabs, isBrowserTab, getSettings, setStorage } from "utils/browser"
|
||||
import { getHostOverridesFromSettings } from "./settings"
|
||||
|
||||
let matcher
|
||||
|
||||
const initMatcher = (settings) => {
|
||||
const hostOverrides = getHostOverridesFromSettings(settings, true)
|
||||
matcher = createMatcher(remoteServices, hostOverrides)
|
||||
matcher = createMatcher(remoteServices, settings.hostOverrides)
|
||||
}
|
||||
|
||||
getSettings().then((settings) => {
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { filter, fromPairs, map, toPairs } from "lodash"
|
||||
|
||||
export const getHostOverridesFromSettings = (settings, removePrefix) => {
|
||||
return fromPairs(
|
||||
map(
|
||||
filter(toPairs(settings), (item) => {
|
||||
return item[0].indexOf("hostOverrides") !== -1
|
||||
}),
|
||||
(item) => {
|
||||
if (removePrefix) {
|
||||
item[0] = item[0].replace("hostOverrides:", "")
|
||||
}
|
||||
return item
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -44,7 +44,7 @@ const prepareHostForRegExp = (host) => {
|
||||
return
|
||||
}
|
||||
|
||||
return host.replace(":", "\\:")//.replace(/\//g, "\\/")
|
||||
return host.replace(":", "\\:")
|
||||
}
|
||||
|
||||
const replaceHostInPattern = (host, pattern) => {
|
||||
|
||||
Reference in New Issue
Block a user