Skip to content

Commit 81ad54b

Browse files
committed
Moved constants and functions related to names and paths from common_storage.ts to names.ts.
1 parent fedb96d commit 81ad54b

File tree

10 files changed

+183
-156
lines changed

10 files changed

+183
-156
lines changed

src/blocks/mrc_component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2929
import { getAllowedTypesForSetCheck, getClassData, getModuleData, getSubclassNames } from './utils/python';
3030
import * as toolboxItems from '../toolbox/items';
3131
import * as commonStorage from '../storage/common_storage';
32+
import * as storageNames from '../storage/names';
3233
import { createPortShadow } from './mrc_port';
3334
import { createNumberShadowValue } from './utils/value';
3435
import { ClassData, FunctionData } from './utils/python_json_types';
@@ -216,7 +217,7 @@ export function getAllPossibleComponents(moduleType: string): toolboxItems.Conte
216217

217218
const componentName = (
218219
'my_' +
219-
commonStorage.pascalCaseToSnakeCase(
220+
storageNames.pascalCaseToSnakeCase(
220221
componentType.substring(componentType.lastIndexOf('.') + 1)));
221222

222223
classData.staticMethods.forEach(staticFunctionData => {

src/blocks/mrc_mechanism.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2929
import { getAllowedTypesForSetCheck } from './utils/python';
3030
import * as toolboxItems from '../toolbox/items';
3131
import * as commonStorage from '../storage/common_storage';
32+
import * as storageNames from '../storage/names';
3233
import * as value from './utils/value';
3334
import { renameMethodCallers } from './mrc_call_python_function'
3435

@@ -186,7 +187,7 @@ const MECHANISM = {
186187
if (this.getFieldValue(FIELD_TYPE) !== foundMechanism.className) {
187188
this.setFieldValue(foundMechanism.className, FIELD_TYPE);
188189
}
189-
const importModule = commonStorage.pascalCaseToSnakeCase(foundMechanism.className);
190+
const importModule = storageNames.pascalCaseToSnakeCase(foundMechanism.className);
190191
if (this.mrcImportModule !== importModule) {
191192
this.mrcImportModule = importModule;
192193
}
@@ -246,7 +247,7 @@ export const pythonFromBlock = function (
246247

247248
export function createMechanismBlock(
248249
mechanism: commonStorage.Mechanism, components: commonStorage.Component[]): toolboxItems.Block {
249-
const snakeCaseName = commonStorage.pascalCaseToSnakeCase(mechanism.className);
250+
const snakeCaseName = storageNames.pascalCaseToSnakeCase(mechanism.className);
250251
const mechanismName = 'my_' + snakeCaseName;
251252
const extraState: MechanismExtraState = {
252253
importModule: snakeCaseName,

src/editor/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as Blockly from 'blockly/core';
2424
import { extendedPythonGenerator } from './extended_python_generator';
2525
import { GeneratorContext } from './generator_context';
2626
import * as commonStorage from '../storage/common_storage';
27+
import * as storageNames from '../storage/names';
2728
import * as eventHandler from '../blocks/mrc_event_handler';
2829
import * as classMethodDef from '../blocks/mrc_class_method_def';
2930
import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder';
@@ -382,7 +383,7 @@ export class Editor {
382383
public getMechanism(mechanismInRobot: commonStorage.MechanismInRobot): commonStorage.Mechanism | null {
383384
if (this.currentProject) {
384385
for (const mechanism of this.currentProject.mechanisms) {
385-
const fullClassName = commonStorage.pascalCaseToSnakeCase(mechanism.className) + '.' + mechanism.className;
386+
const fullClassName = storageNames.pascalCaseToSnakeCase(mechanism.className) + '.' + mechanism.className;
386387
if (fullClassName === mechanismInRobot.className) {
387388
return mechanism;
388389
}

src/reactComponents/Menu.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as Antd from 'antd';
2222
import * as React from 'react';
2323
import { RcFile, UploadRequestOption } from 'rc-upload/lib/interface';
2424
import * as commonStorage from '../storage/common_storage';
25+
import * as storageNames from '../storage/names';
2526
import * as createPythonFiles from '../storage/create_python_files';
2627
import * as I18Next from 'react-i18next';
2728
import {TabType } from '../types/TabType';
@@ -335,7 +336,7 @@ export function Component(props: MenuProps): React.JSX.Element {
335336

336337
try {
337338
const blobUrl = await props.storage.downloadProject(props.project.projectName);
338-
const filename = props.project.projectName + commonStorage.UPLOAD_DOWNLOAD_FILE_EXTENSION;
339+
const filename = props.project.projectName + storageNames.UPLOAD_DOWNLOAD_FILE_EXTENSION;
339340

340341
// Create a temporary link to download the file
341342
const link = document.createElement('a');
@@ -361,9 +362,9 @@ export function Component(props: MenuProps): React.JSX.Element {
361362
}
362363

363364
const uploadProps: Antd.UploadProps = {
364-
accept: commonStorage.UPLOAD_DOWNLOAD_FILE_EXTENSION,
365+
accept: storageNames.UPLOAD_DOWNLOAD_FILE_EXTENSION,
365366
beforeUpload: (file) => {
366-
const isBlocks = file.name.endsWith(commonStorage.UPLOAD_DOWNLOAD_FILE_EXTENSION)
367+
const isBlocks = file.name.endsWith(storageNames.UPLOAD_DOWNLOAD_FILE_EXTENSION)
367368
if (!isBlocks) {
368369
// TODO: i18n
369370
props.setAlertErrorMessage(file.name + ' is not a blocks file');

src/reactComponents/ProjectNameComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as Antd from 'antd';
2222
import * as I18Next from 'react-i18next';
2323
import * as React from 'react';
2424
import * as commonStorage from '../storage/common_storage';
25+
import * as storageNames from '../storage/names';
2526

2627
/** Props for the ProjectNameComponent. */
2728
interface ProjectNameComponentProps {
@@ -63,7 +64,7 @@ export default function ProjectNameComponent(props: ProjectNameComponentProps):
6364
return;
6465
}
6566

66-
if (!commonStorage.isValidClassName(newProjectName)) {
67+
if (!storageNames.isValidClassName(newProjectName)) {
6768
showError(newProjectName + INVALID_NAME_MESSAGE_SUFFIX);
6869
return;
6970
}

src/storage/client_side_storage.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
import * as commonStorage from './common_storage';
23+
import * as names from './names';
2324

2425
// Functions for saving blocks modules to client side storage.
2526

@@ -148,8 +149,8 @@ class ClientSideStorage implements commonStorage.Storage {
148149
const module: commonStorage.Module = {
149150
modulePath: path,
150151
moduleType: moduleType,
151-
projectName: commonStorage.getProjectName(path),
152-
className: commonStorage.getClassName(path),
152+
projectName: names.getProjectName(path),
153+
className: names.getClassName(path),
153154
dateModifiedMillis: value.dateModifiedMillis,
154155
}
155156
if (moduleType === commonStorage.MODULE_TYPE_ROBOT) {
@@ -243,8 +244,8 @@ class ClientSideStorage implements commonStorage.Storage {
243244
}
244245

245246
async createProject(projectName: string, robotContent: string, opmodeContent : string): Promise<void> {
246-
const modulePath = commonStorage.makeRobotPath(projectName);
247-
const opmodePath = commonStorage.makeModulePath(projectName, commonStorage.CLASS_NAME_TELEOP);
247+
const modulePath = names.makeRobotPath(projectName);
248+
const opmodePath = names.makeModulePath(projectName, names.CLASS_NAME_TELEOP);
248249

249250
await this._saveModule(commonStorage.MODULE_TYPE_ROBOT, modulePath, robotContent);
250251
await this._saveModule(commonStorage.MODULE_TYPE_OPMODE, opmodePath, opmodeContent);
@@ -340,13 +341,13 @@ class ClientSideStorage implements commonStorage.Storage {
340341
const value = cursor.value;
341342
const path = value.path;
342343
const moduleType = value.type;
343-
if (commonStorage.getProjectName(path) === oldProjectName) {
344+
if (names.getProjectName(path) === oldProjectName) {
344345
let newPath;
345346
if (moduleType === commonStorage.MODULE_TYPE_ROBOT) {
346-
newPath = commonStorage.makeRobotPath(newProjectName);
347+
newPath = names.makeRobotPath(newProjectName);
347348
} else {
348-
const className = commonStorage.getClassName(path);
349-
newPath = commonStorage.makeModulePath(newProjectName, className);
349+
const className = names.getClassName(path);
350+
newPath = names.makeModulePath(newProjectName, className);
350351
}
351352
oldToNewModulePaths[path] = newPath;
352353
}
@@ -433,8 +434,8 @@ class ClientSideStorage implements commonStorage.Storage {
433434
reject(new Error('IndexedDB transaction aborted.'));
434435
};
435436
const modulesObjectStore = transaction.objectStore(MODULES_STORE_NAME);
436-
const oldModulePath = commonStorage.makeModulePath(projectName, oldClassName);
437-
const newModulePath = commonStorage.makeModulePath(projectName, newClassName);
437+
const oldModulePath = names.makeModulePath(projectName, oldClassName);
438+
const newModulePath = names.makeModulePath(projectName, newClassName);
438439
const getRequest = modulesObjectStore.get(oldModulePath);
439440
getRequest.onerror = () => {
440441
console.log('IndexedDB get request failed. getRequest.error is...');
@@ -496,7 +497,7 @@ class ClientSideStorage implements commonStorage.Storage {
496497
if (cursor) {
497498
const value = cursor.value;
498499
const path = value.path;
499-
if (commonStorage.getProjectName(path) === projectName) {
500+
if (names.getProjectName(path) === projectName) {
500501
modulePaths.push(path);
501502
}
502503
cursor.continue();
@@ -559,8 +560,8 @@ class ClientSideStorage implements commonStorage.Storage {
559560
const cursor = openCursorRequest.result;
560561
if (cursor) {
561562
const value = cursor.value;
562-
if (commonStorage.getProjectName(value.path) === projectName) {
563-
const className = commonStorage.getClassName(value.path);
563+
if (names.getProjectName(value.path) === projectName) {
564+
const className = names.getClassName(value.path);
564565
classNameToModuleContentText[className] = value.content;
565566
}
566567
cursor.continue();
@@ -602,7 +603,7 @@ class ClientSideStorage implements commonStorage.Storage {
602603
for (const className in classNameToModuleType) {
603604
const moduleType = classNameToModuleType[className];
604605
const moduleContentText = classNameToModuleContentText[className];
605-
const modulePath = commonStorage.makeModulePath(projectName, className);
606+
const modulePath = names.makeModulePath(projectName, className);
606607
const getRequest = modulesObjectStore.get(modulePath);
607608
getRequest.onerror = () => {
608609
console.log('IndexedDB get request failed. getRequest.error is...');

0 commit comments

Comments
 (0)