Skip to content

Commit aa496fd

Browse files
author
Sebastian Benjamin
committed
Add share button to VariantTable
1 parent 763e79b commit aa496fd

File tree

4 files changed

+82
-23
lines changed

4 files changed

+82
-23
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { Button } from '@mui/material';
3+
import LinkIcon from '@mui/icons-material/Link';
4+
5+
export const ShareButton = () => {
6+
return (
7+
<Button
8+
startIcon={<LinkIcon />}
9+
size="small"
10+
color="primary"
11+
onClick={() => {
12+
navigator.clipboard.writeText(window.location.href)
13+
.then(() => {
14+
alert('URL copied to clipboard.');
15+
})
16+
.catch(err => {
17+
console.error('Failed to copy the URL: ', err);
18+
alert('Failed to copy the URL.');
19+
});
20+
}}
21+
>
22+
Share
23+
</Button>
24+
);
25+
};

jbrowse/src/client/JBrowse/VariantSearch/components/VariantTableWidget.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
GridToolbarExport
1414
} from '@mui/x-data-grid';
1515
import SearchIcon from '@mui/icons-material/Search';
16-
import LinkIcon from '@mui/icons-material/Link';
1716
import React, { useEffect, useState } from 'react';
1817
import { getConf } from '@jbrowse/core/configuration';
1918
import { AppBar, Box, Button, Dialog, Paper, Popover, Toolbar, Tooltip, Typography } from '@mui/material';
@@ -37,6 +36,7 @@ import '../../jbrowse.css';
3736
import LoadingIndicator from './LoadingIndicator';
3837
import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
3938
import { lastValueFrom } from 'rxjs';
39+
import { ShareButton } from './ShareButton';
4040

4141
const VariantTableWidget = observer(props => {
4242
const numberFormatter = new Intl.NumberFormat('en-US');
@@ -201,25 +201,7 @@ const VariantTableWidget = observer(props => {
201201
delimiter: ';',
202202
}} />
203203

204-
<Button
205-
startIcon={<LinkIcon />}
206-
size="small"
207-
color="primary"
208-
onClick={() => {
209-
navigator.clipboard.writeText(window.location.href)
210-
.then(() => {
211-
// Popup message for successful copy
212-
alert('URL copied to clipboard.');
213-
})
214-
.catch(err => {
215-
// Error handling
216-
console.error('Failed to copy the URL: ', err);
217-
alert('Failed to copy the URL.');
218-
});
219-
}}
220-
>
221-
Share
222-
</Button>
204+
<ShareButton />
223205
</GridToolbarContainer>
224206
);
225207
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { Button } from '@mui/material';
3+
import LinkIcon from '@mui/icons-material/Link';
4+
5+
export const ShareButton = () => {
6+
return (
7+
<Button
8+
startIcon={<LinkIcon />}
9+
size="small"
10+
color="primary"
11+
onClick={() => {
12+
navigator.clipboard.writeText(window.location.href)
13+
.then(() => {
14+
alert('URL copied to clipboard.');
15+
})
16+
.catch(err => {
17+
console.error('Failed to copy the URL: ', err);
18+
alert('Failed to copy the URL.');
19+
});
20+
}}
21+
>
22+
Share
23+
</Button>
24+
);
25+
};

jbrowse/src/client/JBrowse/VariantTable/components/VariantTableWidget.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@ import React, { useEffect, useState } from 'react';
33
import { getConf } from '@jbrowse/core/configuration';
44
import { ParsedLocString, parseLocString } from '@jbrowse/core/util';
55
import { getAdapter } from '@jbrowse/core/data_adapters/dataAdapterCache';
6-
import { AppBar, Box, Button, Dialog, Grid, MenuItem, Paper, Toolbar, Typography } from '@mui/material';
6+
import {
7+
AppBar,
8+
Box,
9+
Button,
10+
Dialog,
11+
Grid,
12+
MenuItem,
13+
Paper,
14+
Toolbar,
15+
Typography,
16+
} from '@mui/material';
717
import ScopedCssBaseline from '@mui/material/ScopedCssBaseline';
818
import {
919
DataGrid,
1020
GridColDef,
1121
GridColumnVisibilityModel, GridFilterPanel,
1222
GridPaginationModel,
1323
GridRenderCellParams,
14-
GridToolbar
24+
GridToolbar,
25+
GridToolbarColumnsButton,
26+
GridToolbarFilterButton,
27+
GridToolbarDensitySelector,
28+
GridToolbarExport
1529
} from '@mui/x-data-grid';
1630
import MenuButton from './MenuButton';
1731
import '../../jbrowse.css';
@@ -27,6 +41,7 @@ import {
2741
passesSampleFilters
2842
} from '../../utils';
2943
import LoadingIndicator from './LoadingIndicator';
44+
import { ShareButton } from './ShareButton';
3045
import { NoAssemblyRegion } from '@jbrowse/core/util/types';
3146
import StandaloneSearchComponent from '../../Search/components/StandaloneSearchComponent';
3247
import { VcfFeature } from '@jbrowse/plugin-variants';
@@ -352,12 +367,24 @@ const VariantTableWidget = observer(props => {
352367
}
353368
}
354369

370+
const CustomToolbar = () => (
371+
<Box sx={{ display: 'flex', justifyContent: 'space-between', p: 1 }}>
372+
<Box>
373+
<GridToolbarColumnsButton />
374+
<GridToolbarFilterButton />
375+
<GridToolbarDensitySelector />
376+
<GridToolbarExport />
377+
<ShareButton />
378+
</Box>
379+
</Box>
380+
);
381+
355382
const gridElement = (
356383
// NOTE: the filterPanel/sx override is added to fix an issue where the grid column filter value input doesn't align with the field and operator inputs
357384
<DataGrid
358385
columns={[...gridColumns, actionsCol]}
359386
rows={features.map((rawFeature, id) => rawFeatureToRow(rawFeature, id, gridColumns, trackId))}
360-
slots={{ toolbar: GridToolbar, filterPanel: GridFilterPanel }}
387+
slots={{ toolbar: CustomToolbar, filterPanel: GridFilterPanel }}
361388
slotProps={{
362389
filterPanel: {
363390
filterFormProps: {

0 commit comments

Comments
 (0)