Skip to content

Commit 3a7d83b

Browse files
added case where user clicks save all even when there is multiple top level files or folders
1 parent a6f46c3 commit 3a7d83b

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/commons/sagas/GitHubPersistenceSaga.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import FileExplorerDialog, { FileExplorerDialogProps } from '../gitHubOverlay/Fi
3030
import RepositoryDialog, { RepositoryDialogProps } from '../gitHubOverlay/RepositoryDialog';
3131
import { actions } from '../utils/ActionsHelper';
3232
import Constants from '../utils/Constants';
33-
import { promisifyDialog } from '../utils/DialogHelper';
33+
import { promisifyDialog, showSimpleErrorDialog } from '../utils/DialogHelper';
3434
import { dismiss, showMessage, showSuccessMessage, showWarningMessage } from '../utils/notifications/NotificationsHelper';
3535
import { EditorTabState } from '../workspace/WorkspaceTypes';
3636
import { Intent } from '@blueprintjs/core';
37+
import { filePathRegex } from '../utils/PersistenceHelper';
3738

3839
export function* GitHubPersistenceSaga(): SagaIterator {
3940
yield takeLatest(LOGIN_GITHUB, githubLoginSaga);
@@ -288,6 +289,39 @@ function* githubSaveAll(): any {
288289
>;
289290

290291
if (store.getState().fileSystem.persistenceFileArray.length === 0) {
292+
// check if there is only one top level folder
293+
const fileSystem: FSModule | null = yield select(
294+
(state: OverallState) => state.fileSystem.inBrowserFileSystem
295+
);
296+
297+
// If the file system is not initialised, do nothing.
298+
if (fileSystem === null) {
299+
yield call(console.log, 'no filesystem!'); // TODO change to throw new Error
300+
return;
301+
}
302+
const currFiles: Record<string, string> = yield call(
303+
retrieveFilesInWorkspaceAsRecord,
304+
'playground',
305+
fileSystem
306+
);
307+
const testPaths: Set<string> = new Set();
308+
Object.keys(currFiles).forEach(e => {
309+
const regexResult = filePathRegex.exec(e)!;
310+
testPaths.add(regexResult![1].slice('/playground/'.length, -1).split('/')[0]); //TODO hardcoded playground
311+
});
312+
if (testPaths.size !== 1) {
313+
yield call(showSimpleErrorDialog, {
314+
title: 'Unable to Save All',
315+
contents: (
316+
"There must be exactly one top level folder present in order to use Save All."
317+
),
318+
label: 'OK'
319+
});
320+
return;
321+
}
322+
323+
//only one top level folder, proceeding to selection
324+
291325
type ListForAuthenticatedUserData = GetResponseDataTypeFromEndpointMethod<
292326
typeof octokit.repos.listForAuthenticatedUser
293327
>;

src/features/github/GitHubUtils.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,9 @@ export async function checkIsFile(
207207
const files = results.data;
208208

209209
if (Array.isArray(files)) {
210-
console.log('folder detected');
211210
return false;
212211
}
213212

214-
console.log('file detected');
215213
return true;
216214
}
217215

@@ -256,9 +254,7 @@ export async function openFileInEditor(
256254

257255
store.dispatch(actions.deleteAllGithubSaveInfo());
258256
const fileSystem: FSModule | null = store.getState().fileSystem.inBrowserFileSystem;
259-
if (fileSystem === null) {
260-
console.log('no filesystem!');
261-
} else {
257+
if (fileSystem !== null) {
262258
await rmFilesInDirRecursively(fileSystem, '/playground');
263259
}
264260
type GetContentResponse = GetResponseTypeFromEndpointMethod<typeof octokit.repos.getContent>;
@@ -271,7 +267,6 @@ export async function openFileInEditor(
271267

272268
const regexResult = filePathRegex.exec(filePath);
273269
if (regexResult === null) {
274-
console.log('Regex null');
275270
return;
276271
}
277272
const newFilePath = regexResult[2] + regexResult[3];

0 commit comments

Comments
 (0)