Skip to content

Commit

Permalink
F #3951: Add tooltip & some fixes (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Betanzos authored and rsmontero committed Sep 24, 2020
1 parent 757b405 commit 8fa45a8
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import React, { memo } from 'react';
import PropTypes from 'prop-types';

import { FormControl, FormControlLabel, Checkbox } from '@material-ui/core';
import {
FormControl,
FormControlLabel,
Checkbox,
Tooltip
} from '@material-ui/core';
import { Controller } from 'react-hook-form';

import ErrorHelper from 'client/components/FormControl/ErrorHelper';

const CheckboxController = memo(
({ control, cy, name, label, error }) => (
({ control, cy, name, label, tooltip, error }) => (
<Controller
render={({ onChange, value }) => (
<FormControl error={Boolean(error)}>
<FormControlLabel
control={
<Checkbox
onChange={e => onChange(e.target.checked)}
name={name}
checked={value}
color="primary"
inputProps={{ 'data-cy': cy }}
/>
}
label={label}
labelPlacement="end"
/>
{Boolean(error) && <ErrorHelper label={error?.message} />}
</FormControl>
<Tooltip title={tooltip ?? ''}>
<FormControl error={Boolean(error)}>
<FormControlLabel
control={
<Checkbox
onChange={e => onChange(e.target.checked)}
name={name}
checked={value}
color="primary"
inputProps={{ 'data-cy': cy }}
/>
}
label={label}
labelPlacement="end"
/>
{Boolean(error) && <ErrorHelper label={error?.message} />}
</FormControl>
</Tooltip>
)}
name={name}
control={control}
Expand All @@ -39,6 +46,7 @@ CheckboxController.propTypes = {
cy: PropTypes.string,
name: PropTypes.string.isRequired,
label: PropTypes.string,
tooltip: PropTypes.string,
error: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.objectOf(PropTypes.any)
Expand All @@ -50,6 +58,7 @@ CheckboxController.defaultProps = {
cy: 'cy',
name: '',
label: '',
tooltip: undefined,
values: [],
error: false
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EmptyCard } from 'client/components/Cards';

function FormListSelect({ step, data, setFormData }) {
const { errors } = useFormContext();
const { id, onlyOneSelect, preRender, list, ItemComponent } = step;
const { id, multiple, preRender, list, ItemComponent } = step;

useEffect(() => {
if (preRender) preRender();
Expand All @@ -18,7 +18,7 @@ function FormListSelect({ step, data, setFormData }) {
const handleSelect = index =>
setFormData(prevData => ({
...prevData,
[id]: onlyOneSelect ? [index] : [...prevData[id], index]
[id]: multiple ? [...prevData[id], index] : [index]
}));

const handleUnselect = indexRemove =>
Expand Down
3 changes: 2 additions & 1 deletion src/fireedge/src/public/components/Forms/FormWithSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const FormWithSchema = ({ id, cy, fields }) => {

return (
<Grid container spacing={1}>
{fields?.map(({ name, type, label, values, dependOf }) => {
{fields?.map(({ name, type, label, values, dependOf, tooltip }) => {
const dataCy = `${cy}-${name}`;
const inputName = id ? `${id}.${name}` : name;
const formError = id ? errors[id] : errors;
Expand All @@ -39,6 +39,7 @@ const FormWithSchema = ({ id, cy, fields }) => {
cy: dataCy,
name: inputName,
label,
tooltip,
values: dependOf ? values(dependValue) : values,
error: inputError
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ export const FORM_FIELDS = [
},
{
name: 'ready_status_gate',
label:
'Wait for VMs to report that they are READY via OneGate to consider them running',
label: 'Wait for Tier Full Boot',
tooltip:
'Wait for VM/containers to finish their boot process to report that they are READY and allow children tiers to spawn',
type: TYPE_INPUT.CHECKBOX,
validation: yup.boolean().default(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const Clusters = () => {
label: 'Where will it run?',
content: FormListSelect,
resolver: STEP_FORM_SCHEMA,
onlyOneSelect: true,
preRender: getClusters,
list: clusters?.sort((a, b) => a.ID - b.ID),
ItemComponent: ClusterCard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ListCards from 'client/components/List/ListCards';
import { FORM_FIELDS, NETWORK_FORM_SCHEMA, STEP_FORM_SCHEMA } from './schema';

const Networks = () => {
const STEP_ID = 'networks';
const STEP_ID = 'networking';
const { getVNetworks, getVNetworksTemplates } = useOpennebula();

return useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BasicConfiguration = () => {

return {
id: STEP_ID,
label: 'Role configuration',
label: 'Configuration',
content: FormStep,
resolver: STEP_FORM_SCHEMA,
FormComponent: () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const FORM_FIELDS = [
.min(1)
.trim()
.required('Name field is required')
.default('Main')
.default('')
},
{
name: 'cardinality',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Template = () => {

return {
id: STEP_ID,
label: 'Template VM',
label: 'Template',
content: FormStep,
resolver: STEP_FORM_SCHEMA,
FormComponent: props => ProcessScreen({ screens: SCREENS, ...props })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import * as yup from 'yup';

import BasicConfiguration from './BasicConfiguration';
import Clusters from './Clusters';
import Networks from './Networks';
import Networking from './Networking';
import Roles from './Roles';

const Steps = () => {
const basic = BasicConfiguration();
const clusters = Clusters();
const networks = Networks();
const networking = Networking();
const roles = Roles();

const steps = [basic, clusters, networks, roles];
const steps = [basic, clusters, networking, roles];

const resolvers = yup.object({
[basic.id]: basic.resolver,
[clusters.id]: clusters.resolver,
[networks.id]: networks.resolver,
[networking.id]: networking.resolver,
[roles.id]: roles.resolver
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function ApplicationCreate() {
const { steps, defaultValues, resolvers } = Steps();

const methods = useForm({
mode: 'onBlur',
mode: 'onSubmit',
defaultValues,
resolver: yupResolver(resolvers)
});
Expand Down

0 comments on commit 8fa45a8

Please sign in to comment.