diff --git a/web/src/AppContext.tsx b/web/src/AppContext.tsx index 358a89490..19ef5bdcf 100644 --- a/web/src/AppContext.tsx +++ b/web/src/AppContext.tsx @@ -27,6 +27,7 @@ import { newCacheStrategy } from 'utils/CacheStrategy' import { useGetSettingValue } from 'hooks/useGetSettingValue' import { useFeatureFlags } from 'hooks/useFeatureFlag' import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot' +import { defaultDelegateSelectorsV2 } from 'components/DelegateSelector/DelegateSelector' interface AppContextProps extends AppProps { setAppContext: (value: Partial) => void @@ -50,7 +51,8 @@ const AppContext = React.createContext({ hooks: {}, currentUser: defaultCurrentUser, customComponents: { - UsefulOrNot: defaultUsefulOrNot + UsefulOrNot: defaultUsefulOrNot, + DelegateSelectorsV2: defaultDelegateSelectorsV2 }, currentUserProfileURL: '', routingId: '', diff --git a/web/src/AppProps.ts b/web/src/AppProps.ts index 98e543052..b4de47a96 100644 --- a/web/src/AppProps.ts +++ b/web/src/AppProps.ts @@ -17,7 +17,7 @@ import type React from 'react' import type { CODERoutes } from 'RouteDefinitions' 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' /** @@ -61,6 +61,7 @@ export interface AppProps { /** React Components which are passed down from the Parent that are needed by the child app */ customComponents: { 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 */ hooks: Partial<{ @@ -77,6 +78,7 @@ export interface AppProps { useListAggregatedTokens?: Unknown useDeleteToken?: Unknown useCreateToken?: Unknown + useGetDelegateSelectorsUpTheHierarchyV2?: Unknown }> currentUser: Required diff --git a/web/src/bootstrap.tsx b/web/src/bootstrap.tsx index 7c12d3604..5d21229f3 100644 --- a/web/src/bootstrap.tsx +++ b/web/src/bootstrap.tsx @@ -23,6 +23,7 @@ import { useFeatureFlags } from 'hooks/useFeatureFlag' import { useGetSettingValue } from 'hooks/useGetSettingValue' import { useGetAuthSettings } from 'hooks/useGetAuthSettings' import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot' +import { defaultDelegateSelectorsV2 } from 'components/DelegateSelector/DelegateSelector' import App from './App' import './bootstrap.scss' @@ -47,7 +48,8 @@ ReactDOM.render( }} currentUser={defaultCurrentUser} customComponents={{ - UsefulOrNot: defaultUsefulOrNot + UsefulOrNot: defaultUsefulOrNot, + DelegateSelectorsV2: defaultDelegateSelectorsV2 }} currentUserProfileURL="" routingId="" diff --git a/web/src/cde-gitness/components/SelectInfraProvider/SelectInfraProvider.tsx b/web/src/cde-gitness/components/SelectInfraProvider/SelectInfraProvider.tsx index 9cc9c0b6f..7119484a9 100644 --- a/web/src/cde-gitness/components/SelectInfraProvider/SelectInfraProvider.tsx +++ b/web/src/cde-gitness/components/SelectInfraProvider/SelectInfraProvider.tsx @@ -64,7 +64,7 @@ export const SelectInfraProvider = () => { infraOptions.push(payload) } }) - if (CDE_HYBRID_ENABLED && !isHybridAvailable) { + if (CDE_HYBRID_ENABLED && !isHybridAvailable && data) { history.push( routes.toCDEGitspaceInfra({ accountId: accountInfo?.identifier diff --git a/web/src/cde-gitness/constants/index.ts b/web/src/cde-gitness/constants/index.ts index 9205bb379..6d48a3372 100644 --- a/web/src/cde-gitness/constants/index.ts +++ b/web/src/cde-gitness/constants/index.ts @@ -42,6 +42,11 @@ export enum IDEType { RIDER = 'rider' } +export interface DelegateSelector { + connected?: boolean + name?: string +} + export interface regionProp { location: string defaultSubnet: string diff --git a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/BasicDetails.tsx b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/BasicDetails.tsx index 4d5302329..9dac1b7e8 100644 --- a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/BasicDetails.tsx +++ b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/BasicDetails.tsx @@ -1,11 +1,28 @@ import React from 'react' import { Container, FormInput, Layout, Text } from '@harnessio/uicore' import { Color } from '@harnessio/design-system' +import type { FormikProps } from 'formik' import { useStrings } from 'framework/strings' +import { useAppContext } from 'AppContext' import css from './InfraDetails.module.scss' -const BasicDetails = () => { +interface BasicDetailProps { + formikProps: FormikProps +} + +const BasicDetails = ({ formikProps }: BasicDetailProps) => { 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 ( {getString('cde.configureInfra.basicDetails')} @@ -34,6 +51,14 @@ const BasicDetails = () => { placeholder={getString('cde.configureInfra.domain')} /> {getString('cde.configureInfra.basicNoteText')} + + {getString('cde.delegate.DelegateSelector')} + + ) diff --git a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss index a1ab789a6..6902cff93 100644 --- a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss +++ b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss @@ -127,3 +127,17 @@ line-height: var(--spacing-main) !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; +} diff --git a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss.d.ts b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss.d.ts index fb608dcef..f0f418780 100644 --- a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss.d.ts +++ b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.module.scss.d.ts @@ -21,6 +21,8 @@ export declare const basicDetailsContainer: string export declare const basicDetailsHeading: string export declare const bottomSpacing: string export declare const containerSpacing: string +export declare const delegateContainer: string +export declare const delegateSelector: string export declare const deleteContainer: string export declare const dnone: string export declare const formFooter: string diff --git a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.tsx b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.tsx index bf9025b3b..ef04bbf56 100644 --- a/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.tsx +++ b/web/src/cde-gitness/pages/InfraConfigure/InfraDetails/InfraDetails.tsx @@ -25,6 +25,7 @@ interface InfraDetailsFormikProps { machine_type?: string instances?: string project?: string + delegateSelector?: string[] } const InfraDetails = () => { @@ -59,13 +60,15 @@ const InfraDetails = () => { useEffect(() => { if (data) { const { identifier, metadata, name }: OpenapiCreateInfraProviderConfigRequest = data + const delegate = metadata?.delegate_selectors?.map((del: { selector: string }) => del.selector) const payload: InfraDetailsFormikProps = { identifier: identifier, name: name, domain: metadata?.domain, machine_type: metadata?.gateway?.machine_type, instances: metadata?.gateway?.instances, - project: metadata?.project?.id + project: metadata?.project?.id, + delegateSelector: delegate } const regions: regionProp[] = [] Object?.keys(data?.metadata?.region_configs ?? {}).forEach((key: string, index: number) => { @@ -103,7 +106,7 @@ const InfraDetails = () => { onSubmit={async (values: InfraDetailsFormikProps) => { try { 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 = {} regionData?.forEach((region: regionProp) => { 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 = { identifier, metadata: { domain, name: identifier, + delegate_selectors: delegates, region_configs, project: { id: project @@ -168,7 +173,7 @@ const InfraDetails = () => { return ( - + diff --git a/web/src/cde-gitness/strings/strings.en.yaml b/web/src/cde-gitness/strings/strings.en.yaml index f201cd23b..83c7bdb18 100644 --- a/web/src/cde-gitness/strings/strings.en.yaml +++ b/web/src/cde-gitness/strings/strings.en.yaml @@ -63,6 +63,8 @@ id: ID gitspaceInfra: Gitspace Infrastructure configureGCPInfra: Configure GCP Infrastructure configureGitspaceInfra: Configure Gitspace Infrastructure +delegate: + DelegateSelector: Delegate Selector gitspaceInfraHome: configureGCPButton: Configure GCP infrastructure description: Configure an infrastructure with locations and machines to be used as one of the infrastructure while creating a Gitspace diff --git a/web/src/components/DelegateSelector/DelegateSelector.tsx b/web/src/components/DelegateSelector/DelegateSelector.tsx new file mode 100644 index 000000000..bc53a33c3 --- /dev/null +++ b/web/src/components/DelegateSelector/DelegateSelector.tsx @@ -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 +} diff --git a/web/src/framework/strings/stringTypes.ts b/web/src/framework/strings/stringTypes.ts index 68ddbd446..744f006ce 100644 --- a/web/src/framework/strings/stringTypes.ts +++ b/web/src/framework/strings/stringTypes.ts @@ -1313,6 +1313,7 @@ export interface StringsMap { 'cde.createImport': string 'cde.createRepo': string 'cde.created': string + 'cde.delegate.DelegateSelector': string 'cde.deleteGitspace': string 'cde.deleteGitspaceText': string 'cde.deleteGitspaceTitle': string diff --git a/web/src/utils/test/TestWrapper.tsx b/web/src/utils/test/TestWrapper.tsx index 390624462..a314b3b51 100644 --- a/web/src/utils/test/TestWrapper.tsx +++ b/web/src/utils/test/TestWrapper.tsx @@ -16,6 +16,7 @@ import type { LangLocale } from 'framework/strings/languageLoader' import { AppContextProvider, defaultCurrentUser } from 'AppContext' import { defaultUsefulOrNot } from 'components/DefaultUsefulOrNot/UsefulOrNot' import { StringsContextProvider } from 'framework/strings/StringsContextProvider' +import { defaultDelegateSelectorsV2 } from 'components/DelegateSelector/DelegateSelector' export interface TestWrapperProps { path?: string @@ -70,7 +71,8 @@ export default function TestWrapper(props: PropsWithChildren) hooks: {}, currentUser, customComponents: { - UsefulOrNot: defaultUsefulOrNot + UsefulOrNot: defaultUsefulOrNot, + DelegateSelectorsV2: defaultDelegateSelectorsV2 }, currentUserProfileURL, defaultSettingsURL, diff --git a/web/src/utils/types.ts b/web/src/utils/types.ts index 08f475640..f78e82c6c 100644 --- a/web/src/utils/types.ts +++ b/web/src/utils/types.ts @@ -15,6 +15,7 @@ */ import type { DiffFile } from 'diff2html/lib/types' +import type { DelegateSelector } from 'cde-gitness/constants' export interface DiffFileEntry extends DiffFile { fileId: string @@ -43,6 +44,12 @@ export interface UsefulOrNotProps { className?: string } +export interface DelegateSelectorsV2Props { + data?: DelegateSelector[] + selectedItems?: string[] + onTagInputChange?: (values: string[]) => void +} + enum Vote { None, Up,