Skip to content

Commit

Permalink
dev: add missing types to various new func inputs & outputs
Browse files Browse the repository at this point in the history
Instantiate source id regex only once & use const name convention.
  • Loading branch information
jaredscheib committed Aug 1, 2018
1 parent 032fa61 commit e031ef4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions ui/src/dashboards/components/ImportDashboardMappings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ImportDashboardMappings extends Component<Props, State> {
)
}

private getSourceItems(importedSourceID: string) {
private getSourceItems(importedSourceID: string): SourceItemValue[] {
const {sources} = this.props

const sourceItems = sources.map(source => {
Expand All @@ -204,7 +204,7 @@ class ImportDashboardMappings extends Component<Props, State> {
return sourceItems
}

private get header() {
private get header(): JSX.Element {
return (
<thead>
<tr>
Expand All @@ -228,7 +228,7 @@ class ImportDashboardMappings extends Component<Props, State> {
return sources[0].name
}

private getCellsForSource(sourceID): JSX.Element[] {
private getCellsForSource(sourceID: string): JSX.Element[] {
const {sourcesCells} = this.state

return _.map(sourcesCells[sourceID], c => {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dashboards/components/ImportDashboardOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ImportDashboardOverlay extends PureComponent<Props, State> {
}
}

private handleUploadDashboard = (cells: Cell[]) => {
private handleUploadDashboard = (cells: Cell[]): void => {
const {dashboard} = this.state

const {onImportDashboard, onDismissOverlay} = this.props
Expand Down
21 changes: 15 additions & 6 deletions ui/src/dashboards/utils/importDashboardMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import {
ImportedSources,
} from 'src/types/dashboards'

export const createSourceMappings = (source, cells, importedSources) => {
const REGEX_SOURCE_ID = /sources\/(\d+)/g

export const createSourceMappings = (
source,
cells,
importedSources
): {sourcesCells: SourcesCells; sourceMappings: SourceMappings} => {
let sourcesCells: SourcesCells = {}
const sourceMappings: SourceMappings = {}
const sourceInfo: SourceInfo = getSourceInfo(source)
Expand Down Expand Up @@ -73,7 +79,7 @@ export const mapCells = (
cells: Cell[],
sourceMappings: SourceMappings,
importedSources: ImportedSources
) => {
): Cell[] => {
const mappedCells = cells.map(c => {
const query = getDeep<CellQuery>(c, 'queries.0', null)
if (_.isEmpty(query)) {
Expand Down Expand Up @@ -106,7 +112,11 @@ export const mapCells = (
return mappedCells
}

export const mapQueriesInCell = (sourceMappings, cell, sourceID) => {
export const mapQueriesInCell = (
sourceMappings: SourceMappings,
cell: Cell,
sourceID: string
): Cell => {
const mappedSourceLink = sourceMappings[sourceID].link
let queries = getDeep<CellQuery[]>(cell, 'queries', [])
if (queries.length) {
Expand All @@ -125,9 +135,8 @@ export const getSourceInfo = (source: Source): SourceInfo => {
}
}

export const getSourceIDFromLink = (sourceLink: string) => {
const sourceIDRegex = /sources\/(\d+)/g
export const getSourceIDFromLink = (sourceLink: string): string => {
// first capture group
const sourceLinkSID = sourceIDRegex.exec(sourceLink)[1]
const sourceLinkSID = REGEX_SOURCE_ID.exec(sourceLink)[1]
return sourceLinkSID
}

0 comments on commit e031ef4

Please sign in to comment.