-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e08b3b
commit f7cabf0
Showing
8 changed files
with
245 additions
and
43 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
frontend/packages/dev-console/src/components/QueryFocusApplication.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { setActiveApplication } from '@console/internal/actions/ui'; | ||
import { RootState } from '@console/internal/redux'; | ||
import { getActiveApplication } from '@console/internal/reducers/ui'; | ||
import { QUERY_PROPERTIES } from '../const'; | ||
|
||
type StateProps = { | ||
application: string; | ||
}; | ||
type DispatchProps = { | ||
onSetApp: (application: string) => void; | ||
}; | ||
type OwnProps = { | ||
children: (desiredApplication?: string) => React.ReactNode; | ||
keepOnUnmount?: boolean; | ||
searchParams: URLSearchParams; | ||
}; | ||
|
||
type QueryFocusApplicationProps = StateProps & DispatchProps & OwnProps; | ||
|
||
const QueryFocusApplication: React.FC<QueryFocusApplicationProps> = ({ | ||
children, | ||
application, | ||
keepOnUnmount, | ||
searchParams, | ||
onSetApp, | ||
}) => { | ||
const [originalApp] = React.useState(application); | ||
const desiredApplication = searchParams.get(QUERY_PROPERTIES.APPLICATION); | ||
|
||
React.useEffect(() => { | ||
if (desiredApplication && desiredApplication !== originalApp) { | ||
onSetApp(desiredApplication); | ||
} | ||
|
||
return () => { | ||
if (!keepOnUnmount && application !== originalApp) { | ||
onSetApp(originalApp); | ||
} | ||
}; | ||
}, [desiredApplication, keepOnUnmount, onSetApp, originalApp, application]); | ||
|
||
return <>{children(desiredApplication)}</>; | ||
}; | ||
|
||
export default connect<StateProps, DispatchProps, OwnProps>( | ||
(state: RootState): StateProps => ({ | ||
application: getActiveApplication(state), | ||
}), | ||
{ | ||
onSetApp: setActiveApplication, | ||
}, | ||
)(QueryFocusApplication); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
export const ALLOW_SERVICE_BINDING = 'ALLOW_SERVICE_BINDING'; | ||
export const FLAG_OPENSHIFT_PIPELINE = 'OPENSHIFT_PIPELINE'; | ||
export const CLUSTER_PIPELINE_NS = 'openshift'; | ||
|
||
/** URL query params that adjust scope / purpose of the page */ | ||
export enum QUERY_PROPERTIES { | ||
/** For defining a contextual application group (ie, add new workload into this application group) */ | ||
APPLICATION = 'application', | ||
/** For defining a contextual source of the redirect (ie, connect a new workload from this contextual source) */ | ||
CONTEXT_SOURCE = 'contextSource', | ||
} |
Oops, something went wrong.