remove regions/locations from variable editor

This commit is contained in:
Adam Simpson 2023-07-20 15:08:04 -04:00
parent 5861d4a6a9
commit 41dc6a8bfb
No known key found for this signature in database
3 changed files with 0 additions and 69 deletions

View File

@ -258,12 +258,10 @@ describe('VariableEditor:', () => {
await waitFor(() => expect(screen.getByText('Logs')).toBeInTheDocument());
await selectAndRerender('select query type', 'Resource Names', onChange, rerender);
await selectAndRerender('select subscription', 'Primary Subscription', onChange, rerender);
await selectAndRerender('select region', 'North Europe', onChange, rerender);
expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
queryType: AzureQueryType.ResourceNamesQuery,
subscription: 'sub',
region: 'northeurope',
refId: 'A',
})
);
@ -325,21 +323,5 @@ describe('VariableEditor:', () => {
})
);
});
it('should run the query if requesting regions', async () => {
const onChange = jest.fn();
const { rerender } = render(<VariableEditor {...defaultProps} onChange={onChange} />);
// wait for initial load
await waitFor(() => expect(screen.getByText('Logs')).toBeInTheDocument());
await selectAndRerender('select query type', 'Regions', onChange, rerender);
await selectAndRerender('select subscription', 'Primary Subscription', onChange, rerender);
expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
queryType: AzureQueryType.LocationsQuery,
subscription: 'sub',
refId: 'A',
})
);
});
});
});

View File

@ -30,7 +30,6 @@ const VariableEditor = (props: Props) => {
{ label: 'Subscriptions', value: AzureQueryType.SubscriptionsQuery },
{ label: 'Resource Groups', value: AzureQueryType.ResourceGroupsQuery },
{ label: 'Namespaces', value: AzureQueryType.NamespacesQuery },
{ label: 'Regions', value: AzureQueryType.LocationsQuery },
{ label: 'Resource Names', value: AzureQueryType.ResourceNamesQuery },
{ label: 'Metric Names', value: AzureQueryType.MetricNamesQuery },
{ label: 'Workspaces', value: AzureQueryType.WorkspacesQuery },
@ -51,7 +50,6 @@ const VariableEditor = (props: Props) => {
const [requireSubscription, setRequireSubscription] = useState(false);
const [hasResourceGroup, setHasResourceGroup] = useState(false);
const [hasNamespace, setHasNamespace] = useState(false);
const [hasRegion, setHasRegion] = useState(false);
const [requireResourceGroup, setRequireResourceGroup] = useState(false);
const [requireNamespace, setRequireNamespace] = useState(false);
const [requireResource, setRequireResource] = useState(false);
@ -59,7 +57,6 @@ const VariableEditor = (props: Props) => {
const [resourceGroups, setResourceGroups] = useState<SelectableValue[]>([]);
const [namespaces, setNamespaces] = useState<SelectableValue[]>([]);
const [resources, setResources] = useState<SelectableValue[]>([]);
const [regions, setRegions] = useState<SelectableValue[]>([]);
const [errorMessage, setError] = useLastError();
const queryType = typeof query === 'string' ? '' : query.queryType;
@ -91,7 +88,6 @@ const VariableEditor = (props: Props) => {
setRequireSubscription(true);
setHasResourceGroup(true);
setHasNamespace(true);
setHasRegion(true);
break;
case AzureQueryType.MetricNamesQuery:
setRequireSubscription(true);
@ -99,9 +95,6 @@ const VariableEditor = (props: Props) => {
setRequireNamespace(true);
setRequireResource(true);
break;
case AzureQueryType.LocationsQuery:
setRequireSubscription(true);
break;
}
}, [queryType]);
@ -142,16 +135,6 @@ const VariableEditor = (props: Props) => {
}
}, [datasource, subscription, resourceGroup]);
useEffect(() => {
if (subscription) {
datasource.azureMonitorDatasource.getLocations([subscription]).then((rgs) => {
const regions: SelectableValue[] = [];
rgs.forEach((r) => regions.push({ label: r.displayName, value: r.name }));
setRegions(regions);
});
}
}, [datasource, subscription, resourceGroup]);
const namespace = (typeof query === 'object' && query.namespace) || '';
useEffect(() => {
if (subscription) {
@ -208,13 +191,6 @@ const VariableEditor = (props: Props) => {
});
};
const onChangeRegion = (selectableValue: SelectableValue) => {
onChange({
...query,
region: selectableValue.value,
});
};
const onChangeResource = (selectableValue: SelectableValue) => {
onChange({
...query,
@ -320,22 +296,6 @@ const VariableEditor = (props: Props) => {
/>
</InlineField>
)}
{hasRegion && (
<InlineField
label="Select region"
labelWidth={20}
data-testid={selectors.components.variableEditor.region.input}
>
<Select
aria-label="select region"
onChange={onChangeRegion}
options={regions.concat(variableOptionGroup)}
width={25}
value={query.region || null}
placeholder="Optional"
/>
</InlineField>
)}
{requireResource && (
<InlineField
label="Select resource"

View File

@ -109,17 +109,6 @@ export class VariableSupport extends CustomVariableSupport<DataSource, AzureMoni
};
}
return { data: [] };
case AzureQueryType.LocationsQuery:
if (queryObj.subscription && this.hasValue(queryObj.subscription)) {
const locationMap = await this.datasource.azureMonitorDatasource.getLocations([queryObj.subscription]);
const res: Array<{ text: string; value: string }> = [];
locationMap.forEach((loc) => {
res.push({ text: loc.displayName, value: loc.name });
});
return {
data: res?.length ? [toDataFrame(res)] : [],
};
}
default:
request.targets[0] = queryObj;
const queryResp = await lastValueFrom(this.datasource.query(request));