Skip to content

Commit

Permalink
Merge pull request #671 from ProteinsWebTeam/min_changes_sprint_54
Browse files Browse the repository at this point in the history
ScriptGen in subpages + Search propagated to ScriptGen + Homepage browsing by tab changes
  • Loading branch information
matthiasblum authored Nov 4, 2024
2 parents 46146db + 0085956 commit 4617421
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 101 deletions.
24 changes: 15 additions & 9 deletions src/components/DownloadForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ export class DownloadForm extends PureComponent<LoadedProps> {
// eslint-disable-next-line complexity, max-statements
_handleChange = (event?: FormEvent) => {
if (!this._ref.current) return;
const object: {
description: InterProPartialDescription;
search?: Record<string, string>;
subset?: boolean;
fileType?: string;
} = {
description: {},
const {
description,
search,
fileType: ft,
subset,
} = extractDataFromHash(this.props.matched);

const object = {
description: { ...description },
search: { ...search },
subset: subset,
fileType: ft,
};

const target = event?.target as HTMLElement;
// Only the add filters buttons trigger this method directly
if (target instanceof HTMLButtonElement) {
Expand Down Expand Up @@ -191,6 +197,7 @@ export class DownloadForm extends PureComponent<LoadedProps> {
// Since we can only have counter objects in JSON, change type to default
object.fileType = 'json';
}

const nextHash = [path, object.fileType, object.subset && 'subset']
.filter(Boolean)
.join('|');
Expand All @@ -201,7 +208,6 @@ export class DownloadForm extends PureComponent<LoadedProps> {
});
}
};

render() {
const { matched, api, lowGraphics, data } = this.props;
if (!data || !api) return null;
Expand All @@ -211,6 +217,7 @@ export class DownloadForm extends PureComponent<LoadedProps> {
fileType: ft,
subset,
} = extractDataFromHash(matched);

if (!description) return null;

const fileType = ft || 'json';
Expand Down Expand Up @@ -280,7 +287,6 @@ export class DownloadForm extends PureComponent<LoadedProps> {
};

const mainEndpoint = description[main as Endpoint];

return (
<form
onChange={this._handleChange}
Expand Down
18 changes: 18 additions & 0 deletions src/components/Matches/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ const Matches = ({
}

const isTaxonomySubpage = primary === 'taxonomy' && secondary === 'entry';

/* For matches in subpages, the URL is a composite one (e.g /entry/pfam/protein/UniProt)
The the browser URL needs to be reversed so that it is accepted by the API (e.g. /entry/pfam/protein/UniProt)
This already happens for the Browsable API button, but it doesn't for the script generator (which at this time uses the descriptionToPath function).
The processedSubPath variable will store the subpath computed based on the reversed URL.
*/
const reversedURL = toPublicAPI(
includeTaxonFocusedOnURL(getReversedUrl(state), focused),
);

const urlNoParams = reversedURL.split('?')[0];
const processedSubPath = '/' + urlNoParams.split('/api/')[1];

return (
<Table
dataTable={dataTable}
Expand Down Expand Up @@ -317,6 +330,11 @@ const Matches = ({
includeTaxonFocusedOnURL(getReversedUrl(state), focused),
)}
/>
<ExternalExportButton
search={search}
type={'scriptgen'}
subpath={processedSubPath}
/>
</div>
</Exporter>
)}
Expand Down
78 changes: 62 additions & 16 deletions src/components/home/BySpecies/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,146 +9,192 @@ exports[`<BySpecies /> By Species 1`] = `
element="div"
>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#5bc0de",
"description": "Saccharomyces cerevisiae (strain ATCC 204508 / S288c)",
"icon": "Y",
"kingdom": "Eukaryota",
"proteome_id": "UP000002311",
"tax_id": "559292",
"title": "Baker’s yeast",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#d9534f",
"description": "Caenorhabditis elegans",
"icon": "W",
"kingdom": "Eukaryota",
"proteome_id": "UP000001940",
"tax_id": "6239",
"title": "Caenorhabditis elegans",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#5bc0de",
"description": "Escherichia virus T4",
"icon": "v",
"kingdom": "Virus",
"proteome_id": "UP000009087",
"tax_id": "10665",
"title": "Enterobacteria phage T4",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#5bc0de",
"description": "Escherichia coli O127:H6 (strain E2348/69 / EPEC)",
"icon": "L",
"kingdom": "Bacteria",
"proteome_id": "UP000000625",
"tax_id": "83333",
"title": "Escherichia coli",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#5bc0de",
"description": "Schizosaccharomyces pombe (strain 972 / ATCC 24843)",
"icon": "Y",
"kingdom": "Eukaryota",
"proteome_id": "UP000002485",
"tax_id": "284812",
"title": "Fission yeast",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#d9534f",
"description": "Drosophila melanogaster",
"icon": "F",
"kingdom": "Eukaryota",
"proteome_id": "UP000000803",
"tax_id": "7227",
"title": "Fruit fly",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#5bc0de",
"description": "Escherichia virus T4",
"description": "Halobacterium salinarum",
"icon": "v",
"kingdom": "Archea",
"kingdom": "Archaea",
"proteome_id": "UP000000554",
"tax_id": "2242",
"title": "Halobacterium salinarum",
}
}
/>
<Species
entries={64093}
proteins={170588}
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#d9534f",
"description": "Homo sapiens",
"icon": "H",
"kingdom": "Eukaryota",
"proteome_id": "UP000005640",
"tax_id": "9606",
"title": "Human",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#d9534f",
"description": "Mus musculus",
"icon": "M",
"kingdom": "Eukaryota",
"proteome_id": "UP000000589",
"tax_id": "10090",
"title": "Mouse",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#5cb85c",
"description": "Arabidopsis thaliana",
"icon": "B",
"kingdom": "Eukaryota",
"proteome_id": "UP000006548",
"tax_id": "3702",
"title": "Mouse-ear cress",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#5cb85c",
"description": "Oryza sativa subsp. japonica",
"icon": "6",
"kingdom": "Eukaryota",
"proteome_id": "UP000059680",
"tax_id": "39947",
"title": "Rice",
}
}
/>
<Species
entries="..."
loading={true}
proteins="..."
species={
{
"color": "#d9534f",
"description": "Danio rerio",
"icon": "Z",
"kingdom": "Eukaryota",
"proteome_id": "UP000000437",
"tax_id": "7955",
"title": "Zebrafish",
}
Expand All @@ -161,9 +207,9 @@ exports[`<BySpecies /> By Species 1`] = `
{
"description": {
"main": {
"key": "taxonomy",
"key": "proteome",
},
"taxonomy": {
"proteome": {
"db": "uniprot",
},
},
Expand All @@ -181,15 +227,15 @@ exports[`<Species /> Species 1`] = `
data-testid="by-species-box"
>
<Memo(Connect(Link))
data-testid="species-9606"
data-testid="species-undefined"
to={
{
"description": {
"main": {
"key": "taxonomy",
"key": "proteome",
},
"taxonomy": {
"accession": "9606",
"proteome": {
"accession": undefined,
"db": "uniprot",
},
},
Expand Down Expand Up @@ -225,10 +271,10 @@ exports[`<Species /> Species 1`] = `
"isFilter": true,
},
"main": {
"key": "taxonomy",
"key": "proteome",
},
"taxonomy": {
"accession": "9606",
"proteome": {
"accession": undefined,
"db": "uniprot",
},
},
Expand All @@ -252,14 +298,14 @@ exports[`<Species /> Species 1`] = `
{
"description": {
"main": {
"key": "taxonomy",
"key": "proteome",
},
"protein": {
"db": "UniProt",
"isFilter": true,
},
"taxonomy": {
"accession": "9606",
"proteome": {
"accession": undefined,
"db": "uniprot",
},
},
Expand Down
Loading

0 comments on commit 4617421

Please sign in to comment.