diff --git a/.eslintrc.js b/.eslintrc.js index 71fdec0bd..2865cf979 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -76,12 +76,11 @@ module.exports = { // eslint-plugin-tsdoc rules 'tsdoc/syntax': 'warn', // eslint-plugin-unicorn rules (override recommended) - 'unicorn/consistent-destructuring': 'off', - 'unicorn/filename-case': 'off', + 'unicorn/filename-case': 'off', // Doesn't match our file naming, maybe can be configured later 'unicorn/no-empty-file': 'off', // False positives - 'unicorn/no-null': 'off', + 'unicorn/no-null': 'off', // A lot of null in React and other libraries 'unicorn/prefer-module': 'off', // Cypress and apollo-collaboration-server need this - 'unicorn/prevent-abbreviations': 'off', + 'unicorn/prevent-abbreviations': 'off', // Doesn't guess a lot of abbreviations correctly // Special case @typescript-eslint/eslint-plugin rule // Will be part of "plugin:@typescript-eslint/recommended-type-checked" when // that extension is enabled. Remove from here at that time. diff --git a/packages/apollo-collaboration-server/src/operations/operations.service.ts b/packages/apollo-collaboration-server/src/operations/operations.service.ts index d41a07863..059ebedec 100644 --- a/packages/apollo-collaboration-server/src/operations/operations.service.ts +++ b/packages/apollo-collaboration-server/src/operations/operations.service.ts @@ -47,24 +47,36 @@ export class OperationsService { async executeOperation( serializedOperation: ReturnType, ): Promise> { - const { logger } = this + const { + assemblyModel, + connection, + countersService, + featureModel, + fileModel, + filesService, + logger, + pluginsService, + refSeqChunkModel, + refSeqModel, + userModel, + } = this const OperationType = operationRegistry.getOperationType( serializedOperation.typeName, ) const operation = new OperationType(serializedOperation, { logger }) - const session = await this.connection.startSession() + const session = await connection.startSession() const result = (await operation.execute({ typeName: 'Server', - featureModel: this.featureModel, - assemblyModel: this.assemblyModel, - refSeqModel: this.refSeqModel, - refSeqChunkModel: this.refSeqChunkModel, - fileModel: this.fileModel, - userModel: this.userModel, + featureModel, + assemblyModel, + refSeqModel, + refSeqChunkModel, + fileModel, + userModel, session, - filesService: this.filesService, - counterService: this.countersService, - pluginsService: this.pluginsService, + filesService, + counterService: countersService, + pluginsService, user: '', })) as ReturnType await session.endSession() diff --git a/packages/apollo-common/src/AssemblySpecificChange.ts b/packages/apollo-common/src/AssemblySpecificChange.ts index 209c481d6..45690d518 100644 --- a/packages/apollo-common/src/AssemblySpecificChange.ts +++ b/packages/apollo-common/src/AssemblySpecificChange.ts @@ -125,19 +125,19 @@ export abstract class AssemblySpecificChange extends Change { if (!refSeqDoc) { throw new Error('No refSeq document found') } - const { chunkSize } = refSeqDoc + const { _id, chunkSize } = refSeqDoc sequenceBuffer += line.replaceAll(/\s/g, '') // If sequence block > chunk size then save chunk into Mongo while (sequenceBuffer.length >= chunkSize) { const sequence = sequenceBuffer.slice(0, chunkSize) refSeqLen += sequence.length logger.debug?.( - `Creating refSeq chunk number ${chunkIndex} of "${refSeqDoc._id}"`, + `Creating refSeq chunk number ${chunkIndex} of "${_id}"`, ) // We cannot use Mongo 'session' / transaction here because Mongo has 16 MB limit for transaction await refSeqChunkModel.create([ { - refSeq: refSeqDoc._id, + refSeq: _id, n: chunkIndex, sequence, user, diff --git a/packages/apollo-shared/src/Changes/AddFeatureChange.ts b/packages/apollo-shared/src/Changes/AddFeatureChange.ts index ce64f7bef..a0ce15599 100644 --- a/packages/apollo-shared/src/Changes/AddFeatureChange.ts +++ b/packages/apollo-shared/src/Changes/AddFeatureChange.ts @@ -86,7 +86,7 @@ export class AddFeatureChange extends FeatureChange { for (const change of changes) { logger.debug?.(`change: ${JSON.stringify(change)}`) const { addedFeature, allIds, copyFeature, parentFeatureId } = change - const { refSeq } = addedFeature + const { _id, refSeq } = addedFeature const refSeqDoc = await refSeqModel .findById(refSeq) .session(session) @@ -111,7 +111,7 @@ export class AddFeatureChange extends FeatureChange { ) featureCnt++ } else { - addedFeature.gffId = addedFeature._id // User added manually new feature so then gffId = _id + addedFeature.gffId = _id // User added manually new feature so then gffId = _id // Adding new child feature if (parentFeatureId) { const topLevelFeature = await featureModel @@ -146,19 +146,19 @@ export class AddFeatureChange extends FeatureChange { } parentFeature.attributes = attributes } - parentFeature.children.set(addedFeature._id, { + parentFeature.children.set(_id, { allIds: [], ...addedFeature, // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error - _id: addedFeature._id, + _id, }) const childIds = this.getChildFeatureIds(addedFeature) - topLevelFeature.allIds.push(addedFeature._id, ...childIds) + topLevelFeature.allIds.push(_id, ...childIds) await topLevelFeature.save() } else { const childIds = this.getChildFeatureIds(addedFeature) - const allIdsV2 = [addedFeature._id, ...childIds] + const allIdsV2 = [_id, ...childIds] const [newFeatureDoc] = await featureModel.create( [{ allIds: allIdsV2, ...addedFeature }], { session }, diff --git a/packages/apollo-shared/src/Changes/DeleteAssemblyChange.ts b/packages/apollo-shared/src/Changes/DeleteAssemblyChange.ts index 70bd88089..c902aa71c 100644 --- a/packages/apollo-shared/src/Changes/DeleteAssemblyChange.ts +++ b/packages/apollo-shared/src/Changes/DeleteAssemblyChange.ts @@ -64,7 +64,7 @@ export class DeleteAssemblyChange extends AssemblySpecificChange { await refSeqModel.deleteMany({ assembly }).exec() await assemblyModel.findByIdAndDelete(assembly).exec() - this.logger.debug?.(`Assembly "${assembly}" deleted from database.`) + logger.debug?.(`Assembly "${assembly}" deleted from database.`) } async executeOnLocalGFF3(_backend: LocalGFF3DataStore) { diff --git a/packages/apollo-shared/src/Changes/DeleteFeatureChange.ts b/packages/apollo-shared/src/Changes/DeleteFeatureChange.ts index fd3d03d39..bc1c3eba6 100644 --- a/packages/apollo-shared/src/Changes/DeleteFeatureChange.ts +++ b/packages/apollo-shared/src/Changes/DeleteFeatureChange.ts @@ -132,7 +132,7 @@ export class DeleteFeatureChange extends FeatureChange { if (!feature.children) { throw new Error(`Feature ${feature._id} has no children`) } - const { children } = feature + const { _id, children } = feature const child = children.get(featureIdToDelete) if (child) { const deletedIds = this.getChildFeatureIds(child) @@ -147,9 +147,7 @@ export class DeleteFeatureChange extends FeatureChange { } } - throw new Error( - `Feature "${featureIdToDelete}" not found in ${feature._id}`, - ) + throw new Error(`Feature "${featureIdToDelete}" not found in ${_id}`) } async executeOnLocalGFF3(_backend: LocalGFF3DataStore) { diff --git a/packages/jbrowse-plugin-apollo/src/ApolloInternetAccount/model.ts b/packages/jbrowse-plugin-apollo/src/ApolloInternetAccount/model.ts index 6de4a3810..08e5c2ad5 100644 --- a/packages/jbrowse-plugin-apollo/src/ApolloInternetAccount/model.ts +++ b/packages/jbrowse-plugin-apollo/src/ApolloInternetAccount/model.ts @@ -230,11 +230,11 @@ const stateModelFactory = ( 'No LastChangeSequence stored in session. Please, refresh you browser to get last updates from server', ) } - const { baseURL } = self + const { baseURL, lastChangeSequenceNumber } = self const url = new URL('changes', baseURL) const searchParams = new URLSearchParams({ - since: String(self.lastChangeSequenceNumber), + since: String(lastChangeSequenceNumber), sort: '1', }) url.search = searchParams.toString() @@ -319,7 +319,7 @@ const stateModelFactory = ( 'label' in menuItem && menuItem.label === 'Add Assembly', ) ) { - pluginManager.rootModel.insertInMenu( + rootModel.insertInMenu( 'Apollo', { label: 'Add Assembly', @@ -339,7 +339,7 @@ const stateModelFactory = ( }, 0, ) - pluginManager.rootModel.insertInMenu( + rootModel.insertInMenu( 'Apollo', { label: 'Delete Assembly', @@ -359,7 +359,7 @@ const stateModelFactory = ( }, 1, ) - pluginManager.rootModel.insertInMenu( + rootModel.insertInMenu( 'Apollo', { label: 'Import Features', @@ -379,7 +379,7 @@ const stateModelFactory = ( }, 2, ) - pluginManager.rootModel.insertInMenu( + rootModel.insertInMenu( 'Apollo', { label: 'Manage Users', @@ -399,7 +399,7 @@ const stateModelFactory = ( }, 9, ) - pluginManager.rootModel.insertInMenu( + rootModel.insertInMenu( 'Apollo', { label: 'Undo', @@ -555,8 +555,11 @@ const stateModelFactory = ( })) .actions((self) => { const { + authType, getFetcher: superGetFetcher, getPreAuthorizationInformation: superGetPreAuthorizationInformation, + googleAuthInternetAccount, + microsoftAuthInternetAccount, retrieveToken: superRetrieveToken, } = self let authTypePromise: Promise | undefined @@ -574,16 +577,16 @@ const stateModelFactory = ( } }, retrieveToken() { - if (self.authType === 'google') { - return self.googleAuthInternetAccount.retrieveToken() + if (authType === 'google') { + return googleAuthInternetAccount.retrieveToken() } - if (self.authType === 'microsoft') { - return self.microsoftAuthInternetAccount.retrieveToken() + if (authType === 'microsoft') { + return microsoftAuthInternetAccount.retrieveToken() } - if (self.authType === 'guest') { + if (authType === 'guest') { return superRetrieveToken() } - throw new Error(`Unknown authType "${self.authType}"`) + throw new Error(`Unknown authType "${authType}"`) }, getFetcher( location?: UriLocation, @@ -593,6 +596,7 @@ const stateModelFactory = ( init?: RequestInit, ): Promise => { let { authType } = self + const { googleClientId, microsoftClientId } = self if (!authType) { if (!authTypePromise) { if (location?.internetAccountPreAuthorization) { @@ -624,8 +628,8 @@ const stateModelFactory = ( } doneCallback() }, - google: Boolean(self.googleClientId), - microsoft: Boolean(self.microsoftClientId), + google: Boolean(googleClientId), + microsoft: Boolean(microsoftClientId), allowGuestUser, }, ]) diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/components/LinearApolloDisplay.tsx b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/components/LinearApolloDisplay.tsx index 2bbc212f7..f20ba2fc7 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/components/LinearApolloDisplay.tsx +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/components/LinearApolloDisplay.tsx @@ -37,6 +37,7 @@ export const LinearApolloDisplay = observer(function LinearApolloDisplay( contextMenuItems: getContextMenuItems, cursor, featuresHeight, + isShown, onMouseDown, onMouseLeave, onMouseMove, @@ -54,7 +55,7 @@ export const LinearApolloDisplay = observer(function LinearApolloDisplay( const [contextCoord, setContextCoord] = useState() const [contextMenuItems, setContextMenuItems] = useState([]) const message = regionCannotBeRendered() - if (!model.isShown) { + if (!isShown) { return null } return ( diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts index d5123b096..29c84740c 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/CanonicalGeneGlyph.ts @@ -59,14 +59,14 @@ export class CanonicalGeneGlyph extends Glyph { row: number, reversed: boolean, ): void { - const { lgv, session, theme } = stateModel + const { apolloRowHeight, lgv, session, theme } = stateModel const { bpPerPx } = lgv - const rowHeight = stateModel.apolloRowHeight + const rowHeight = apolloRowHeight const utrHeight = Math.round(0.6 * rowHeight) const cdsHeight = Math.round(0.9 * rowHeight) - const { strand } = feature + const { _id, children, max, min, strand } = feature let currentCDS = 0 - for (const [, mrna] of feature.children ?? new Map()) { + for (const [, mrna] of children ?? new Map()) { if (mrna.type !== 'mRNA') { return } @@ -74,7 +74,7 @@ export class CanonicalGeneGlyph extends Glyph { if (cds.type !== 'CDS') { return } - const offsetPx = (mrna.start - feature.min) / bpPerPx + const offsetPx = (mrna.start - min) / bpPerPx const widthPx = mrna.length / bpPerPx const startPx = reversed ? xOffset - offsetPx - widthPx @@ -90,7 +90,7 @@ export class CanonicalGeneGlyph extends Glyph { } } currentCDS = 0 - for (const [, mrna] of feature.children ?? new Map()) { + for (const [, mrna] of children ?? new Map()) { if (mrna.type !== 'mRNA') { return } @@ -102,7 +102,7 @@ export class CanonicalGeneGlyph extends Glyph { if (exon.type !== 'exon') { return } - const offsetPx = (exon.start - feature.min) / bpPerPx + const offsetPx = (exon.start - min) / bpPerPx const widthPx = exon.length / bpPerPx const startPx = reversed ? xOffset - offsetPx - widthPx @@ -142,7 +142,7 @@ export class CanonicalGeneGlyph extends Glyph { } } currentCDS = 0 - for (const [, mrna] of feature.children ?? new Map()) { + for (const [, mrna] of children ?? new Map()) { if (mrna.type !== 'mRNA') { return } @@ -152,7 +152,7 @@ export class CanonicalGeneGlyph extends Glyph { } if (cds.discontinuousLocations) { for (const cdsLocation of cds.discontinuousLocations) { - const offsetPx = (cdsLocation.start - feature.min) / bpPerPx + const offsetPx = (cdsLocation.start - min) / bpPerPx const widthPx = (cdsLocation.end - cdsLocation.start) / bpPerPx const startPx = reversed ? xOffset - offsetPx - widthPx @@ -193,8 +193,8 @@ export class CanonicalGeneGlyph extends Glyph { } } const { apolloSelectedFeature } = session - if (apolloSelectedFeature && feature._id === apolloSelectedFeature._id) { - const widthPx = feature.max - feature.min + if (apolloSelectedFeature && _id === apolloSelectedFeature._id) { + const widthPx = max - min const startPx = reversed ? xOffset - widthPx : xOffset const top = row * rowHeight const height = this.getRowCount(feature, bpPerPx) * rowHeight @@ -214,7 +214,7 @@ export class CanonicalGeneGlyph extends Glyph { } const rowHeight = stateModel.apolloRowHeight const rowNumber = Math.floor(mousePosition.y / rowHeight) - const { featureLayouts } = stateModel + const { displayedRegions, featureLayouts, lgv, theme } = stateModel const layout = featureLayouts[mousePosition.regionNumber] const row = layout.get(rowNumber) const featureRowEntry = row?.find( @@ -223,25 +223,24 @@ export class CanonicalGeneGlyph extends Glyph { if (!featureRowEntry) { return } - const displayedRegion = - stateModel.displayedRegions[mousePosition.regionNumber] + const displayedRegion = displayedRegions[mousePosition.regionNumber] const x = - (stateModel.lgv.bpToPx({ + (lgv.bpToPx({ refName: displayedRegion.refName, coord: topLevelFeature.min, regionNumber: mousePosition.regionNumber, - })?.offsetPx ?? 0) - stateModel.lgv.offsetPx + })?.offsetPx ?? 0) - lgv.offsetPx const [featureRowNumber] = featureRowEntry const topRowNumber = rowNumber - featureRowNumber const y = topRowNumber * rowHeight - const { bpPerPx } = stateModel.lgv + const { bpPerPx } = lgv const width = topLevelFeature.end - topLevelFeature.start const widthPx = width / bpPerPx const startBp = displayedRegion.reversed ? topLevelFeature.max - topLevelFeature.end : topLevelFeature.start - topLevelFeature.min const startPx = startBp / bpPerPx - ctx.fillStyle = stateModel.theme?.palette.action.focus ?? 'rgba(0,0,0,0.04)' + ctx.fillStyle = theme?.palette.action.focus ?? 'rgba(0,0,0,0.04)' const height = this.getRowCount(topLevelFeature, bpPerPx) * rowHeight ctx.fillRect(x + startPx, y, widthPx, height) } diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts index 1a404c84c..161c67118 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/Glyph.ts @@ -103,7 +103,9 @@ export abstract class Glyph { changeManager, getAssemblyId, regions, + selectedFeature, session, + setSelectedFeature, } = display const { feature: sourceFeature } = apolloHover ?? {} const { getRole } = internetAccount @@ -167,8 +169,8 @@ export abstract class Glyph { changeManager, sourceFeature, sourceAssemblyId: currentAssemblyId, - selectedFeature: display.selectedFeature, - setSelectedFeature: display.setSelectedFeature, + selectedFeature, + setSelectedFeature, }, ]) }, diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts index 8d2059cf0..7b202e513 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/glyphs/ImplicitExonGeneGlyph.ts @@ -57,18 +57,18 @@ export class ImplicitExonGeneGlyph extends Glyph { row: number, reversed?: boolean, ): void { - const { lgv, session, theme } = stateModel + const { apolloRowHeight, lgv, session, theme } = stateModel const { bpPerPx } = lgv - const rowHeight = stateModel.apolloRowHeight + const rowHeight = apolloRowHeight const utrHeight = Math.round(0.6 * rowHeight) const cdsHeight = Math.round(0.9 * rowHeight) - const { strand } = feature + const { _id, children, max, min, strand } = feature let currentMRNA = 0 - for (const [, mrna] of feature.children ?? new Map()) { + for (const [, mrna] of children ?? new Map()) { if (mrna.type !== 'mRNA') { return } - const offsetPx = (mrna.start - feature.min) / bpPerPx + const offsetPx = (mrna.start - min) / bpPerPx const widthPx = mrna.length / bpPerPx const startPx = reversed ? xOffset - offsetPx - widthPx @@ -83,7 +83,7 @@ export class ImplicitExonGeneGlyph extends Glyph { currentMRNA += 1 } currentMRNA = 0 - for (const [, mrna] of feature.children ?? new Map()) { + for (const [, mrna] of children ?? new Map()) { if (mrna.type !== 'mRNA') { return } @@ -97,7 +97,7 @@ export class ImplicitExonGeneGlyph extends Glyph { if (!(isCDS || isUTR)) { return } - const offsetPx = (cdsOrUTR.start - feature.min) / bpPerPx + const offsetPx = (cdsOrUTR.start - min) / bpPerPx const widthPx = cdsOrUTR.length / bpPerPx const startPx = reversed ? xOffset - offsetPx - widthPx @@ -138,8 +138,8 @@ export class ImplicitExonGeneGlyph extends Glyph { currentMRNA += 1 } const { apolloSelectedFeature } = session - if (apolloSelectedFeature && feature._id === apolloSelectedFeature._id) { - const widthPx = feature.max - feature.min + if (apolloSelectedFeature && _id === apolloSelectedFeature._id) { + const widthPx = max - min const startPx = reversed ? xOffset - widthPx : xOffset const top = row * rowHeight const height = this.getRowCount(feature) * rowHeight diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/base.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/base.ts index b83b69129..442d9b0ad 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/base.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/base.ts @@ -36,13 +36,13 @@ export function baseModelFactory( lgv: getContainingView(self) as unknown as LinearGenomeViewModel, })) .views((self) => { - const { renderProps: superRenderProps } = self + const { configuration, renderProps: superRenderProps } = self return { renderProps() { return { ...superRenderProps(), ...getParentRenderProps(self), - config: self.configuration.renderer, + config: configuration.renderer, } }, } diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/mouseEvents.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/mouseEvents.ts index 19f3ee404..e2fec5214 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/mouseEvents.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/mouseEvents.ts @@ -157,12 +157,12 @@ export function mouseEventsModelFactory( return LinearApolloDisplayMouseEvents.views((self) => ({ contextMenuItems(contextCoord?: Coord): MenuItem[] { - const { apolloHover } = self + const { apolloHover, lgv } = self const { topLevelFeature } = apolloHover ?? {} if (!(topLevelFeature && contextCoord)) { return [] } - const glyph = getGlyph(topLevelFeature, self.lgv.bpPerPx) + const glyph = getGlyph(topLevelFeature, lgv.bpPerPx) return glyph.getContextMenuItems(self) }, })) diff --git a/packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts b/packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts index af7f5613a..3123926f7 100644 --- a/packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts +++ b/packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts @@ -119,12 +119,12 @@ export default class OntologyStore { const errors = [] // validate the source's file type - const { sourceType } = this + const { sourceLocation, sourceType } = this if (!sourceType) { errors.push( new Error( `unable to determine format of ontology source file ${JSON.stringify( - this.sourceLocation, + sourceLocation, )}, file name must end with ".json", ".obo", or ".owl"`, ), ) @@ -132,7 +132,7 @@ export default class OntologyStore { errors.push( new Error( `ontology source file ${JSON.stringify( - this.sourceLocation, + sourceLocation, )} has type ${sourceType}, which is not yet supported`, ), ) @@ -173,13 +173,13 @@ export default class OntologyStore { return db } - const { sourceType } = this + const { sourceLocation, sourceType } = this if (sourceType === 'obo-graph-json') { await this.loadOboGraphJson(db) } else { throw new Error( `ontology source file ${JSON.stringify( - this.sourceLocation, + sourceLocation, )} has type ${sourceType}, which is not yet supported`, ) } diff --git a/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts b/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts index 7e0741f0b..ac217215b 100644 --- a/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts +++ b/packages/jbrowse-plugin-apollo/src/SixFrameFeatureDisplay/stateModel.ts @@ -54,13 +54,13 @@ export function stateModelFactory( apolloRowUnderMouse: undefined as number | undefined, })) .views((self) => { - const { renderProps: superRenderProps } = self + const { configuration, renderProps: superRenderProps } = self return { renderProps() { return { ...superRenderProps(), ...getParentRenderProps(self), - config: self.configuration.renderer, + config: configuration.renderer, } }, } diff --git a/packages/jbrowse-plugin-apollo/src/TabularEditor/HybridGrid/Feature.tsx b/packages/jbrowse-plugin-apollo/src/TabularEditor/HybridGrid/Feature.tsx index 6c840ec4b..369dd77a8 100644 --- a/packages/jbrowse-plugin-apollo/src/TabularEditor/HybridGrid/Feature.tsx +++ b/packages/jbrowse-plugin-apollo/src/TabularEditor/HybridGrid/Feature.tsx @@ -65,13 +65,20 @@ function makeContextMenuItems( display: DisplayStateModel, feature: AnnotationFeatureI, ) { - const { changeManager, getAssemblyId, regions, session } = display + const { + changeManager, + getAssemblyId, + regions, + selectedFeature, + session, + setSelectedFeature, + } = display return featureContextMenuItems( feature, regions[0], getAssemblyId, - display.selectedFeature, - display.setSelectedFeature, + selectedFeature, + setSelectedFeature, session, changeManager, ) @@ -105,17 +112,22 @@ export const Feature = observer(function Feature({ setContextMenu: (menu: ContextMenuState) => void }) { const { classes } = useStyles() - const { tabularEditor: tabularEditorState } = displayState - const { filterText } = tabularEditorState - const expanded = !tabularEditorState.featureCollapsed.get(feature._id) + const { + apolloHover, + changeManager, + selectedFeature, + session, + tabularEditor: tabularEditorState, + } = displayState + const { featureCollapsed, filterText } = tabularEditorState + const expanded = !featureCollapsed.get(feature._id) const toggleExpanded = (e: React.MouseEvent) => { e.stopPropagation() tabularEditorState.setFeatureCollapsed(feature._id, expanded) } // pop up a snackbar in the session notifying user of an error - const notifyError = (e: Error) => - displayState.session.notify(e.message, 'error') + const notifyError = (e: Error) => session.notify(e.message, 'error') return ( <> @@ -167,7 +179,7 @@ export const Feature = observer(function Feature({ ) : null}
{ if (newValue) { handleFeatureTypeChange( - displayState.changeManager, + changeManager, feature, oldValue, newValue, @@ -209,7 +221,7 @@ export const Feature = observer(function Feature({ const newValue = Number(e.target.textContent) if (!Number.isNaN(newValue) && newValue !== feature.start) { handleFeatureStartChange( - displayState.changeManager, + changeManager, feature, feature.start, newValue, @@ -225,7 +237,7 @@ export const Feature = observer(function Feature({ const newValue = Number(e.target.textContent) if (!Number.isNaN(newValue) && newValue !== feature.end) { handleFeatureEndChange( - displayState.changeManager, + changeManager, feature, feature.end, newValue, @@ -252,9 +264,8 @@ export const Feature = observer(function Feature({ }) .map(([featureId, childFeature]) => { const childHovered = - displayState.apolloHover?.feature?._id === childFeature._id - const childSelected = - displayState.selectedFeature?._id === childFeature._id + apolloHover?.feature?._id === childFeature._id + const childSelected = selectedFeature?._id === childFeature._id return ( (null) const [contextMenu, setContextMenu] = useState(null) - const { filterText } = model.tabularEditor + const { filterText } = tabularEditor const internetAccount = useMemo(() => { return getApolloInternetAccount(getSession(model)) @@ -107,7 +107,7 @@ const HybridGrid = observer(function HybridGrid({ }) .map(([featureId, feature]) => { const isSelected = selectedFeature?._id === featureId - const isHovered = model.apolloHover?.feature?._id === featureId + const isHovered = apolloHover?.feature?._id === featureId return ( () const [selectedAssembly, setSelectedAssembly] = useState() @@ -47,14 +47,13 @@ export function ImportFeatures({ const [deleteFeatures, setDeleteFeatures] = useState(false) const [loading, setLoading] = useState(false) - const { collaborationServerDriver, getInternetAccount } = - session.apolloDataStore as { - collaborationServerDriver: CollaborationServerDriver - getInternetAccount( - assemblyName?: string, - internetAccountId?: string, - ): ApolloInternetAccount - } + const { collaborationServerDriver, getInternetAccount } = apolloDataStore as { + collaborationServerDriver: CollaborationServerDriver + getInternetAccount( + assemblyName?: string, + internetAccountId?: string, + ): ApolloInternetAccount + } const assemblies = collaborationServerDriver.getAssemblies() function handleChangeAssembly(e: SelectChangeEvent) { diff --git a/packages/jbrowse-plugin-apollo/src/makeDisplayComponent.tsx b/packages/jbrowse-plugin-apollo/src/makeDisplayComponent.tsx index 64785cc65..5170eb0ee 100644 --- a/packages/jbrowse-plugin-apollo/src/makeDisplayComponent.tsx +++ b/packages/jbrowse-plugin-apollo/src/makeDisplayComponent.tsx @@ -41,11 +41,11 @@ function scrollSelectedFeatureIntoView( model: LinearApolloDisplayI, scrollContainerRef: React.RefObject, ) { - const { selectedFeature } = model + const { apolloRowHeight, selectedFeature } = model if (scrollContainerRef.current && selectedFeature) { const position = model.getFeatureLayoutPosition(selectedFeature) if (position) { - const scrollPosition = position.layoutRow * model.apolloRowHeight + const scrollPosition = position.layoutRow * apolloRowHeight const oldScrollPosition = scrollContainerRef.current.scrollTop scrollContainerRef.current.scroll({ top: scrollPosition - oldScrollPosition, @@ -148,9 +148,15 @@ export const DisplayComponent = observer(function DisplayComponent({ }) { const { classes } = useStyles() - const { height: overallHeight, selectedFeature } = model - const detailsHeight = model.tabularEditor.isShown ? model.detailsHeight : 0 - const featureAreaHeight = model.isShown + const { + height: overallHeight, + isShown, + selectedFeature, + tabularEditor, + toggleShown, + } = model + const detailsHeight = tabularEditor.isShown ? model.detailsHeight : 0 + const featureAreaHeight = isShown ? overallHeight - detailsHeight - accordionControlHeight * 2 : 0 @@ -166,9 +172,9 @@ export const DisplayComponent = observer(function DisplayComponent({ return (
diff --git a/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts b/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts index 649da28b2..f5f7d70b8 100644 --- a/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts +++ b/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts @@ -83,12 +83,12 @@ export function clientDataStoreFactory( if (!feature) { throw new Error(`Could not find feature "${featureId}" to delete`) } - const { parent } = feature + const { _id, parent } = feature if (parent) { parent.deleteChild(featureId) } else { const refSeq = getParentOfType(feature, ApolloRefSeq) - refSeq.deleteFeature(feature._id) + refSeq.deleteFeature(_id) } }, deleteAssembly(assemblyId: string) { @@ -110,11 +110,11 @@ export function clientDataStoreFactory( // Merge in the ontologies from our plugin configuration. // Ontologies of a given name that are already in the session // take precedence over the ontologies in the configuration. - const { ontologyManager } = self - const configuredOntologies = self.pluginConfiguration - .ontologies as ConfigurationModel< - typeof OntologyRecordConfiguration - >[] + const { ontologyManager, pluginConfiguration } = self + const configuredOntologies = + pluginConfiguration.ontologies as ConfigurationModel< + typeof OntologyRecordConfiguration + >[] for (const ont of configuredOntologies || []) { const [name, version, source, indexFields] = [ @@ -225,7 +225,7 @@ export function clientDataStoreFactory( const { refSeq, seq } = yield ( self as unknown as { backendDriver: BackendDriver } ).backendDriver.getSequence(region) - const { assemblyName, refName } = region + const { assemblyName, end, refName, start } = region let assembly = self.assemblies.get(assemblyName) if (!assembly) { assembly = self.assemblies.put({ _id: assemblyName, refSeqs: {} }) @@ -239,8 +239,8 @@ export function clientDataStoreFactory( }) } ref.addSequence({ - start: region.start, - stop: region.end, + start, + stop: end, sequence: seq, }) } diff --git a/packages/jbrowse-plugin-apollo/src/session/session.ts b/packages/jbrowse-plugin-apollo/src/session/session.ts index 1748610af..50e19d7fd 100644 --- a/packages/jbrowse-plugin-apollo/src/session/session.ts +++ b/packages/jbrowse-plugin-apollo/src/session/session.ts @@ -255,7 +255,7 @@ export function extendSession( continue } - const { baseURL } = internetAccount + const { baseURL, configuration } = internetAccount const uri = new URL('assemblies', baseURL).href const fetch = internetAccount.getFetcher({ locationType: 'UriLocation', @@ -286,7 +286,7 @@ export function extendSession( continue } for (const assembly of fetchedAssemblies) { - const { assemblyManager } = self + const { addAssembly, addSessionAssembly, assemblyManager } = self const selectedAssembly = assemblyManager.get(assembly.name) if (selectedAssembly) { self.addApolloTrackConfig(selectedAssembly, baseURL) @@ -340,8 +340,7 @@ export function extendSession( }, metadata: { apollo: true, - internetAccountConfigId: - internetAccount.configuration.internetAccountId, + internetAccountConfigId: configuration.internetAccountId, ids, }, }, @@ -352,7 +351,7 @@ export function extendSession( }, }, } - ;(self.addSessionAssembly || self.addAssembly)(assemblyConfig) + ;(addSessionAssembly || addAssembly)(assemblyConfig) const a = yield assemblyManager.waitForAssembly(assemblyConfig.name) self.addApolloTrackConfig(a, baseURL) }