mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-13 06:37:47 -04:00
Add flow to EnvironmentsDropdown
This commit is contained in:
1 parent
3bac7fea9c
commit
d3c95e9c87
5 files changed
+58
-33
No files matched your search
+17
-1
@@ -318,6 +318,22 @@ export async function docUpdate<T: BaseModel> (originalDoc: T, patch: Object = {
|
||||
return update(doc);
|
||||
}
|
||||
|
||||
export async function docCreateNoMigrate<T: BaseModel> (
|
||||
type: string,
|
||||
...patches: Array<Object>
|
||||
): Promise<T> {
|
||||
const doc = await initModel(
|
||||
type,
|
||||
...patches,
|
||||
|
||||
// Fields that the user can't touch
|
||||
{type: type},
|
||||
{__NO_MIGRATE: true}
|
||||
);
|
||||
|
||||
return insert(doc);
|
||||
}
|
||||
|
||||
export async function docCreate<T: BaseModel> (
|
||||
type: string,
|
||||
...patches: Array<Object>
|
||||
@@ -415,7 +431,7 @@ export async function duplicate<T: BaseModel> (originalDoc: T, patch: Object = {
|
||||
delete newDoc.created;
|
||||
delete newDoc.modified;
|
||||
|
||||
const createdDoc = await docCreate(newDoc.type, newDoc);
|
||||
const createdDoc = await docCreateNoMigrate(newDoc.type, newDoc);
|
||||
|
||||
// 2. Get all the children
|
||||
for (const type of allTypes()) {
|
||||
|
||||
@@ -49,18 +49,18 @@ export function findByParentId (parentId: string): Promise<Array<Environment>> {
|
||||
}
|
||||
|
||||
export async function getOrCreateForWorkspaceId (workspaceId: string): Promise<Environment> {
|
||||
let environment = await db.getWhere(type, {
|
||||
parentId: workspaceId
|
||||
});
|
||||
const environments = await db.find(type, {parentId: workspaceId});
|
||||
|
||||
if (!environment) {
|
||||
environment = await create({
|
||||
console.log('ALL', await db.find(type, {parentId: workspaceId}));
|
||||
|
||||
if (!environments.length) {
|
||||
return await create({
|
||||
parentId: workspaceId,
|
||||
name: 'Base Environment'
|
||||
});
|
||||
}
|
||||
|
||||
return environment;
|
||||
return environments[environments.length - 1];
|
||||
}
|
||||
|
||||
export async function getOrCreateForWorkspace (workspace: Workspace): Promise<Environment> {
|
||||
|
||||
+8
-2
@@ -85,7 +85,10 @@ export function getModelName (type: string, count: number = 1) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function initModel <T: BaseModel> (type: string, ...sources: Array<Object>): Promise<T> {
|
||||
export async function initModel<T: BaseModel> (
|
||||
type: string,
|
||||
...sources: Array<Object>
|
||||
): Promise<T> {
|
||||
const model = getModel(type);
|
||||
|
||||
if (!model) {
|
||||
@@ -111,7 +114,10 @@ export async function initModel <T: BaseModel> (type: string, ...sources: Array<
|
||||
|
||||
// Migrate the model
|
||||
// NOTE: Do migration before pruning because we might need to look at those fields
|
||||
const migratedDoc = await model.migrate(fullObject);
|
||||
const noMigrate = fullObject.__NO_MIGRATE;
|
||||
const migratedDoc = noMigrate
|
||||
? fullObject
|
||||
: await model.migrate(fullObject);
|
||||
|
||||
// Prune extra keys from doc
|
||||
for (const key of Object.keys(migratedDoc)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, {PureComponent} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import autobind from 'autobind-decorator';
|
||||
import EnvironmentsModal from '../modals/workspace-environments-edit-modal';
|
||||
import {Dropdown, DropdownButton, DropdownDivider, DropdownHint, DropdownItem} from '../base/dropdown';
|
||||
@@ -9,10 +9,25 @@ import Tooltip from '../tooltip';
|
||||
import {executeHotKey} from '../../../common/hotkeys';
|
||||
import * as hotkeys from '../../../common/hotkeys';
|
||||
import KeydownBinder from '../keydown-binder';
|
||||
import type {Workspace} from '../../../models/workspace';
|
||||
import type {Environment} from '../../../models/environment';
|
||||
|
||||
type Props = {
|
||||
workspace: Workspace,
|
||||
handleChangeEnvironment: Function,
|
||||
workspace: Workspace,
|
||||
environments: Array<Environment>,
|
||||
|
||||
// Optional
|
||||
className?: string,
|
||||
activeEnvironment: Environment | null
|
||||
};
|
||||
|
||||
@autobind
|
||||
class EnvironmentsDropdown extends PureComponent {
|
||||
_handleActivateEnvironment (environmentId) {
|
||||
class EnvironmentsDropdown extends React.PureComponent<Props> {
|
||||
_dropdown: ?Dropdown;
|
||||
|
||||
_handleActivateEnvironment (environmentId: string) {
|
||||
this.props.handleChangeEnvironment(environmentId);
|
||||
trackEvent('Environment', environmentId ? 'Activate' : 'Deactivate');
|
||||
}
|
||||
@@ -21,11 +36,11 @@ class EnvironmentsDropdown extends PureComponent {
|
||||
showModal(EnvironmentsModal, this.props.workspace);
|
||||
}
|
||||
|
||||
_setDropdownRef (n) {
|
||||
_setDropdownRef (n: ?Dropdown) {
|
||||
this._dropdown = n;
|
||||
}
|
||||
|
||||
renderEnvironmentItem (environment) {
|
||||
renderEnvironmentItem (environment: Environment) {
|
||||
return (
|
||||
<DropdownItem key={environment._id}
|
||||
value={environment._id}
|
||||
@@ -36,7 +51,7 @@ class EnvironmentsDropdown extends PureComponent {
|
||||
);
|
||||
}
|
||||
|
||||
_handleKeydown (e) {
|
||||
_handleKeydown (e: KeyboardEvent) {
|
||||
executeHotKey(e, hotkeys.TOGGLE_ENVIRONMENTS_MENU, () => {
|
||||
this._dropdown && this._dropdown.toggle(true);
|
||||
});
|
||||
@@ -77,9 +92,9 @@ class EnvironmentsDropdown extends PureComponent {
|
||||
</Tooltip>
|
||||
)}
|
||||
<div className="sidebar__menu__thing__text">
|
||||
{activeEnvironment && activeEnvironment.color && (
|
||||
{(activeEnvironment && activeEnvironment.color) ? (
|
||||
<i className="fa fa-circle space-right" style={{color: activeEnvironment.color}}/>
|
||||
)}
|
||||
) : null}
|
||||
{description}
|
||||
</div>
|
||||
<i className="space-left fa fa-caret-down"/>
|
||||
@@ -105,17 +120,4 @@ class EnvironmentsDropdown extends PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
EnvironmentsDropdown.propTypes = {
|
||||
// Functions
|
||||
handleChangeEnvironment: PropTypes.func.isRequired,
|
||||
|
||||
// Other
|
||||
workspace: PropTypes.object.isRequired,
|
||||
environments: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
|
||||
// Optional
|
||||
activeEnvironment: PropTypes.object,
|
||||
className: PropTypes.string
|
||||
};
|
||||
|
||||
export default EnvironmentsDropdown;
|
||||
@@ -316,8 +316,9 @@ class RequestPane extends React.PureComponent<Props> {
|
||||
</button>
|
||||
</Tab>
|
||||
</TabList>
|
||||
<TabPanel key={uniqueKey} className="react-tabs__tab-panel editor-wrapper">
|
||||
<TabPanel className="react-tabs__tab-panel editor-wrapper">
|
||||
<BodyEditor
|
||||
key={uniqueKey}
|
||||
handleUpdateRequestMimeType={updateRequestMimeType}
|
||||
handleRender={handleRender}
|
||||
handleGetRenderContext={handleGetRenderContext}
|
||||
@@ -413,7 +414,7 @@ class RequestPane extends React.PureComponent<Props> {
|
||||
</button>
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel key={uniqueKey} className="react-tabs__tab-panel tall scrollable">
|
||||
<TabPanel key={`docs::${uniqueKey}`} className="react-tabs__tab-panel tall scrollable">
|
||||
{request.description ? (
|
||||
<div>
|
||||
<div className="pull-right pad bg-default">
|
||||
|
||||
Reference in new issue
Block a user