Skip to content

Commit

Permalink
renames base project to default project in code and copy (Kong#3939)
Browse files Browse the repository at this point in the history
Co-authored-by: Opender Singh <[email protected]>
  • Loading branch information
dimitropoulos and develohpanda authored Aug 25, 2021
1 parent 2bf4370 commit 7f7b9f5
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 74 deletions.
4 changes: 2 additions & 2 deletions packages/insomnia-app/app/__jest__/redux-state-for-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ACTIVITY_HOME } from '../common/constants';
import { BASE_PROJECT_ID } from '../models/project';
import { DEFAULT_PROJECT_ID } from '../models/project';
import { RootState } from '../ui/redux/modules';
import * as entities from '../ui/redux/modules/entities';
import { GlobalState } from '../ui/redux/modules/global';
Expand All @@ -9,7 +9,7 @@ export const reduxStateForTest = async (global: Partial<GlobalState> = {}): Prom
global: {
activeWorkspaceId: null,
activeActivity: ACTIVITY_HOME,
activeProjectId: BASE_PROJECT_ID,
activeProjectId: DEFAULT_PROJECT_ID,
dashboardSortOrder: 'modified-desc',
isLoading: false,
isLoggedIn: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-app/app/account/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function changePasswordWithToken(rawNewPassphrase, confirmationCode
// Fetch some things
const { saltEnc, encSymmetricKey } = await _whoami();
const { saltKey, saltAuth } = await _getAuthSalts(newEmail);
// Generate some secrets for the user base'd on password
// Generate some secrets for the user based on password
const newSecret = await crypt.deriveKey(newPassphrase, newEmail, saltEnc);
const newAuthSecret = await crypt.deriveKey(newPassphrase, newEmail, saltKey);
const newVerifier = srp
Expand Down
8 changes: 4 additions & 4 deletions packages/insomnia-app/app/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type StringId =
| 'home'
| 'project'
| 'workspace'
| 'baseProject'
| 'defaultProject'
| 'localProject'
| 'remoteProject'
;
Expand All @@ -35,9 +35,9 @@ export const strings: Record<StringId, StringInfo> = {
singular: 'Workspace',
plural: 'Workspaces',
},
baseProject: {
singular: 'Base',
plural: 'Base',
defaultProject: {
singular: 'Default',
plural: 'Default',
},
localProject: {
singular: 'Local',
Expand Down
12 changes: 6 additions & 6 deletions packages/insomnia-app/app/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const prefix = 'proj';
export const canDuplicate = false;
export const canSync = false;

export const BASE_PROJECT_ID = `${prefix}_base-project`;
export const DEFAULT_PROJECT_ID = `${prefix}_default-project`;

export const isBaseProject = (project: Project) => project._id === BASE_PROJECT_ID;
export const isNotBaseProject = (project: Project) => !isBaseProject(project);
export const isDefaultProject = (project: Project) => project._id === DEFAULT_PROJECT_ID;
export const isNotDefaultProject = (project: Project) => !isDefaultProject(project);
export const isLocalProject = (project: Project): project is LocalProject => project.remoteId === null;
export const isRemoteProject = (project: Project): project is RemoteProject => !isLocalProject(project);
export const projectHasSettings = (project: Project) => !isBaseProject(project);
export const projectHasSettings = (project: Project) => !isDefaultProject(project);

interface CommonProject {
name: string;
Expand Down Expand Up @@ -77,8 +77,8 @@ export function update(project: Project, patch: Partial<Project>) {
export async function all() {
const projects = await db.all<Project>(type);

if (!projects.find(c => c._id === BASE_PROJECT_ID)) {
await create({ _id: BASE_PROJECT_ID, name: getAppName(), remoteId: null });
if (!projects.find(c => c._id === DEFAULT_PROJECT_ID)) {
await create({ _id: DEFAULT_PROJECT_ID, name: getAppName(), remoteId: null });
return db.all<Project>(type);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/insomnia-app/app/models/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { database as db } from '../common/database';
import { strings } from '../common/strings';
import type { BaseModel } from './index';
import * as models from './index';
import { BASE_PROJECT_ID, isProjectId } from './project';
import { DEFAULT_PROJECT_ID, isProjectId } from './project';

export const name = 'Workspace';
export const type = 'Workspace';
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function migrate(doc: Workspace) {
fileName: doc.name,
});
doc = _migrateScope(doc);
doc = _migrateIntoBaseProject(doc);
doc = _migrateIntoDefaultProject(doc);
return doc;
}

Expand Down Expand Up @@ -158,9 +158,9 @@ function _migrateScope(workspace: MigrationWorkspace) {
return workspace as Workspace;
}

function _migrateIntoBaseProject(workspace: Workspace) {
function _migrateIntoDefaultProject(workspace: Workspace) {
if (!workspace.parentId) {
workspace.parentId = BASE_PROJECT_ID;
workspace.parentId = DEFAULT_PROJECT_ID;
}

return workspace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { globalBeforeEach } from '../../../__jest__/before-each';
import { getAppVersion } from '../../../common/constants';
import { database as db } from '../../../common/database';
import * as models from '../../../models/index';
import { BASE_PROJECT_ID, Project } from '../../../models/project';
import { DEFAULT_PROJECT_ID, Project } from '../../../models/project';
import { WorkspaceScopeKeys } from '../../../models/workspace';
import * as plugin from '../data';

Expand All @@ -15,7 +15,7 @@ describe('init()', () => {
beforeEach(globalBeforeEach);

it('initializes correctly', async () => {
const { data } = plugin.init(BASE_PROJECT_ID);
const { data } = plugin.init(DEFAULT_PROJECT_ID);
expect(Object.keys(data)).toEqual(['import', 'export']);
expect(Object.keys(data.export).sort()).toEqual(['har', 'insomnia']);
expect(Object.keys(data.import).sort()).toEqual(['raw', 'uri']);
Expand Down
6 changes: 3 additions & 3 deletions packages/insomnia-app/app/plugins/context/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { exportWorkspacesData, exportWorkspacesHAR } from '../../common/export';
import type { ImportRawConfig } from '../../common/import';
import { importRaw, importUri } from '../../common/import';
import * as models from '../../models';
import { BASE_PROJECT_ID } from '../../models/project';
import { DEFAULT_PROJECT_ID } from '../../models/project';
import type { Workspace, WorkspaceScope } from '../../models/workspace';

interface PluginImportOptions {
Expand Down Expand Up @@ -42,10 +42,10 @@ export const init = (activeProjectId?: string) => ({
data: {
import: {
uri: async (uri: string, options: PluginImportOptions = {}) => {
await importUri(uri, buildImportRawConfig(options, activeProjectId || BASE_PROJECT_ID));
await importUri(uri, buildImportRawConfig(options, activeProjectId || DEFAULT_PROJECT_ID));
},
raw: async (text: string, options: PluginImportOptions = {}) => {
await importRaw(text, buildImportRawConfig(options, activeProjectId || BASE_PROJECT_ID));
await importRaw(text, buildImportRawConfig(options, activeProjectId || DEFAULT_PROJECT_ID));
},
},
export: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { globalBeforeEach } from '../../../__jest__/before-each';
import { database as db } from '../../../common/database';
import * as models from '../../../models';
import { workspaceModelSchema } from '../../../models/__schemas__/model-schemas';
import { BASE_PROJECT_ID } from '../../../models/project';
import { DEFAULT_PROJECT_ID } from '../../../models/project';
import { GIT_CLONE_DIR, GIT_INSOMNIA_DIR, GIT_INSOMNIA_DIR_NAME } from '../git-vcs';
import { NeDBClient } from '../ne-db-client';
import { assertAsyncError, setupDateMocks } from './util';
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('NeDBClient', () => {

describe('readdir()', () => {
it('reads model IDs from model type folders', async () => {
const neDbClient = new NeDBClient('wrk_1', BASE_PROJECT_ID);
const neDbClient = new NeDBClient('wrk_1', DEFAULT_PROJECT_ID);
const reqDir = path.join(GIT_INSOMNIA_DIR, models.request.type);
const wrkDir = path.join(GIT_INSOMNIA_DIR, models.workspace.type);
expect(await neDbClient.readdir(GIT_CLONE_DIR)).toEqual([GIT_INSOMNIA_DIR_NAME]);
Expand All @@ -68,7 +68,7 @@ describe('NeDBClient', () => {
const wrk1Yml = path.join(GIT_INSOMNIA_DIR, models.workspace.type, 'wrk_1.yml');
const req1Yml = path.join(GIT_INSOMNIA_DIR, models.request.type, 'req_1.yml');
const reqXYml = path.join(GIT_INSOMNIA_DIR, models.request.type, 'req_x.yml');
const pNeDB = new NeDBClient('wrk_1', BASE_PROJECT_ID);
const pNeDB = new NeDBClient('wrk_1', DEFAULT_PROJECT_ID);
expect(YAML.parse((await pNeDB.readFile(wrk1Yml, 'utf8')).toString())).toEqual(
expect.objectContaining({
_id: 'wrk_1',
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('NeDBClient', () => {
type: 'file',
});
// Act
const neDbClient = new NeDBClient('wrk_1', BASE_PROJECT_ID);
const neDbClient = new NeDBClient('wrk_1', DEFAULT_PROJECT_ID);
// Assert
expect(await neDbClient.stat(GIT_CLONE_DIR)).toEqual(dirType);
expect(await neDbClient.stat(GIT_INSOMNIA_DIR)).toEqual(dirType);
Expand All @@ -112,7 +112,7 @@ describe('NeDBClient', () => {
// Arrange
const upsertSpy = jest.spyOn(db, 'upsert');
const workspaceId = 'wrk_1';
const neDbClient = new NeDBClient(workspaceId, BASE_PROJECT_ID);
const neDbClient = new NeDBClient(workspaceId, DEFAULT_PROJECT_ID);
const env = {
_id: 'env_1',
type: models.environment.type,
Expand All @@ -130,7 +130,7 @@ describe('NeDBClient', () => {
it('should write files in GIT_INSOMNIA_DIR directory to db', async () => {
// Arrange
const workspaceId = 'wrk_1';
const neDbClient = new NeDBClient(workspaceId, BASE_PROJECT_ID);
const neDbClient = new NeDBClient(workspaceId, DEFAULT_PROJECT_ID);
const upsertSpy = jest.spyOn(db, 'upsert');
const env = {
_id: 'env_1',
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('NeDBClient', () => {
it('should throw error if id does not match', async () => {
// Arrange
const workspaceId = 'wrk_1';
const neDbClient = new NeDBClient(workspaceId, BASE_PROJECT_ID);
const neDbClient = new NeDBClient(workspaceId, DEFAULT_PROJECT_ID);
const env = {
_id: 'env_1',
type: models.environment.type,
Expand All @@ -222,7 +222,7 @@ describe('NeDBClient', () => {
it('should throw error if type does not match', async () => {
// Arrange
const workspaceId = 'wrk_1';
const neDbClient = new NeDBClient(workspaceId, BASE_PROJECT_ID);
const neDbClient = new NeDBClient(workspaceId, DEFAULT_PROJECT_ID);
const env = {
_id: 'env_1',
type: models.environment.type,
Expand All @@ -241,7 +241,7 @@ describe('NeDBClient', () => {
describe('mkdir()', () => {
it('should throw error', async () => {
const workspaceId = 'wrk_1';
const neDbClient = new NeDBClient(workspaceId, BASE_PROJECT_ID);
const neDbClient = new NeDBClient(workspaceId, DEFAULT_PROJECT_ID);
const promiseResult = neDbClient.mkdir();
await expect(promiseResult).rejects.toThrowError('NeDBClient is not writable');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-app/app/sync/git/ne-db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class NeDBClient {
console.log('[git] setting workspace parent to be that of the active project', { original: doc.parentId, new: this._projectId });
// Whenever we write a workspace into nedb we should set the parentId to be that of the current project
// This is because the parentId (or a project) is not synced into git, so it will be cleared whenever git writes the workspace into the db, thereby removing it from the project on the client
// In order to reproduce this bug, comment out the following line, then clone a repository into a local project, then open the workspace, you'll notice it will have moved into the base project
// In order to reproduce this bug, comment out the following line, then clone a repository into a local project, then open the workspace, you'll notice it will have moved into the default project
doc.parentId = this._projectId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { globalBeforeEach } from '../../../__jest__/before-each';
import { isLoggedIn as _isLoggedIn } from '../../../account/session';
import { database } from '../../../common/database';
import * as models from '../../../models';
import { BASE_PROJECT_ID } from '../../../models/project';
import { DEFAULT_PROJECT_ID } from '../../../models/project';
import { backendProjectWithTeamSchema, teamSchema } from '../../__schemas__/type-schemas';
import MemoryDriver from '../../store/drivers/memory-driver';
import { initializeProjectFromTeam } from '../initialize-model-from';
Expand Down Expand Up @@ -49,8 +49,8 @@ describe('migrateCollectionsIntoRemoteProject', () => {
// Arrange
const vcs = newMockedVcs();

const baseProject = await models.project.getById(BASE_PROJECT_ID);
const workspaceInBase = await models.workspace.create({ parentId: baseProject?._id });
const defaultProject = await models.project.getById(DEFAULT_PROJECT_ID);
const workspaceInBase = await models.workspace.create({ parentId: defaultProject?._id });

const localProject = await models.project.create();
const workspaceInLocal = await models.workspace.create({ parentId: localProject._id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';

import { strings } from '../../../common/strings';
import { isBaseProject, isNotBaseProject, isRemoteProject, Project, projectHasSettings } from '../../../models/project';
import { isDefaultProject, isNotDefaultProject, isRemoteProject, Project, projectHasSettings } from '../../../models/project';
import { VCS } from '../../../sync/vcs/vcs';
import { useRemoteProjects } from '../../hooks/project';
import { setActiveProject } from '../../redux/modules/global';
Expand Down Expand Up @@ -39,7 +39,7 @@ const TooltipIcon = ({ message, icon }: { message: string, icon: SvgIconProps['i
);

const spinner = <i className="fa fa-spin fa-refresh" />;
const home = <TooltipIcon message={`${strings.baseProject.singular} ${strings.project.singular} (Always ${strings.localProject.singular})`} icon="home" />;
const home = <TooltipIcon message={`${strings.defaultProject.singular} ${strings.project.singular} (Always ${strings.localProject.singular})`} icon="home" />;
const remoteProject = <TooltipIcon message={`${strings.remoteProject.singular} ${strings.project.singular}`} icon="globe" />;
const localProject = <TooltipIcon message={`${strings.localProject.singular} ${strings.project.singular}`} icon="laptop" />;

Expand All @@ -53,7 +53,7 @@ const ProjectDropdownItem: FC<{
setActive: (projectId: string) => void;
}> = ({ isActive, project, setActive }) => {
const { _id, name } = project;
const isBase = isBaseProject(project);
const isBase = isDefaultProject(project);
const isRemote = isRemoteProject(project);

return (
Expand Down Expand Up @@ -100,9 +100,9 @@ export const ProjectDropdown: FC<Props> = ({ vcs }) => {

return (
<Dropdown renderButton={button} onOpen={refresh}>
{projects.filter(isBaseProject).map(renderProject)}
{projects.filter(isDefaultProject).map(renderProject)}
<DropdownDivider>All {strings.project.plural.toLowerCase()}{' '}{loading && spinner}</DropdownDivider>
{projects.filter(isNotBaseProject).map(renderProject)}
{projects.filter(isNotDefaultProject).map(renderProject)}
{projectHasSettings(activeProject) && <>
<DropdownDivider />
<DropdownItem icon={<StyledSvgIcon icon="gear" />} onClick={showSettings}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as models from '../../../models';
import { ApiSpec } from '../../../models/api-spec';
import getWorkspaceName from '../../../models/helpers/get-workspace-name';
import * as workspaceOperations from '../../../models/helpers/workspace-operations';
import { isBaseProject, isLocalProject, isRemoteProject, Project } from '../../../models/project';
import { isDefaultProject, isLocalProject, isRemoteProject, Project } from '../../../models/project';
import { Workspace } from '../../../models/workspace';
import { initializeLocalBackendProjectAndMarkForSync } from '../../../sync/vcs/initialize-backend-project';
import { VCS } from '../../../sync/vcs/vcs';
Expand Down Expand Up @@ -40,7 +40,7 @@ interface InnerProps extends Options, Props {

const ProjectOption: FC<Project> = project => (
<option key={project._id} value={project._id}>
{project.name} ({isBaseProject(project) ? strings.baseProject.singular : isLocalProject(project) ? strings.localProject.singular : strings.remoteProject.singular})
{project.name} ({isDefaultProject(project) ? strings.defaultProject.singular : isLocalProject(project) ? strings.localProject.singular : strings.remoteProject.singular})
</option>
);

Expand Down
6 changes: 3 additions & 3 deletions packages/insomnia-app/app/ui/containers/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { isEnvironment } from '../../models/environment';
import { GrpcRequest, isGrpcRequest, isGrpcRequestId } from '../../models/grpc-request';
import { GrpcRequestMeta } from '../../models/grpc-request-meta';
import * as requestOperations from '../../models/helpers/request-operations';
import { isNotBaseProject } from '../../models/project';
import { isNotDefaultProject } from '../../models/project';
import { Request, updateMimeType } from '../../models/request';
import { isRequestGroup, RequestGroup } from '../../models/request-group';
import { RequestMeta } from '../../models/request-meta';
Expand Down Expand Up @@ -1339,7 +1339,7 @@ class App extends PureComponent<AppProps, State> {
console.log(`[developer] clearing all "${type}" entities`);
const allEntities = await db.all(type);
const filteredEntites = allEntities
.filter(isNotBaseProject); // don't clear the base project
.filter(isNotDefaultProject); // don't clear the default project
await db.batchModifyDocs({ remove: filteredEntites });
db.flushChanges(bufferId);
}
Expand All @@ -1363,7 +1363,7 @@ class App extends PureComponent<AppProps, State> {
console.log(`[developer] clearing all "${type}" entities`);
const allEntities = await db.all(type);
const filteredEntites = allEntities
.filter(isNotBaseProject); // don't clear the base project
.filter(isNotDefaultProject); // don't clear the default project
await db.batchModifyDocs({ remove: filteredEntites });
});
await Promise.all(promises);
Expand Down
6 changes: 3 additions & 3 deletions packages/insomnia-app/app/ui/hooks/__tests__/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { globalBeforeEach } from '../../../__jest__/before-each';
import { reduxStateForTest } from '../../../__jest__/redux-state-for-test';
import { withReduxStore } from '../../../__jest__/with-redux-store';
import * as models from '../../../models';
import { BASE_PROJECT_ID, Project } from '../../../models/project';
import { DEFAULT_PROJECT_ID, Project } from '../../../models/project';
import MemoryDriver from '../../../sync/store/drivers/memory-driver';
import { VCS } from '../../../sync/vcs/vcs';
import { RootState } from '../../redux/modules';
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('useRemoteProjects', () => {
expect(allProjects).toHaveLength(3);
expect(allProjects).toEqual(expect.arrayContaining([
expect.objectContaining<Partial<Project>>({
_id: BASE_PROJECT_ID,
_id: DEFAULT_PROJECT_ID,
}),
expect.objectContaining<Partial<Project>>({
remoteId: team1.id,
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('useRemoteProjects', () => {
expect(allProjects).toHaveLength(3);
expect(allProjects).toEqual(expect.arrayContaining([
expect.objectContaining<Partial<Project>>({
_id: BASE_PROJECT_ID,
_id: DEFAULT_PROJECT_ID,
}),
expect.objectContaining<Partial<Project>>({
remoteId: team1.id,
Expand Down
Loading

0 comments on commit 7f7b9f5

Please sign in to comment.