Stricter tsconfig for the browser extension (#2411)

* Stricter tsconfig for the browsr extension

* Refactor getPhabricatorState() to async function

This was the best way to fix the many noImplicitReturns violations in this function.

* Fix Alerts.tsx

* Update client/browser/src/shared/repo/backend.tsx

Co-Authored-By: lguychard <l.guychard@gmail.com>

* `| null` -> `| undefined`

* Add return type
This commit is contained in:
Loic Guychard 2019-02-25 19:48:03 +01:00 committed by GitHub
parent cfde2da5de
commit 077319232d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 273 additions and 345 deletions

View File

@ -1,5 +1,5 @@
import fs from 'fs'
import { omit, pick } from 'lodash'
import { omit } from 'lodash'
import path from 'path'
import shelljs from 'shelljs'
import signale from 'signale'
@ -10,15 +10,17 @@ import schema from '../src/extension/schema.json'
export type BuildEnv = 'dev' | 'prod'
type Browser = 'firefox' | 'chrome'
const BUILDS_DIR = 'build'
export const WEBPACK_STATS_OPTIONS = {
export const WEBPACK_STATS_OPTIONS: Stats.ToStringOptions = {
all: false,
timings: true,
errors: true,
warnings: true,
colors: true,
} as Stats.ToStringOptions
}
function ensurePaths(): void {
shelljs.mkdir('-p', 'build/dist')
@ -49,43 +51,33 @@ export function copyPhabricator(): void {
shelljs.cp('build/dist/css/style.bundle.css', 'build/phabricator/dist/css')
}
const browserTitles = {
const BROWSER_TITLES = {
firefox: 'Firefox',
chrome: 'Chrome',
}
const browserBundleZips = {
const BROWSER_BUNDLE_ZIPS = {
firefox: 'firefox-bundle.xpi',
chrome: 'chrome-bundle.zip',
}
const browserBlacklist = {
const BROWSER_BLACKLIST = {
chrome: ['applications'],
firefox: ['key'],
}
const browserWhitelist = {}
function writeSchema(env, browser, writeDir): void {
function writeSchema(env: BuildEnv, browser: Browser, writeDir: string): void {
fs.writeFileSync(`${writeDir}/schema.json`, JSON.stringify(schema, null, 4))
}
const version = utcVersion()
function writeManifest(env, browser, writeDir): void {
let envInfo = omit(extensionInfo[env], browserBlacklist[browser])
let manifest
const whitelist = browserWhitelist[browser]
if (whitelist) {
manifest = pick(extensionInfo, whitelist)
envInfo = pick(envInfo, whitelist)
} else {
manifest = omit(extensionInfo, ['dev', 'prod', ...browserBlacklist[browser]])
function writeManifest(env: BuildEnv, browser: Browser, writeDir: string): void {
const manifest = {
...omit(extensionInfo, ['dev', 'prod', ...BROWSER_BLACKLIST[browser]]),
...omit(extensionInfo[env], BROWSER_BLACKLIST[browser]),
}
manifest = { ...manifest, ...envInfo }
if (browser === 'firefox') {
manifest.permissions.push('<all_urls>')
delete manifest.storage
@ -100,10 +92,10 @@ function writeManifest(env, browser, writeDir): void {
fs.writeFileSync(`${writeDir}/manifest.json`, JSON.stringify(manifest, null, 4))
}
function buildForBrowser(browser): (env: string) => () => void {
function buildForBrowser(browser: Browser): (env: BuildEnv) => () => void {
ensurePaths()
return env => {
const title = browserTitles[browser]
const title = BROWSER_TITLES[browser]
const buildDir = path.resolve(process.cwd(), `${BUILDS_DIR}/${browser}`)
@ -115,7 +107,7 @@ function buildForBrowser(browser): (env: string) => () => void {
copyDist(buildDir)
const zipDest = path.resolve(process.cwd(), `${BUILDS_DIR}/bundles/${browserBundleZips[browser]}`)
const zipDest = path.resolve(process.cwd(), `${BUILDS_DIR}/bundles/${BROWSER_BUNDLE_ZIPS[browser]}`)
if (zipDest) {
shelljs.mkdir('-p', `./${BUILDS_DIR}/bundles`)
shelljs.exec(`cd ${buildDir} && zip -q -r ${zipDest} *`)

View File

@ -68,6 +68,10 @@ export interface StorageItems {
*/
clientSettings: string
sideloadedExtensionURL: string | null
NeedsServerConfigurationAlertDismissed?: boolean
NeedsRepoConfigurationAlertDismissed?: {
[repoName: string]: boolean
}
}
interface ClientConfigurationDetails {

View File

@ -124,7 +124,7 @@ describe('Sourcegraph Chrome extension', () => {
test(`provides tooltips for diff files (${diffType}, ${side})`, async () => {
await page.goto(`https://github.com/gorilla/mux/pull/328/files?diff=${diffType}`)
const token = tokens[side]
const token = tokens[side as 'base' | 'head']
const element = await getTokenWithSelector(page, token.text, token.selector)
// Scrolls the element into view so that code view is in view.

View File

@ -177,7 +177,7 @@ storage.setSyncMigration(items => {
const keysToRemove: string[] = []
// Ensure all feature flags are in storage.
for (const key of Object.keys(featureFlagDefaults)) {
for (const key of Object.keys(featureFlagDefaults) as (keyof FeatureFlags)[]) {
if (typeof featureFlags[key] === 'undefined') {
keysToRemove.push(key)
featureFlags = {

View File

@ -199,6 +199,7 @@ function getResolvedDiffForCompare(): DiffResolvedRevSpec | undefined {
if (branchElements && branchElements.length === 2) {
return { baseCommitID: branchElements[0].innerText, headCommitID: branchElements[1].innerText }
}
return undefined
}
function getDiffResolvedRevFromPageSource(pageSource: string): DiffResolvedRevSpec | null {

View File

@ -89,6 +89,7 @@ interface ConduitDiffDetails {
status: string
refs: ConduitRef[]
}
'local:commits': string[]
}
}
@ -316,7 +317,7 @@ export function getRepoDetailsFromCallsign(callsign: string): Promise<Phabricato
phabricatorURL: window.location.origin,
}).subscribe(() => resolve(details))
} else {
reject(new Error('could not parse repo details'))
return reject(new Error('could not parse repo details'))
}
})
})
@ -394,7 +395,7 @@ function getRepoDetailsFromRepoPHID(phid: string): Promise<PhabricatorRepoDetail
resolve(details)
})
} else {
reject(new Error('could not parse repo details'))
return reject(new Error('could not parse repo details'))
}
})
})
@ -681,8 +682,8 @@ export function resolveDiffRev(props: ResolveDiffOpt): Observable<ResolvedDiff>
}
if (!propsWithInfo.isBase) {
for (const cmit of Object.keys(propsWithInfo.info.properties['local:commits'])) {
return resolve({ commitID: cmit })
for (const commit of Object.keys(propsWithInfo.info.properties['local:commits'])) {
return resolve({ commitID: commit })
}
}
// last ditch effort to search conduit API for commit ID

View File

@ -85,34 +85,6 @@ function getMaxDiffFromTabView(): { diffID: number; revDescription: string } | n
return null
}
// function getCallsignDifferentialPage(): string | null {
// const mainColumn = document.getElementsByClassName('phui-main-column').item(0)
// if (!mainColumn) {
// console.warn('no \'phui-main-column\'[0] class found')
// return null
// }
// const diffDetailBox = mainColumn.children[1]
// const repositoryTag = diffDetailBox.getElementsByClassName('phui-property-list-value').item(0)
// if (!repositoryTag) {
// console.warn('no \'phui-property-list-value\'[0] class found')
// return null
// }
// let diffusionPath = repositoryTag.children[0].getAttribute('href') // e.g. /source/CALLSIGN/ or /diffusion/CALLSIGN/
// if (!diffusionPath) {
// console.warn('no diffusion path found')
// return null
// }
// if (diffusionPath.startsWith('/source/')) {
// diffusionPath = diffusionPath.substr('/source/'.length)
// } else if (diffusionPath.startsWith('/diffusion/')) {
// diffusionPath = diffusionPath.substr('/diffusion/'.length)
// } else {
// console.error(`unexpected prefix on diffusion path ${diffusionPath}`)
// return null
// }
// return diffusionPath.substr(0, diffusionPath.length - 1)
// }
const DIFF_PATTERN = /Diff ([0-9]+)/
function getDiffIdFromDifferentialPage(): string | null {
const diffsContainer = document.getElementById('differential-review-stage')
@ -160,283 +132,243 @@ function getBaseCommitIDFromRevisionPage(): string | null {
return null
}
export function getPhabricatorState(
export async function getPhabricatorState(
loc: Location
): Promise<DiffusionState | DifferentialState | RevisionState | ChangeState | null> {
return new Promise((resolve, reject) => {
const stateUrl = loc.href.replace(loc.origin, '')
const diffusionMatch = PHAB_DIFFUSION_REGEX.exec(stateUrl)
const { protocol, hostname, port } = loc
if (diffusionMatch) {
const match = {
protocol,
hostname,
port,
viewType: diffusionMatch[1],
callsign: diffusionMatch[2],
branch: diffusionMatch[3],
filePath: diffusionMatch[4],
revInUrl: diffusionMatch[5], // only on previous versions
}
if (match.branch && match.branch.endsWith('/')) {
// Remove trailing slash (included b/c branch group is optional)
match.branch = match.branch.substr(match.branch.length - 1)
}
const callsign = getCallsignFromPageTag()
if (!callsign) {
console.error('could not locate callsign for differential page')
resolve(null)
return
}
match.callsign = callsign
getRepoDetailsFromCallsign(callsign)
.then(({ repoName }) => {
const commitID = getCommitIDFromPageTag()
if (!commitID) {
console.error('cannot determine commitIDision from page')
resolve(null)
return
}
resolve({
repoName,
filePath: match.filePath,
mode: PhabricatorMode.Diffusion,
commitID,
})
})
.catch(reject)
return
const stateUrl = loc.href.replace(loc.origin, '')
const diffusionMatch = PHAB_DIFFUSION_REGEX.exec(stateUrl)
const { protocol, hostname, port } = loc
if (diffusionMatch) {
const match = {
protocol,
hostname,
port,
viewType: diffusionMatch[1],
callsign: diffusionMatch[2],
branch: diffusionMatch[3],
filePath: diffusionMatch[4],
revInUrl: diffusionMatch[5], // only on previous versions
}
const differentialMatch = PHAB_DIFFERENTIAL_REGEX.exec(stateUrl)
if (differentialMatch) {
const match = {
protocol,
hostname,
port,
differentialID: differentialMatch[1],
diffID: differentialMatch[6],
comparison: differentialMatch[7],
}
const differentialID = parseInt(match.differentialID.split('D')[1], 10)
let diffID = match.diffID ? parseInt(match.diffID, 10) : undefined
getRepoDetailsFromDifferentialID(differentialID)
.then(({ callsign }) => {
if (!callsign) {
console.error(`callsign not found`)
resolve(null)
return
}
if (!diffID) {
const fromPage = getDiffIdFromDifferentialPage()
if (fromPage) {
diffID = parseInt(fromPage, 10)
}
}
if (!diffID) {
console.error(`differential id not found on page.`)
resolve(null)
return
}
getRepoDetailsFromCallsign(callsign)
.then(({ repoName }) => {
let baseRev = `phabricator/base/${diffID}`
let headRev = `phabricator/diff/${diffID}`
let leftDiffID: number | undefined
const maxDiff = getMaxDiffFromTabView()
const diffLanded = isDifferentialLanded()
if (diffLanded && !maxDiff) {
console.error(
'looking for the final diff id in the revision contents table failed. expected final row to have the commit in the description field.'
)
return null
}
if (match.comparison) {
// urls that looks like this: http://phabricator.aws.sgdev.org/D3?vs=on&id=8&whitespace=ignore-most#toc
// if the first parameter (vs=) is not 'on', not sure how to handle
const comparisonMatch = COMPARISON_REGEX.exec(match.comparison)!
const leftID = comparisonMatch[1]
if (leftID !== 'on') {
leftDiffID = parseInt(leftID, 10)
baseRev = `phabricator/diff/${leftDiffID}`
} else {
baseRev = `phabricator/base/${comparisonMatch[2]}`
}
headRev = `phabricator/diff/${comparisonMatch[2]}`
if (diffLanded && maxDiff && comparisonMatch[2] === `${maxDiff.diffID}`) {
headRev = maxDiff.revDescription
baseRev = headRev.concat('~1')
}
} else {
// check if the diff we are viewing is the max diff. if so,
// right is the merged rev into master, and left is master~1
if (diffLanded && maxDiff && diffID === maxDiff.diffID) {
headRev = maxDiff.revDescription
baseRev = maxDiff.revDescription.concat('~1')
}
}
resolve({
baseRepoName: repoName,
baseRev,
headRepoName: repoName,
headRev, // This will be blank on GitHub, but on a manually staged instance should exist
differentialID,
diffID,
leftDiffID,
mode: PhabricatorMode.Differential,
})
})
.catch(err => {
reject(err)
})
})
.catch(err => {
console.log('uhoh', err)
reject(err)
})
return
if (match.branch && match.branch.endsWith('/')) {
// Remove trailing slash (included b/c branch group is optional)
match.branch = match.branch.substr(match.branch.length - 1)
}
const revisionMatch = PHAB_REVISION_REGEX.exec(stateUrl)
if (revisionMatch) {
const match = {
protocol,
hostname,
port,
callsign: revisionMatch[1],
rev: revisionMatch[2],
}
getRepoDetailsFromCallsign(match.callsign)
.then(({ repoName }) => {
const headCommitID = match.rev
const baseCommitID = getBaseCommitIDFromRevisionPage()
if (!baseCommitID) {
console.error(`did not successfully determine parent revision.`)
return null
}
resolve({
repoName,
baseCommitID,
headCommitID,
mode: PhabricatorMode.Revision,
})
})
.catch(reject)
return
const callsign = getCallsignFromPageTag()
if (!callsign) {
console.error('could not locate callsign for differential page')
return null
}
match.callsign = callsign
const { repoName } = await getRepoDetailsFromCallsign(callsign)
const commitID = getCommitIDFromPageTag()
if (!commitID) {
console.error('cannot determine commitIDision from page')
return null
}
return {
repoName,
filePath: match.filePath,
mode: PhabricatorMode.Diffusion,
commitID,
}
}
const differentialMatch = PHAB_DIFFERENTIAL_REGEX.exec(stateUrl)
if (differentialMatch) {
const match = {
protocol,
hostname,
port,
differentialID: differentialMatch[1],
diffID: differentialMatch[6],
comparison: differentialMatch[7],
}
const changeMatch = PHAB_CHANGE_REGEX.exec(stateUrl)
if (changeMatch) {
const match = {
protocol: changeMatch[1],
hostname: changeMatch[2],
tld: changeMatch[3],
port: changeMatch[4],
viewType: changeMatch[5],
callsign: changeMatch[6],
branch: changeMatch[7],
filePath: changeMatch[8],
revInUrl: changeMatch[9], // only on previous versions
}
const differentialID = parseInt(match.differentialID.split('D')[1], 10)
let diffID = match.diffID ? parseInt(match.diffID, 10) : undefined
const callsign = getCallsignFromPageTag()
if (!callsign) {
console.error('could not locate callsign for differential page')
return null
const { callsign } = await getRepoDetailsFromDifferentialID(differentialID)
if (!callsign) {
console.error(`callsign not found`)
return null
}
if (!diffID) {
const fromPage = getDiffIdFromDifferentialPage()
if (fromPage) {
diffID = parseInt(fromPage, 10)
}
match.callsign = callsign
getRepoDetailsFromCallsign(callsign)
.then(({ repoName }) => {
const commitID = getCommitIDFromPageTag()
if (!commitID) {
console.error('cannot determine revision from page.')
return null
}
resolve({
repoName,
filePath: match.filePath,
mode: PhabricatorMode.Change,
commitID,
})
})
.catch(reject)
return
}
if (!diffID) {
console.error(`differential id not found on page.`)
return null
}
const { repoName } = await getRepoDetailsFromCallsign(callsign)
let baseRev = `phabricator/base/${diffID}`
let headRev = `phabricator/diff/${diffID}`
let leftDiffID: number | undefined
const maxDiff = getMaxDiffFromTabView()
const diffLanded = isDifferentialLanded()
if (diffLanded && !maxDiff) {
console.error(
'looking for the final diff id in the revision contents table failed. expected final row to have the commit in the description field.'
)
return null
}
if (match.comparison) {
// urls that looks like this: http://phabricator.aws.sgdev.org/D3?vs=on&id=8&whitespace=ignore-most#toc
// if the first parameter (vs=) is not 'on', not sure how to handle
const comparisonMatch = COMPARISON_REGEX.exec(match.comparison)!
const leftID = comparisonMatch[1]
if (leftID !== 'on') {
leftDiffID = parseInt(leftID, 10)
baseRev = `phabricator/diff/${leftDiffID}`
} else {
baseRev = `phabricator/base/${comparisonMatch[2]}`
}
headRev = `phabricator/diff/${comparisonMatch[2]}`
if (diffLanded && maxDiff && comparisonMatch[2] === `${maxDiff.diffID}`) {
headRev = maxDiff.revDescription
baseRev = headRev.concat('~1')
}
} else {
// check if the diff we are viewing is the max diff. if so,
// right is the merged rev into master, and left is master~1
if (diffLanded && maxDiff && diffID === maxDiff.diffID) {
headRev = maxDiff.revDescription
baseRev = maxDiff.revDescription.concat('~1')
}
}
return {
baseRepoName: repoName,
baseRev,
headRepoName: repoName,
headRev, // This will be blank on GitHub, but on a manually staged instance should exist
differentialID,
diffID,
leftDiffID,
mode: PhabricatorMode.Differential,
}
}
const revisionMatch = PHAB_REVISION_REGEX.exec(stateUrl)
if (revisionMatch) {
const match = {
protocol,
hostname,
port,
callsign: revisionMatch[1],
rev: revisionMatch[2],
}
const { repoName } = await getRepoDetailsFromCallsign(match.callsign)
const headCommitID = match.rev
const baseCommitID = getBaseCommitIDFromRevisionPage()
if (!baseCommitID) {
console.error(`did not successfully determine parent revision.`)
return null
}
return {
repoName,
baseCommitID,
headCommitID,
mode: PhabricatorMode.Revision,
}
}
const changeMatch = PHAB_CHANGE_REGEX.exec(stateUrl)
if (changeMatch) {
const match = {
protocol: changeMatch[1],
hostname: changeMatch[2],
tld: changeMatch[3],
port: changeMatch[4],
viewType: changeMatch[5],
callsign: changeMatch[6],
branch: changeMatch[7],
filePath: changeMatch[8],
revInUrl: changeMatch[9], // only on previous versions
}
const changesetMatch = PHAB_CHANGESET_REGEX.exec(stateUrl)
if (changesetMatch) {
const crumbs = document.querySelector('.phui-crumbs-view')
if (!crumbs) {
reject(new Error('failed parsing changeset dom'))
return
}
const callsign = getCallsignFromPageTag()
if (!callsign) {
console.error('could not locate callsign for differential page')
return null
}
match.callsign = callsign
const { repoName } = await getRepoDetailsFromCallsign(callsign)
const commitID = getCommitIDFromPageTag()
if (!commitID) {
console.error('cannot determine revision from page.')
return null
}
return {
repoName,
filePath: match.filePath,
mode: PhabricatorMode.Change,
commitID,
}
}
const [, differentialHref, diffHref] = crumbs.querySelectorAll('a')
const differentialMatch = differentialHref.getAttribute('href')!.match(/D(\d+)/)
if (!differentialMatch) {
reject(new Error('failed parsing differentialID'))
return
}
const differentialID = parseInt(differentialMatch[1], 10)
const diffMatch = diffHref.getAttribute('href')!.match(/\/differential\/diff\/(\d+)/)
if (!diffMatch) {
reject(new Error('failed parsing diffID'))
return
}
const diffID = parseInt(diffMatch[1], 10)
getRepoDetailsFromDifferentialID(differentialID)
.then(({ callsign }) => {
if (!callsign) {
console.error(`callsign not found`)
return null
}
getRepoDetailsFromCallsign(callsign)
.then(({ repoName }) => {
let baseRev = `phabricator/base/${diffID}`
let headRev = `phabricator/diff/${diffID}`
const maxDiff = getMaxDiffFromTabView()
const diffLanded = isDifferentialLanded()
if (diffLanded && !maxDiff) {
console.error(
'looking for the final diff id in the revision contents table failed. expected final row to have the commit in the description field.'
)
return null
}
// check if the diff we are viewing is the max diff. if so,
// right is the merged rev into master, and left is master~1
if (diffLanded && maxDiff && diffID === maxDiff.diffID) {
headRev = maxDiff.revDescription
baseRev = maxDiff.revDescription.concat('~1')
}
resolve({
baseRepoName: repoName,
baseRev,
headRepoName: repoName,
headRev, // This will be blank on GitHub, but on a manually staged instance should exist
differentialID,
diffID,
mode: PhabricatorMode.Differential,
})
})
.catch(reject)
})
.catch(reject)
return
const changesetMatch = PHAB_CHANGESET_REGEX.exec(stateUrl)
if (changesetMatch) {
const crumbs = document.querySelector('.phui-crumbs-view')
if (!crumbs) {
throw new Error('failed parsing changeset dom')
}
resolve(null)
})
const [, differentialHref, diffHref] = crumbs.querySelectorAll('a')
const differentialMatch = differentialHref.getAttribute('href')!.match(/D(\d+)/)
if (!differentialMatch) {
throw new Error('failed parsing differentialID')
}
const differentialID = parseInt(differentialMatch[1], 10)
const diffMatch = diffHref.getAttribute('href')!.match(/\/differential\/diff\/(\d+)/)
if (!diffMatch) {
throw new Error('failed parsing diffID')
}
const diffID = parseInt(diffMatch[1], 10)
const { callsign } = await getRepoDetailsFromDifferentialID(differentialID)
if (!callsign) {
console.error(`callsign not found`)
return null
}
const { repoName } = await getRepoDetailsFromCallsign(callsign)
let baseRev = `phabricator/base/${diffID}`
let headRev = `phabricator/diff/${diffID}`
const maxDiff = getMaxDiffFromTabView()
const diffLanded = isDifferentialLanded()
if (diffLanded && !maxDiff) {
console.error(
'looking for the final diff id in the revision contents table failed. expected final row to have the commit in the description field.'
)
return null
}
// check if the diff we are viewing is the max diff. if so,
// right is the merged rev into master, and left is master~1
if (diffLanded && maxDiff && diffID === maxDiff.diffID) {
headRev = maxDiff.revDescription
baseRev = maxDiff.revDescription.concat('~1')
}
return {
baseRepoName: repoName,
baseRev,
headRepoName: repoName,
headRev, // This will be blank on GitHub, but on a manually staged instance should exist
differentialID,
diffID,
mode: PhabricatorMode.Differential,
}
}
return null
}
/**
@ -449,7 +381,11 @@ export function metaClickOverride(): void {
return
}
JX.Stratcom._dispatchProxyPreMeta = JX.Stratcom._dispatchProxy
JX.Stratcom._dispatchProxy = proxyEvent => {
JX.Stratcom._dispatchProxy = (proxyEvent: {
__auto__type: string
__auto__rawEvent: KeyboardEvent
__auto__target: HTMLElement
}) => {
if (
proxyEvent.__auto__type === 'click' &&
proxyEvent.__auto__rawEvent.metaKey &&

View File

@ -2,8 +2,8 @@ import * as React from 'react'
import storage from '../../browser/storage'
import { resolveRev } from '../repo/backend'
import { isSourcegraphDotCom } from '../util/context'
import { NeedsRepositoryConfigurationAlert } from './NeedsRepositoryConfigurationAlert'
import { NeedsServerConfigurationAlert } from './ServerAlert'
import { NeedsRepositoryConfigurationAlert, REPO_CONFIGURATION_KEY } from './NeedsRepositoryConfigurationAlert'
import { NeedsServerConfigurationAlert, SERVER_CONFIGURATION_KEY } from './ServerAlert'
interface State {
needsConfig: boolean
@ -14,9 +14,6 @@ interface Props {
repoName: string
}
const SERVER_CONFIGURATION_KEY = 'NeedsServerConfigurationAlertDismissed'
const REPO_CONFIGURATION_KEY = 'NeedsRepoConfigurationAlertDismissed'
export class Alerts extends React.Component<Props, State> {
constructor(props: Props) {
super(props)
@ -41,7 +38,7 @@ export class Alerts extends React.Component<Props, State> {
if (!items[SERVER_CONFIGURATION_KEY]) {
alerts.push(SERVER_CONFIGURATION_KEY)
}
if (!items[REPO_CONFIGURATION_KEY] || !items[REPO_CONFIGURATION_KEY][this.props.repoName]) {
if (!items[REPO_CONFIGURATION_KEY] || !items[REPO_CONFIGURATION_KEY]![this.props.repoName]) {
alerts.push(REPO_CONFIGURATION_KEY)
}
this.setState(() => ({ ...this.state, alerts }))
@ -50,17 +47,11 @@ export class Alerts extends React.Component<Props, State> {
public render(): JSX.Element | null {
if (this.state.needsConfig && isSourcegraphDotCom() && this.state.alerts.includes(SERVER_CONFIGURATION_KEY)) {
return <NeedsServerConfigurationAlert alertKey={SERVER_CONFIGURATION_KEY} onClose={this.updateAlerts} />
return <NeedsServerConfigurationAlert onClose={this.updateAlerts} />
}
if (this.state.needsConfig && this.state.alerts.includes(REPO_CONFIGURATION_KEY) && !isSourcegraphDotCom()) {
return (
<NeedsRepositoryConfigurationAlert
repoName={this.props.repoName}
alertKey={REPO_CONFIGURATION_KEY}
onClose={this.updateAlerts}
/>
)
return <NeedsRepositoryConfigurationAlert repoName={this.props.repoName} onClose={this.updateAlerts} />
}
return null

View File

@ -6,17 +6,18 @@ import { sourcegraphUrl } from '../util/context'
interface Props {
onClose: () => void
alertKey: string
repoName: string
}
export const REPO_CONFIGURATION_KEY = 'NeedsRepoConfigurationAlertDismissed'
/**
* A global alert telling the site admin that they need to configure
* external services on this site.
*/
export class NeedsRepositoryConfigurationAlert extends React.Component<Props, {}> {
private sync = () => {
const obj = { [this.props.alertKey]: { [this.props.repoName]: true } }
const obj = { [REPO_CONFIGURATION_KEY]: { [this.props.repoName]: true } }
storage.setSync(obj, () => {
this.props.onClose()
})

View File

@ -5,16 +5,17 @@ import storage from '../../browser/storage'
interface Props {
onClose: () => void
alertKey: string
}
export const SERVER_CONFIGURATION_KEY = 'NeedsServerConfigurationAlertDismissed'
/**
* A global alert telling the user that they need to configure Sourcegraph
* to get code intelligence and search on private code.
*/
export class NeedsServerConfigurationAlert extends React.Component<Props, {}> {
private sync(): void {
storage.setSync({ [this.props.alertKey]: true }, () => {
storage.setSync({ [SERVER_CONFIGURATION_KEY]: true }, () => {
this.props.onClose()
})
}

View File

@ -103,7 +103,11 @@ export function retryWhenCloneInProgressError<T>(): (v: Observable<T>) => Observ
)
}
const trimRepoName = ({ repoName, ...rest }) => ({ ...rest, repoName: repoName.replace(/.git$/, '') })
const trimRepoName = <T extends { repoName: string }>({ repoName, ...rest }: T): T =>
({
repoName: repoName.replace(/.git$/, ''),
...rest,
} as T)
export const fetchBlobContentLines = memoizeObservable(
(ctx: RepoSpec & ResolvedRevSpec & FileSpec): Observable<string[]> =>

View File

@ -8,7 +8,7 @@ import { logUserEvent } from '../backend/userEvents'
const uidKey = 'sourcegraphAnonymousUid'
export class EventLogger implements TelemetryService {
private uid: string
private uid: string | null = null
constructor() {
// Fetch user ID on initial load.

View File

@ -3,9 +3,6 @@
"compilerOptions": {
"typeRoots": ["../../shared/src/types", "../../node_modules/@types", "src/types"],
"jsx": "react",
"noImplicitAny": false,
"noImplicitReturns": false,
"strictPropertyInitialization": false,
"resolveJsonModule": true,
"checkJs": true
},