mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 06:16:01 +00:00
File editor tree improvements
Sort files and folders by type, then by name Hide hidden files/folders (starting with “.”) - WIP
This commit is contained in:
parent
0e872c99e6
commit
f3431eecbd
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {Treebeard, decorators} from 'react-treebeard';
|
||||
import {Form} from 'tabler-react';
|
||||
|
||||
const Header = ({style, node}) => {
|
||||
const iconType = node.children ? 'folder' : 'file';
|
||||
@ -27,7 +28,9 @@ decorators.Header = Header;
|
||||
class FileExplorer extends React.Component {
|
||||
constructor(props){
|
||||
super(props);
|
||||
this.state = {};
|
||||
this.state = {
|
||||
files: this.props.files
|
||||
};
|
||||
}
|
||||
|
||||
onToggle(node, toggled){
|
||||
@ -44,13 +47,23 @@ class FileExplorer extends React.Component {
|
||||
this.setState({ cursor: node });
|
||||
}
|
||||
|
||||
onHiddenToggle(value){
|
||||
this.setState({files: this.props.files.filter((file) => {
|
||||
return;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<Treebeard
|
||||
data={this.props.files}
|
||||
decorators={decorators}
|
||||
onToggle={this.onToggle.bind(this)}
|
||||
/>
|
||||
<React.Fragment>
|
||||
<Form.Switch type="checkbox" name="toggle" value={true} label="Show hidden files" ref={(input) => { this.showHidden = input; }} onToggle={this.onHiddenToggle.bind(this)} />
|
||||
<Treebeard
|
||||
data={this.props.files}
|
||||
decorators={decorators}
|
||||
onToggle={this.onToggle.bind(this)}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -73,14 +73,46 @@ class Pipeline {
|
||||
'/embark-api/files',
|
||||
(req, res) => {
|
||||
const rootPath = fs.dappPath();
|
||||
|
||||
function fileTreeSort(objects){
|
||||
function isFolder(object) {
|
||||
return object.children && object.children.length;
|
||||
}
|
||||
|
||||
function isNotFolder(object){
|
||||
return !isFolder(object);
|
||||
}
|
||||
|
||||
function byName(a, b) {
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
|
||||
const folders = objects.filter(isFolder).sort(byName);
|
||||
const files = objects.filter(isNotFolder).sort(byName);
|
||||
|
||||
return folders.concat(files);
|
||||
}
|
||||
|
||||
const walk = (dir, filelist = []) => fs.readdirSync(dir).map(name => {
|
||||
let isRoot = rootPath === dir;
|
||||
if (fs.statSync(path.join(dir, name)).isDirectory()) {
|
||||
return { isRoot, name, dirname: dir, children: walk(path.join(dir, name), filelist)};
|
||||
return {
|
||||
isRoot,
|
||||
name,
|
||||
dirname: dir,
|
||||
path: path.join(dir, name),
|
||||
isHidden: name.indexOf('.') === 0,
|
||||
children: fileTreeSort(walk(path.join(dir, name), filelist))};
|
||||
}
|
||||
return {name, isRoot, path: path.join(dir, name), dirname: dir};
|
||||
return {
|
||||
name,
|
||||
isRoot,
|
||||
path: path.join(dir, name),
|
||||
dirname: dir,
|
||||
isHidden: name.indexOf('.') === 0
|
||||
};
|
||||
});
|
||||
const files = walk(fs.dappPath());
|
||||
const files = fileTreeSort(walk(fs.dappPath()));
|
||||
res.send(files);
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user