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

Add ability to run field formatters on the feature details panel #3003

Merged
merged 10 commits into from Jun 9, 2022

Conversation

cmdcolin
Copy link
Collaborator

@cmdcolin cmdcolin commented Jun 3, 2022

Fixes #1981

This is a possible proposal for adding field formatters on the feature detail panel

Overview

Examples:

      "formatFields":  { "feature": "jexl:{name:'https://google.com/?q='+feature.id}" }

The above updates all name fields to be google links

      "formatFields": { "feature": "jexl:{name:'https://google.com/?q='+feature.name, newfield:'Wow'}" }

And if you had a complicated callback you could create a custom jexl callback e.g.

      "formatFields": { "feature": "jexl:{name:customFormatter(feature)}" }

The above only updates the top level feature to a google link, and adds a new field called newfield with the text Wow :)

Implementation

It is a little tricky but you can see that the jexl callback returns an object containing multiple fields which are merged directly onto the featureData

One other design I considered was something like

"formatFields": {
    "name":"jexl:\"https://google.com/?q=\"+feature.name",
    "random":"Wow"
}

This may be easier for the developer, and if needed, we can consider it, but the getConf would be evaluated in a non-standard way to achieve this (e.g. I'd have to manually run stringToJexlExpression and evaluate on the children of formatFields.

@github-actions github-actions bot added the needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) label Jun 3, 2022
@cmdcolin
Copy link
Collaborator Author

cmdcolin commented Jun 3, 2022

earlier pr #1987

@cmdcolin cmdcolin added enhancement New feature or request and removed needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) labels Jun 3, 2022
@cmdcolin cmdcolin force-pushed the add_extra_fields branch 2 times, most recently from f08d936 to 4cc02f4 Compare June 6, 2022 17:51
@cmdcolin cmdcolin requested a review from rbuels June 6, 2022 17:51
@cmdcolin
Copy link
Collaborator Author

cmdcolin commented Jun 7, 2022

the concept of origName/origId/origType was removed, now just dumps the HTML "innerText" of whatever is used for id/name/type into the accordion titles

@cmdcolin cmdcolin force-pushed the add_extra_fields branch 2 times, most recently from 68c0974 to 35a0d11 Compare June 7, 2022 18:18
@codecov
Copy link

codecov bot commented Jun 7, 2022

Codecov Report

Merging #3003 (e5ee9c3) into main (8df7c74) will increase coverage by 0.02%.
The diff coverage is 71.42%.

❗ Current head e5ee9c3 differs from pull request most recent head b09eca0. Consider uploading reports for the commit b09eca0 to get more accurate results

@@            Coverage Diff             @@
##             main    #3003      +/-   ##
==========================================
+ Coverage   61.33%   61.36%   +0.02%     
==========================================
  Files         584      584              
  Lines       26589    26609      +20     
  Branches     6439     6445       +6     
==========================================
+ Hits        16309    16328      +19     
- Misses       9973     9974       +1     
  Partials      307      307              
Impacted Files Coverage Δ
...re/pluggableElementTypes/models/baseTrackConfig.ts 58.33% <ø> (ø)
...breakpoint-split-view/src/components/Breakends.tsx 88.09% <ø> (ø)
...aseLinearDisplay/models/BaseLinearDisplayModel.tsx 85.91% <ø> (ø)
packages/core/BaseFeatureWidget/index.ts 62.50% <61.76%> (-12.50%) ⬇️
packages/core/util/jexl.ts 75.00% <68.57%> (+7.20%) ⬆️
...kages/core/BaseFeatureWidget/BaseFeatureDetail.tsx 78.65% <87.50%> (+1.63%) ⬆️
...ns/alignments/src/AlignmentsFeatureDetail/index.ts 100.00% <100.00%> (+16.66%) ⬆️
plugins/variants/src/VariantFeatureWidget/index.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8df7c74...b09eca0. Read the comment docs.

@cmdcolin cmdcolin force-pushed the add_extra_fields branch 2 times, most recently from 77f79cb to 0b510e4 Compare June 7, 2022 21:12
@cmdcolin
Copy link
Collaborator Author

cmdcolin commented Jun 7, 2022

made a slightly new alternative approach in this PR

the original concept completely overwrote the original feature data fields, so it replaced feature.name with a customized content

I wanted to avoid totally overwriting the feature data such as feature.name though, because for example, if it contained a hyperlink then it would get displayed badly in accordion headers or the sequence feature detail FASTA output

so, this PR now retains the old data but puts the formatted data in a field called _fmt on the feature object

so for example if I have a jexl callback that customizes name it might say

{
  "name": "EDEN",
  "start": 1,
  "end": 100,
  "_fmt": {
    "name": "https://google.com/?q=EDEN"
  }
}

Then, the core details and the attributes display the merged object data from basically {...obj, ...obj._fmt }

@cmdcolin
Copy link
Collaborator Author

cmdcolin commented Jun 7, 2022

also now uses a nested subschema for the config so we have

formatFields: {
   feature,
   subfeatures,
   depth
}

https://github.com/GMOD/jbrowse-components/pull/3003/files#diff-8e728ba842d4db42eaaa38288424736b839611cf13788776283fc67bb6a2b8e5R54-R72

This helps organize the related set of config slots!

@cmdcolin
Copy link
Collaborator Author

cmdcolin commented Jun 8, 2022

should be good to go

@cmdcolin cmdcolin force-pushed the add_extra_fields branch 3 times, most recently from 4b4934d to e5ee9c3 Compare June 8, 2022 21:28
@cmdcolin cmdcolin merged commit 112a0af into main Jun 9, 2022
@cmdcolin cmdcolin deleted the add_extra_fields branch June 9, 2022 23:13
@cmdcolin
Copy link
Collaborator Author

example screenshot

Screenshot from 2022-06-13 16-59-37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make feature detail formatters to allow things like external links
1 participant