Skip to content

Commit

Permalink
Fixed up types ++ Added cancel on click handler to datasource page la…
Browse files Browse the repository at this point in the history
…yout
  • Loading branch information
paul-tavares committed Jun 12, 2020
1 parent 91bda2e commit b67c048
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ interface IntraAppState<S extends AnyIntraAppRouteState = AnyIntraAppRouteState>
forRoute: string;
routeState?: S;
}
type UseIntraAppStateHook = <S extends AnyIntraAppRouteState = AnyIntraAppRouteState>() =>
| IntraAppState<S>['routeState']
| undefined;

const IntraAppStateContext = React.createContext<IntraAppState>({ forRoute: '' });
const wasHandled = new WeakSet<IntraAppState>();
Expand Down Expand Up @@ -47,7 +44,9 @@ export const IntraAppStateProvider = memo<{
* This state can be used by other Kibana Apps to influence certain behaviours in Ingest, for example,
* redirecting back to an given Application after a craete action.
*/
export const useIntraAppState: UseIntraAppStateHook = () => {
export function useIntraAppState<S = AnyIntraAppRouteState>():
| IntraAppState<S>['routeState']
| undefined {
const location = useLocation();
const intraAppState = useContext(IntraAppStateContext);
if (!intraAppState) {
Expand All @@ -60,7 +59,7 @@ export const useIntraAppState: UseIntraAppStateHook = () => {
// consistently either.
if (location.pathname === intraAppState.forRoute && !wasHandled.has(intraAppState)) {
wasHandled.add(intraAppState);
return intraAppState.routeState;
return intraAppState.routeState as S;
}
}, [intraAppState, location.pathname]);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ import { CreateDatasourceFrom } from '../types';
export const CreateDatasourcePageLayout: React.FunctionComponent<{
from: CreateDatasourceFrom;
cancelUrl: string;
cancelOnClick?: React.ReactEventHandler;
agentConfig?: AgentConfig;
packageInfo?: PackageInfo;
}> = ({ from, cancelUrl, agentConfig, packageInfo, children }) => {
}> = ({ from, cancelUrl, cancelOnClick, agentConfig, packageInfo, children }) => {
const leftColumn = (
<EuiFlexGroup direction="column" gutterSize="s" alignItems="flexStart">
<EuiFlexItem>
<EuiButtonEmpty size="xs" iconType="arrowLeft" flush="left" href={cancelUrl}>
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButtonEmpty
size="xs"
iconType="arrowLeft"
flush="left"
href={cancelUrl}
onClick={cancelOnClick}
>
<FormattedMessage
id="xpack.ingestManager.createDatasource.cancelLinkText"
defaultMessage="Cancel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const CreateDatasourcePage: React.FunctionComponent = () => {
const layoutProps = {
from,
cancelUrl,
cancelOnClick: cancelClickHandler,
agentConfig,
packageInfo,
};
Expand Down

0 comments on commit b67c048

Please sign in to comment.