2020-02-03 10:37:03 +00:00
|
|
|
import React, { ReactNode } from "react";
|
|
|
|
|
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
|
|
|
|
|
import { ControlGroup, InputGroup, IIconProps } from "@blueprintjs/core";
|
|
|
|
|
import Button from "components/editorComponents/Button";
|
2019-11-21 10:52:49 +00:00
|
|
|
import styled from "styled-components";
|
2020-01-20 08:07:00 +00:00
|
|
|
import _ from "lodash";
|
2019-11-21 10:52:49 +00:00
|
|
|
|
|
|
|
|
const SubHeaderWrapper = styled.div`
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
2020-01-27 08:24:58 +00:00
|
|
|
padding: ${props => props.theme.spaces[5]}px
|
|
|
|
|
${props => props.theme.spaces[5]}px;
|
2019-11-21 10:52:49 +00:00
|
|
|
`;
|
|
|
|
|
const StyledAddButton = styled(Button)<IIconProps>`
|
|
|
|
|
&&& {
|
|
|
|
|
outline: none;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
const SearchContainer = styled.div``;
|
|
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
type SubHeaderProps = {
|
2019-11-21 10:52:49 +00:00
|
|
|
add?: {
|
|
|
|
|
form: ReactNode;
|
|
|
|
|
title: string;
|
|
|
|
|
formName: string;
|
|
|
|
|
isAdding: boolean;
|
|
|
|
|
formSubmitIntent: string;
|
|
|
|
|
errorAdding?: string;
|
2020-02-03 10:37:03 +00:00
|
|
|
formSubmitText: string;
|
2019-11-21 10:52:49 +00:00
|
|
|
};
|
|
|
|
|
search?: {
|
|
|
|
|
placeholder: string;
|
2020-01-20 08:07:00 +00:00
|
|
|
debounce?: boolean;
|
|
|
|
|
queryFn?: (keyword: string) => void;
|
2019-11-21 10:52:49 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
export const ApplicationsSubHeader = (props: SubHeaderProps) => {
|
2020-01-20 08:07:00 +00:00
|
|
|
const query =
|
|
|
|
|
props.search &&
|
|
|
|
|
props.search.queryFn &&
|
|
|
|
|
_.debounce(props.search.queryFn, 250, { maxWait: 1000 });
|
|
|
|
|
const searchQuery = (e: any) => {
|
|
|
|
|
query && query(e.target.value);
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
const createTrigger = props.add && (
|
|
|
|
|
<StyledAddButton
|
|
|
|
|
text={props.add.title}
|
|
|
|
|
icon="plus"
|
|
|
|
|
title={props.add.title}
|
|
|
|
|
filled
|
|
|
|
|
intent="primary"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2019-11-21 10:52:49 +00:00
|
|
|
return (
|
|
|
|
|
<SubHeaderWrapper>
|
|
|
|
|
<SearchContainer>
|
|
|
|
|
{props.search && (
|
|
|
|
|
<ControlGroup>
|
|
|
|
|
<InputGroup
|
|
|
|
|
placeholder={props.search.placeholder}
|
|
|
|
|
leftIcon="search"
|
2020-01-20 08:07:00 +00:00
|
|
|
onChange={searchQuery}
|
2019-11-21 10:52:49 +00:00
|
|
|
/>
|
|
|
|
|
</ControlGroup>
|
|
|
|
|
)}
|
|
|
|
|
</SearchContainer>
|
2020-02-03 10:37:03 +00:00
|
|
|
|
2019-11-21 10:52:49 +00:00
|
|
|
{props.add && (
|
|
|
|
|
<FormDialogComponent
|
2020-02-03 10:37:03 +00:00
|
|
|
trigger={createTrigger}
|
|
|
|
|
Form={props.add.form}
|
2019-11-21 10:52:49 +00:00
|
|
|
title={props.add.title}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</SubHeaderWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ApplicationsSubHeader;
|