From d8ce89f42d2831f3d201de1a805eb8f9cb532e14 Mon Sep 17 00:00:00 2001 From: John Murphy Date: Thu, 1 Jun 2017 17:17:37 -0500 Subject: [PATCH] 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. --- .../decorators/ManageDecoratorsPage/ManageDecoratorsPage.jsx | 5 +++-- server/service/endpoint_decorators.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/pages/decorators/ManageDecoratorsPage/ManageDecoratorsPage.jsx b/frontend/pages/decorators/ManageDecoratorsPage/ManageDecoratorsPage.jsx index d6df76b14d..6d66480df6 100644 --- a/frontend/pages/decorators/ManageDecoratorsPage/ManageDecoratorsPage.jsx +++ b/frontend/pages/decorators/ManageDecoratorsPage/ManageDecoratorsPage.jsx @@ -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 }; diff --git a/server/service/endpoint_decorators.go b/server/service/endpoint_decorators.go index bcd0cbcc38..891ef47986 100644 --- a/server/service/endpoint_decorators.go +++ b/server/service/endpoint_decorators.go @@ -8,7 +8,7 @@ import ( ) type listDecoratorResponse struct { - Decorators []*kolide.Decorator `json:"decorators,omitempty"` + Decorators []*kolide.Decorator `json:"decorators"` Err error `json:"error,omitempty"` }