-
Notifications
You must be signed in to change notification settings - Fork 5
add system alerts banner component in order to display alerts via jso… #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SaqAsh
merged 4 commits into
overture-stack:feature/bannerComponent
from
SaqAsh:feature/custom-banner
May 21, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,114 @@ | ||
/* | ||
* | ||
* Copyright (c) 2025 The Ontario Institute for Cancer Research. All rights reserved | ||
* | ||
* This program and the accompanying materials are made available under the terms of | ||
* the GNU Affero General Public License v3.0. You should have received a copy of the | ||
* GNU Affero General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
import { AlertDef } from '@/components/SystemAlerts/types'; | ||
import { default as theme } from '@/components/theme'; | ||
import { Error as ErrorIcon, Info, Warning } from '@/components/theme/icons'; | ||
import Dismiss from '@/components/theme/icons/dismiss'; | ||
import { css } from '@emotion/react'; | ||
import React from 'react'; | ||
|
||
type Props = { | ||
alert: AlertDef; | ||
onClose: () => void; | ||
}; | ||
|
||
const AlertVariants = { | ||
critical: { | ||
backgroundColor: theme.colors.error_2, | ||
icon: <ErrorIcon height={26} width={26} />, | ||
textColor: theme.colors.black, | ||
outline: theme.colors.error_dark, | ||
}, | ||
warning: { | ||
backgroundColor: theme.colors.warning_light, | ||
icon: <Warning height={26} width={26} />, | ||
textColor: theme.colors.black, | ||
outline: theme.colors.warning_dark, | ||
}, | ||
info: { | ||
backgroundColor: theme.colors.secondary_1, | ||
icon: <Info fill={theme.colors.secondary_accessible} />, | ||
textColor: theme.colors.black, | ||
outline: theme.colors.secondary_dark, | ||
}, | ||
}; | ||
|
||
export const SystemAlert: React.FC<Props> = ({ alert, onClose }) => { | ||
const { backgroundColor, icon, textColor, outline } = AlertVariants[alert.level]; | ||
|
||
return ( | ||
<div | ||
css={css` | ||
padding: 12px; | ||
display: flex; | ||
justify-content: space-between; | ||
background-color: ${backgroundColor}; | ||
border-bottom: 1px solid ${outline}; | ||
`} | ||
> | ||
<div | ||
css={css` | ||
display: flex; | ||
`} | ||
> | ||
<div | ||
css={css` | ||
margin: auto 15px auto auto; | ||
`} | ||
> | ||
{icon} | ||
</div> | ||
<div> | ||
<div | ||
css={css` | ||
color: ${textColor}; | ||
margin-top: ${alert.message ? '0px' : '6px'}; | ||
${theme.typography.heading}; | ||
`} | ||
> | ||
{alert.title} | ||
</div> | ||
{alert.message && ( | ||
<div | ||
css={css` | ||
color: ${textColor}; | ||
margin-bottom: 8px; | ||
${theme.typography.regular}; | ||
`} | ||
dangerouslySetInnerHTML={{ __html: alert.message }} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
{alert.dismissable && ( | ||
<div | ||
css={css` | ||
cursor: pointer; | ||
`} | ||
onClick={onClose} | ||
> | ||
<Dismiss height={15} width={15} fill={theme.colors.black} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains hidden or 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,72 @@ | ||
/* | ||
* | ||
* Copyright (c) 2025 The Ontario Institute for Cancer Research. All rights reserved | ||
* | ||
* This program and the accompanying materials are made available under the terms of | ||
* the GNU Affero General Public License v3.0. You should have received a copy of the | ||
* GNU Affero General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
import { getConfig } from '@/global/config'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { SystemAlert } from '@/components/SystemAlerts/SystemAlert'; | ||
import { AlertDef, isAlertDefs } from '@/components/SystemAlerts/types'; | ||
|
||
const LOCAL_STORAGE_KEY = 'SYSTEM_ALERTS_DISMISSED_IDS'; | ||
|
||
type Props = { | ||
alerts?: AlertDef[]; | ||
}; | ||
|
||
export const SystemAlerts: React.ComponentType<Props> = ({ alerts }) => { | ||
const [displayAlerts, setDisplayAlerts] = useState<AlertDef[]>([]); | ||
const [dismissedIds, setDismissedIds] = useState<string[]>([]); | ||
|
||
const getParsedSystemAlerts = () => { | ||
try { | ||
const { NEXT_PUBLIC_SYSTEM_ALERTS } = getConfig(); | ||
const parsed = JSON.parse(NEXT_PUBLIC_SYSTEM_ALERTS); | ||
if (!isAlertDefs(parsed)) throw new Error('System Alert types are invalid!'); | ||
return parsed; | ||
} catch (e) { | ||
console.error('Failed to parse systems alerts! Using empty array!', e); | ||
return []; | ||
} | ||
}; | ||
|
||
const systemAlerts = alerts ?? getParsedSystemAlerts(); | ||
const systemAlertIds = systemAlerts.map((a) => a.id); | ||
|
||
const handleClose = (id: string) => { | ||
const updated = dismissedIds.concat(id).filter((id) => systemAlertIds.includes(id)); | ||
setDisplayAlerts(systemAlerts.filter((a) => !updated.includes(a.id))); | ||
setDismissedIds(updated); | ||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(updated)); | ||
}; | ||
|
||
useEffect(() => { | ||
const stored = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY) || '[]'); | ||
setDismissedIds(stored); | ||
setDisplayAlerts(systemAlerts.filter((a) => !stored.includes(a.id))); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{displayAlerts.map((alert) => ( | ||
<SystemAlert key={alert.id} alert={alert} onClose={() => handleClose(alert.id)} /> | ||
))} | ||
</> | ||
); | ||
}; |
This file contains hidden or 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,48 @@ | ||
/* | ||
* | ||
* Copyright (c) 2025 The Ontario Institute for Cancer Research. All rights reserved | ||
* | ||
* This program and the accompanying materials are made available under the terms of | ||
* the GNU Affero General Public License v3.0. You should have received a copy of the | ||
* GNU Affero General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
export type AlertLevel = 'info' | 'warning' | 'critical'; | ||
|
||
export const ALERT_LEVELS = { | ||
info: 'info', | ||
warning: 'warning', | ||
critical: 'critical', | ||
} as const; | ||
|
||
export type AlertDef = { | ||
level: AlertLevel; | ||
title: string; | ||
message?: string; | ||
dismissable: boolean; | ||
id: string; | ||
}; | ||
|
||
export const isAlertLevel = (level: any): level is AlertLevel => { | ||
return level === 'info' || level === 'warning' || level === 'critical'; | ||
}; | ||
|
||
export const isAlertDef = (obj: any): obj is AlertDef => { | ||
return obj.id && obj.title && obj.dismissable !== undefined && isAlertLevel(obj.level); | ||
}; | ||
|
||
export const isAlertDefs = (obj: any): obj is AlertDef[] => { | ||
return Array.isArray(obj) && obj.every(isAlertDef); | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
/* | ||
* | ||
* Copyright (c) 2025 The Ontario Institute for Cancer Research. All rights reserved | ||
* | ||
* This program and the accompanying materials are made available under the terms of | ||
* the GNU Affero General Public License v3.0. You should have received a copy of the | ||
* GNU Affero General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
import { ReactElement } from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add copyright |
||
import { css } from '@emotion/react'; | ||
|
||
import { IconProps } from './types'; | ||
|
||
const Info = ({ fill, size = 30, style }: IconProps): ReactElement => { | ||
return ( | ||
<svg | ||
css={css` | ||
${style}; | ||
height: ${size}px; | ||
width: ${size}px; | ||
`} | ||
width={size} | ||
height={size} | ||
viewBox="0 0 30 30" | ||
> | ||
<g fill="none" fillRule="evenodd"> | ||
<g fill={fill}> | ||
<path d="M15 0c8.284 0 15 6.716 15 15 0 8.284-6.716 15-15 15-8.284 0-15-6.716-15-15C0 6.716 6.716 0 15 0z" /> | ||
<path | ||
d="M14.62 10.985c1.104 0 2.019-.888 2.019-1.992S15.724 7 14.619 7c-1.103 0-2.019.889-2.019 1.993s.916 1.992 2.02 1.992zM12.6 21.083c0 1.023.916 1.858 2.02 1.858s2.019-.835 2.019-1.858v-7.217c0-1.023-.915-1.858-2.02-1.858-1.103 0-2.019.835-2.019 1.858v7.217z" | ||
fill="white" | ||
/> | ||
</g> | ||
</g> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default Info; |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add copyright