Skip to content

Commit

Permalink
feat(import-flow): add visibility annotation on component creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil143 committed Oct 12, 2023
1 parent c111901 commit a74094d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/components/ImportForm/SourceSection/SourceSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const SourceSection: React.FC<SourceSectionProps> = () => {
name: 'source.git.url',
type: 'input',
});
const [, , { setValue: setRepoAccessibility }] = useField<string>({
name: 'repoAccessibility',
});
const [, { value: isValidated }] = useField<boolean>('source.isValidated');
const {
values: { secret: authSecret },
Expand Down Expand Up @@ -87,6 +90,13 @@ const SourceSection: React.FC<SourceSectionProps> = () => {

const debouncedHandleSourceChange = useDebounceCallback(handleSourceChange);

React.useEffect(() => {
if (accessCheckLoaded && accessibility) {
setRepoAccessibility(accessibility);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [accessCheckLoaded, accessibility]);

React.useEffect(() => {
if (accessCheckLoaded) {
if (isRepoAccessible) {
Expand Down
11 changes: 10 additions & 1 deletion src/components/ImportForm/utils/submit-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FormikHelpers } from 'formik';
import { ApplicationKind } from '../../../types';
import { ApplicationKind, SPIAccessCheckAccessibilityStatus } from '../../../types';
import { SAMPLE_ANNOTATION } from '../../../utils/component-utils';
import { createApplication, createComponent, createSecret } from '../../../utils/create-utils';
import {
Expand Down Expand Up @@ -91,6 +91,15 @@ export const createResources = async (
componentAnnotations = { [SAMPLE_ANNOTATION]: 'true' };
}

if (formValues.repoAccessibility !== SPIAccessCheckAccessibilityStatus.unknown) {
componentAnnotations = {
...(componentAnnotations ?? {}),
['image.redhat.com/generate']: JSON.stringify({
visibility: formValues.repoAccessibility,
}),
};
}

const integrationTestValues: IntegrationTestFormValues = {
name: `${applicationName}-enterprise-contract`,
url: EC_INTEGRATION_TEST_URL,
Expand Down
3 changes: 2 additions & 1 deletion src/components/ImportForm/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentSpecs } from '../../../types';
import { ComponentSpecs, SPIAccessCheckAccessibilityStatus } from '../../../types';

export const enum ImportStrategy {
GIT = 'git',
Expand Down Expand Up @@ -74,4 +74,5 @@ export type ImportFormValues = {
min: FormResources;
max: FormResources;
};
repoAccessibility?: SPIAccessCheckAccessibilityStatus;
};

0 comments on commit a74094d

Please sign in to comment.