Skip to content

Commit

Permalink
Add context provider for passing global configuration to components
Browse files Browse the repository at this point in the history
  • Loading branch information
alisman committed May 24, 2022
1 parent 46f5fd5 commit d2440fb
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 57 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
"rc-tooltip": "^5.0.2",
"rc-trigger": "^5.2.1",
"rc-util": "^5.8.0",
"react": "16.14.0",
"react": "^16.4",
"react-addons-pure-render-mixin": "^15.4.2",
"react-addons-test-utils": "^15.4.2",
"react-bootstrap": "^0.31.5",
Expand All @@ -251,7 +251,7 @@
"react-collapse": "^4.0.3",
"react-color": "^2.18.1",
"react-column-resizer": "^1.1.9",
"react-dom": "^16.6.3",
"react-dom": "^16.6",
"react-draggable": "^3.3.0",
"react-file-download": "^0.3.2",
"react-fontawesome": "^1.5.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { Context } from 'react';

export interface IAppContext {
showDownloadControls: boolean;
}

export const AppContext: Context<IAppContext> = React.createContext<
IAppContext
>({
showDownloadControls: true,
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import classnames from 'classnames';
import styles from './DownloadControls.module.scss';
import { saveSvg, saveSvgAsPng } from 'save-svg-as-png';
import svgToPdfDownload from '../../lib/svgToPdfDownload';
import { isPromiseLike } from 'cbioportal-utils';
import { CSSProperties } from 'react';
import { isPromiseLike } from 'cbioportal-utils';
import { AppContext } from '../appContext/AppContext';

type ButtonSpec = {
key: string;
Expand Down Expand Up @@ -290,6 +291,10 @@ export default class DownloadControls extends React.Component<
}

render() {
if (this.context.showDownloadControls === false) {
return null;
}

let element: any = null;
if (this.props.type === 'buttonGroup') {
element = (
Expand Down Expand Up @@ -399,3 +404,5 @@ export default class DownloadControls extends React.Component<
}
}
}

DownloadControls.contextType = AppContext;
1 change: 1 addition & 0 deletions packages/cbioportal-frontend-commons/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ export * from './theme/cBioPortalTheme';
export { default as TruncatedText } from './components/truncatedText/TruncatedText';
export * from './lib/hashString';
export * from './lib/getColor';
export * from './components/appContext/AppContext';
97 changes: 53 additions & 44 deletions src/appShell/App/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
shouldShowGenieWarning,
} from 'appShell/App/usageAgreements/GenieAgreement';
import makeRoutes from 'routes';
import { AppContext } from 'cbioportal-frontend-commons';
import { IAppContext } from 'cbioportal-frontend-commons/src';

interface IContainerProps {
location: Location;
Expand Down Expand Up @@ -60,6 +62,11 @@ export default class Container extends React.Component<IContainerProps, {}> {
);
}

get appContext(): IAppContext {
//return { showDownloadControls: this.appStore.getServerConfig.some_prop }
return { showDownloadControls: true };
}

render() {
if (
!isLocalDBServer() &&
Expand All @@ -86,56 +93,58 @@ export default class Container extends React.Component<IContainerProps, {}> {
}

return (
<div>
<Helmet>
<meta charSet="utf-8" />
<title>{getServerConfig().skin_title}</title>
<meta
name="description"
content={getServerConfig().skin_description}
/>
</Helmet>
<AppContext.Provider value={this.appContext}>
<div>
<Helmet>
<meta charSet="utf-8" />
<title>{getServerConfig().skin_title}</title>
<meta
name="description"
content={getServerConfig().skin_description}
/>
</Helmet>

<div id="pageTopContainer" className="pageTopContainer">
<UserMessager />
<div id="pageTopContainer" className="pageTopContainer">
<UserMessager />

{shouldShowStudyViewWarning() && <StudyAgreement />}
{shouldShowStudyViewWarning() && <StudyAgreement />}

{shouldShowGenieWarning() && <GenieAgreement />}
{shouldShowGenieWarning() && <GenieAgreement />}

<div className="contentWidth">
<PortalHeader appStore={this.appStore} />
<div className="contentWidth">
<PortalHeader appStore={this.appStore} />
</div>
</div>
</div>
<If condition={this.appStore.isErrorCondition}>
<Then>
<div className="contentWrapper">
<ErrorScreen
title={
formatErrorTitle(
<If condition={this.appStore.isErrorCondition}>
<Then>
<div className="contentWrapper">
<ErrorScreen
title={
formatErrorTitle(
this.appStore.undismissedSiteErrors
) ||
'Oops. There was an error retrieving data.'
}
body={
<a href={buildCBioPortalPageUrl('/')}>
Return to homepage
</a>
}
errorLog={formatErrorLog(
this.appStore.undismissedSiteErrors
) ||
'Oops. There was an error retrieving data.'
}
body={
<a href={buildCBioPortalPageUrl('/')}>
Return to homepage
</a>
}
errorLog={formatErrorLog(
this.appStore.undismissedSiteErrors
)}
errorMessages={formatErrorMessages(
this.appStore.undismissedSiteErrors
)}
/>
</div>
</Then>
<Else>
<div className="contentWrapper">{makeRoutes()}</div>
</Else>
</If>
</div>
)}
errorMessages={formatErrorMessages(
this.appStore.undismissedSiteErrors
)}
/>
</div>
</Then>
<Else>
<div className="contentWrapper">{makeRoutes()}</div>
</Else>
</If>
</div>
</AppContext.Provider>
);
}
}
38 changes: 28 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20513,6 +20513,16 @@ react-column-resizer@^1.1.9:
resolved "https://registry.yarnpkg.com/react-column-resizer/-/react-column-resizer-1.1.9.tgz#b3e591003d1373ae9a9f85ef9d855813743773dd"
integrity sha512-l25LPyN3Gu33RC726cv3ZnS9EaI/B+ZIY1MrJiiHcBqsY4BKRYNBbrZolUfzBjjWDwHOBMc/fZLiSxmDGPqCrQ==

[email protected], react-dom@^16.6:
version "16.14.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.14.0.tgz#7ad838ec29a777fb3c75c3a190f661cf92ab8b89"
integrity sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.19.1"

react-dom@^15.3.1:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.2.tgz#41cfadf693b757faf2708443a1d1fd5a02bef730"
Expand All @@ -20523,7 +20533,7 @@ react-dom@^15.3.1:
object-assign "^4.1.0"
prop-types "^15.5.10"

react-dom@^16.6.3, react-dom@^16.7.0:
react-dom@^16.7.0:
version "16.8.4"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.4.tgz#1061a8e01a2b3b0c8160037441c3bf00a0e3bc48"
integrity sha512-Ob2wK7XG2tUDt7ps7LtLzGYYB6DXMCLj0G5fO6WeEICtT4/HdpOi7W/xLzZnR6RCG1tYza60nMdqtxzA8FaPJQ==
Expand Down Expand Up @@ -20995,15 +21005,6 @@ react-zeroclipboard@^3.2.2:
create-react-class "^15.5.3"
envify "^3"

[email protected]:
version "16.14.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"

react@^0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/react/-/react-0.13.3.tgz#a2dfa85335d7dc02b82b482f089582e64cc13356"
Expand All @@ -21021,6 +21022,15 @@ react@^16.0.0, react@^16.7.0:
prop-types "^15.6.2"
scheduler "^0.13.4"

react@^16.4:
version "16.14.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"

reactable@^0.14.1:
version "0.14.1"
resolved "https://registry.yarnpkg.com/reactable/-/reactable-0.14.1.tgz#2ab9895e3df6da2498625de46d3691592d18c93b"
Expand Down Expand Up @@ -22288,6 +22298,14 @@ scheduler@^0.13.4:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.19.1:
version "0.19.1"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
Expand Down

0 comments on commit d2440fb

Please sign in to comment.