Flow for RequestGroup and sidebar children component

This commit is contained in:
Gregory Schier 2017-09-18 18:25:51 +02:00
parent 1962256029
commit 28ab0af409
2 changed files with 53 additions and 31 deletions

View File

@ -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<RequestGroup> {
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<RequestGroup> {
return db.docUpdate(requestGroup, patch);
}
export function getById (id) {
export function getById (id: string): Promise<RequestGroup | null> {
return db.get(type, id);
}
export function findByParentId (parentId) {
export function findByParentId (parentId: string): Promise<Array<RequestGroup>> {
return db.find(type, {parentId});
}
export function remove (requestGroup) {
export function remove (requestGroup: RequestGroup): Promise<void> {
return db.remove(requestGroup);
}
export function all () {
export function all (): Promise<Array<RequestGroup>> {
return db.all(type);
}
export async function duplicate (requestGroup) {
export async function duplicate (requestGroup: RequestGroup): Promise<RequestGroup> {
const name = `${requestGroup.name} (Copy)`;
// Get sort key of next request

View File

@ -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<Child>,
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<Child>,
workspace: Workspace,
// Optional
activeRequest?: Request
};
class SidebarChildren extends React.PureComponent {
props: Props;
_renderChildren (children: Array<Child>) {
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;