Azure Monitor: Add validation for namespace field in AdvancedResourcePicker when entering a forward slash (#89288)

* Add validation for namespace field in AdvancedResourcePicker when entering a forward slash

* Add test

* Fix formatting

* Remove unused import
This commit is contained in:
Adam Yeats 2024-06-17 18:43:27 +01:00 committed by GitHub
parent 92233350f8
commit 0bdd613f3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -101,4 +101,17 @@ describe('AdvancedResourcePicker', () => {
expect(screen.getByDisplayValue('rg2')).toBeInTheDocument(); expect(screen.getByDisplayValue('rg2')).toBeInTheDocument();
expect(screen.getByDisplayValue('res2')).toBeInTheDocument(); expect(screen.getByDisplayValue('res2')).toBeInTheDocument();
}); });
it('should display an error when the namespace field ends in a /', async () => {
const onChange = jest.fn();
render(
<AdvancedResourcePicker
onChange={onChange}
resources={[{ metricNamespace: 'Microsoft.OperationalInsights/workspaces/' }]}
/>
);
expect(screen.getByText('Namespace cannot end with a "/"')).toBeInTheDocument();
});
}); });

View File

@ -81,6 +81,8 @@ const AdvancedResourcePicker = ({ resources, onChange }: ResourcePickerProps<Azu
htmlFor={`input-advanced-resource-picker-metricNamespace`} htmlFor={`input-advanced-resource-picker-metricNamespace`}
labelWidth={15} labelWidth={15}
data-testid={selectors.components.queryEditor.resourcePicker.advanced.namespace.input} data-testid={selectors.components.queryEditor.resourcePicker.advanced.namespace.input}
invalid={resources[0]?.metricNamespace?.endsWith('/')}
error={'Namespace cannot end with a "/"'}
> >
<Input <Input
id={`input-advanced-resource-picker-metricNamespace`} id={`input-advanced-resource-picker-metricNamespace`}