Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into add_canvas_feature_re…
Browse files Browse the repository at this point in the history
…nderer
  • Loading branch information
cmdcolin committed Nov 17, 2024
2 parents def3bf9 + 2d52a06 commit 7a89844
Show file tree
Hide file tree
Showing 223 changed files with 7,238 additions and 4,957 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default tseslint.config(
markers: ['/'],
},
],

'one-var': ['error', 'never'],
'react-refresh/only-export-components': 'warn',
'react/no-unescaped-entities': 'off',
'react/no-is-mounted': 'off',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"dependency-graph": "^1.0.0",
"dotenv": "^16.3.1",
"dotenv-expand": "^11.0.3",
"electron": "33.0.2",
"electron": "33.2.0",
"electron-builder": "^25.1.6",
"electron-mock-ipc": "^0.3.8",
"eslint": "^9.0.0",
Expand Down
67 changes: 45 additions & 22 deletions packages/core/BaseFeatureWidget/SequenceFeatureDetails/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,54 @@ function localStorageGetNumber(key: string, defaultVal: number) {
return +(localStorageGetItem(key) ?? defaultVal)
}

function localStorageGetBoolean(key: string, defaultVal: boolean) {
return Boolean(
JSON.parse(localStorageGetItem(key) || JSON.stringify(defaultVal)),
)
}

function localStorageSetNumber(key: string, value: number) {
localStorageSetItem(key, JSON.stringify(value))
}

function localStorageSetBoolean(key: string, value: boolean) {
localStorageSetItem(key, JSON.stringify(value))
}

const p = 'sequenceFeatureDetails'

export function SequenceFeatureDetailsF() {
return types
.model('SequenceFeatureDetails')
.volatile(() => ({
/**
* #volatile
*/
showCoordinatesSetting:
localStorageGetItem('sequenceFeatureDetails-showCoordinatesSetting') ||
'none',
intronBp: localStorageGetNumber('sequenceFeatureDetails-intronBp', 10),
upDownBp: localStorageGetNumber('sequenceFeatureDetails-upDownBp', 100),
upperCaseCDS: Boolean(
JSON.parse(
localStorageGetItem('sequenceFeatureDetails-upperCaseCDS') || 'true',
),
),
localStorageGetItem(`${p}-showCoordinatesSetting`) || 'none',
/**
* #volatile
*/
intronBp: localStorageGetNumber(`${p}-intronBp`, 10),
/**
* #volatile
*/
upDownBp: localStorageGetNumber(`${p}-upDownBp`, 100),
/**
* #volatile
*/
upperCaseCDS: localStorageGetBoolean(`${p}-upperCaseCDS`, true),
/**
* #volatile
*/
charactersPerRow: 100,
/**
* #volatile
*/
feature: undefined as SimpleFeatureSerialized | undefined,
/**
* #volatile
*/
mode: '',
}))
.actions(self => ({
Expand Down Expand Up @@ -110,20 +142,11 @@ export function SequenceFeatureDetailsF() {
addDisposer(
self,
autorun(() => {
localStorageSetNumber(`${p}-upDownBp`, self.upDownBp)
localStorageSetNumber(`${p}-intronBp`, self.intronBp)
localStorageSetBoolean(`${p}-upperCaseCDS`, self.upperCaseCDS)
localStorageSetItem(
'sequenceFeatureDetails-upDownBp',
JSON.stringify(self.upDownBp),
)
localStorageSetItem(
'sequenceFeatureDetails-intronBp',
JSON.stringify(self.intronBp),
)
localStorageSetItem(
'sequenceFeatureDetails-upperCaseCDS',
JSON.stringify(self.upperCaseCDS),
)
localStorageSetItem(
'sequenceFeatureDetails-showCoordinatesSetting',
`${p}-showCoordinatesSetting`,
self.showCoordinatesSetting,
)
}),
Expand Down
25 changes: 13 additions & 12 deletions packages/core/data_adapters/CytobandAdapter/CytobandAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { unzip } from '@gmod/bgzf-filehandle'

// locals
import { isGzip, SimpleFeature } from '../../util'
import { fetchAndMaybeUnzip, SimpleFeature } from '../../util'
import { openLocation } from '../../util/io'
import { BaseAdapter } from '../BaseAdapter'
import { BaseOptions } from '../BaseAdapter/BaseOptions'

export default class CytobandAdapter extends BaseAdapter {
async getData() {
const pm = this.pluginManager
const loc = this.getConf('cytobandLocation')
if (loc.uri === '' || loc.uri === '/path/to/cytoband.txt.gz') {
async getData(opts?: BaseOptions) {
const conf = this.getConf('cytobandLocation')
if (conf.uri === '' || conf.uri === '/path/to/cytoband.txt.gz') {
return []
}
const buffer = await openLocation(loc, pm).readFile()
const buf = isGzip(buffer) ? await unzip(buffer) : buffer
const text = new TextDecoder('utf8', { fatal: true }).decode(buf)

const pm = this.pluginManager
const buf = await fetchAndMaybeUnzip(openLocation(conf, pm), opts)
const decoder = new TextDecoder('utf8', { fatal: true })
const text = decoder.decode(buf)
return text
.split(/\n|\r\n|\r/)
.filter(f => !!f.trim())
Expand All @@ -25,8 +25,9 @@ export default class CytobandAdapter extends BaseAdapter {
refName: refName!,
start: +start!,
end: +end!,
name: name!,
type: type!,
name,
type,
gieStain: type || name,
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"copy-to-clipboard": "^3.3.1",
"deepmerge": "^4.2.2",
"detect-node": "^2.1.0",
"dompurify": "^3.0.0",
"dompurify": "^3.2.0",
"escape-html": "^1.0.3",
"fast-deep-equal": "^3.1.3",
"generic-filehandle": "^3.0.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/core/ui/AssemblySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ const AssemblySelector = observer(function ({
variant="outlined"
helperText={error || helperText}
value={selection || ''}
inputProps={{ 'data-testid': 'assembly-selector' }}
onChange={event => {
setLastSelected(event.target.value)
}}
error={!!error}
InputProps={InputProps}
disabled={!!error}
className={classes.importFormEntry}
{...TextFieldProps}
slotProps={{
input: InputProps,
htmlInput: { 'data-testid': 'assembly-selector' },
}}
>
{assemblyNames.map(name => {
const assembly = assemblyManager.get(name)
Expand Down
4 changes: 3 additions & 1 deletion packages/core/ui/FileSelector/UrlChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const UrlChooser = observer(function ({
<TextField
fullWidth
variant="outlined"
inputProps={{ 'data-testid': 'urlInput' }}
defaultValue={location && isUriLocation(location) ? location.uri : ''}
label={label || 'Enter URL'}
onChange={event => {
Expand All @@ -25,6 +24,9 @@ const UrlChooser = observer(function ({
locationType: 'UriLocation',
})
}}
slotProps={{
htmlInput: { 'data-testid': 'urlInput' },
}}
/>
)
})
Expand Down
21 changes: 9 additions & 12 deletions packages/core/ui/SanitizedHTML.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ export default function SanitizedHTML({
// see https://github.com/cure53/DOMPurify/issues/317
// only have to add this once, and can't do it globally because dompurify
// not yet initialized at global scope
dompurify.addHook(
'afterSanitizeAttributes',
(node: {
tagName: string
setAttribute: (arg0: string, arg1: string) => void
}) => {
if (node.tagName === 'A') {
node.setAttribute('rel', 'noopener noreferrer')
node.setAttribute('target', '_blank')
}
},
)
dompurify.addHook('afterSanitizeAttributes', node => {
// @ts-expect-error
if (node.tagName === 'A') {
// @ts-expect-error
node.setAttribute('rel', 'noopener noreferrer')
// @ts-expect-error
node.setAttribute('target', '_blank')
}
})
}

return (
Expand Down
78 changes: 28 additions & 50 deletions packages/core/ui/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const midnight = '#0D233F'
const grape = '#721E63'
const forest = refTheme.palette.augmentColor({ color: { main: '#135560' } })
const mandarin = refTheme.palette.augmentColor({ color: { main: '#FFB11D' } })
const lightgrey = refTheme.palette.augmentColor({ color: { main: '#aaa' } })
const bases = {
A: refTheme.palette.augmentColor({ color: green }),
C: refTheme.palette.augmentColor({ color: blue }),
Expand Down Expand Up @@ -468,66 +469,43 @@ export function createJBrowseTheme(
return createTheme(
createJBrowseBaseTheme(
themeName === 'default'
? deepmerge(themes.default!, augmentTheme(configTheme), {
? deepmerge(themes.default!, augmentThemeColors(configTheme), {
arrayMerge: overwriteArrayMerge,
})
: augmentThemePlus(themes[themeName]),
: addMissingColors(themes[themeName]),
),
)
}

function augmentTheme(theme: ThemeOptions = {}) {
if (theme.palette?.tertiary) {
theme = deepmerge(theme, {
palette: {
tertiary: refTheme.palette.augmentColor(
'color' in theme.palette.tertiary
? (theme.palette.tertiary as PaletteAugmentColorOptions)
: { color: theme.palette.tertiary },
),
},
})
}

if (theme.palette?.quaternary) {
theme = deepmerge(theme, {
palette: {
quaternary: refTheme.palette.augmentColor(
'color' in theme.palette.quaternary
? (theme.palette.quaternary as PaletteAugmentColorOptions)
: { color: theme.palette.quaternary },
),
},
})
// MUI by default allows strings like '#f00' for primary and secondary and
// augments them to have light and dark variants but not for anything else, so
// we augment them here
function augmentThemeColors(theme: ThemeOptions = {}) {
for (const entry of ['tertiary', 'quaternary', 'highlight'] as const) {
if (theme.palette?.[entry]) {
theme = deepmerge(theme, {
palette: {
[entry]: refTheme.palette.augmentColor(
'color' in theme.palette[entry]
? (theme.palette[entry] as PaletteAugmentColorOptions)
: { color: theme.palette[entry] },
),
},
})
}
}

return theme
}

// creates some blank quaternary/tertiary colors if unsupplied by a user theme
function augmentThemePlus(theme: ThemeOptions = {}) {
theme = augmentTheme(theme)
if (!theme.palette?.quaternary) {
theme = deepmerge(theme, {
// adds missing colors to users theme
function addMissingColors(theme: ThemeOptions = {}) {
return augmentThemeColors(
deepmerge(theme, {
palette: {
quaternary: refTheme.palette.augmentColor({
color: {
main: '#aaa',
},
}),
},
})
}
if (!theme.palette?.tertiary) {
theme = deepmerge(theme, {
palette: {
tertiary: refTheme.palette.augmentColor({
color: {
main: '#aaa',
},
}),
quaternary: theme.palette?.quaternary || lightgrey,
tertiary: theme.palette?.tertiary || lightgrey,
highlight: theme.palette?.highlight || mandarin,
},
})
}
return theme
}),
)
}
Loading

0 comments on commit 7a89844

Please sign in to comment.