Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for alternative radars in JSON format #363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,52 @@ If you do not want to host the JSON file publicly, you can follow [these steps](

**_Note:_** The JSON file parsing is using D3 library, so consult the [D3 documentation](https://github.com/d3/d3-request/blob/master/README.md#json) for the data format details.

#### Multiple alternative radars in JSON

Just like with Google Spreadsheets, you can provide multiple alternative radars in the same JSON file by returning an object instead of an array.
The keys of the object will be the names of the alternative radars, and show up as buttons at the bottom of the radar, allowing the user to choose which radar to view:

![Alternative Radar buttons shown on the radar](assets/alternative_radars-min.png)

The above example of a JSON structure, split into two different radars would look like this:

```json
{
"First": [
{
"name": "Composer",
"ring": "adopt",
"quadrant": "tools",
"isNew": "TRUE",
"description": "Although the idea of dependency..."
},
{
"name": "Canary builds",
"ring": "trial",
"quadrant": "techniques",
"isNew": "FALSE",
"description": "Many projects have external code..."
}
],
"Second": [
{
"name": "Apache Kylin",
"ring": "assess",
"quadrant": "platforms",
"isNew": "TRUE",
"description": "Apache Kylin is an open source..."
},
{
"name": "JSF",
"ring": "hold",
"quadrant": "languages & frameworks",
"isNew": "FALSE",
"description": "We continue to see teams run..."
}
]
}
```

### Building the radar

Paste the URL in the input field on the home page.
Expand Down
Binary file added assets/alternative_radars-min.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions spec/end_to_end_tests/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"CSV_FILE_URL": "https://raw.githubusercontent.com/thoughtworks/build-your-own-radar/master/spec/end_to_end_tests/resources/sheet.csv",
"JSON_FILE_URL": "https://raw.githubusercontent.com/thoughtworks/build-your-own-radar/master/spec/end_to_end_tests/resources/data.json",
"CSV_FILE_URL": "/e2e_resources/sheet.csv",
"JSON_FILE_URL": "/e2e_resources/data.json",
"JSON_MULTI_RADAR_FILE_URL": "/e2e_resources/multi_data.json",
"PUBLIC_GOOGLE_SHEET_URL": "https://docs.google.com/spreadsheets/d/1wZVb8V53O0Lzr4iMaz4qjJZKteA1xQhJNajGq0jE9sw",
"PUBLIC_GOOGLE_SHEET_TITLE": "BYOR Test - Public Google Sheet",
"PUBLIC_GOOGLE_SHEET_RADAR_SHEET_NAMES": ["Build your Technology Radar", "Build your Technology Radar - Sheet 2"],
Expand Down
5 changes: 5 additions & 0 deletions spec/end_to_end_tests/pageObjects/byor_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class ByorPage {
cy.get(this.textBox).type(config.JSON_FILE_URL)
}

provideMultiJsonName() {
cy.get(this.textBox).clear()
cy.get(this.textBox).type(config.JSON_MULTI_RADAR_FILE_URL)
}

providePublicSheetUrl() {
cy.get(this.textBox).clear()
cy.get(this.textBox).type(config.PUBLIC_GOOGLE_SHEET_URL)
Expand Down
272 changes: 272 additions & 0 deletions spec/end_to_end_tests/resources/multi_data.json

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions spec/end_to_end_tests/specs/end_to_end.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,71 @@ describe('Build radar with CSV', () => {
})
})

describe('Support multiple radars in one JSON', () => {
beforeEach(function () {
if (Cypress.currentTest.title == 'verify initial view of Radar') {
cy.visit(Cypress.env('host') + `/?documentId=${encodeURIComponent(testConfig.JSON_MULTI_RADAR_FILE_URL)}`)
} else if (
Cypress.currentTest.title !== 'verify url input and submit' &&
Cypress.currentTest.title !== 'verify keypress / to focus url input'
) {
cy.visit(
Cypress.env('host') +
`/?documentId=${encodeURIComponent(testConfig.JSON_MULTI_RADAR_FILE_URL)}&sheetName=Second`,
)
} else {
cy.visit(Cypress.env('host'))
}
})

context('No chosen radar', () => {
it('verify url input and submit', () => {
byorPage.provideMultiJsonName()
byorPage.clickSubmitButton()

radarPage.validateGraphTitle('Multi_data - First')

radarPage.validateMobileQuadrantsHidden()
radarPage.validateGraphVisible()
radarPage.validateQuadrantOrder()
radarPage.validateRingOrder()

radarPage.validateActiveAlternateRadar(1)
radarPage.validateInactiveAlternateRadar(2)
radarPage.clickAlternateRadarItem(2)
radarPage.validateActiveAlternateRadar(2)
radarPage.validateInactiveAlternateRadar(1)
radarPage.validateGraphTitle('Multi_data - Second')
})

it('verify initial view of Radar', () => {
radarPage.validateGraphTitle('Multi_data - First')

radarPage.validateMobileQuadrantsHidden()
radarPage.validateGraphVisible()
radarPage.validateQuadrantOrder()
radarPage.validateRingOrder()

radarPage.validateActiveAlternateRadar(1)
radarPage.validateInactiveAlternateRadar(2)
})
})

context('Second chosen radar', () => {
it('verify initial view of Radar when alternative is chosen', () => {
radarPage.validateGraphTitle('Multi_data - Second')

radarPage.validateMobileQuadrantsHidden()
radarPage.validateGraphVisible()
radarPage.validateQuadrantOrder()
radarPage.validateRingOrder()

radarPage.validateActiveAlternateRadar(2)
radarPage.validateInactiveAlternateRadar(1)
})
})
})

describe('Build radar with JSON', () => {
beforeEach(function () {
if (
Expand Down
39 changes: 32 additions & 7 deletions src/util/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const CSVDocument = function (url) {
return self
}

const JSONFile = function (url) {
const JSONFile = function (url, radarName) {
var self = {}

self.build = function () {
Expand All @@ -252,16 +252,41 @@ const JSONFile = function (url) {
})
}

var sheetName = radarName
var createBlips = function (data) {
var radarName = sheetName
try {
var columnNames = Object.keys(data[0])
var source
var alternativeRadars = []

// If the JSON is an object, but not an array it might contain
// multiple sheets of arrays, so we treat it as such
if (typeof data === 'object' && !Array.isArray(data)) {
alternativeRadars = Object.keys(data)

if (!radarName || radarName == 'JSON File') {
radarName = alternativeRadars[0]
}

source = data[radarName]
} else {
source = data
}

var columnNames = Object.keys(source[0])
var contentValidator = new ContentValidator(columnNames)
contentValidator.verifyContent()
contentValidator.verifyHeaders()
var blips = _.map(data, new InputSanitizer().sanitize)
var blips = _.map(source, new InputSanitizer().sanitize)

var title = FileName(url)
if (radarName) {
title = title.substring(0, title.length - 5) + ' - ' + radarName
}

featureToggles.UIRefresh2022
? plotRadarGraph(FileName(url), blips, 'JSON File', [])
: plotRadar(FileName(url), blips, 'JSON File', [])
? plotRadarGraph(title, blips, radarName, alternativeRadars)
: plotRadar(title, blips, radarName, alternativeRadars)
} catch (exception) {
const invalidContentError = new InvalidContentError(ExceptionMessages.INVALID_JSON_CONTENT)
plotErrorMessage(featureToggles.UIRefresh2022 ? invalidContentError : exception, 'json')
Expand Down Expand Up @@ -319,14 +344,14 @@ const Factory = function () {
const domainName = DomainName(window.location.search.substring(1))

const paramId = getDocumentOrSheetId()
const sheetName = getSheetName()
if (paramId && paramId.endsWith('.csv')) {
sheet = CSVDocument(paramId)
sheet.init().build()
} else if (paramId && paramId.endsWith('.json')) {
sheet = JSONFile(paramId)
sheet = JSONFile(paramId, sheetName)
sheet.init().build()
} else if (domainName && domainName.endsWith('google.com') && paramId) {
const sheetName = getSheetName()
sheet = GoogleSheet(paramId, sheetName)
sheet.init().build()
} else {
Expand Down
7 changes: 7 additions & 0 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const postcssPresetEnv = require('postcss-preset-env')
const cssnano = require('cssnano')
const path = require('path')

const common = require('./webpack.common.js')
const config = require('./src/config')
Expand All @@ -27,6 +28,12 @@ Object.entries(featureToggles).forEach(function ([key, value]) {
module.exports = merge(common, {
mode: 'development',
entry: { main: main },
devServer: {
static: {
directory: path.resolve(__dirname, './spec/end_to_end_tests/resources'),
publicPath: '/e2e_resources',
},
},
performance: {
hints: false,
},
Expand Down