Add ability to handle empty set of decorators (#1515)

Normally a Kolide user will always have at least two built in decorators that they can't delete through the UI so a situation with zero decorators should never happen; however, in the event we change this behavior in the future, or a user manually deletes decorators from the database the UI should handle an empty decorator set.
This commit is contained in:
John Murphy 2017-06-01 17:17:37 -05:00 committed by GitHub
parent 7a8f418d0f
commit d8ce89f42d
2 changed files with 4 additions and 3 deletions

View file

@ -11,7 +11,7 @@ import decoratorInterface from 'interfaces/decorators';
import entityGetter from 'redux/utilities/entityGetter';
import { renderFlash } from 'redux/nodes/notifications/actions';
import paths from 'router/paths';
import { pull, get } from 'lodash';
import { pull, get, isEmpty } from 'lodash';
const baseClass = 'manage-decorators-page';
@ -239,7 +239,8 @@ export class ManageDecoratorsPage extends Component {
const mapStateToProps = (state, { location }) => {
const decoratorEntities = entityGetter(state).get('decorators');
const { entities: decorators } = decoratorEntities;
let { entities: decorators } = decoratorEntities;
decorators = decorators.filter((decorator) => { return !isEmpty(decorator); });
const selectedDecoratorID = get(location, 'query.selectedDecorator');
const selectedDecorator = selectedDecoratorID && decoratorEntities.findBy({ id: selectedDecoratorID });
return { decorators, selectedDecorator };

View file

@ -8,7 +8,7 @@ import (
)
type listDecoratorResponse struct {
Decorators []*kolide.Decorator `json:"decorators,omitempty"`
Decorators []*kolide.Decorator `json:"decorators"`
Err error `json:"error,omitempty"`
}