Skip to content
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

Expose popup config #250

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,53 @@ When `upgradeInsecureRequests` is set to `true` and at least one of your URLs (s

This feature was implemented in response to [issue #159](https://github.com/ImagingDataCommons/slim/issues/159) where PACS servers would return HTTP bulkdata URIs even when accessed via HTTPS.

### Messages/Popups Configuration

Configure message popup notifications that appear at the top of the screen. By default, all message popups are enabled.

```javascript
window.config = {
// ... other config options ...
messages: {
disabled: ['warning', 'info'], // Disable specific message types
duration: 5, // Show messages for 5 seconds
top: 100 // Show 100px from top of screen
}
}
```

Options:
- `disabled`: Disable specific message types or all messages
- `duration`: How long messages are shown (in seconds)
- `top`: Distance from top of screen (in pixels)

Available message types:
- `success` - Green popups
- `error` - Red popups
- `warning` - Yellow popups
- `info` - Blue popups

Examples:
```javascript
// Disable specific types with custom duration and position
messages: {
disabled: ['warning', 'info'],
duration: 5, // Show for 5 seconds
top: 50 // Show 50px from top
}
```

```javascript
// Disable all popups
messages: {
disabled: true
}
```

Default values if not specified:
- `duration`: 5 seconds
- `top`: 100 pixels

## Deployment

Download the latest release from [github.com/imagingdatacommons/slim/releases](https://github.com/imagingdatacommons/slim/releases) and then run the following commands to install build dependencies and build the app:
Expand Down
5 changes: 5 additions & 0 deletions src/AppConfig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ export default interface AppConfig {
enableServerSelection?: boolean
mode?: string
preload?: boolean
messages?: {
disabled?: boolean | string[]
top?: number
duration?: number
}
}
35 changes: 34 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,41 @@ if (config.mode === 'dark') {
App = React.lazy(async () => await import('./AppLight'))
}

const isMessageTypeDisabled = ({ type }: { type: string }): boolean => {
const { messages } = config
if (messages === undefined) return false
if (typeof messages.disabled === 'boolean') {
return messages.disabled
}
return Array.isArray(messages.disabled) && messages.disabled.includes(type)
}

// Store original message methods
const originalMessage = { ...message }

/** Create a proxy to control antd message */
const messageProxy = new Proxy(originalMessage, {
get (target, prop: PropertyKey) {
if (prop === 'config') {
return message.config.bind(message)
}
if (typeof target[prop as keyof typeof target] === 'function') {
return (...args: any[]) => {
const isMessageEnabled = isMessageTypeDisabled({ type: prop as string })
if (!isMessageEnabled) {
return (target[prop as keyof typeof target] as Function).apply(message, args)
}
return { then: () => {} }
}
}
return Reflect.get(target, prop)
}
})
Object.assign(message, messageProxy)

message.config({
top: 100
top: config.messages?.top ?? 100,
duration: config.messages?.duration ?? 5
})

const container = document.getElementById('root')
Expand Down