-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
staging changes reordered form added lint error coorection lint error correction
- Loading branch information
1 parent
e37dec7
commit 8d0069e
Showing
8 changed files
with
175 additions
and
77 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
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
57 changes: 57 additions & 0 deletions
57
app/javascript/components/c-and-u-collections-form/index.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,57 @@ | ||
import React, {useState} from 'react'; | ||
import MiqFormRenderer from '@@ddf'; | ||
import createSchema from './schema'; | ||
import NotificationMessage from '../notification-message'; | ||
|
||
// import handleFailure from '../../helpers/handle-failure'; | ||
|
||
const DiagnosticsCURepairForm = ({ timezones }) => { | ||
|
||
const [data, setData] = useState({ | ||
response: undefined | ||
}); | ||
|
||
/** Function to append 0 to beginning of a number if it is a single digit. */ | ||
const padStart = (number) => String(number).padStart(2, '0'); | ||
|
||
/** This function format the date. */ | ||
const formatDate = (date) => { | ||
const newDate = new Date(date[0]); | ||
return `${padStart(newDate.getMonth()+1)}/${padStart(newDate.getDate())}/${newDate.getFullYear()}`; | ||
} | ||
|
||
const onSubmit = (values) => { | ||
const data = { | ||
timezone: values.timezone, | ||
start_date: formatDate(values.startDate), | ||
end_date: formatDate(values.endDate), | ||
} | ||
console.log(data); | ||
http.post(`/ops/cu_repair?button=submit`, data, { skipErrors: [400, 500] }) | ||
.then(({status, message}) => { | ||
['startDate', 'endDate'].forEach((item) => document.getElementById(item).value = ""); | ||
setData({ | ||
...data, | ||
response: { status, message } | ||
}); | ||
}); | ||
}; | ||
|
||
const renderMessage = ({status, message}) => <NotificationMessage type={status} message={message} /> | ||
|
||
return ( | ||
<> | ||
{ data.response && renderMessage(data.response) } | ||
<MiqFormRenderer | ||
schema={createSchema(timezones)} | ||
onSubmit={onSubmit} | ||
/> | ||
{ | ||
`${__('Note')} : ${__('Gap Collection is only available for VMware vSphere Infrastructures')}` | ||
} | ||
</> | ||
) | ||
}; | ||
|
||
|
||
export default DiagnosticsCURepairForm; |
39 changes: 39 additions & 0 deletions
39
app/javascript/components/c-and-u-collections-form/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,39 @@ | ||
import { componentTypes, validatorTypes } from '@@ddf'; | ||
|
||
const createSchema = (timezones) => ({ | ||
title: __('Collection Options'), | ||
fields: [ | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'timezone', | ||
name: 'timezone', | ||
label: __('Timezone'), | ||
initialValue: 'UTC', | ||
validate: [{ type: validatorTypes.REQUIRED }], | ||
isRequired: true, | ||
includeEmpty: true, | ||
options: timezones.map((timezone) => ({ | ||
label: timezone[0], | ||
value: timezone[1], | ||
})), | ||
}, | ||
{ | ||
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 createSchema; |
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
23 changes: 23 additions & 0 deletions
23
app/javascript/spec/c-and-u-collections-form/c-and-u-collections-form.spec.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,23 @@ | ||
import React from 'react'; | ||
import toJson from 'enzyme-to-json'; | ||
import fetchMock from 'fetch-mock'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { mount } from '../helpers/mountForm'; | ||
import DiagnosticsCURepairForm from '../../components/c-and-u-collections-form'; | ||
|
||
describe('DiagnosticsCURepairForm Component', () => { | ||
afterEach(() => { | ||
fetchMock.reset(); | ||
fetchMock.restore(); | ||
}); | ||
it('Should render a new DiagnosticsCURepair form', async () => { | ||
let wrapper; | ||
await act(async () => { | ||
wrapper = mount(<DiagnosticsCURepairForm />); | ||
}); | ||
wrapper.update(); | ||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
|
||
}); |
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,2 @@ | ||
<%= react('DiagnosticsCURepairForm', {:timezones => ViewHelper::ALL_TIMEZONES}) =%> | ||
|
This file was deleted.
Oops, something went wrong.