From 88983c6af08d3c7c6398b5da9704f987ad0d8c6f Mon Sep 17 00:00:00 2001 From: Edward Gou Date: Thu, 14 Jul 2022 16:42:25 +0200 Subject: [PATCH 1/2] wraps fetch in feature flag --- .../customMeasurementsProvider.tsx | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/static/app/utils/customMeasurements/customMeasurementsProvider.tsx b/static/app/utils/customMeasurements/customMeasurementsProvider.tsx index 0926287440c732..0d9225268442c3 100644 --- a/static/app/utils/customMeasurements/customMeasurementsProvider.tsx +++ b/static/app/utils/customMeasurements/customMeasurementsProvider.tsx @@ -57,34 +57,37 @@ export function CustomMeasurementsProvider({ useEffect(() => { let shouldCancelRequest = false; - fetchCustomMeasurements(api, organization, selection) - .then(response => { - if (shouldCancelRequest) { - return; - } + if (organization.features.includes('dashboard-custom-measurement-widgets')) { + fetchCustomMeasurements(api, organization, selection) + .then(response => { + if (shouldCancelRequest) { + return; + } - const newCustomMeasurements = Object.keys( - response - ).reduce((acc, customMeasurement) => { - acc[customMeasurement] = { - key: customMeasurement, - name: customMeasurement, - functions: response[customMeasurement].functions, - }; - return acc; - }, {}); + const newCustomMeasurements = Object.keys( + response + ).reduce((acc, customMeasurement) => { + acc[customMeasurement] = { + key: customMeasurement, + name: customMeasurement, + functions: response[customMeasurement].functions, + }; + return acc; + }, {}); - setState({customMeasurements: newCustomMeasurements}); - }) - .catch(e => { - if (shouldCancelRequest) { - return; - } + setState({customMeasurements: newCustomMeasurements}); + }) + .catch(e => { + if (shouldCancelRequest) { + return; + } - const errorResponse = e?.responseJSON ?? t('Unable to fetch custom measurements'); - addErrorMessage(errorResponse); - handleXhrErrorResponse(errorResponse)(e); - }); + const errorResponse = + e?.responseJSON ?? t('Unable to fetch custom measurements'); + addErrorMessage(errorResponse); + handleXhrErrorResponse(errorResponse)(e); + }); + } return () => { shouldCancelRequest = true; From 105f940924f210da30811101b97e6ab1067d199e Mon Sep 17 00:00:00 2001 From: Edward Gou Date: Thu, 14 Jul 2022 17:22:23 +0200 Subject: [PATCH 2/2] fix test --- tests/js/spec/utils/useCustomMeasurements.spec.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/js/spec/utils/useCustomMeasurements.spec.tsx b/tests/js/spec/utils/useCustomMeasurements.spec.tsx index f32ef014697aaa..38f58d4defa6d4 100644 --- a/tests/js/spec/utils/useCustomMeasurements.spec.tsx +++ b/tests/js/spec/utils/useCustomMeasurements.spec.tsx @@ -33,7 +33,12 @@ function mockMeasurementsMeta() { describe('useCustomMeasurements', function () { it('provides customMeasurements from the custom measurements context', async function () { - const {organization} = initializeOrg(); + const {organization} = initializeOrg({ + organization: {features: ['dashboard-custom-measurement-widgets']}, + project: undefined, + projects: [], + router: {}, + }); const measurementsMetaMock = mockMeasurementsMeta(); render(