-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Uptime] add monitor edit and add pages #118947
Changes from all commits
6554b17
7983404
71e3c80
fabe20a
e7de9ce
ea29332
d9013e3
3eb88f5
49ad6f9
3b77118
b28ab8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import { DataStream } from '../types'; | |
|
||
interface IPolicyConfigContext { | ||
setMonitorType: React.Dispatch<React.SetStateAction<DataStream>>; | ||
setName: React.Dispatch<React.SetStateAction<string>>; | ||
setLocations: React.Dispatch<React.SetStateAction<string[]>>; | ||
setIsTLSEnabled: React.Dispatch<React.SetStateAction<boolean>>; | ||
setIsZipUrlTLSEnabled: React.Dispatch<React.SetStateAction<boolean>>; | ||
monitorType: DataStream; | ||
|
@@ -19,13 +21,19 @@ interface IPolicyConfigContext { | |
defaultIsTLSEnabled?: boolean; | ||
defaultIsZipUrlTLSEnabled?: boolean; | ||
isEditable?: boolean; | ||
defaultName?: string; | ||
name?: string; | ||
defaultLocations?: string[]; | ||
locations?: string[]; | ||
} | ||
|
||
interface IPolicyConfigContextProvider { | ||
children: React.ReactNode; | ||
defaultMonitorType?: DataStream; | ||
defaultIsTLSEnabled?: boolean; | ||
defaultIsZipUrlTLSEnabled?: boolean; | ||
defaultName?: string; | ||
defaultLocations?: string[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this might end up becoming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the heads up. |
||
isEditable?: boolean; | ||
} | ||
|
||
|
@@ -35,6 +43,12 @@ const defaultContext: IPolicyConfigContext = { | |
setMonitorType: (_monitorType: React.SetStateAction<DataStream>) => { | ||
throw new Error('setMonitorType was not initialized, set it when you invoke the context'); | ||
}, | ||
setName: (_name: React.SetStateAction<string>) => { | ||
throw new Error('setName was not initialized, set it when you invoke the context'); | ||
}, | ||
setLocations: (_locations: React.SetStateAction<string[]>) => { | ||
throw new Error('setLocations was not initialized, set it when you invoke the context'); | ||
}, | ||
setIsTLSEnabled: (_isTLSEnabled: React.SetStateAction<boolean>) => { | ||
throw new Error('setIsTLSEnabled was not initialized, set it when you invoke the context'); | ||
}, | ||
|
@@ -47,19 +61,25 @@ const defaultContext: IPolicyConfigContext = { | |
defaultMonitorType: initialValue, // immutable, | ||
defaultIsTLSEnabled: false, | ||
defaultIsZipUrlTLSEnabled: false, | ||
defaultName: '', | ||
defaultLocations: [], | ||
isEditable: false, | ||
}; | ||
|
||
export const PolicyConfigContext = createContext(defaultContext); | ||
|
||
export const PolicyConfigContextProvider = ({ | ||
export function PolicyConfigContextProvider<ExtraFields = unknown>({ | ||
children, | ||
defaultMonitorType = initialValue, | ||
defaultIsTLSEnabled = false, | ||
defaultIsZipUrlTLSEnabled = false, | ||
defaultName = '', | ||
defaultLocations = [], | ||
isEditable = false, | ||
}: IPolicyConfigContextProvider) => { | ||
}: IPolicyConfigContextProvider) { | ||
const [monitorType, setMonitorType] = useState<DataStream>(defaultMonitorType); | ||
const [name, setName] = useState<string>(defaultName); | ||
const [locations, setLocations] = useState<string[]>(defaultLocations); | ||
const [isTLSEnabled, setIsTLSEnabled] = useState<boolean>(defaultIsTLSEnabled); | ||
const [isZipUrlTLSEnabled, setIsZipUrlTLSEnabled] = useState<boolean>(defaultIsZipUrlTLSEnabled); | ||
|
||
|
@@ -75,6 +95,12 @@ export const PolicyConfigContextProvider = ({ | |
defaultIsTLSEnabled, | ||
defaultIsZipUrlTLSEnabled, | ||
isEditable, | ||
defaultName, | ||
name, | ||
setName, | ||
defaultLocations, | ||
locations, | ||
setLocations, | ||
}; | ||
}, [ | ||
monitorType, | ||
|
@@ -84,9 +110,15 @@ export const PolicyConfigContextProvider = ({ | |
defaultIsTLSEnabled, | ||
defaultIsZipUrlTLSEnabled, | ||
isEditable, | ||
name, | ||
defaultName, | ||
locations, | ||
defaultLocations, | ||
]); | ||
|
||
return <PolicyConfigContext.Provider value={value} children={children} />; | ||
}; | ||
} | ||
|
||
export const usePolicyConfigContext = () => useContext(PolicyConfigContext); | ||
export function usePolicyConfigContext() { | ||
return useContext(PolicyConfigContext); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { HTTPFields, TCPFields, ICMPFields, BrowserFields, ITLSFields, DataStream } from '../types'; | ||
import { | ||
PolicyConfigContextProvider, | ||
TCPContextProvider, | ||
ICMPSimpleFieldsContextProvider, | ||
HTTPContextProvider, | ||
BrowserContextProvider, | ||
TLSFieldsContextProvider, | ||
} from '.'; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
httpDefaultValues?: HTTPFields; | ||
tcpDefaultValues?: TCPFields; | ||
icmpDefaultValues?: ICMPFields; | ||
browserDefaultValues?: BrowserFields; | ||
tlsDefaultValues?: ITLSFields; | ||
policyDefaultValues?: { | ||
defaultMonitorType: DataStream; | ||
defaultIsTLSEnabled: boolean; | ||
defaultIsZipUrlTLSEnabled: boolean; | ||
defaultName?: string; | ||
defaultLocations?: string[]; | ||
isEditable: boolean; | ||
}; | ||
} | ||
|
||
export const SyntheticsProviders = ({ | ||
children, | ||
httpDefaultValues, | ||
tcpDefaultValues, | ||
icmpDefaultValues, | ||
browserDefaultValues, | ||
tlsDefaultValues, | ||
policyDefaultValues, | ||
}: Props) => { | ||
return ( | ||
<PolicyConfigContextProvider {...(policyDefaultValues || {})}> | ||
<HTTPContextProvider defaultValues={httpDefaultValues}> | ||
<TCPContextProvider defaultValues={tcpDefaultValues}> | ||
<TLSFieldsContextProvider defaultValues={tlsDefaultValues}> | ||
<ICMPSimpleFieldsContextProvider defaultValues={icmpDefaultValues}> | ||
<BrowserContextProvider defaultValues={browserDefaultValues}> | ||
{children} | ||
</BrowserContextProvider> | ||
</ICMPSimpleFieldsContextProvider> | ||
</TLSFieldsContextProvider> | ||
</TCPContextProvider> | ||
</HTTPContextProvider> | ||
</PolicyConfigContextProvider> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { BrowserFields, ConfigKeys } from '../../fleet_package/types'; | ||
import { Formatter, commonFormatters, objectFormatter, arrayFormatter } from './common'; | ||
|
||
export type BrowserFormatMap = Record<keyof BrowserFields, Formatter>; | ||
|
||
export const browserFormatters: BrowserFormatMap = { | ||
[ConfigKeys.METADATA]: (fields) => objectFormatter(fields[ConfigKeys.METADATA]), | ||
[ConfigKeys.SOURCE_ZIP_URL]: null, | ||
[ConfigKeys.SOURCE_ZIP_USERNAME]: null, | ||
[ConfigKeys.SOURCE_ZIP_PASSWORD]: null, | ||
[ConfigKeys.SOURCE_ZIP_FOLDER]: null, | ||
[ConfigKeys.SOURCE_ZIP_PROXY_URL]: null, | ||
[ConfigKeys.SOURCE_INLINE]: null, | ||
Comment on lines
+15
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't all of this goes in nested way now? but i think if we want to keep parity with fleet we may have to continue using existing key format. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right that it's best to continue to do this to keep parity with fleet. The actual UI fields are mapped to the flattened keys. Keeping it this way allows us to have to do the least amount of work short term. |
||
[ConfigKeys.PARAMS]: null, | ||
[ConfigKeys.SCREENSHOTS]: null, | ||
[ConfigKeys.SYNTHETICS_ARGS]: (fields) => null, | ||
[ConfigKeys.ZIP_URL_TLS_CERTIFICATE_AUTHORITIES]: null, | ||
[ConfigKeys.ZIP_URL_TLS_CERTIFICATE]: null, | ||
[ConfigKeys.ZIP_URL_TLS_KEY]: null, | ||
[ConfigKeys.ZIP_URL_TLS_KEY_PASSPHRASE]: null, | ||
[ConfigKeys.ZIP_URL_TLS_VERIFICATION_MODE]: null, | ||
[ConfigKeys.ZIP_URL_TLS_VERSION]: (fields) => | ||
arrayFormatter(fields[ConfigKeys.ZIP_URL_TLS_VERSION]), | ||
[ConfigKeys.JOURNEY_FILTERS_MATCH]: null, | ||
[ConfigKeys.JOURNEY_FILTERS_TAGS]: null, | ||
[ConfigKeys.IGNORE_HTTPS_ERRORS]: null, | ||
...commonFormatters, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change triggered with linting. I'm assuming this has already been discovered by the team, and if I merge upstream before merging the PR, it'll most likely have already been resolved.