diff --git a/app/models/request-group.js b/app/models/request-group.js index 0e4887062..dba1b8f76 100644 --- a/app/models/request-group.js +++ b/app/models/request-group.js @@ -1,10 +1,21 @@ +// @flow import * as db from '../common/database'; +import type {BaseModel} from './index'; export const name = 'Folder'; export const type = 'RequestGroup'; export const prefix = 'fld'; export const canDuplicate = true; +type BaseRequestGroup = { + name: string, + description: string, + environment: Object, + metaSortKey: number +}; + +export type RequestGroup = BaseModel & BaseRequestGroup; + export function init () { return { name: 'New Folder', @@ -14,39 +25,39 @@ export function init () { }; } -export function migrate (doc) { +export function migrate (doc: RequestGroup) { return doc; } -export function create (patch = {}) { +export function create (patch: Object = {}): Promise { if (!patch.parentId) { - throw new Error('New Requests missing `parentId`', patch); + throw new Error('New RequestGroup missing `parentId`: ' + JSON.stringify(patch)); } return db.docCreate(type, patch); } -export function update (requestGroup, patch) { +export function update (requestGroup: RequestGroup, patch: Object = {}): Promise { return db.docUpdate(requestGroup, patch); } -export function getById (id) { +export function getById (id: string): Promise { return db.get(type, id); } -export function findByParentId (parentId) { +export function findByParentId (parentId: string): Promise> { return db.find(type, {parentId}); } -export function remove (requestGroup) { +export function remove (requestGroup: RequestGroup): Promise { return db.remove(requestGroup); } -export function all () { +export function all (): Promise> { return db.all(type); } -export async function duplicate (requestGroup) { +export async function duplicate (requestGroup: RequestGroup): Promise { const name = `${requestGroup.name} (Copy)`; // Get sort key of next request diff --git a/app/ui/components/sidebar/sidebar-children.js b/app/ui/components/sidebar/sidebar-children.js index d6aa307fc..7d68994c3 100644 --- a/app/ui/components/sidebar/sidebar-children.js +++ b/app/ui/components/sidebar/sidebar-children.js @@ -1,11 +1,40 @@ -import React, {PureComponent} from 'react'; -import PropTypes from 'prop-types'; +// @flow +import React from 'react'; import SidebarRequestRow from './sidebar-request-row'; import SidebarRequestGroupRow from './sidebar-request-group-row'; import * as models from '../../../models/index'; +import type {RequestGroup} from '../../../models/request-group'; +import type {Workspace} from '../../../models/workspace'; +import type {Request} from '../../../models/request'; -class SidebarChildren extends PureComponent { - _renderChildren (children) { +type Child = { + doc: Request | RequestGroup, + children: Array, + collapsed: boolean +}; + +type Props = { + // Required + handleActivateRequest: Function, + handleCreateRequest: Function, + handleCreateRequestGroup: Function, + handleSetRequestGroupCollapsed: Function, + handleDuplicateRequest: Function, + handleDuplicateRequestGroup: Function, + handleGenerateCode: Function, + handleCopyAsCurl: Function, + moveDoc: Function, + childObjects: Array, + workspace: Workspace, + + // Optional + activeRequest?: Request +}; + +class SidebarChildren extends React.PureComponent { + props: Props; + + _renderChildren (children: Array) { const { handleCreateRequest, handleCreateRequestGroup, @@ -95,22 +124,4 @@ class SidebarChildren extends PureComponent { } } -SidebarChildren.propTypes = { - // Required - handleActivateRequest: PropTypes.func.isRequired, - handleCreateRequest: PropTypes.func.isRequired, - handleCreateRequestGroup: PropTypes.func.isRequired, - handleSetRequestGroupCollapsed: PropTypes.func.isRequired, - handleDuplicateRequest: PropTypes.func.isRequired, - handleDuplicateRequestGroup: PropTypes.func.isRequired, - handleGenerateCode: PropTypes.func.isRequired, - handleCopyAsCurl: PropTypes.func.isRequired, - moveDoc: PropTypes.func.isRequired, - childObjects: PropTypes.arrayOf(PropTypes.object).isRequired, - workspace: PropTypes.object.isRequired, - - // Optional - activeRequest: PropTypes.object -}; - export default SidebarChildren;