mirror of
https://github.com/harness/drone.git
synced 2025-05-17 01:20:13 +08:00
feat: [CDE-704]: Added new delegate selector dropdown with options at infra level (#3615)
* fix: Added missing string * fix: lint issues * fix: Resolved the conflicts * fix: lint issues * fix: lint issues * fix: lint issues * fix: Passed the delegateSelector component from harness-core-ui to CDE module * fix: lint issues * feat: Added new delegate selector dropdown with options at infra level
This commit is contained in:
parent
cc64066d9a
commit
0a34d44cdd
@ -27,6 +27,7 @@ import { newCacheStrategy } from 'utils/CacheStrategy'
|
|||||||
import { useGetSettingValue } from 'hooks/useGetSettingValue'
|
import { useGetSettingValue } from 'hooks/useGetSettingValue'
|
||||||
import { useFeatureFlags } from 'hooks/useFeatureFlag'
|
import { useFeatureFlags } from 'hooks/useFeatureFlag'
|
||||||
import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot'
|
import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot'
|
||||||
|
import { defaultDelegateSelectorsV2 } from 'components/DelegateSelector/DelegateSelector'
|
||||||
|
|
||||||
interface AppContextProps extends AppProps {
|
interface AppContextProps extends AppProps {
|
||||||
setAppContext: (value: Partial<AppProps>) => void
|
setAppContext: (value: Partial<AppProps>) => void
|
||||||
@ -50,7 +51,8 @@ const AppContext = React.createContext<AppContextProps>({
|
|||||||
hooks: {},
|
hooks: {},
|
||||||
currentUser: defaultCurrentUser,
|
currentUser: defaultCurrentUser,
|
||||||
customComponents: {
|
customComponents: {
|
||||||
UsefulOrNot: defaultUsefulOrNot
|
UsefulOrNot: defaultUsefulOrNot,
|
||||||
|
DelegateSelectorsV2: defaultDelegateSelectorsV2
|
||||||
},
|
},
|
||||||
currentUserProfileURL: '',
|
currentUserProfileURL: '',
|
||||||
routingId: '',
|
routingId: '',
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import type React from 'react'
|
import type React from 'react'
|
||||||
import type { CODERoutes } from 'RouteDefinitions'
|
import type { CODERoutes } from 'RouteDefinitions'
|
||||||
import type { TypesUser } from 'services/code'
|
import type { TypesUser } from 'services/code'
|
||||||
import type { UsefulOrNotProps } from 'utils/types'
|
import type { DelegateSelectorsV2Props, UsefulOrNotProps } from 'utils/types'
|
||||||
import type { LangLocale } from './framework/strings/languageLoader'
|
import type { LangLocale } from './framework/strings/languageLoader'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,6 +61,7 @@ export interface AppProps {
|
|||||||
/** React Components which are passed down from the Parent that are needed by the child app */
|
/** React Components which are passed down from the Parent that are needed by the child app */
|
||||||
customComponents: {
|
customComponents: {
|
||||||
UsefulOrNot: (props: UsefulOrNotProps) => React.ReactElement
|
UsefulOrNot: (props: UsefulOrNotProps) => React.ReactElement
|
||||||
|
DelegateSelectorsV2: (props: DelegateSelectorsV2Props) => React.ReactElement
|
||||||
}
|
}
|
||||||
/** React Hooks that Harness Platform passes down. Note: Pass only hooks that your app need */
|
/** React Hooks that Harness Platform passes down. Note: Pass only hooks that your app need */
|
||||||
hooks: Partial<{
|
hooks: Partial<{
|
||||||
@ -77,6 +78,7 @@ export interface AppProps {
|
|||||||
useListAggregatedTokens?: Unknown
|
useListAggregatedTokens?: Unknown
|
||||||
useDeleteToken?: Unknown
|
useDeleteToken?: Unknown
|
||||||
useCreateToken?: Unknown
|
useCreateToken?: Unknown
|
||||||
|
useGetDelegateSelectorsUpTheHierarchyV2?: Unknown
|
||||||
}>
|
}>
|
||||||
|
|
||||||
currentUser: Required<TypesUser>
|
currentUser: Required<TypesUser>
|
||||||
|
@ -23,6 +23,7 @@ import { useFeatureFlags } from 'hooks/useFeatureFlag'
|
|||||||
import { useGetSettingValue } from 'hooks/useGetSettingValue'
|
import { useGetSettingValue } from 'hooks/useGetSettingValue'
|
||||||
import { useGetAuthSettings } from 'hooks/useGetAuthSettings'
|
import { useGetAuthSettings } from 'hooks/useGetAuthSettings'
|
||||||
import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot'
|
import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot'
|
||||||
|
import { defaultDelegateSelectorsV2 } from 'components/DelegateSelector/DelegateSelector'
|
||||||
import App from './App'
|
import App from './App'
|
||||||
import './bootstrap.scss'
|
import './bootstrap.scss'
|
||||||
|
|
||||||
@ -47,7 +48,8 @@ ReactDOM.render(
|
|||||||
}}
|
}}
|
||||||
currentUser={defaultCurrentUser}
|
currentUser={defaultCurrentUser}
|
||||||
customComponents={{
|
customComponents={{
|
||||||
UsefulOrNot: defaultUsefulOrNot
|
UsefulOrNot: defaultUsefulOrNot,
|
||||||
|
DelegateSelectorsV2: defaultDelegateSelectorsV2
|
||||||
}}
|
}}
|
||||||
currentUserProfileURL=""
|
currentUserProfileURL=""
|
||||||
routingId=""
|
routingId=""
|
||||||
|
@ -64,7 +64,7 @@ export const SelectInfraProvider = () => {
|
|||||||
infraOptions.push(payload)
|
infraOptions.push(payload)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (CDE_HYBRID_ENABLED && !isHybridAvailable) {
|
if (CDE_HYBRID_ENABLED && !isHybridAvailable && data) {
|
||||||
history.push(
|
history.push(
|
||||||
routes.toCDEGitspaceInfra({
|
routes.toCDEGitspaceInfra({
|
||||||
accountId: accountInfo?.identifier
|
accountId: accountInfo?.identifier
|
||||||
|
@ -42,6 +42,11 @@ export enum IDEType {
|
|||||||
RIDER = 'rider'
|
RIDER = 'rider'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DelegateSelector {
|
||||||
|
connected?: boolean
|
||||||
|
name?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface regionProp {
|
export interface regionProp {
|
||||||
location: string
|
location: string
|
||||||
defaultSubnet: string
|
defaultSubnet: string
|
||||||
|
@ -1,11 +1,28 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Container, FormInput, Layout, Text } from '@harnessio/uicore'
|
import { Container, FormInput, Layout, Text } from '@harnessio/uicore'
|
||||||
import { Color } from '@harnessio/design-system'
|
import { Color } from '@harnessio/design-system'
|
||||||
|
import type { FormikProps } from 'formik'
|
||||||
import { useStrings } from 'framework/strings'
|
import { useStrings } from 'framework/strings'
|
||||||
|
import { useAppContext } from 'AppContext'
|
||||||
import css from './InfraDetails.module.scss'
|
import css from './InfraDetails.module.scss'
|
||||||
|
|
||||||
const BasicDetails = () => {
|
interface BasicDetailProps {
|
||||||
|
formikProps: FormikProps<any>
|
||||||
|
}
|
||||||
|
|
||||||
|
const BasicDetails = ({ formikProps }: BasicDetailProps) => {
|
||||||
const { getString } = useStrings()
|
const { getString } = useStrings()
|
||||||
|
const { hooks, accountInfo, customComponents } = useAppContext()
|
||||||
|
const { DelegateSelectorsV2 } = customComponents
|
||||||
|
const queryParams = { accountId: accountInfo?.identifier }
|
||||||
|
const { data: delegateData } = hooks.useGetDelegateSelectorsUpTheHierarchyV2({
|
||||||
|
queryParams
|
||||||
|
})
|
||||||
|
|
||||||
|
const delegateHandler = (val: string[]) => {
|
||||||
|
formikProps.setFieldValue('delegateSelector', val)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout.Vertical spacing="medium" className={css.containerSpacing}>
|
<Layout.Vertical spacing="medium" className={css.containerSpacing}>
|
||||||
<Text className={css.basicDetailsHeading}>{getString('cde.configureInfra.basicDetails')}</Text>
|
<Text className={css.basicDetailsHeading}>{getString('cde.configureInfra.basicDetails')}</Text>
|
||||||
@ -34,6 +51,14 @@ const BasicDetails = () => {
|
|||||||
placeholder={getString('cde.configureInfra.domain')}
|
placeholder={getString('cde.configureInfra.domain')}
|
||||||
/>
|
/>
|
||||||
<Text className={css.noteText}>{getString('cde.configureInfra.basicNoteText')}</Text>
|
<Text className={css.noteText}>{getString('cde.configureInfra.basicNoteText')}</Text>
|
||||||
|
<Container className={css.delegateContainer}>
|
||||||
|
<Text className={css.delegateSelector}>{getString('cde.delegate.DelegateSelector')}</Text>
|
||||||
|
<DelegateSelectorsV2
|
||||||
|
data={delegateData?.resource ?? []}
|
||||||
|
selectedItems={formikProps?.values?.delegateSelector}
|
||||||
|
onTagInputChange={delegateHandler}
|
||||||
|
/>
|
||||||
|
</Container>
|
||||||
</Container>
|
</Container>
|
||||||
</Layout.Vertical>
|
</Layout.Vertical>
|
||||||
)
|
)
|
||||||
|
@ -127,3 +127,17 @@
|
|||||||
line-height: var(--spacing-main) !important;
|
line-height: var(--spacing-main) !important;
|
||||||
text-transform: uppercase !important;
|
text-transform: uppercase !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.delegateContainer {
|
||||||
|
margin: var(--padding-button) 0 !important;
|
||||||
|
|
||||||
|
[class*='DelegateSelectors-module_delegateInput'] {
|
||||||
|
border: 1px solid var(--grey-200) !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.delegateSelector {
|
||||||
|
padding-bottom: var(--spacing-xsmall) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@ export declare const basicDetailsContainer: string
|
|||||||
export declare const basicDetailsHeading: string
|
export declare const basicDetailsHeading: string
|
||||||
export declare const bottomSpacing: string
|
export declare const bottomSpacing: string
|
||||||
export declare const containerSpacing: string
|
export declare const containerSpacing: string
|
||||||
|
export declare const delegateContainer: string
|
||||||
|
export declare const delegateSelector: string
|
||||||
export declare const deleteContainer: string
|
export declare const deleteContainer: string
|
||||||
export declare const dnone: string
|
export declare const dnone: string
|
||||||
export declare const formFooter: string
|
export declare const formFooter: string
|
||||||
|
@ -25,6 +25,7 @@ interface InfraDetailsFormikProps {
|
|||||||
machine_type?: string
|
machine_type?: string
|
||||||
instances?: string
|
instances?: string
|
||||||
project?: string
|
project?: string
|
||||||
|
delegateSelector?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const InfraDetails = () => {
|
const InfraDetails = () => {
|
||||||
@ -59,13 +60,15 @@ const InfraDetails = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
const { identifier, metadata, name }: OpenapiCreateInfraProviderConfigRequest = data
|
const { identifier, metadata, name }: OpenapiCreateInfraProviderConfigRequest = data
|
||||||
|
const delegate = metadata?.delegate_selectors?.map((del: { selector: string }) => del.selector)
|
||||||
const payload: InfraDetailsFormikProps = {
|
const payload: InfraDetailsFormikProps = {
|
||||||
identifier: identifier,
|
identifier: identifier,
|
||||||
name: name,
|
name: name,
|
||||||
domain: metadata?.domain,
|
domain: metadata?.domain,
|
||||||
machine_type: metadata?.gateway?.machine_type,
|
machine_type: metadata?.gateway?.machine_type,
|
||||||
instances: metadata?.gateway?.instances,
|
instances: metadata?.gateway?.instances,
|
||||||
project: metadata?.project?.id
|
project: metadata?.project?.id,
|
||||||
|
delegateSelector: delegate
|
||||||
}
|
}
|
||||||
const regions: regionProp[] = []
|
const regions: regionProp[] = []
|
||||||
Object?.keys(data?.metadata?.region_configs ?? {}).forEach((key: string, index: number) => {
|
Object?.keys(data?.metadata?.region_configs ?? {}).forEach((key: string, index: number) => {
|
||||||
@ -103,7 +106,7 @@ const InfraDetails = () => {
|
|||||||
onSubmit={async (values: InfraDetailsFormikProps) => {
|
onSubmit={async (values: InfraDetailsFormikProps) => {
|
||||||
try {
|
try {
|
||||||
if (regionData?.length > 0) {
|
if (regionData?.length > 0) {
|
||||||
const { identifier, name, domain, machine_type, instances, project } = values
|
const { identifier, name, domain, machine_type, instances, project, delegateSelector } = values
|
||||||
const region_configs: Unknown = {}
|
const region_configs: Unknown = {}
|
||||||
regionData?.forEach((region: regionProp) => {
|
regionData?.forEach((region: regionProp) => {
|
||||||
const { location, defaultSubnet, proxySubnet, dns, domain: regionDomain } = region
|
const { location, defaultSubnet, proxySubnet, dns, domain: regionDomain } = region
|
||||||
@ -122,11 +125,13 @@ const InfraDetails = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
const delegates = delegateSelector?.map((del: string) => ({ selector: del }))
|
||||||
const payload: OpenapiCreateInfraProviderConfigRequest = {
|
const payload: OpenapiCreateInfraProviderConfigRequest = {
|
||||||
identifier,
|
identifier,
|
||||||
metadata: {
|
metadata: {
|
||||||
domain,
|
domain,
|
||||||
name: identifier,
|
name: identifier,
|
||||||
|
delegate_selectors: delegates,
|
||||||
region_configs,
|
region_configs,
|
||||||
project: {
|
project: {
|
||||||
id: project
|
id: project
|
||||||
@ -168,7 +173,7 @@ const InfraDetails = () => {
|
|||||||
return (
|
return (
|
||||||
<FormikForm>
|
<FormikForm>
|
||||||
<Layout.Vertical spacing="medium">
|
<Layout.Vertical spacing="medium">
|
||||||
<BasicDetails />
|
<BasicDetails formikProps={formikProps} />
|
||||||
<GatewayDetails formikProps={formikProps} />
|
<GatewayDetails formikProps={formikProps} />
|
||||||
<ConfigureLocations regionData={regionData} setRegionData={setRegionData} initialData={initialData} />
|
<ConfigureLocations regionData={regionData} setRegionData={setRegionData} initialData={initialData} />
|
||||||
<Layout.Horizontal className={css.formFooter}>
|
<Layout.Horizontal className={css.formFooter}>
|
||||||
|
@ -63,6 +63,8 @@ id: ID
|
|||||||
gitspaceInfra: Gitspace Infrastructure
|
gitspaceInfra: Gitspace Infrastructure
|
||||||
configureGCPInfra: Configure GCP Infrastructure
|
configureGCPInfra: Configure GCP Infrastructure
|
||||||
configureGitspaceInfra: Configure Gitspace Infrastructure
|
configureGitspaceInfra: Configure Gitspace Infrastructure
|
||||||
|
delegate:
|
||||||
|
DelegateSelector: Delegate Selector
|
||||||
gitspaceInfraHome:
|
gitspaceInfraHome:
|
||||||
configureGCPButton: Configure GCP infrastructure
|
configureGCPButton: Configure GCP infrastructure
|
||||||
description: Configure an infrastructure with locations and machines to be used as one of the infrastructure while creating a Gitspace
|
description: Configure an infrastructure with locations and machines to be used as one of the infrastructure while creating a Gitspace
|
||||||
|
7
web/src/components/DelegateSelector/DelegateSelector.tsx
Normal file
7
web/src/components/DelegateSelector/DelegateSelector.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { Container } from '@harnessio/uicore'
|
||||||
|
import type { DelegateSelectorsV2Props } from 'utils/types'
|
||||||
|
|
||||||
|
export const defaultDelegateSelectorsV2 = (props: DelegateSelectorsV2Props): React.ReactElement => {
|
||||||
|
return <Container {...(props as any)} />
|
||||||
|
}
|
@ -1313,6 +1313,7 @@ export interface StringsMap {
|
|||||||
'cde.createImport': string
|
'cde.createImport': string
|
||||||
'cde.createRepo': string
|
'cde.createRepo': string
|
||||||
'cde.created': string
|
'cde.created': string
|
||||||
|
'cde.delegate.DelegateSelector': string
|
||||||
'cde.deleteGitspace': string
|
'cde.deleteGitspace': string
|
||||||
'cde.deleteGitspaceText': string
|
'cde.deleteGitspaceText': string
|
||||||
'cde.deleteGitspaceTitle': string
|
'cde.deleteGitspaceTitle': string
|
||||||
|
@ -16,6 +16,7 @@ import type { LangLocale } from 'framework/strings/languageLoader'
|
|||||||
import { AppContextProvider, defaultCurrentUser } from 'AppContext'
|
import { AppContextProvider, defaultCurrentUser } from 'AppContext'
|
||||||
import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot'
|
import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot'
|
||||||
import { StringsContextProvider } from 'framework/strings/StringsContextProvider'
|
import { StringsContextProvider } from 'framework/strings/StringsContextProvider'
|
||||||
|
import { defaultDelegateSelectorsV2 } from 'components/DelegateSelector/DelegateSelector'
|
||||||
|
|
||||||
export interface TestWrapperProps {
|
export interface TestWrapperProps {
|
||||||
path?: string
|
path?: string
|
||||||
@ -70,7 +71,8 @@ export default function TestWrapper(props: PropsWithChildren<TestWrapperProps>)
|
|||||||
hooks: {},
|
hooks: {},
|
||||||
currentUser,
|
currentUser,
|
||||||
customComponents: {
|
customComponents: {
|
||||||
UsefulOrNot: defaultUsefulOrNot
|
UsefulOrNot: defaultUsefulOrNot,
|
||||||
|
DelegateSelectorsV2: defaultDelegateSelectorsV2
|
||||||
},
|
},
|
||||||
currentUserProfileURL,
|
currentUserProfileURL,
|
||||||
defaultSettingsURL,
|
defaultSettingsURL,
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { DiffFile } from 'diff2html/lib/types'
|
import type { DiffFile } from 'diff2html/lib/types'
|
||||||
|
import type { DelegateSelector } from 'cde-gitness/constants'
|
||||||
|
|
||||||
export interface DiffFileEntry extends DiffFile {
|
export interface DiffFileEntry extends DiffFile {
|
||||||
fileId: string
|
fileId: string
|
||||||
@ -43,6 +44,12 @@ export interface UsefulOrNotProps {
|
|||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DelegateSelectorsV2Props {
|
||||||
|
data?: DelegateSelector[]
|
||||||
|
selectedItems?: string[]
|
||||||
|
onTagInputChange?: (values: string[]) => void
|
||||||
|
}
|
||||||
|
|
||||||
enum Vote {
|
enum Vote {
|
||||||
None,
|
None,
|
||||||
Up,
|
Up,
|
||||||
|
Loading…
Reference in New Issue
Block a user