diff --git a/app/javascript/components/automate-entry-points/index.jsx b/app/javascript/components/automate-entry-points/index.jsx
index c65e722a3c2..9fdaa316732 100644
--- a/app/javascript/components/automate-entry-points/index.jsx
+++ b/app/javascript/components/automate-entry-points/index.jsx
@@ -131,83 +131,110 @@ const DirectoryTreeView = () => {
// },
// ]);
- const folder = {
- id: 'root',
- name: '',
- children: [
- {
- id: 'src_folder',
- name: 'src',
- children: [
- {
- id: 'index.js_file',
- name: 'index.js',
- metadata: { a: '1', b: '2', c: 'test' },
- },
- {
- id: 'styles.css_file',
- name: 'styles.css',
- metadata: { a: '1', b: '2', c: 'test' },
- }],
- },
- {
- id: 'node_modules_folder',
- name: 'node_modules',
- children: [
- {
- id: 'react-accessible-treeview-folder',
- name: 'react-accessible-treeview',
- children: [{
- id: 'index.js_file2',
- name: 'index.js',
- }],
- },
- {
- id: 'react_folder',
- name: 'react',
- children: [{
- id: 'index.js_file3',
- name: 'index.js',
- }],
- },
- ],
- },
- {
- id: '.npmignore_file',
- name: '.npmignore',
- },
- {
- id: 'package.json_file',
- name: 'package.json',
- },
- {
- id: 'webpack.config.js_file',
- name: 'webpack.config.js',
- },
- ],
- };
+ // const folder = {
+ // id: 'root',
+ // name: '',
+ // children: [
+ // {
+ // id: 'src_folder',
+ // name: 'src',
+ // children: [
+ // {
+ // id: 'index.js_file',
+ // name: 'index.js',
+ // metadata: { a: '1', b: '2', c: 'test' },
+ // },
+ // {
+ // id: 'styles.css_file',
+ // name: 'styles.css',
+ // metadata: { a: '1', b: '2', c: 'test' },
+ // }],
+ // },
+ // {
+ // id: 'node_modules_folder',
+ // name: 'node_modules',
+ // children: [
+ // {
+ // id: 'react-accessible-treeview-folder',
+ // name: 'react-accessible-treeview',
+ // children: [{
+ // id: 'index.js_file2',
+ // name: 'index.js',
+ // }],
+ // },
+ // {
+ // id: 'react_folder',
+ // name: 'react',
+ // children: [{
+ // id: 'index.js_file3',
+ // name: 'index.js',
+ // }],
+ // },
+ // ],
+ // },
+ // {
+ // id: '.npmignore_file',
+ // name: '.npmignore',
+ // },
+ // {
+ // id: 'package.json_file',
+ // name: 'package.json',
+ // },
+ // {
+ // id: 'webpack.config.js_file',
+ // name: 'webpack.config.js',
+ // },
+ // ],
+ // };
- const data = flattenTree(folder);
- console.log(data);
-
- const initialData = {
+ const root = {
id: 'root',
name: '',
children: [
- {
- id: 'root-node',
- name: '',
- },
+ // {
+ // id: 'datastore_folder',
+ // name: __('Datastore'),
+ // children: [{}],
+ // },
],
};
- const [rawTreeData, setRawTreeData] = useState(folder);
- const [treeData, setTreeData] = useState(flattenTree(initialData));
+ const [rawTreeData, setRawTreeData] = useState(root);
+ const [treeData, setTreeData] = useState(flattenTree(root));
const [expandedIds, setExpandedIds] = useState([]);
+ const [treeIds, setTreeIds] = useState(['datastore_folder']);
const [key, setKey] = useState('initial');
useEffect(() => {
- setTreeData(data);
+ const newChildren = [];
+ API.get('/api/automate_domains?expand=resources').then((apiData) => {
+ console.log(apiData);
+ apiData.resources.forEach((domain) => {
+ newChildren.push({
+ id: domain.id,
+ name: domain.name,
+ children: [{}],
+ parent: 'datastore_folder',
+ metadata: {},
+ });
+ });
+ return newChildren;
+ }).then((newChildren) => {
+ const tempIdsArray = treeIds;
+ newChildren.forEach((node) => {
+ if (!treeIds.includes(node.id)) {
+ tempIdsArray.push(node.id);
+ }
+ });
+ const tempData = root;
+ tempData.children = [{
+ id: 'datastore_folder',
+ name: __('Datastore'),
+ }];
+ tempData.children[0].children = newChildren;
+ setTreeIds(tempIdsArray);
+ setTreeData(flattenTree(tempData));
+ });
}, []);
useEffect(() => {
@@ -217,9 +244,9 @@ const DirectoryTreeView = () => {
useEffect(() => {
console.log(treeData);
- if (treeData.length > 12) {
- setExpandedIds(['src_folder']);
- setKey('new');
+ if (treeData.length > 3) {
+ setExpandedIds(['datastore_folder']);
+ setKey(treeData.length);
}
}, [treeData]);
@@ -231,18 +258,22 @@ const DirectoryTreeView = () => {
));
const FileIcon = ({ filename }) => {
- const extension = filename.slice(filename.lastIndexOf('.') + 1);
- switch (extension) {
- case 'js':
- return