2019-10-18 08:16:26 +00:00
|
|
|
import React from "react";
|
2019-10-21 15:12:45 +00:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { RouteComponentProps } from "react-router";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { AppState } from "../../reducers";
|
|
|
|
|
import { ActionDataState } from "../../reducers/entityReducers/actionsReducer";
|
2019-10-25 05:35:20 +00:00
|
|
|
import { API_EDITOR_ID_URL, API_EDITOR_URL } from "../../constants/routes";
|
2019-10-30 10:23:20 +00:00
|
|
|
import { BaseButton } from "../../components/blueprint/ButtonComponent";
|
2019-10-25 05:35:20 +00:00
|
|
|
import { FormIcons } from "../../icons/FormIcons";
|
2019-10-29 12:02:58 +00:00
|
|
|
import { Spinner } from "@blueprintjs/core";
|
2019-10-25 05:35:20 +00:00
|
|
|
|
|
|
|
|
const ApiSidebarWrapper = styled.div`
|
|
|
|
|
height: 100%;
|
2019-10-29 12:02:58 +00:00
|
|
|
width: 100%;
|
2019-10-25 05:35:20 +00:00
|
|
|
flex-direction: column;
|
|
|
|
|
`;
|
|
|
|
|
const ApiItemsWrapper = styled.div`
|
|
|
|
|
flex: 1;
|
|
|
|
|
`;
|
2019-10-21 15:12:45 +00:00
|
|
|
|
|
|
|
|
const ApiItem = styled.div<{ isSelected: boolean }>`
|
2019-10-25 05:35:20 +00:00
|
|
|
height: 32px;
|
2019-10-21 15:12:45 +00:00
|
|
|
width: 100%;
|
2019-10-25 05:35:20 +00:00
|
|
|
padding: 5px 12px;
|
2019-10-21 15:12:45 +00:00
|
|
|
border-radius: 4px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
display: flex;
|
2019-10-25 05:35:20 +00:00
|
|
|
align-items: center;
|
|
|
|
|
margin-bottom: 2px;
|
2019-10-21 15:12:45 +00:00
|
|
|
background-color: ${props =>
|
|
|
|
|
props.isSelected ? props.theme.colors.paneCard : props.theme.colors.paneBG}
|
|
|
|
|
:hover {
|
|
|
|
|
background-color: ${props => props.theme.colors.paneCard};
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2019-10-22 14:54:23 +00:00
|
|
|
const HTTPMethod = styled.span<{ method: string | undefined }>`
|
2019-10-21 15:12:45 +00:00
|
|
|
flex: 1;
|
2019-10-25 05:35:20 +00:00
|
|
|
font-size: 12px;
|
2019-10-21 15:12:45 +00:00
|
|
|
color: ${props => {
|
|
|
|
|
switch (props.method) {
|
|
|
|
|
case "GET":
|
|
|
|
|
return "#29CCA3";
|
|
|
|
|
case "POST":
|
|
|
|
|
return "#F7C75B";
|
|
|
|
|
case "PUT":
|
|
|
|
|
return "#30A5E0";
|
|
|
|
|
case "DELETE":
|
|
|
|
|
return "#CE4257";
|
|
|
|
|
default:
|
|
|
|
|
return "#333";
|
|
|
|
|
}
|
|
|
|
|
}};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ActionName = styled.span`
|
|
|
|
|
flex: 3;
|
2019-10-25 05:35:20 +00:00
|
|
|
padding: 0 2px;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const CreateNewButton = styled(BaseButton)`
|
|
|
|
|
&& {
|
|
|
|
|
border: none;
|
|
|
|
|
color: ${props => props.theme.colors.textOnDarkBG};
|
|
|
|
|
height: 32px;
|
|
|
|
|
&:hover {
|
|
|
|
|
color: ${props => props.theme.colors.paneBG};
|
|
|
|
|
svg {
|
|
|
|
|
path {
|
|
|
|
|
fill: ${props => props.theme.colors.paneBG};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
svg {
|
|
|
|
|
height: 12px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface ReduxStateProps {
|
|
|
|
|
actions: ActionDataState;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 07:11:32 +00:00
|
|
|
type Props = ReduxStateProps & RouteComponentProps<{ id: string }>;
|
2019-10-21 15:12:45 +00:00
|
|
|
|
|
|
|
|
class ApiSidebar extends React.Component<Props> {
|
2019-10-25 05:35:20 +00:00
|
|
|
handleCreateNew = () => {
|
|
|
|
|
const { history } = this.props;
|
|
|
|
|
history.push(API_EDITOR_URL);
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-18 08:16:26 +00:00
|
|
|
render() {
|
2019-10-21 15:12:45 +00:00
|
|
|
const { actions, history, match } = this.props;
|
|
|
|
|
const activeActionId = match.params.id;
|
|
|
|
|
return (
|
2019-10-25 05:35:20 +00:00
|
|
|
<ApiSidebarWrapper>
|
2019-10-29 12:02:58 +00:00
|
|
|
{actions.isFetching && <Spinner size={30} />}
|
2019-10-25 05:35:20 +00:00
|
|
|
<ApiItemsWrapper>
|
|
|
|
|
{actions.data.map(action => (
|
|
|
|
|
<ApiItem
|
|
|
|
|
key={action.id}
|
|
|
|
|
onClick={() => history.push(API_EDITOR_ID_URL(action.id))}
|
|
|
|
|
isSelected={activeActionId === action.id}
|
|
|
|
|
>
|
|
|
|
|
<HTTPMethod method={action.actionConfiguration.httpMethod}>
|
|
|
|
|
{action.actionConfiguration.httpMethod}
|
|
|
|
|
</HTTPMethod>
|
|
|
|
|
<ActionName>{action.name}</ActionName>
|
|
|
|
|
</ApiItem>
|
|
|
|
|
))}
|
2019-10-29 12:02:58 +00:00
|
|
|
{!activeActionId && !actions.isFetching && (
|
|
|
|
|
<ApiItem isSelected>
|
|
|
|
|
<HTTPMethod method="" />
|
|
|
|
|
<ActionName>New Api</ActionName>
|
|
|
|
|
</ApiItem>
|
|
|
|
|
)}
|
2019-10-25 05:35:20 +00:00
|
|
|
</ApiItemsWrapper>
|
|
|
|
|
<CreateNewButton
|
|
|
|
|
text="Create new API"
|
|
|
|
|
icon={FormIcons.ADD_NEW_ICON()}
|
|
|
|
|
onClick={this.handleCreateNew}
|
|
|
|
|
/>
|
|
|
|
|
</ApiSidebarWrapper>
|
2019-10-21 15:12:45 +00:00
|
|
|
);
|
2019-10-18 08:16:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
const mapStateToProps = (state: AppState): ReduxStateProps => ({
|
|
|
|
|
actions: state.entities.actions,
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-01 07:11:32 +00:00
|
|
|
export default connect(mapStateToProps)(ApiSidebar);
|