Skip to content

Commit

Permalink
feat: support backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jul 14, 2023
1 parent f22216c commit 0954c6b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
14 changes: 13 additions & 1 deletion spec/util/urlUtils-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { constructSheetUrl, getDocumentOrSheetId } = require('../../src/util/urlUtils')
const { constructSheetUrl, getDocumentOrSheetId, getSheetName } = require('../../src/util/urlUtils')
const config = require('../../src/config')
const queryParams = require('../../src/util/queryParamProcessor')

Expand Down Expand Up @@ -68,4 +68,16 @@ describe('Url Utils', () => {

expect(id).toEqual('sheetId')
})

it('supports sheetName', () => {
queryParams.mockReturnValue({ sheetName: 'sheetName' })
delete window.location
window.location = Object.create(window)
window.location.href = 'https://thoughtworks.com/radar?sheetName=sheetName'
window.location.search = '?'

const sheetName = getSheetName()

expect(sheetName).toEqual('sheetName')
})
})
19 changes: 8 additions & 11 deletions src/util/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ExceptionMessages = require('./exceptionMessages')
const GoogleAuth = require('./googleAuth')
const config = require('../config')
const featureToggles = config().featureToggles
const { getDocumentOrSheetId } = require('./urlUtils')
const { getDocumentOrSheetId, getSheetName } = require('./urlUtils')
const { getGraphSize, graphConfig, isValidConfig } = require('../graphing/config')
const InvalidConfigError = require('../exceptions/invalidConfigError')
const InvalidContentError = require('../exceptions/invalidContentError')
Expand Down Expand Up @@ -76,8 +76,8 @@ const plotRadar = function (title, blips, currentRadarName, alternativeRadars) {
const size = featureToggles.UIRefresh2022
? getGraphSize()
: window.innerHeight - 133 < 620
? 620
: window.innerHeight - 133
? 620
: window.innerHeight - 133
new GraphingRadar(size, radar).init().plot()
}

Expand Down Expand Up @@ -316,10 +316,6 @@ const Factory = function () {
})

const domainName = DomainName(window.location.search.substring(1))
const queryString = featureToggles.UIRefresh2022
? window.location.href.match(/documentId(.*)/)
: window.location.href.match(/sheetId(.*)/)
const queryParams = queryString ? QueryParams(queryString[0]) : {}

const paramId = getDocumentOrSheetId()
if (paramId && paramId.endsWith('.csv')) {
Expand All @@ -329,7 +325,8 @@ const Factory = function () {
sheet = JSONFile(paramId)
sheet.init().build()
} else if (domainName && domainName.endsWith('google.com') && paramId) {
sheet = GoogleSheet(paramId, queryParams.sheetName)
const sheetName = getSheetName()
sheet = GoogleSheet(paramId, sheetName)
sheet.init().build()
} else {
if (!featureToggles.UIRefresh2022) {
Expand Down Expand Up @@ -396,9 +393,9 @@ function plotFooter(content) {
.append('p')
.html(
'Powered by <a href="https://www.thoughtworks.com"> Thoughtworks</a>. ' +
'By using this service you agree to <a href="https://www.thoughtworks.com/radar/tos">Thoughtworks\' terms of use</a>. ' +
'You also agree to our <a href="https://www.thoughtworks.com/privacy-policy">privacy policy</a>, which describes how we will gather, use and protect any personal data contained in your public Google Sheet. ' +
'This software is <a href="https://github.com/thoughtworks/build-your-own-radar">open source</a> and available for download and self-hosting.',
'By using this service you agree to <a href="https://www.thoughtworks.com/radar/tos">Thoughtworks\' terms of use</a>. ' +
'You also agree to our <a href="https://www.thoughtworks.com/privacy-policy">privacy policy</a>, which describes how we will gather, use and protect any personal data contained in your public Google Sheet. ' +
'This software is <a href="https://github.com/thoughtworks/build-your-own-radar">open source</a> and available for download and self-hosting.',
)
}

Expand Down
8 changes: 8 additions & 0 deletions src/util/urlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ function getDocumentOrSheetId() {
return queryParams.documentId ?? queryParams.sheetId
}

function getSheetName() {
const queryString = window.location.href.match(/sheetName(.*)/)
const queryParams = queryString ? QueryParams(queryString[0]) : {}

return queryParams.sheetName
}

module.exports = {
constructSheetUrl,
getDocumentOrSheetId,
getSheetName
}

0 comments on commit 0954c6b

Please sign in to comment.