22 consoleFetchJSON ,
33 DocumentTitle ,
44 NamespaceBar ,
5+ useActiveNamespace ,
56} from '@openshift-console/dynamic-plugin-sdk' ;
67import {
78 ActionGroup ,
@@ -50,10 +51,9 @@ import { ExternalLink } from '../console/utils/link';
5051import { useBoolean } from '../hooks/useBoolean' ;
5152import { getSilenceAlertUrl , usePerspective } from '../hooks/usePerspective' ;
5253import { DataTestIDs } from '../data-test' ;
53- import { ALL_NAMESPACES_KEY , getAlertmanagerSilencesUrl } from '../utils' ;
54+ import { getAlertmanagerSilencesUrl } from '../utils' ;
5455import { useAlerts } from '../../hooks/useAlerts' ;
5556import { useMonitoring } from '../../hooks/useMonitoring' ;
56- import { useQueryNamespace } from '../hooks/useQueryNamespace' ;
5757
5858const durationOff = '-' ;
5959
@@ -133,8 +133,8 @@ const NegativeMatcherHelp = () => {
133133
134134const SilenceForm_ : FC < SilenceFormProps > = ( { defaults, Info, title, isNamespaced } ) => {
135135 const { t } = useTranslation ( process . env . I18N_NAMESPACE ) ;
136- const { namespace } = useQueryNamespace ( ) ;
137- const { prometheus, useAlertsTenancy } = useMonitoring ( ) ;
136+ const [ namespace ] = useActiveNamespace ( ) ;
137+ const { prometheus } = useMonitoring ( ) ;
138138 const navigate = useNavigate ( ) ;
139139
140140 const durations = useMemo ( ( ) => {
@@ -151,8 +151,6 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
151151 } ;
152152 } , [ t ] ) ;
153153
154- const requireNamespace = isNamespaced && namespace !== ALL_NAMESPACES_KEY ;
155-
156154 const now = new Date ( ) ;
157155
158156 // Default to starting now if we have no default start time or if the default start time is in the
@@ -189,7 +187,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
189187 // Since the namespace matcher MUST be the same as the namespace the request is being
190188 // made in, we remove the namespace value here and re-add it before sending the request
191189 const [ matchers , setMatchers ] = useState < Array < Matcher > > (
192- ( requireNamespace
190+ ( isNamespaced
193191 ? ( defaults . matchers as Matcher [ ] ) ?. filter ( ( matcher ) => matcher . name !== 'namespace' )
194192 : defaults . matchers ) ?? [ { isRegex : false , isEqual : true , name : '' , value : '' } ] ,
195193 ) ;
@@ -224,7 +222,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
224222
225223 const removeMatcher = ( i : number ) : void => {
226224 // If we require the namespace don't allow removing it
227- if ( requireNamespace && i === 0 ) {
225+ if ( isNamespaced && i === 0 ) {
228226 return ;
229227 }
230228
@@ -251,7 +249,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
251249 const url = getAlertmanagerSilencesUrl ( {
252250 prometheus,
253251 namespace,
254- useTenancyPath : useAlertsTenancy ,
252+ useTenancyPath : isNamespaced ,
255253 } ) ;
256254 if ( ! url ) {
257255 setError ( 'Alertmanager URL not set' ) ;
@@ -284,7 +282,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
284282
285283 consoleFetchJSON
286284 . post (
287- getAlertmanagerSilencesUrl ( { prometheus, namespace, useTenancyPath : useAlertsTenancy } ) ,
285+ getAlertmanagerSilencesUrl ( { prometheus, namespace, useTenancyPath : isNamespaced } ) ,
288286 body ,
289287 )
290288 . then ( ( { silenceID } ) => {
@@ -311,7 +309,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
311309 return (
312310 < >
313311 < DocumentTitle > { title } </ DocumentTitle >
314- < NamespaceBar />
312+ { isNamespaced && < NamespaceBar /> }
315313 < PageSection hasBodyWrapper = { false } >
316314 < Title headingLevel = "h1" > { title } </ Title >
317315 < HelperText >
@@ -427,7 +425,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
427425 </ HelperText >
428426 </ FormHelperText >
429427
430- { requireNamespace && (
428+ { isNamespaced && (
431429 < Grid key = { 'namespace' } sm = { 12 } md = { 4 } hasGutter >
432430 < GridItem >
433431 < FormGroup label = { t ( 'Label name' ) } >
0 commit comments