Skip to content

Commit

Permalink
chore: Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Its-treason committed Oct 19, 2023
1 parent b8bbe86 commit 8e68b8f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CreateEnvironment = ({ collection, onClose }) => {
},
validationSchema: Yup.object({
name: Yup.string()
.min(1, 'must be atleast 1 characters')
.min(1, 'must be at least 1 character')
.max(250, 'must be 250 characters or less')
.required('name is required')
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const CreateCollection = ({ onClose }) => {
.max(50, 'must be 50 characters or less')
.required('collection name is required'),
collectionFolderName: Yup.string()
.max(250, 'must be 250 characters or less')
.trim()
.matches(dirnameRegex, 'Folder name contains invalid characters')
.max(250, 'must be 250 characters or less')
.min(1, 'must be at least 1 character')
.required('folder name is required'),
collectionLocation: Yup.string().min(1, 'location is required').required('location is required')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const NewFolder = ({ collection, item, onClose }) => {
.min(1, 'must be at least 1 character')
.required('name is required')
.max(250, 'must be 250 characters or less')
.trim()
.matches(dirnameRegex, 'Folder name contains invalid characters')
.test({
name: 'folderName',
message: 'The folder name "environments" at the root of the collection is reserved in bruno',
test: (value) => {
// If the the item has a uid, it is inside a sub folder
if (item && item.uid) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export const renameItem = (newName, itemUid, collectionUid) => (dispatch, getSta
if (!collection) {
return reject(new Error('Collection not found'));
}

const collectionCopy = cloneDeep(collection);
const item = findItemInCollection(collectionCopy, itemUid);
if (!item) {
Expand Down
36 changes: 18 additions & 18 deletions packages/bruno-electron/src/ipc/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
createDirectory,
searchForBruFiles,
sanitizeDirectoryName,
sanitizeFilenme
sanitizeFilename
} = require('../utils/filesystem');
const { stringifyJson } = require('../utils/common');
const { openCollectionDialog } = require('../app/collections');
Expand Down Expand Up @@ -104,7 +104,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
// new request
ipcMain.handle('renderer:new-request', async (event, pathname, request) => {
try {
const sanitizedPathname = path.join(pathname, sanitizeFilenme(request.name) + '.bru');
const sanitizedPathname = path.join(pathname, sanitizeFilename(request.name) + '.bru');

if (fs.existsSync(sanitizedPathname)) {
throw new Error(`path: ${sanitizedPathname} already exists`);
Expand Down Expand Up @@ -141,8 +141,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
await createDirectory(envDirPath);
}

const filenameSanatized = sanitizeFilenme(`${name}.bru`);
const envFilePath = path.join(envDirPath, filenameSanatized);
const filenameSanitized = sanitizeFilename(`${name}.bru`);
const envFilePath = path.join(envDirPath, filenameSanitized);
if (fs.existsSync(envFilePath)) {
throw new Error(`environment: ${envFilePath} already exists`);
}
Expand Down Expand Up @@ -172,9 +172,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
await createDirectory(envDirPath);
}

let envFilePath = path.join(envDirPath, `${sanitizeFilenme(environment.name)}.bru`);
let envFilePath = path.join(envDirPath, `${sanitizeFilename(environment.name)}.bru`);
if (!fs.existsSync(envFilePath)) {
// Fallback to unsatized filename for old envs
// Fallback to unsanitized filename for old envs
envFilePath = path.join(envDirPath, `${environment.name}.bru`);
if (!fs.existsSync(envFilePath)) {
throw new Error(`environment: ${envFilePath} does not exist`);
Expand All @@ -196,16 +196,16 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
ipcMain.handle('renderer:rename-environment', async (event, collectionPathname, environmentName, newName) => {
try {
const envDirPath = path.join(collectionPathname, 'environments');
let envFilePath = path.join(envDirPath, `${sanitizeFilenme(environmentName)}.bru`);
let envFilePath = path.join(envDirPath, `${sanitizeFilename(environmentName)}.bru`);
if (!fs.existsSync(envFilePath)) {
// Fallback to unsatized env name
// Fallback to unsanitized env name
envFilePath = path.join(envDirPath, `${environmentName}.bru`);
if (!fs.existsSync(envFilePath)) {
throw new Error(`environment: ${envFilePath} does not exist`);
}
}

const newEnvFilePath = path.join(envDirPath, `${sanitizeFilenme(newName)}.bru`);
const newEnvFilePath = path.join(envDirPath, `${sanitizeFilename(newName)}.bru`);
if (fs.existsSync(newEnvFilePath) && envFilePath !== newEnvFilePath) {
throw new Error(`environment: ${newEnvFilePath} already exists`);
}
Expand All @@ -228,9 +228,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
ipcMain.handle('renderer:delete-environment', async (event, collectionPathname, environmentName) => {
try {
const envDirPath = path.join(collectionPathname, 'environments');
let envFilePath = path.join(envDirPath, `${sanitizeFilenme(environmentName)}.bru`);
let envFilePath = path.join(envDirPath, `${sanitizeFilename(environmentName)}.bru`);
if (!fs.existsSync(envFilePath)) {
// Fallback to unsatized env name
// Fallback to unsanitized env name
envFilePath = path.join(envDirPath, `${environmentName}.bru`);
if (!fs.existsSync(envFilePath)) {
throw new Error(`environment: ${envFilePath} does not exist`);
Expand Down Expand Up @@ -273,9 +273,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
throw new Error(`path: ${oldPathFull} is not a bru file`);
}

const newSantitizedPath = path.join(newPath, sanitizeFilenme(newName) + '.bru');
if (fs.existsSync(newSantitizedPath) && newSantitizedPath !== oldPathFull) {
throw new Error(`path: ${newSantitizedPath} already exists`);
const newSanitizedPath = path.join(newPath, sanitizeFilename(newName) + '.bru');
if (fs.existsSync(newSanitizedPath) && newSanitizedPath !== oldPathFull) {
throw new Error(`path: ${newSanitizedPath} already exists`);
}

// update name in file and save new copy, then delete old copy
Expand All @@ -284,13 +284,13 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection

jsonData.name = newName;

moveRequestUid(oldPathFull, newSantitizedPath);
moveRequestUid(oldPathFull, newSanitizedPath);

const content = jsonToBru(jsonData);
await writeFile(newSantitizedPath, content);
await writeFile(newSanitizedPath, content);

// Because of santization the name can change but the path stays the same
if (newSantitizedPath !== oldPathFull) {
// Because of sanitization the name can change but the path stays the same
if (newSanitizedPath !== oldPathFull) {
fs.unlinkSync(oldPathFull);
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions packages/bruno-electron/src/utils/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const sanitizeDirectoryName = (name) => {
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
};

const sanitizeFilenme = (name) => {
const sanitizeFilename = (name) => {
return name.replace(/[<>:"/\\|?*\x00-\x1F]/g, '_');
};

Expand All @@ -137,5 +137,5 @@ module.exports = {
searchForFiles,
searchForBruFiles,
sanitizeDirectoryName,
sanitizeFilenme
sanitizeFilename
};

0 comments on commit 8e68b8f

Please sign in to comment.