2020-02-03 10:37:03 +00:00
|
|
|
import React, { ReactNode } from "react";
|
|
|
|
|
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
|
2020-09-16 11:50:47 +00:00
|
|
|
import { ControlGroup } from "@blueprintjs/core";
|
2019-11-21 10:52:49 +00:00
|
|
|
import styled from "styled-components";
|
2020-09-16 11:50:47 +00:00
|
|
|
import _, { noop } from "lodash";
|
|
|
|
|
import SearchInput, { SearchVariant } from "components/ads/SearchInput";
|
|
|
|
|
import Button, { Size } from "components/ads/Button";
|
2020-10-14 10:35:19 +00:00
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
import { getIsFetchingApplications } from "selectors/applicationSelectors";
|
2021-05-20 12:03:08 +00:00
|
|
|
import { Indices } from "constants/Layers";
|
2019-11-21 10:52:49 +00:00
|
|
|
|
|
|
|
|
const SubHeaderWrapper = styled.div`
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
2020-09-16 11:50:47 +00:00
|
|
|
position: fixed;
|
|
|
|
|
padding-top: 30px;
|
2020-12-24 04:32:25 +00:00
|
|
|
background: ${(props) => props.theme.colors.homepageBackground};
|
|
|
|
|
top: ${(props) => props.theme.homePage.header}px;
|
2020-09-16 11:50:47 +00:00
|
|
|
left: 369px;
|
2021-05-20 12:03:08 +00:00
|
|
|
z-index: ${Indices.Layer3};
|
2019-11-21 10:52:49 +00:00
|
|
|
`;
|
2020-08-03 11:44:18 +00:00
|
|
|
const SearchContainer = styled.div`
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
.bp3-control-group {
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
|
|
|
|
&& {
|
|
|
|
|
.bp3-input {
|
|
|
|
|
width: 40%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
2019-11-21 10:52:49 +00:00
|
|
|
|
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;
|
2020-03-06 04:59:24 +00:00
|
|
|
onClick: () => void;
|
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;
|
2021-07-23 07:31:16 +00:00
|
|
|
defaultValue?: string;
|
2019-11-21 10:52:49 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function ApplicationsSubHeader(props: SubHeaderProps) {
|
2020-10-14 10:35:19 +00:00
|
|
|
const isFetchingApplications = useSelector(getIsFetchingApplications);
|
2020-01-20 08:07:00 +00:00
|
|
|
const query =
|
|
|
|
|
props.search &&
|
|
|
|
|
props.search.queryFn &&
|
|
|
|
|
_.debounce(props.search.queryFn, 250, { maxWait: 1000 });
|
2020-02-03 10:37:03 +00:00
|
|
|
const createTrigger = props.add && (
|
2021-04-28 10:28:39 +00:00
|
|
|
<Button size={Size.medium} text={props.add.title} />
|
2020-02-03 10:37:03 +00:00
|
|
|
);
|
|
|
|
|
|
2019-11-21 10:52:49 +00:00
|
|
|
return (
|
|
|
|
|
<SubHeaderWrapper>
|
|
|
|
|
<SearchContainer>
|
|
|
|
|
{props.search && (
|
|
|
|
|
<ControlGroup>
|
2020-09-16 11:50:47 +00:00
|
|
|
<SearchInput
|
|
|
|
|
cypressSelector={"t--application-search-input"}
|
2021-07-23 07:31:16 +00:00
|
|
|
defaultValue={props.search.defaultValue}
|
2021-04-28 10:28:39 +00:00
|
|
|
disabled={isFetchingApplications}
|
|
|
|
|
onChange={query || noop}
|
2019-11-21 10:52:49 +00:00
|
|
|
placeholder={props.search.placeholder}
|
2020-09-16 11:50:47 +00:00
|
|
|
variant={SearchVariant.SEAMLESS}
|
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
|
|
|
Form={props.add.form}
|
2019-11-21 10:52:49 +00:00
|
|
|
title={props.add.title}
|
2021-04-28 10:28:39 +00:00
|
|
|
trigger={createTrigger}
|
2019-11-21 10:52:49 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</SubHeaderWrapper>
|
|
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-11-21 10:52:49 +00:00
|
|
|
|
|
|
|
|
export default ApplicationsSubHeader;
|