Skip to content

Commit

Permalink
Use install properties to check if triggers is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-edouard.breteche committed May 12, 2020
1 parent 57082bc commit 4d772a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/containers/SideNav/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,19 @@ import { selectNamespace } from '../../actions/namespaces';
import {
getExtensions,
getSelectedNamespace,
isReadOnly
isReadOnly,
isTriggersInstalled
} from '../../reducers';
import { getCustomResource } from '../../api';

import './SideNav.scss';

class SideNav extends Component {
state = {
isTriggersInstalled: false
};

componentDidMount() {
const { match } = this.props;

if (match && match.params.namespace) {
this.props.selectNamespace(match.params.namespace);
}

this.checkTriggersInstalled();
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -150,22 +144,8 @@ class SideNav extends Component {
history.push('/');
};

checkTriggersInstalled() {
getCustomResource({
group: 'apiextensions.k8s.io',
version: 'v1beta1',
type: 'customresourcedefinitions',
name: 'eventlisteners.triggers.tekton.dev'
})
.then(() => {
this.setState({ isTriggersInstalled: true });
})
.catch(() => {});
}

render() {
const { extensions, intl, namespace } = this.props;
const { isTriggersInstalled } = this.state;

return (
<CarbonSideNav
Expand Down Expand Up @@ -224,7 +204,7 @@ class SideNav extends Component {
>
TaskRuns
</SideNavMenuItem>
{isTriggersInstalled && (
{this.props.isTriggersInstalled && (
<>
<SideNavMenuItem
element={NavLink}
Expand Down Expand Up @@ -362,6 +342,7 @@ class SideNav extends Component {
const mapStateToProps = state => ({
extensions: getExtensions(state),
isReadOnly: isReadOnly(state),
isTriggersInstalled: isTriggersInstalled(state),
namespace: getSelectedNamespace(state)
});

Expand Down
4 changes: 4 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,7 @@ export function isFetchingEventListeners(state) {
export function isReadOnly(state) {
return propertiesSelectors.isReadOnly(state.properties);
}

export function isTriggersInstalled(state) {
return propertiesSelectors.isTriggersInstalled(state.properties);
}
6 changes: 6 additions & 0 deletions src/reducers/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,9 @@ it('isReadOnly', () => {
expect(isReadOnly(state)).toBe(true);
expect(propertiesSelectors.isReadOnly).toHaveBeenCalledWith(state.properties);
});

it('isTriggersInstalled', () => {
jest.spyOn(propertiesSelectors, 'isTriggersInstalled').mockImplementation(() => true);
expect(isTriggersInstalled(state)).toBe(true);
expect(propertiesSelectors.isTriggersInstalled).toHaveBeenCalledWith(state.properties);
});
4 changes: 4 additions & 0 deletions src/reducers/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ export function isReadOnly(state) {
return state.ReadOnly;
}

export function isTriggersInstalled(state) {
return state.TriggersNamespace && state.TriggersVersion;
}

export default properties;
1 change: 1 addition & 0 deletions src/reducers/properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ it('INSTALL_PROPERTIES_SUCCESS', () => {

const state = propertiesReducer({}, action);
expect(selectors.isReadOnly(state)).toBe(false);
expect(selectors.isTriggersInstalled(state)).toBe(false);
});

0 comments on commit 4d772a4

Please sign in to comment.