Skip to content

Commit 2881848

Browse files
Fix bugs with select
1 parent 0050c5e commit 2881848

File tree

7 files changed

+125
-81
lines changed

7 files changed

+125
-81
lines changed

app/javascript/components/automate-entry-points/index.jsx

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useState } from 'react';
22
import { Loading, Modal, ModalBody } from 'carbon-components-react';
3-
import PropTypes, { number } from 'prop-types';
3+
import PropTypes from 'prop-types';
44
import {
55
Document16,
66
Folder16,
@@ -18,12 +18,14 @@ const initialData = [
1818
},
1919
];
2020

21-
const MultiSelectCheckboxAsync = () => {
21+
const AutomateEntryPoints = ({
22+
selected, selectedValue, showModal, setShowModal, setSelectedValue,
23+
}) => {
2224
const [data, setData] = useState(initialData);
25+
const [isLoading, setIsLoading] = useState(true);
2326
const [nodesAlreadyLoaded, setNodesAlreadyLoaded] = useState([]);
24-
const [open, setOpen] = useState(true);
25-
const [selectedValue, setSelectedValue] = useState();
2627
const [disableSubmit, setDisableSubmit] = useState(true);
28+
const [selectedNode, setSelectedNode] = useState();
2729

2830
const updateTreeData = (list, id, children) => {
2931
const data = list.map((node) => {
@@ -35,6 +37,18 @@ const MultiSelectCheckboxAsync = () => {
3537
return data.concat(children);
3638
};
3739

40+
useEffect(() => {
41+
if (selectedValue.element) {
42+
data.forEach((node) => {
43+
if (node.id === selectedValue.element.id) {
44+
console.log(document.getElementById(node.id));
45+
document.getElementById(node.id).classList.add('currently-selected');
46+
document.getElementById(node.id).style.backgroundColor = 'rgba(0, 0, 0, 0.2)';
47+
}
48+
});
49+
}
50+
}, [selectedValue]);
51+
3852
useEffect(() => {
3953
miqSparkleOn();
4054
const newChildren = [];
@@ -57,6 +71,7 @@ const MultiSelectCheckboxAsync = () => {
5771
resolve();
5872
}, 1000);
5973
})).then(() => {
74+
setIsLoading(false);
6075
miqSparkleOff();
6176
});
6277
}, []);
@@ -120,18 +135,40 @@ const MultiSelectCheckboxAsync = () => {
120135
}
121136
};
122137
wrappedOnLoadData.propTypes = {
123-
element: PropTypes.objectOf({ children: PropTypes.array, id: number }).isRequired,
138+
element: PropTypes.objectOf({ children: PropTypes.array, id: PropTypes.number }).isRequired,
124139
};
125140
wrappedOnLoadData.defaultProps = {
126141
};
127142

128143
const onSelect = (value) => {
144+
console.log(value.element);
129145
if (value.isBranch === false && value.isSelected) {
130-
setSelectedValue(value);
146+
data.forEach((node) => {
147+
if (selectedNode && (node.id === selectedNode.element.id)) {
148+
console.log(selectedNode);
149+
document.getElementById(node.id).style.backgroundColor = 'transparent';
150+
// #b8b8b8
151+
// document.getElementById(node.id).classList.remove('prevSelected');
152+
// document.getElementById(node.id).parentNode.className = 'tree-leaf-list-item';
153+
// document.getElementById(node.id).className = 'tree-node';
154+
// document.getElementById(node.id).setAttribute('aria-selected', 'false');
155+
}
156+
});
157+
document.getElementById(value.element.id).style.backgroundColor = 'rgba(0, 0, 0, 0.2)';
158+
setSelectedNode(value);
131159
setDisableSubmit(false);
132160
}
133161
};
134162

163+
const onExpand = ((value) => {
164+
console.log('test');
165+
console.log(value);
166+
console.log(selectedNode);
167+
if (value.isExpanded && selectedNode && document.getElementById(selectedNode.element.id)) {
168+
document.getElementById(selectedNode.element.id).style.backgroundColor = 'rgba(0, 0, 0, 0.2)';
169+
}
170+
});
171+
135172
const FolderIcon = ({ isOpen }) =>
136173
(isOpen ? (
137174
<FolderOpen16 className="icon" />
@@ -148,31 +185,32 @@ const MultiSelectCheckboxAsync = () => {
148185

149186
const FileIcon = () => <Document16 className="icon" />;
150187

151-
return (
188+
return !isLoading && (
152189
<Modal
153-
open={open}
190+
open={showModal}
154191
primaryButtonText={__('OK')}
155192
secondaryButtonText={__('Cancel')}
156193
onRequestSubmit={() => {
157-
console.log(selectedValue);
158-
setOpen(false);
194+
setSelectedValue(selectedNode);
195+
setShowModal(false);
159196
}}
160197
onRequestClose={() => {
161-
setOpen(false);
198+
setShowModal(false);
162199
}}
163200
onSecondarySubmit={() => {
164-
setOpen(false);
201+
setShowModal(false);
165202
}}
166203
primaryButtonDisabled={disableSubmit}
167204
>
168205
<ModalBody>
169206
<div>
170-
<div className="checkbox">
207+
<div className="automate_entry_points">
171208
<TreeView
172209
data={data}
173-
aria-label="Checkbox tree"
210+
aria-label="Automate Entry Points tree"
174211
onSelect={(value) => onSelect(value)}
175212
onLoadData={wrappedOnLoadData}
213+
onExpand={(value) => onExpand(value)}
176214
togglableSelect
177215
nodeRenderer={({
178216
element,
@@ -192,6 +230,7 @@ const MultiSelectCheckboxAsync = () => {
192230
<div
193231
{...getNodeProps()}
194232
style={{ marginLeft: 40 * (level - 1) }}
233+
id={element.id}
195234
>
196235
{isBranch && branchNode(isExpanded, element)}
197236
{isBranch ? (
@@ -215,10 +254,20 @@ const MultiSelectCheckboxAsync = () => {
215254
);
216255
};
217256

218-
MultiSelectCheckboxAsync.propTypes = {
257+
AutomateEntryPoints.propTypes = {
258+
field: PropTypes.string.isRequired,
259+
type: PropTypes.string.isRequired,
260+
selected: PropTypes.string,
261+
selectedValue: PropTypes.objectOf(PropTypes.any),
262+
showModal: PropTypes.bool,
263+
setShowModal: PropTypes.func.isRequired,
264+
setSelectedValue: PropTypes.func.isRequired,
219265
};
220266

221-
MultiSelectCheckboxAsync.defaultProps = {
267+
AutomateEntryPoints.defaultProps = {
268+
selected: '',
269+
selectedValue: {},
270+
showModal: false,
222271
};
223272

224-
export default MultiSelectCheckboxAsync;
273+
export default AutomateEntryPoints;

app/javascript/components/automate-entry-points/styles.css

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,59 +58,61 @@
5858
margin-right: 1rem;
5959
}
6060

61-
.checkbox {
61+
.automate_entry_points {
6262
font-size: 16px;
6363
user-select: none;
6464
min-height: 320px;
6565
padding: 20px;
6666
box-sizing: content-box;
6767
}
6868

69-
.checkbox .tree,
70-
.checkbox .tree-node,
71-
.checkbox .tree-node-group {
69+
.automate_entry_points .tree,
70+
.automate_entry_points .tree-node,
71+
.automate_entry_points .tree-node-group {
7272
list-style: none;
7373
margin: 0;
7474
padding: 0;
7575
}
7676

77-
.checkbox .tree-branch-wrapper,
78-
.checkbox .tree-node__leaf {
77+
.automate_entry_points .tree-branch-wrapper,
78+
.automate_entry_points .tree-node__leaf {
7979
outline: none;
8080
}
8181

82-
.checkbox .tree-node {
82+
.automate_entry_points .tree-node {
8383
cursor: pointer;
8484
}
8585

86-
.checkbox .tree-node .name:hover {
86+
.automate_entry_points .tree-node .name:hover {
8787
background: rgba(0, 0, 0, 0.1);
88+
background-color: transparent;
8889
}
8990

90-
.checkbox .tree-node--focused .name {
91+
.automate_entry_points .tree-node--focused .name {
9192
background: rgba(0, 0, 0, 0.2);
93+
background-color: transparent;
9294
}
9395

94-
.checkbox .tree-node {
96+
.automate_entry_points .tree-node {
9597
display: inline-block;
9698
}
9799

98-
.checkbox .checkbox-icon {
100+
.automate_entry_points .checkbox-icon {
99101
margin: 0 5px;
100102
vertical-align: middle;
101103
}
102104

103-
.checkbox button {
105+
.automate_entry_points button {
104106
border: none;
105107
background: transparent;
106108
cursor: pointer;
107109
}
108110

109-
.checkbox .arrow {
111+
.automate_entry_points .arrow {
110112
margin-left: 5px;
111113
vertical-align: middle;
112114
}
113115

114-
.checkbox .arrow--open {
116+
.automate_entry_points .arrow--open {
115117
transform: rotate(270deg);
116118
}

app/javascript/components/embedded-automate-entry-point/index.jsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ const EmbeddedAutomateEntryPoint = (props) => {
1212
const { input } = useFieldApi(props);
1313

1414
const [showModal, setShowModal] = useState(false);
15-
const [selectedValue, setSelectedValue] = useState({});
15+
const [selectedValue, setSelectedValue] = useState();
1616
const [textValue, setTextValue] = useState('');
1717

1818
useEffect(() => {
19-
if (selectedValue && selectedValue.name && selectedValue.name.text) {
20-
setTextValue(selectedValue.name.text);
19+
console.log(selectedValue);
20+
if (selectedValue && selectedValue.element && selectedValue.element.name && selectedValue.element.metadata) {
21+
setTextValue(selectedValue.element.metadata.fqname);
2122
} else {
2223
setTextValue('');
2324
}
@@ -32,15 +33,15 @@ const EmbeddedAutomateEntryPoint = (props) => {
3233

3334
return (
3435
<div>
35-
{showModal ? (
36-
<AutomateEntryPoints
37-
field={field}
38-
selected={selected}
39-
type={type}
40-
setShowModal={setShowModal}
41-
setSelectedValue={setSelectedValue}
42-
/>
43-
) : undefined}
36+
<AutomateEntryPoints
37+
field={field}
38+
selected={selected}
39+
selectedValue={selectedValue}
40+
showModal={showModal}
41+
type={type}
42+
setShowModal={setShowModal}
43+
setSelectedValue={setSelectedValue}
44+
/>
4445
<div className="entry-point-wrapper">
4546
<div className="entry-point-text-input">
4647
<TextInput id={id} type="text" labelText={__(label)} onChange={(value) => setTextValue(value.target.value)} value={textValue} />

app/javascript/components/terraform-template-catalog-form/terraform-template-catalog-form.schema.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,30 @@ const basicInformationTabSchema = (availableCatalogs, tenantTree, roleAllows, zo
3838
initialValue: 'embedded_automate',
3939
options: [{ value: 'embedded_automate', label: __('Embedded Automate') }, { value: 'embedded_workflow', label: __('Embedded Workflow') }],
4040
},
41-
{
42-
component: componentTypes.TEXT_FIELD,
43-
id: 'provisioning_entry_point_automate',
44-
name: 'provisioning_entry_point_automate',
45-
label: __('Provisioning Entry Point'),
46-
initialValue: '/Service/Generic/StateMachines/GenericLifecycle/provision',
47-
condition: {
48-
when: 'provisioning_entry_point_type',
49-
is: 'embedded_automate',
50-
},
51-
},
5241
// {
53-
// component: 'embedded-automate-entry-point',
42+
// component: componentTypes.TEXT_FIELD,
5443
// id: 'provisioning_entry_point_automate',
5544
// name: 'provisioning_entry_point_automate',
56-
// label: 'Provisioning Entry Point',
57-
// field: 'fqname',
58-
// selected: '',
59-
// type: 'provision',
45+
// label: __('Provisioning Entry Point'),
46+
// initialValue: '/Service/Generic/StateMachines/GenericLifecycle/provision',
6047
// condition: {
6148
// when: 'provisioning_entry_point_type',
6249
// is: 'embedded_automate',
6350
// },
6451
// },
52+
{
53+
component: 'embedded-automate-entry-point',
54+
id: 'provisioning_entry_point_automate',
55+
name: 'provisioning_entry_point_automate',
56+
label: 'Provisioning Entry Point',
57+
field: 'fqname',
58+
selected: '',
59+
type: 'provision',
60+
condition: {
61+
when: 'provisioning_entry_point_type',
62+
is: 'embedded_automate',
63+
},
64+
},
6565
{
6666
component: 'embedded-workflow-entry-point',
6767
id: 'provisioning_entry_point_workflow',

app/javascript/components/visual-settings-form/index.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
33
import { Loading } from 'carbon-components-react';
44
import MiqFormRenderer from '@@ddf';
55
import createSchema from './visual-settings-form.schema';
6-
import DirectoryTreeView from '../automate-entry-points';
76

87
const VisualSettingsForm = ({ recordId }) => {
98
const [{ initialValues, timezoneOptions, isLoading }, setState] = useState({ isLoading: true });
@@ -43,7 +42,6 @@ const VisualSettingsForm = ({ recordId }) => {
4342
}
4443
return (
4544
<div>
46-
<DirectoryTreeView />
4745
<MiqFormRenderer
4846
schema={createSchema(timezoneOptions)}
4947
initialValues={initialValues}

app/javascript/components/visual-settings-form/visual-settings-form.schema.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import { componentTypes } from '@@ddf';
22

3-
// const loadData = API.get('/api/automate?depth=1&attributes=klass,id,fqname,domain_fqname,name').then((data) => {
4-
// console.log(data);
5-
// const tree = [];
6-
// if (data && data.resources) {
7-
// data.resources.forEach((domain) => {
8-
// // console.log(domain);
9-
// tree.push({
10-
// key: domain.fqname,
11-
// icon: 'pficon pficon-folder-close',
12-
// selectable: false,
13-
// text: domain.name,
14-
// tooltip: 'root node',
15-
// state: {},
16-
// });
17-
// });
18-
// }
19-
// return tree;
20-
// });
21-
223
const createSchema = (timezoneOptions) => ({
234
fields: [
5+
{
6+
component: 'embedded-automate-entry-point',
7+
id: 'provisioning_entry_point_automate',
8+
name: 'provisioning_entry_point_automate',
9+
label: 'Provisioning Entry Point',
10+
field: 'fqname',
11+
selected: '',
12+
type: 'provision',
13+
// condition: {
14+
// when: 'provisioning_entry_point_type',
15+
// is: 'embedded_automate',
16+
// },
17+
},
2418
{
2519
component: componentTypes.SUB_FORM,
2620
name: 'general-subform',

0 commit comments

Comments
 (0)