-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include enabling/disabling default catalog sources in
operator-hub detail view Signed-off-by: Harish <hgovinda@redhat.com>
- Loading branch information
1 parent
33da36b
commit d350d16
Showing
6 changed files
with
236 additions
and
10 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...s/operator-lifecycle-manager/integration-tests-cypress/tests/edit-default-sources.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { detailsPage } from '../../../integration-tests-cypress/views/details-page'; | ||
import { checkErrors } from '../../../integration-tests-cypress/support'; | ||
import { modal } from '../../../integration-tests-cypress/views/modal'; | ||
|
||
describe('Create namespace from install operators', () => { | ||
before(() => { | ||
cy.login(); | ||
}); | ||
|
||
afterEach(() => { | ||
checkErrors(); | ||
}); | ||
|
||
after(() => { | ||
cy.logout(); | ||
}); | ||
|
||
it('disables default catalog sources from operatorHub details page', () => { | ||
cy.log('navigate to operatorHub page'); | ||
cy.visit(`/settings/cluster`); | ||
cy.byLegacyTestID('horizontal-link-Global configuration').click(); | ||
cy.byLegacyTestID('OperatorHub').click(); | ||
|
||
// verfiy operatorHub details page is open | ||
detailsPage.sectionHeaderShouldExist('OperatorHub details'); | ||
|
||
// Toggle default sources modal | ||
const defaultSourceToBeToggled = 'redhat-operators'; | ||
cy.byTestID('Default Sources-details-item__edit-button').click(); | ||
modal.modalTitleShouldContain('Edit Default Sources'); | ||
cy.byTestID(defaultSourceToBeToggled) | ||
.find('span.pf-c-switch__toggle') | ||
.click(); | ||
modal.submit(); | ||
|
||
// Verify status change | ||
cy.byTestID(`status_${defaultSourceToBeToggled}`).should('have.text', 'Disabled'); | ||
|
||
// switch the toggle back to previous state | ||
cy.byTestID('Default Sources-details-item__edit-button').click(); | ||
modal.modalTitleShouldContain('Edit Default Sources'); | ||
cy.byTestID(defaultSourceToBeToggled) | ||
.find('span.pf-c-switch__toggle') | ||
.click(); | ||
modal.submit(); | ||
|
||
// Verify status change | ||
cy.byTestID(`status_${defaultSourceToBeToggled}`).should('have.text', 'Enabled'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
.../packages/operator-lifecycle-manager/src/components/modals/edit-default-sources-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import * as React from 'react'; | ||
import { k8sPatch } from '@console/internal/module/k8s'; | ||
import { | ||
ModalTitle, | ||
ModalBody, | ||
createModalLauncher, | ||
ModalComponentProps, | ||
ModalSubmitFooter, | ||
} from '@console/internal/components/factory/modal'; | ||
import { withHandlePromise, HandlePromiseProps } from '@console/internal/components/utils'; | ||
import { OperatorHubKind } from '../operator-hub'; | ||
import { Switch, Alert, Form, FormGroup } from '@patternfly/react-core'; | ||
import { OperatorHubModel } from '../../models'; | ||
|
||
const EditDefaultSourcesModal: React.FC<EditDefaultSourcesModalProps> = ({ | ||
cancel, | ||
close, | ||
operatorHub, | ||
handlePromise, | ||
errorMessage, | ||
}) => { | ||
// state to maintain user selection of toggle, maintained as an [] of {defaultCatalogSourceName: <booleanFlagForToggle>} | ||
const [ | ||
userSelectedDefaultSourceToggleState, | ||
setUserSelectedDefaultSourceToggleState, | ||
] = React.useState( | ||
(operatorHub.spec.sources ?? []).reduce( | ||
(acc, source) => ({ | ||
...acc, | ||
[source.name]: source.disabled, | ||
}), | ||
{}, | ||
), | ||
); | ||
|
||
const submit = React.useCallback( | ||
(event: React.FormEvent<EventTarget>): void => { | ||
event.preventDefault(); | ||
const patch = [ | ||
{ | ||
op: 'replace', | ||
path: '/spec/sources', | ||
value: Object.keys(userSelectedDefaultSourceToggleState).map((name) => ({ | ||
name, | ||
disabled: userSelectedDefaultSourceToggleState[name], | ||
})), | ||
}, | ||
]; | ||
return handlePromise(k8sPatch(OperatorHubModel, operatorHub, patch), close); | ||
}, | ||
[close, handlePromise, operatorHub, userSelectedDefaultSourceToggleState], | ||
); | ||
|
||
const onToggle = (sourceName, checked) => { | ||
setUserSelectedDefaultSourceToggleState((currState) => ({ | ||
...currState, | ||
[sourceName]: !checked, | ||
})); | ||
}; | ||
|
||
return ( | ||
<Form onSubmit={submit} isHorizontal isWidthLimited> | ||
<div className="modal-content modal-content--no-inner-scroll"> | ||
<ModalTitle>Edit Default Sources</ModalTitle> | ||
<ModalBody> | ||
{operatorHub.status.sources.map((source) => { | ||
return ( | ||
// Todo: Remove <div> after https://github.com/patternfly/patternfly-react/issues/5198 is fixed | ||
<div key={source.name} className="row co-m-form-row pl-4"> | ||
<FormGroup fieldId={source.name} label={source.name} data-test={source.name}> | ||
<Switch | ||
id={source.name} | ||
key={source.name} | ||
label="Enabled" | ||
labelOff="Disabled" | ||
isChecked={!userSelectedDefaultSourceToggleState[source.name] ?? true} | ||
onChange={(checked) => onToggle(source.name, checked)} | ||
data-test={source.name} | ||
/> | ||
</FormGroup> | ||
</div> | ||
); | ||
})} | ||
{Object.values(userSelectedDefaultSourceToggleState).includes(true) && ( | ||
<Alert variant="warning" className="co-alert" title="Disable Catalog Source" isInline> | ||
<p> | ||
By disabling a default source, the operators it provides will no longer appear in | ||
OperatorHub and any operator that has been installed from this source will no longer | ||
receive updates until the source is re-enabled. Disabling the source will also | ||
remove the corresponding OperatorSource and CatalogSource resources from the | ||
cluster. | ||
</p> | ||
</Alert> | ||
)} | ||
</ModalBody> | ||
<ModalSubmitFooter | ||
errorMessage={errorMessage} | ||
inProgress={false} | ||
submitText="Save" | ||
cancel={cancel} | ||
/> | ||
</div> | ||
</Form> | ||
); | ||
}; | ||
|
||
export const editDefaultSourcesModal = createModalLauncher( | ||
withHandlePromise(EditDefaultSourcesModal), | ||
); | ||
|
||
type EditDefaultSourcesModalProps = { | ||
operatorHub: OperatorHubKind; | ||
} & ModalComponentProps & | ||
HandlePromiseProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import { referenceForModel } from '@console/internal/module/k8s'; | ||
import { CatalogSourceModel } from './models'; | ||
|
||
export enum Flags { | ||
OPERATOR_LIFECYCLE_MANAGER = 'OPERATOR_LIFECYCLE_MANAGER', | ||
} | ||
|
||
export const catalogSourceModelReference = referenceForModel(CatalogSourceModel); | ||
export const DEFAULT_SOURCE_NAMESPACE = 'openshift-marketplace'; | ||
export const operatorTypeAnnotation = 'operators.operatorframework.io/operator-type'; | ||
export const nonStandaloneAnnotationValue = 'non-standalone'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters