Skip to content

Commit 2ed4664

Browse files
authored
Merge branch 'develop' into feature/mobile-examples
2 parents 02f51af + 873b2b7 commit 2ed4664

File tree

7 files changed

+132
-26
lines changed

7 files changed

+132
-26
lines changed

client/modules/IDE/actions/files.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ export function deleteFile(id, parentId) {
160160
}
161161
};
162162
apiClient.delete(`/projects/${state.project.id}/files/${id}`, deleteConfig)
163-
.then(() => {
163+
.then((response) => {
164+
dispatch(setProjectSavedTime(response.data.project.updatedAt));
164165
dispatch({
165166
type: ActionTypes.DELETE_FILE,
166167
id,

client/modules/IDE/components/FileNode.jsx

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,61 @@ import FolderRightIcon from '../../../images/triangle-arrow-right.svg';
1010
import FolderDownIcon from '../../../images/triangle-arrow-down.svg';
1111
import FileIcon from '../../../images/file.svg';
1212

13+
function parseFileName(name) {
14+
const nameArray = name.split('.');
15+
if (nameArray.length > 1) {
16+
const extension = `.${nameArray[nameArray.length - 1]}`;
17+
const baseName = nameArray.slice(0, -1).join('');
18+
const firstLetter = baseName[0];
19+
const lastLetter = baseName[baseName.length - 1];
20+
const middleText = baseName.slice(1, -1);
21+
return {
22+
baseName,
23+
firstLetter,
24+
lastLetter,
25+
middleText,
26+
extension
27+
};
28+
}
29+
const firstLetter = name[0];
30+
const lastLetter = name[name.length - 1];
31+
const middleText = name.slice(1, -1);
32+
return {
33+
baseName: name,
34+
firstLetter,
35+
lastLetter,
36+
middleText
37+
};
38+
}
39+
40+
function FileName({ name }) {
41+
const {
42+
baseName,
43+
firstLetter,
44+
lastLetter,
45+
middleText,
46+
extension
47+
} = parseFileName(name);
48+
return (
49+
<span className="sidebar__file-item-name-text">
50+
<span>{firstLetter}</span>
51+
{baseName.length > 2 &&
52+
<span className="sidebar__file-item-name--ellipsis">{middleText}</span>
53+
}
54+
{baseName.length > 1 &&
55+
<span>{lastLetter}</span>
56+
}
57+
{extension &&
58+
<span>{extension}</span>
59+
}
60+
</span>
61+
);
62+
}
63+
64+
FileName.propTypes = {
65+
name: PropTypes.string.isRequired
66+
};
67+
1368
export class FileNode extends React.Component {
1469
constructor(props) {
1570
super(props);
@@ -206,11 +261,12 @@ export class FileNode extends React.Component {
206261
</div>
207262
}
208263
<button
209-
aria-label="Name"
264+
aria-label={this.state.updatedName}
210265
className="sidebar__file-item-name"
211266
onClick={this.handleFileClick}
267+
data-testid="file-name"
212268
>
213-
{this.state.updatedName}
269+
<FileName name={this.state.updatedName} />
214270
</button>
215271
<input
216272
data-testid="input"

client/modules/IDE/components/FileNode.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('<FileNode />', () => {
1313
};
1414

1515
const expectFileNameToBe = async (expectedName) => {
16-
const name = screen.getByLabelText(/Name/i);
16+
const name = screen.getByTestId('file-name');
1717
await waitFor(() => within(name).queryByText(expectedName));
1818
};
1919

client/modules/IDE/pages/IDEView.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class IDEView extends React.Component {
301301
onChange={size => this.setState({ sidebarSize: size })}
302302
onDragFinished={this._handleSidebarPaneOnDragFinished}
303303
allowResize={this.props.ide.sidebarIsExpanded}
304-
minSize={20}
304+
minSize={125}
305305
>
306306
<Sidebar
307307
files={this.props.files}

client/modules/IDE/reducers/files.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const initialState = () => {
4545
name: 'root',
4646
id: r,
4747
_id: r,
48-
children: [a, b, c],
48+
children: [b, a, c],
4949
fileType: 'folder',
5050
content: ''
5151
},
@@ -110,6 +110,32 @@ function deleteMany(state, ids) {
110110
return newState;
111111
}
112112

113+
function sortedChildrenId(state, children) {
114+
const childrenArray = state.filter(file => children.includes(file.id));
115+
childrenArray.sort((a, b) => (a.name > b.name ? 1 : -1));
116+
return childrenArray.map(child => child.id);
117+
}
118+
119+
function updateParent(state, action) {
120+
return state.map((file) => {
121+
if (file.id === action.parentId) {
122+
const newFile = Object.assign({}, file);
123+
newFile.children = [...newFile.children, action.id];
124+
return newFile;
125+
}
126+
return file;
127+
});
128+
}
129+
130+
function renameFile(state, action) {
131+
return state.map((file) => {
132+
if (file.id !== action.id) {
133+
return file;
134+
}
135+
return Object.assign({}, file, { name: action.name });
136+
});
137+
}
138+
113139
const files = (state, action) => {
114140
if (state === undefined) {
115141
state = initialState(); // eslint-disable-line
@@ -138,15 +164,8 @@ const files = (state, action) => {
138164
return initialState();
139165
case ActionTypes.CREATE_FILE: // eslint-disable-line
140166
{
141-
const newState = state.map((file) => {
142-
if (file.id === action.parentId) {
143-
const newFile = Object.assign({}, file);
144-
newFile.children = [...newFile.children, action.id];
145-
return newFile;
146-
}
147-
return file;
148-
});
149-
return [...newState,
167+
const newState = [
168+
...updateParent(state, action),
150169
{
151170
name: action.name,
152171
id: action.id,
@@ -156,15 +175,23 @@ const files = (state, action) => {
156175
children: action.children,
157176
fileType: action.fileType || 'file'
158177
}];
178+
return newState.map((file) => {
179+
if (file.id === action.parentId) {
180+
file.children = sortedChildrenId(newState, file.children);
181+
}
182+
return file;
183+
});
159184
}
160185
case ActionTypes.UPDATE_FILE_NAME:
161-
return state.map((file) => {
162-
if (file.id !== action.id) {
163-
return file;
186+
{
187+
const newState = renameFile(state, action);
188+
return newState.map((file) => {
189+
if (file.children.includes(action.id)) {
190+
file.children = sortedChildrenId(newState, file.children);
164191
}
165-
166-
return Object.assign({}, file, { name: action.name });
192+
return file;
167193
});
194+
}
168195
case ActionTypes.DELETE_FILE:
169196
{
170197
const newState = deleteMany(state, [action.id, ...getAllDescendantIds(state, action.id)]);
@@ -200,7 +227,10 @@ const files = (state, action) => {
200227
return file;
201228
});
202229
default:
203-
return state;
230+
return state.map((file) => {
231+
file.children = sortedChildrenId(state, file.children);
232+
return file;
233+
});
204234
}
205235
};
206236

client/styles/components/_sidebar.scss

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,28 @@
110110
}
111111
}
112112

113+
.sidebar__file-item-name--ellipsis {
114+
overflow-x: hidden;
115+
white-space: nowrap;
116+
text-overflow: ellipsis;
117+
min-width: #{15 / $base-font-size}rem;
118+
}
119+
120+
.sidebar__file-item-name-text {
121+
display: flex;
122+
width: 100%;
123+
overflow: hidden;
124+
min-width: #{50 / $base-font-size}rem;
125+
white-space: nowrap;
126+
text-align: left;
127+
}
128+
113129
.sidebar__file-item-name {
114130
padding: #{4 / $base-font-size}rem 0;
131+
padding-right: #{25 / $base-font-size}rem;
132+
font-family: Inconsolata, monospace;
133+
font-size: #{14 / $base-font-size}rem;
134+
overflow: hidden;
115135
.sidebar__file-item--editing & {
116136
display: none;
117137
}
@@ -174,6 +194,8 @@
174194
padding: 0;
175195
border: 0;
176196
width: calc(100% - #{63 / $base-font-size}rem);
197+
font-family: Inconsolata, monospace;
198+
font-size: #{14 / $base-font-size}rem;
177199
.sidebar__file-item--editing & {
178200
display: inline-block;
179201
}
@@ -254,9 +276,6 @@
254276
fill: getThemifyVariable('secondary-text-color');
255277
}
256278
}
257-
& svg {
258-
height: #{10 / $base-font-size}rem;
259-
}
260279
background-color: transparent;
261280
border: none;
262281
}

server/controllers/file.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ export function deleteFile(req, res) {
103103
const idsToDelete = getAllDescendantIds(project.files, req.params.file_id);
104104
deleteMany(project.files, [req.params.file_id, ...idsToDelete]);
105105
project.files = deleteChild(project.files, req.query.parentId, req.params.file_id);
106-
project.save((innerErr) => {
107-
res.json(project.files);
106+
project.save((innerErr, savedProject) => {
107+
res.json({ project: savedProject });
108108
});
109109
});
110110
}

0 commit comments

Comments
 (0)