fleet/frontend/components/forms/queries/QueryForm/helpers.js
Mike Stone 92d91fdebc Handle server errors (#730)
* consistent error handling

* Display server errors in InviteUserForm

* Handle errors in Form component

* Refactors query form

* creates KolideAce component

* Renders QueryForm from query page and manage hosts page

* Moves ace editor and select targets dropdown to query form

* Render base errors in Form HOC

* LoginPage and ForgotPasswordPage server errors

* Ensure unique key for user blocks

* Adds base error to login form and forgot password form

* Adds base error to query form

* Adds base error to Pack Form

* Adds errors to confirm invite form

* Adds clearErrors action

* clear errors when confirm invite page unmounts

* Handle errors in the App Setting page

* Handle server errors in the User Settings Page

* Handle server errors in the User Management Page
2017-01-05 19:01:17 -05:00

41 lines
934 B
JavaScript

const formChanged = (fields, query) => {
return query.name !== fields.name.value ||
query.description !== fields.description.value ||
query.query !== fields.query.value;
};
const canSaveAsNew = (fields, query = {}) => {
if (!fields.name.value && !fields.description.value) {
return true;
}
if (fields.name.value !== query.name) {
return true;
}
return false;
};
const canSaveChanges = (fields, query = {}) => {
if (!query.name && !query.description) {
return false;
}
if (formChanged(fields, query)) {
return true;
}
return false;
};
const allPlatforms = { label: 'All Platforms', value: '' };
const platformOptions = [
allPlatforms,
{ label: 'macOS', value: 'darwin' },
{ label: 'Windows', value: 'windows' },
{ label: 'Ubuntu', value: 'ubuntu' },
{ label: 'Centos', value: 'centos' },
];
export default { allPlatforms, canSaveAsNew, canSaveChanges, platformOptions };