-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50a535e
commit 07c32fe
Showing
13 changed files
with
5,887 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
app/javascript/components/timeline-options/timeline-options-simple.schema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { componentTypes, validatorTypes } from '@@ddf'; | ||
|
||
const createSchemaSimple = ( | ||
timelineEvents, managementGroupNames, managementGroupLevels, policyGroupNames, policyGroupLevels | ||
) => ({ | ||
fields: [ | ||
{ | ||
component: componentTypes.SUB_FORM, | ||
title: __('Options'), | ||
id: 'options', | ||
name: 'options', | ||
fields: [ | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'timelineEvents', | ||
name: 'timelineEvents', | ||
label: __('Event Types'), | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
includeEmpty: true, | ||
options: timelineEvents, | ||
}, | ||
/// /////////////////// | ||
// Managment Events // | ||
/// /////////////////// | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'managementGroupNames', | ||
name: 'managementGroupNames', | ||
label: __('Category Managements'), | ||
options: managementGroupNames, | ||
isMulti: true, | ||
isSearchable: true, | ||
isClearable: true, | ||
simpleValue: true, | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
condition: { | ||
and: [ | ||
{ | ||
when: 'timelineEvents', | ||
is: 'EmsEvent', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'managementGroupLevels', | ||
name: 'managementGroupLevels', | ||
label: __('Levels Management'), | ||
options: managementGroupLevels, | ||
isMulti: true, | ||
isSearchable: true, | ||
isClearable: true, | ||
simpleValue: true, | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
condition: { | ||
and: [ | ||
{ | ||
when: 'timelineEvents', | ||
is: 'EmsEvent', | ||
}, | ||
], | ||
}, | ||
}, | ||
/// /////////////// | ||
// Policy Events // | ||
/// /////////////// | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'policyGroupNames', | ||
name: 'policyGroupNames', | ||
label: __('Category Policy'), | ||
options: policyGroupNames, | ||
isMulti: true, | ||
isSearchable: true, | ||
isClearable: true, | ||
simpleValue: true, | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
condition: { | ||
and: [ | ||
{ | ||
when: 'timelineEvents', | ||
is: 'MiqEvent', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
component: componentTypes.RADIO, | ||
label: __('Event Result'), | ||
name: 'policyGroupLevels', | ||
id: 'policyGroupLevels', | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
options: policyGroupLevels, | ||
condition: { | ||
and: [ | ||
{ | ||
when: 'timelineEvents', | ||
is: 'MiqEvent', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
/// ////// | ||
// Time // | ||
/// ////// | ||
{ | ||
component: componentTypes.SUB_FORM, | ||
title: __('Dates Range'), | ||
id: 'datesRange', | ||
name: 'datesRange', | ||
fields: [ | ||
{ | ||
component: 'date-picker', | ||
id: 'startDate', | ||
name: 'startDate', | ||
label: __('Start Date'), | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
}, | ||
{ | ||
component: 'date-picker', | ||
id: 'endDate', | ||
name: 'endDate', | ||
label: __('End Date'), | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
export default createSchemaSimple; |
105 changes: 105 additions & 0 deletions
105
app/javascript/components/timeline-options/timeline-options.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import MiqFormRenderer from '@@ddf'; | ||
import PropTypes from 'prop-types'; | ||
import createSchemaSimple from './timeline-options-simple.schema'; | ||
import mapper from '../../forms/mappers/componentMapper'; | ||
|
||
const TimelineOptions = ({ url }) => { | ||
const [{ | ||
isLoading, timelineEvents, managementGroupNames, managementGroupLevels, policyGroupNames, policyGroupLevels, | ||
}, setState] = useState({ | ||
isLoading: true, | ||
}); | ||
|
||
useEffect(() => { | ||
if (isLoading) { | ||
API.options(`/api/event_streams`).then((dropdownValues) => { | ||
const data = dropdownValues.data.timeline_events; | ||
const managementGroupNames = []; const managementGroupLevels = []; const policyGroupNames = []; const | ||
policyGroupLevels = []; | ||
const timelineEvents = [ | ||
{ label: data.EmsEvent.description, value: 'EmsEvent' }, | ||
{ label: data.MiqEvent.description, value: 'MiqEvent' }, | ||
]; | ||
|
||
// Management Events | ||
Object.entries(data.EmsEvent.group_names).forEach((entry) => { | ||
const [key, value] = entry; | ||
managementGroupNames.push({ label: value, value }); | ||
}); | ||
Object.entries(data.EmsEvent.group_levels).forEach((entry) => { | ||
const [key, value] = entry; | ||
managementGroupLevels.push({ label: value, value: key }); | ||
}); | ||
|
||
// Policy Events | ||
Object.entries(data.MiqEvent.group_names).forEach((entry) => { | ||
const [key, value] = entry; | ||
policyGroupNames.push({ label: value, value: key }); | ||
}); | ||
// NOTE: data.MiqEvent.group_levels does not have the expected `Both` option | ||
policyGroupLevels.push({ label: 'Success', value: 'success' }); | ||
policyGroupLevels.push({ label: 'Failure', value: 'failure' }); | ||
policyGroupLevels.push({ label: 'Both', value: 'both' }); | ||
|
||
// TODO: is there a way to make the above more elegant/shorter? | ||
// NOTE: group_names for MiqEvents and MiqEvents includes the 'Other' option, | ||
// this did not exist in previous versions of the timeline | ||
setState((state) => ({ | ||
...state, | ||
isLoading: false, | ||
timelineEvents, | ||
managementGroupNames, | ||
managementGroupLevels, | ||
policyGroupNames, | ||
policyGroupLevels, | ||
})); | ||
}); | ||
} | ||
}); | ||
|
||
const onSubmit = (values) => { | ||
miqSparkleOn(); | ||
const show = values.timelineEvents === 'EmsEvent' ? 'timeline' : 'policy_timeline'; | ||
const categories = values.timelineEvents === 'EmsEvent' ? values.managementGroupNames : values.policyGroupNames; | ||
const vmData = { | ||
tl_show: show, | ||
tl_categories: categories, | ||
tl_levels: values.managementGroupLevels ? values.managementGroupLevels : [], | ||
tl_result: values.policyGroupLevels ? values.policyGroupLevels : 'success', | ||
}; | ||
window.ManageIQ.calendar.calDateFrom = values.startDate; | ||
window.ManageIQ.calendar.calDateTo = values.endDate; | ||
window.miqJqueryRequest(url, { beforeSend: true, data: vmData }); | ||
}; | ||
|
||
const onReset = () => { | ||
setState((state) => ({ | ||
...state, | ||
})); | ||
}; | ||
|
||
return !isLoading && ( | ||
<> | ||
<MiqFormRenderer | ||
componentMapper={mapper} | ||
schema={createSchemaSimple( | ||
timelineEvents, managementGroupNames, managementGroupLevels, policyGroupNames, policyGroupLevels, | ||
)} | ||
onSubmit={onSubmit} | ||
onReset={onReset} | ||
canReset | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
TimelineOptions.propTypes = { | ||
url: PropTypes.string, | ||
}; | ||
|
||
TimelineOptions.defaultProps = { | ||
url: '', | ||
}; | ||
|
||
export default TimelineOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 0 additions & 85 deletions
85
app/javascript/oldjs/controllers/timeline/timeline_options_controller.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.