Skip to content

Commit

Permalink
fix dialog summary pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbonson committed Jul 15, 2024
1 parent 2009602 commit 72a9200
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 46 deletions.
11 changes: 9 additions & 2 deletions app/javascript/components/service/DialogFields.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { DIALOG_FIELD_TYPES } from './constants';
import { DIALOG_FIELD_TYPES, ServiceType } from './constants';
import CheckboxField from './dialogFieldItems/CheckboxField';
import DateField from './dialogFieldItems/DateField';
import DateTimeField from './dialogFieldItems/DateTimeField';
Expand Down Expand Up @@ -59,11 +59,18 @@ const renderFieldItem = (field, data) => {
/** Component to render the Fields in the Service/DialogTabs/DialogGroups component */
const DialogFields = ({ dialogFields }) => {
const { data } = useContext(ServiceContext);
const visible = (field) => {
if (data.serviceType === ServiceType.dialog) {
return true;
}
return field.visible;
};

return (
<>
{
dialogFields.map((field) => (
field.visible ? renderFieldItem(field, data) : <span key={field.id.toString()} />
visible(field) ? renderFieldItem(field, data) : <span key={field.id.toString()} />
))
}
</>
Expand Down
37 changes: 22 additions & 15 deletions app/javascript/components/service/DialogGroups.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import React from 'react';
import PropTypes from 'prop-types';
import { TooltipIcon } from 'carbon-components-react';
import DialogFields from './DialogFields';

/** Component to render the Groups in the Service/DialogTabs component */
const DialogGroups = ({ dialogGroups }) => (
<>
{
dialogGroups.map((item) => (
<div className="section" key={item.id.toString()}>
<div className="section-label">
{item.label}
</div>
<div className="section-fields">
<DialogFields dialogFields={item.dialog_fields} />
const DialogGroups = ({ dialogGroups }) => {
const itemLabel = ({ label, description }) => (description
? <TooltipIcon direction="right" tooltipText={description}>{label}</TooltipIcon>
: label);

return (
<>
{
dialogGroups.map((item) => (
<div className="section" key={item.id.toString()}>
<div className="section-label">
{itemLabel(item)}
</div>
<div className="section-fields">
<DialogFields dialogFields={item.dialog_fields} />
</div>
</div>
</div>
))
}
</>
);
))
}
</>
);
};

DialogGroups.propTypes = {
dialogGroups: PropTypes.arrayOf(PropTypes.any).isRequired,
Expand Down
8 changes: 4 additions & 4 deletions app/javascript/components/service/DialogTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ const DialogTabs = () => {
const { data } = useContext(ServiceContext);
const dialogTabs = extractDialogTabs(data.apiResponse);

const tabLabel = (label, tabIndex) => {
const tabLabel = (tab, tabIndex) => {
const { fieldsToRefresh, groupFieldsByTab } = data;
const refreshInProgress = fieldsToRefresh.some((field) => groupFieldsByTab[tabIndex].includes(field));
return refreshInProgress
? (
<div className="tab-label">
{label}
{tab.label}
<Loading active small withOverlay={false} className="loading" />
</div>
)
: label;
: tab.label;
};

return (
<Tabs className="miq_custom_tabs">
{
dialogTabs.map((tab, tabIndex) => (
<Tab key={tab.id.toString()} label={tabLabel(tab.label, tabIndex)}>
<Tab key={tab.id.toString()} label={tabLabel(tab, tabIndex)}>
<div className="tabs">
<DialogGroups dialogGroups={tab.dialog_groups} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const RadioField = ({ field }) => {
valueSelected={fieldData.value} // Ensure the selected value is correctly handled
>
{
field.values.map((radio) => (
field.values && field.values.map((radio) => (
<RadioButton
key={`radio-${radio[1]}`}
disabled={isDisabled}
Expand All @@ -50,6 +50,7 @@ const RadioField = ({ field }) => {
))
}
</RadioButtonGroup>
{!field.values && <div>{__('Radio button entries are not configured')}</div>}
{field.required && !fieldData.valid && <div className="bx--form__helper-text">{requiredLabel}</div>}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/components/service/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const otherServiceTypesValue = (field) => {
return false;
}
if (field.type === DIALOG_FIELD_TYPES.tag) {
return [];
return {};
}
if (field.type === DIALOG_FIELD_TYPES.date) {
return currentDate();
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/components/service/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const Service = ({
isOrderServiceForm,
locked: false,
groupFieldsByTab: {},
serviceType,
});

const refreshStatus = useRef(RefreshStatus.notStarted);
Expand Down Expand Up @@ -97,8 +98,6 @@ const Service = ({
</ServiceContext.Provider>
);

console.log(data.dialogFields)
console.log(data.groupFieldsByTab)
return (
<div className={classNames('service-container', serviceType)}>
{ data.isLoading ? renderLoader() : renderContent() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ exports[`Service component - Dialog Summary should render the Service component
disabled={true}
id="text_box_1-DialogFieldTextBox-7542"
invalid={false}
invalidText="Required"
invalidText=""
labelText={
<UNDEFINED
field={
Expand Down Expand Up @@ -1622,7 +1622,7 @@ exports[`Service component - Dialog Summary should render the Service component
helperText=""
id="textarea_box_1-DialogFieldTextAreaBox-7543"
invalid={false}
invalidText="Required"
invalidText=""
labelText={
<UNDEFINED
field={
Expand Down Expand Up @@ -3394,7 +3394,7 @@ exports[`Service component - Dialog Summary should render the Service component
hideLegend={false}
id="radio_button_1-DialogFieldRadioButton-7547"
invalid={false}
invalidText="Required"
invalidText=""
labelPosition="right"
legendText={
<UNDEFINED
Expand Down Expand Up @@ -3895,7 +3895,7 @@ exports[`Service component - Dialog Summary should render the Service component
locale="en"
onChange={[Function]}
short={false}
value="7/11/2024"
value="7/15/2024"
>
<div
className="bx--form-item"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ exports[`Service component - Order Service should render the Service component f
disabled={false}
id="text_box_1-DialogFieldTextBox-7542"
invalid={true}
invalidText="Required"
invalidText=""
labelText={
<UNDEFINED
field={
Expand Down Expand Up @@ -1543,9 +1543,7 @@ exports[`Service component - Order Service should render the Service component f
<div
className="bx--form-requirement"
id="text_box_1-DialogFieldTextBox-7542-error-msg"
>
Required
</div>
/>
</div>
</div>
</TextInput>
Expand Down Expand Up @@ -1683,7 +1681,7 @@ exports[`Service component - Order Service should render the Service component f
helperText=""
id="textarea_box_1-DialogFieldTextAreaBox-7543"
invalid={true}
invalidText="Required"
invalidText=""
labelText={
<UNDEFINED
field={
Expand Down Expand Up @@ -1886,9 +1884,7 @@ exports[`Service component - Order Service should render the Service component f
className="bx--form-requirement"
id="textarea_box_1-DialogFieldTextAreaBox-7543-error-msg"
role="alert"
>
Required
</div>
/>
</div>
</TextArea>
</TextAreaField>
Expand Down Expand Up @@ -3617,7 +3613,7 @@ exports[`Service component - Order Service should render the Service component f
hideLegend={false}
id="radio_button_1-DialogFieldRadioButton-7547"
invalid={true}
invalidText="Required"
invalidText=""
labelPosition="right"
legendText={
<UNDEFINED
Expand Down Expand Up @@ -3970,9 +3966,7 @@ exports[`Service component - Order Service should render the Service component f
</RadioButtonGroup>
<div
className="bx--form__helper-text"
>
Required
</div>
/>
</div>
</RadioField>
</div>
Expand Down Expand Up @@ -4128,7 +4122,7 @@ exports[`Service component - Order Service should render the Service component f
locale="en"
onChange={[Function]}
short={false}
value="7/11/2024"
value="7/15/2024"
>
<div
className="bx--form-item"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ exports[`Service component - Service Request should render the Service component
onChange={[Function]}
readOnly={false}
type="text"
value={0}
value="0"
>
<div
className="bx--form-item bx--text-input-wrapper"
Expand Down Expand Up @@ -1511,7 +1511,7 @@ exports[`Service component - Service Request should render the Service component
onClick={[Function]}
readOnly={false}
type="text"
value={0}
value="0"
/>
</div>
</div>
Expand Down Expand Up @@ -3992,7 +3992,7 @@ exports[`Service component - Service Request should render the Service component
onChange={[Function]}
readOnly={false}
type="text"
value="Database, DHCP Server"
value=""
>
<div
className="bx--form-item bx--text-input-wrapper"
Expand Down Expand Up @@ -4147,7 +4147,7 @@ exports[`Service component - Service Request should render the Service component
onClick={[Function]}
readOnly={false}
type="text"
value="Database, DHCP Server"
value=""
/>
</div>
</div>
Expand Down

0 comments on commit 72a9200

Please sign in to comment.