Skip to content

Commit 648d21a

Browse files
author
charles-edouard.breteche
committed
Use install properties to check if triggers is installed
1 parent 57082bc commit 648d21a

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

src/containers/SideNav/SideNav.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,19 @@ import { selectNamespace } from '../../actions/namespaces';
3030
import {
3131
getExtensions,
3232
getSelectedNamespace,
33-
isReadOnly
33+
isReadOnly,
34+
isTriggersInstalled
3435
} from '../../reducers';
35-
import { getCustomResource } from '../../api';
3636

3737
import './SideNav.scss';
3838

3939
class SideNav extends Component {
40-
state = {
41-
isTriggersInstalled: false
42-
};
43-
4440
componentDidMount() {
4541
const { match } = this.props;
4642

4743
if (match && match.params.namespace) {
4844
this.props.selectNamespace(match.params.namespace);
4945
}
50-
51-
this.checkTriggersInstalled();
5246
}
5347

5448
componentDidUpdate(prevProps) {
@@ -150,22 +144,8 @@ class SideNav extends Component {
150144
history.push('/');
151145
};
152146

153-
checkTriggersInstalled() {
154-
getCustomResource({
155-
group: 'apiextensions.k8s.io',
156-
version: 'v1beta1',
157-
type: 'customresourcedefinitions',
158-
name: 'eventlisteners.triggers.tekton.dev'
159-
})
160-
.then(() => {
161-
this.setState({ isTriggersInstalled: true });
162-
})
163-
.catch(() => {});
164-
}
165-
166147
render() {
167148
const { extensions, intl, namespace } = this.props;
168-
const { isTriggersInstalled } = this.state;
169149

170150
return (
171151
<CarbonSideNav
@@ -224,7 +204,7 @@ class SideNav extends Component {
224204
>
225205
TaskRuns
226206
</SideNavMenuItem>
227-
{isTriggersInstalled && (
207+
{this.props.isTriggersInstalled && (
228208
<>
229209
<SideNavMenuItem
230210
element={NavLink}
@@ -362,6 +342,7 @@ class SideNav extends Component {
362342
const mapStateToProps = state => ({
363343
extensions: getExtensions(state),
364344
isReadOnly: isReadOnly(state),
345+
isTriggersInstalled: isTriggersInstalled(state),
365346
namespace: getSelectedNamespace(state)
366347
});
367348

src/containers/SideNav/SideNav.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as selectors from '../../reducers';
2525

2626
beforeEach(() => {
2727
jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => true);
28+
jest.spyOn(selectors, 'isTriggersInstalled').mockImplementation(() => false);
2829
});
2930

3031
it('SideNav renders with extensions', () => {

src/reducers/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,7 @@ export function isFetchingEventListeners(state) {
482482
export function isReadOnly(state) {
483483
return propertiesSelectors.isReadOnly(state.properties);
484484
}
485+
486+
export function isTriggersInstalled(state) {
487+
return propertiesSelectors.isTriggersInstalled(state.properties);
488+
}

src/reducers/index.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ import {
4949
isFetchingSecrets,
5050
isFetchingTaskRuns,
5151
isFetchingTasks,
52-
isReadOnly
52+
isReadOnly,
53+
isTriggersInstalled
5354
} from '.';
5455
import * as clusterTaskSelectors from './clusterTasks';
5556
import * as extensionSelectors from './extensions';
@@ -504,3 +505,13 @@ it('isReadOnly', () => {
504505
expect(isReadOnly(state)).toBe(true);
505506
expect(propertiesSelectors.isReadOnly).toHaveBeenCalledWith(state.properties);
506507
});
508+
509+
it('isTriggersInstalled', () => {
510+
jest
511+
.spyOn(propertiesSelectors, 'isTriggersInstalled')
512+
.mockImplementation(() => true);
513+
expect(isTriggersInstalled(state)).toBe(true);
514+
expect(propertiesSelectors.isTriggersInstalled).toHaveBeenCalledWith(
515+
state.properties
516+
);
517+
});

src/reducers/properties.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ export function isReadOnly(state) {
2525
return state.ReadOnly;
2626
}
2727

28+
export function isTriggersInstalled(state) {
29+
return (state.TriggersNamespace && state.TriggersVersion) || false;
30+
}
31+
2832
export default properties;

src/reducers/properties.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ it('INSTALL_PROPERTIES_SUCCESS', () => {
2828

2929
const state = propertiesReducer({}, action);
3030
expect(selectors.isReadOnly(state)).toBe(false);
31+
expect(selectors.isTriggersInstalled(state)).toBe(false);
3132
});

0 commit comments

Comments
 (0)