Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomMeasurementCollection>((acc, customMeasurement) => {
acc[customMeasurement] = {
key: customMeasurement,
name: customMeasurement,
functions: response[customMeasurement].functions,
};
return acc;
}, {});
const newCustomMeasurements = Object.keys(
response
).reduce<CustomMeasurementCollection>((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;
Expand Down
7 changes: 6 additions & 1 deletion tests/js/spec/utils/useCustomMeasurements.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<CustomMeasurementsProvider organization={organization}>
Expand Down