From 1b510c352867970cde3552fcfb699d49acfca23d Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 9 Jul 2023 10:02:47 -0400 Subject: [PATCH 1/5] feat: deep-link to quadrant --- src/graphing/radar.js | 20 +++++++++++++++++++- src/util/urlUtils.js | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/graphing/radar.js b/src/graphing/radar.js index e4d791525..a315a73f1 100644 --- a/src/graphing/radar.js +++ b/src/graphing/radar.js @@ -20,11 +20,12 @@ const { renderMobileView, renderRadarLegends, removeScrollListener, + selectRadarQuadrant, } = require('./components/quadrants') const { renderQuadrantTables } = require('./components/quadrantTables') const { addQuadrantNameInPdfView, addRadarLinkInPdfView } = require('./pdfPage') -const { constructSheetUrl } = require('../util/urlUtils') +const { constructSheetUrl, getQuadrantFromURL } = require('../util/urlUtils') const { toRadian } = require('../util/mathUtils') const MIN_BLIP_WIDTH = 12 @@ -832,9 +833,26 @@ const Radar = function (size, radar) { hideTooltipOnScroll(tip) addRadarLinkInPdfView() } + + selectQuadrantsToShow(quadrants) } return self } +function selectQuadrantsToShow(quadrants) { + const quadrantToShow = getQuadrantFromURL() + let quadrant + + for (const q of quadrants) { + if (q.order === quadrantToShow) { + quadrant = q + } + } + + if (quadrant) { + selectRadarQuadrant(quadrant.order, quadrant.startAngle, quadrant.quadrant.name()) + } +} + module.exports = Radar diff --git a/src/util/urlUtils.js b/src/util/urlUtils.js index eef0bbe4b..bbedd72b7 100644 --- a/src/util/urlUtils.js +++ b/src/util/urlUtils.js @@ -13,6 +13,13 @@ function constructSheetUrl(sheetName) { return sheetUrl } +function getQuadrantFromURL() { + const queryParams = QueryParams(window.location.search.substring(1)) + const quadrantQueryString = queryParams.quadrant.toLowerCase() + return quadrantQueryString ?? 'all' +} + module.exports = { constructSheetUrl, + getQuadrantFromURL, } From 249660412f60df4835003cd31e8913fdad02c1fc Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 9 Jul 2023 10:11:14 -0400 Subject: [PATCH 2/5] tests --- spec/util/urlUtils-spec.js | 24 +++++++++++++++++++++++- src/util/urlUtils.js | 9 +++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/spec/util/urlUtils-spec.js b/spec/util/urlUtils-spec.js index e2a5f6379..53dd99724 100644 --- a/spec/util/urlUtils-spec.js +++ b/spec/util/urlUtils-spec.js @@ -1,4 +1,4 @@ -const { constructSheetUrl } = require('../../src/util/urlUtils') +const { constructSheetUrl, getQuadrantFromURL } = require('../../src/util/urlUtils') const config = require('../../src/config') const queryParams = require('../../src/util/queryParamProcessor') @@ -32,4 +32,26 @@ describe('Url Utils', () => { expect(config).toHaveBeenCalledTimes(1) expect(queryParams).toHaveBeenCalledTimes(1) }) + + it('should return all if no quadrant found in url', () => { + queryParams.mockReturnValue({ some: 'param' }) + delete window.location + window.location = Object.create(window) + window.location.href = 'https://thoughtworks.com/radar?sheet=radar' + window.location.search = '?' + const quadrant = getQuadrantFromURL() + + expect(quadrant).toBe('all') + }) + + it('should return quadrant if found in url', () => { + queryParams.mockReturnValue({ quadrant: 'FIRST' }) + delete window.location + window.location = Object.create(window) + window.location.href = 'https://thoughtworks.com/radar?sheet=radar' + window.location.search = '?' + const quadrant = getQuadrantFromURL() + + expect(quadrant).toBe('first') + }) }) diff --git a/src/util/urlUtils.js b/src/util/urlUtils.js index bbedd72b7..49a48e6d7 100644 --- a/src/util/urlUtils.js +++ b/src/util/urlUtils.js @@ -15,8 +15,13 @@ function constructSheetUrl(sheetName) { function getQuadrantFromURL() { const queryParams = QueryParams(window.location.search.substring(1)) - const quadrantQueryString = queryParams.quadrant.toLowerCase() - return quadrantQueryString ?? 'all' + const quadrantQueryString = queryParams.quadrant + + if (quadrantQueryString) { + return quadrantQueryString.toLowerCase() + } + + return 'all' } module.exports = { From ed84a7c7700d105b01e7c561bc36f9dcd208ebb9 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 9 Jul 2023 11:07:05 -0400 Subject: [PATCH 3/5] docs: update README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index abab4ce12..7fea1a3e4 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,17 @@ 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. +### Deep linking to a particular quadrant + +You can use the optional query string parameter `quadrant` to specify the quadrant to view. + +Supported values are: + +- `first` +- `second` +- `third` +- `fourth` + ### Building the radar Paste the URL in the input field on the home page. From eb8464efcd09ba6f93e4b706a0ebcd96967836b1 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 16 Jul 2023 14:28:43 -0700 Subject: [PATCH 4/5] refactor: simplify --- src/util/urlUtils.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/util/urlUtils.js b/src/util/urlUtils.js index 49a48e6d7..a94250e09 100644 --- a/src/util/urlUtils.js +++ b/src/util/urlUtils.js @@ -17,11 +17,7 @@ function getQuadrantFromURL() { const queryParams = QueryParams(window.location.search.substring(1)) const quadrantQueryString = queryParams.quadrant - if (quadrantQueryString) { - return quadrantQueryString.toLowerCase() - } - - return 'all' + return quadrantQueryString?.toLowerCase() ?? 'all' } module.exports = { From bd692dd4b1fec0eee1c01cf64c614dc3dbc13505 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 17 Jul 2023 06:11:48 -0700 Subject: [PATCH 5/5] Merge remote-tracking branch 'setchy/master' into feature/5-link-to-quadrant --- spec/util/urlUtils-spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/util/urlUtils-spec.js b/spec/util/urlUtils-spec.js index 628ca0049..af402746b 100644 --- a/spec/util/urlUtils-spec.js +++ b/spec/util/urlUtils-spec.js @@ -1,4 +1,4 @@ -const { constructSheetUrl } = require('../../src/util/urlUtils') +const { constructSheetUrl, getDocumentOrSheetId, getSheetName, getQuadrantFromURL } = require('../../src/util/urlUtils') const config = require('../../src/config') const queryParams = require('../../src/util/queryParamProcessor') @@ -101,4 +101,5 @@ describe('Url Utils', () => { const quadrant = getQuadrantFromURL() expect(quadrant).toBe('first') + }) })