Skip to content

Commit

Permalink
[Backport 5.3.9104] Notices: Add customization for background color, …
Browse files Browse the repository at this point in the history
…text color, and text position. (#61915)

Notices: Add customization for background color, text color, and text position. (#61338)

Closes #59751

Co-authored-by: Bill Caplan <bill.caplan@sourcegraph.com>
  • Loading branch information
RXminuS and billCaplan committed Apr 18, 2024
1 parent fd30e59 commit 6af7844
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ All notable changes to Sourcegraph are documented in this file.
- GitHub apps installation records will only be deleted from the database if the GitHub App has been uninstalled or if the GitHub app has been deleted. [#60460](https://github.com/sourcegraph/sourcegraph/pull/60460)
- The Anthropic provider for Cody has been updated to use the messages API which includes support for Claude 3 models. This is applicable to both BYOK and Cody Gateway users. The messages API does not support model identifiers which only set a major model version such as: `claude-2`, `claude-instant-v1` and `claude-instant-1`. Default values have been updated to `claude-2.0` and `claude-instant-1.2`, any legacy models identifiers in the site config will be set to the corresponding default previously mentioned. [#60953](https://github.com/sourcegraph/sourcegraph/pull/60953) [#61324](https://github.com/sourcegraph/sourcegraph/pull/61324)
- The AWS Bedrock provider for Cody has been updated to use Anthropic's Messages API, bringing support for Claude 3 models. [#61347](https://github.com/sourcegraph/sourcegraph/pull/61347)
- Notices configured in the site config now allow for specifying a style or color. [#61338](https://github.com/sourcegraph/sourcegraph/pull/61338)

### Fixed

Expand Down
16 changes: 14 additions & 2 deletions client/web/src/components/DismissibleAlert/DismissibleAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const DismissibleAlert: React.FunctionComponent<React.PropsWithChildren<D
testId,
children,
variant,
styleOverrides,
}) => {
const [dismissed, setDismissed] = React.useState<boolean>(
partialStorageKey ? isAlertDismissed(partialStorageKey) : false
Expand All @@ -45,8 +46,19 @@ export const DismissibleAlert: React.FunctionComponent<React.PropsWithChildren<D
}

return (
<Alert data-testid={testId} className={classNames(styles.container, className)} variant={variant}>
<div className={styles.content}>{children}</div>
<Alert
data-testid={testId}
className={classNames(styles.container, className)}
variant={variant}
styleOverrides={styleOverrides}
>
<div
className={classNames(styles.content, {
'justify-content-center': styleOverrides?.textCentered,
})}
>
{children}
</div>
<Button aria-label="Dismiss alert" variant="icon" className={styles.closeButton} onClick={onDismiss}>
<Icon aria-hidden={true} svgPath={mdiClose} />
</Button>
Expand Down
11 changes: 11 additions & 0 deletions client/web/src/global/Notices.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ describe('Notices', () => {
{ message: 'a', location: 'home' },
{ message: 'a', location: 'home', dismissible: true },
{ message: 'b', location: 'top' },
{ message: 'a message with a variant', location: 'top', variant: 'note' },
{
message: 'a message with style overrides',
location: 'top',
variant: 'success',
styleOverrides: {
backgroundColor: '#00f0ff',
textCentered: true,
},
},
],
},
}}
>
<Notices location="home" telemetryRecorder={noOpTelemetryRecorder} />
<Notices location="top" telemetryRecorder={noOpTelemetryRecorder} />
</SettingsProvider>
).asFragment()
).toMatchSnapshot())
Expand Down
5 changes: 3 additions & 2 deletions client/web/src/global/Notices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ const NoticeAlert: React.FunctionComponent<React.PropsWithChildren<NoticeAlertPr
}) => {
const content = <Markdown dangerousInnerHTML={renderMarkdown(notice.message)} />

const sharedProps = {
const sharedProps: AlertProps & { 'data-testid': typeof testId } = {
'data-testid': testId,
variant: getAlertVariant(notice.location),
variant: notice.variant || getAlertVariant(notice.location),
className: classNames(notice.location !== 'top' && 'bg transparent border p-2', className),
styleOverrides: notice.styleOverrides,
}

return notice.dismissible ? (
Expand Down
47 changes: 47 additions & 0 deletions client/web/src/global/__snapshots__/Notices.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion client/wildcard/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
* be default.
*/
withIcon?: boolean

styleOverrides?: {
backgroundColor?: string
textColor?: string
textCentered?: boolean
}
}

const userShouldBeImmediatelyNotified = (variant?: AlertVariant): boolean =>
Expand All @@ -33,7 +39,17 @@ const userShouldBeImmediatelyNotified = (variant?: AlertVariant): boolean =>
* Further details: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/alert_role
*/
export const Alert = React.forwardRef(function Alert(
{ children, withIcon = true, as: Component = 'div', variant, className, role = 'alert', ...attributes },
{
children,
withIcon = true,
as: Component = 'div',
variant,
className,
role = 'alert',
styleOverrides,
style,
...attributes
},
reference
) {
const { isBranded } = useWildcardTheme()
Expand All @@ -46,12 +62,22 @@ export const Alert = React.forwardRef(function Alert(
*/
const alertAssertiveness = userShouldBeImmediatelyNotified(variant) ? 'assertive' : 'polite'

// Merge styles with overrides
const { backgroundColor, textColor, textCentered } = styleOverrides || {}
const mergedStyles: React.CSSProperties = {
...style,
...(!!backgroundColor && { backgroundColor }),
...(!!textColor && { color: textColor }),
...(!!textCentered && { textAlign: 'center' }),
}

return (
<Component
ref={reference}
className={classNames(brandedClassName, className, { [styles.alertWithNoIcon]: !withIcon })}
role={role}
aria-live={alertAssertiveness}
style={mergedStyles}
{...attributes}
>
{children}
Expand Down
13 changes: 13 additions & 0 deletions schema/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions schema/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,32 @@
"type": "string",
"enum": ["top", "home"]
},
"variant": {
"type": "string",
"enum": ["primary", "secondary", "success", "danger", "warning", "info", "note"]
},
"dismissible": {
"description": "Whether this notice can be dismissed (closed) by the user.",
"type": "boolean",
"default": false
},
"styleOverrides": {
"description": "Overrides for the notice's default style. You probably want to use notice 'variant' setting instead.",
"type": "object",
"properties": {
"backgroundColor": {
"description": "The hex code of the background color for this notice.",
"type": "string"
},
"textColor": {
"description": "The hex code of the text color for this notice.",
"type": "string"
},
"textCentered": {
"description": "Whether the notice text should be centered.",
"type": "boolean"
}
}
}
}
}
Expand Down

0 comments on commit 6af7844

Please sign in to comment.