Skip to content

Commit

Permalink
Fine tune behavior, clean up code - #1121
Browse files Browse the repository at this point in the history
  • Loading branch information
libpitt committed Dec 21, 2023
1 parent c03ea00 commit a93f2ea
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
7 changes: 6 additions & 1 deletion src/components/custom/BulkExport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const handleCheckAll = (setTotalSelected) => {
getCheckAll().prop('checked', false)
}

function BulkExport({ data, raw, columns, exportKind, onCheckAll, replaceFirst = 'uuid' }) {
function BulkExport({ data, raw, columns, exportKind, onCheckAll, hiddenColumns, replaceFirst = 'uuid' }) {

const [totalSelected, setTotalSelected] = useState(0)

Expand Down Expand Up @@ -217,6 +217,11 @@ function BulkExport({ data, raw, columns, exportKind, onCheckAll, replaceFirst =
}
}

// Disable json output for now if there are hidden columns
if (hiddenColumns && Object.keys(hiddenColumns).length) {
delete actions['json']
}

return actions
}

Expand Down
16 changes: 6 additions & 10 deletions src/components/custom/TableResultsEntities.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function TableResultsEntities({children, filters, onRowClicked, forData = false,
let hasMultipleEntityTypes = checkMultipleFilterType(filters);
const {isLoggedIn, cache, getGroupName} = useContext(AppContext)
const currentColumns = useRef([])
const [tableColumns, setTableColumns] = useState(null)
const [hiddenColumns, setHiddenColumns] = useState([])

const raw = rowFn ? rowFn : ((obj) => obj ? obj.raw : null)

Expand All @@ -34,7 +34,7 @@ function TableResultsEntities({children, filters, onRowClicked, forData = false,
if (!inModal) {
cols.push({
ignoreRowClick: true,
name: <BulkExport data={children} raw={raw} columns={currentColumns} />,
name: <BulkExport data={children} raw={raw} hiddenColumns={hiddenColumns} columns={currentColumns} />,
width: '100px',
className: 'text-center',
selector: row => raw(row.sennet_id),
Expand Down Expand Up @@ -159,7 +159,7 @@ function TableResultsEntities({children, filters, onRowClicked, forData = false,
}
]

const getTableColumns = (applyColumnsFilters) => {
const getTableColumns = (columnsToHide) => {
let cols;
if (checkFilterType(filters) === false) {
cols = defaultColumns({});
Expand Down Expand Up @@ -195,9 +195,10 @@ function TableResultsEntities({children, filters, onRowClicked, forData = false,
cols = cols[typeIndex]
}

if (applyColumnsFilters) {
if (columnsToHide) {
setHiddenColumns(columnsToHide)
for (let col of cols) {
col.omit = applyColumnsFilters[col.name]
col.omit = columnsToHide[col.name]
}
}
currentColumns.current = cols;
Expand All @@ -208,18 +209,13 @@ function TableResultsEntities({children, filters, onRowClicked, forData = false,
return {sourceColumns, sampleColumns, datasetColumns, defaultColumns}
}

useEffect(()=> {
setTableColumns(null)
}, [])

// Prepare opsDict
getOptions(children.length)

return (
<>
<TableResultsProvider columnsRef={currentColumns} getId={getId} getHotLink={getHotLink} rows={children} filters={filters} onRowClicked={onRowClicked} forData={forData} raw={raw} inModal={inModal}>
<ResultsBlock
tableColumns={tableColumns} setTableColumns={setTableColumns}
getTableColumns={getTableColumns}
/>
</TableResultsProvider>
Expand Down
17 changes: 11 additions & 6 deletions src/components/custom/TableResultsFiles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ function TableResultsFiles({children, filters, forData = false, rowFn, inModal =
const [showModalDownloadBtn, setShowModalDownloadBtn] = useState(false)
const currentDatasetUuid = useRef(null)
const selectedFilesModal = useRef({})

const [tableColumns, setTableColumns] = useState(null)
const [columnsDropdown, setColumnsDropdown] = useState([])
const [hiddenColumns, setHiddenColumns] = useState([])

useEffect(() => {
const totalFileCount = rawResponse.records.files.length
Expand Down Expand Up @@ -177,7 +175,7 @@ function TableResultsFiles({children, filters, forData = false, rowFn, inModal =
if (!inModal) {
cols.push({
ignoreRowClick: true,
name: <BulkExport onCheckAll={onCheckAll} data={results} raw={raw} columns={currentColumns} exportKind={'manifest'} />,
name: <BulkExport onCheckAll={onCheckAll} data={results} raw={raw} hiddenColumns={hiddenColumns} columns={currentColumns} exportKind={'manifest'} />,
width: '100px',
className: 'text-center',
selector: row => row.id,
Expand Down Expand Up @@ -272,7 +270,7 @@ function TableResultsFiles({children, filters, forData = false, rowFn, inModal =
}


const getTableColumns = () => {
const getTableColumns = (columnsToHide) => {
let cols;
if (checkFilterType(filters, fileTypeField) === false) {
cols = defaultColumns({});
Expand All @@ -288,6 +286,14 @@ function TableResultsFiles({children, filters, forData = false, rowFn, inModal =
})
cols = cols[typeIndex]
}

if (columnsToHide) {
setHiddenColumns(columnsToHide)
for (let col of cols) {
col.omit = columnsToHide[col.name]
}
}

currentColumns.current = cols;
return cols;
}
Expand All @@ -308,7 +314,6 @@ function TableResultsFiles({children, filters, forData = false, rowFn, inModal =
<br /><small className={'text-muted'}>Note: For transferring data to the local machine, the <a href={'https://www.globus.org/globus-connect-personal'} target='_blank' className={'lnk--ic'}>Globus Connect Personal (GCP)<BoxArrowUpRight/></a> endpoint must also be up and running.</small>
</> />
<ResultsBlock
tableColumns={tableColumns} setTableColumns={setTableColumns}
tableClassName={'rdt_Results--Files'}
getTableColumns={getTableColumns}
/>
Expand Down
6 changes: 3 additions & 3 deletions src/components/custom/search/ColumnsDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import Select from 'react-select'


function ColumnsDropdown({ getTableColumns, setHiddenColumns, setTableColumns, currentColumns }) {
function ColumnsDropdown({ getTableColumns, setHiddenColumns, currentColumns }) {
const handleChange = (e) => {
if (e.length === (getTableColumns().length - 1)) {
e.pop()
Expand All @@ -13,7 +13,7 @@ function ColumnsDropdown({ getTableColumns, setHiddenColumns, setTableColumns, c
for (let out of e) {
removeColumns[out.value] = true
}

setHiddenColumns(removeColumns)
}

Expand Down Expand Up @@ -50,7 +50,7 @@ ColumnsDropdown.defaultProps = {}

ColumnsDropdown.propTypes = {
getTableColumns: PropTypes.func.isRequired,
setTableColumns: PropTypes.func.isRequired,
setHiddenColumns: PropTypes.func.isRequired,
}

export default ColumnsDropdown
9 changes: 2 additions & 7 deletions src/components/custom/search/ResultsBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import TableResultsContext from "../../../context/TableResultsContext";
import ColumnsDropdown from "./ColumnsDropdown";

function ResultsBlock({getTableColumns, tableColumns, setTableColumns, disableRowClick, tableClassName}) {
function ResultsBlock({getTableColumns, disableRowClick, tableClassName}) {

const {
getTableData,
Expand Down Expand Up @@ -36,18 +36,13 @@ function ResultsBlock({getTableColumns, tableColumns, setTableColumns, disableRo
}, [])


const handleTableColumns = (cols) => {
currentColumns.current.current = cols
setTableColumns(cols)
}

return (
<>
<div className='sui-layout-main-header'>
<div className='sui-layout-main-header__inner'>
<PagingInfo />
{<ColumnsDropdown filters={filters} getTableColumns={getTableColumns} setHiddenColumns={setHiddenColumns}
currentColumns={currentColumns.current} setTableColumns={handleTableColumns} />}
currentColumns={currentColumns.current} />}
<ResultsPerPage resultsPerPage={resultsPerPage} setResultsPerPage={setResultsPerPage} totalRows={rows.length} />
</div>
</div>
Expand Down

0 comments on commit a93f2ea

Please sign in to comment.