Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const datasets = [
]

const assembleFullQuery = (isSigningOfficial, isInstitutionQuery, subQuery) => {
const base = [{ match: { _type: 'dataset' } }, { exists: { field: 'study' } }]
const base = []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test mocks the query, hence this extra content is not needed.

if (!isSigningOfficial || !isInstitutionQuery) base.push({ term: { 'study.publicVisibility': true } })
if (subQuery) base.push(subQuery)
return { from: 0, size: 10000, query: { bool: { must: base } } }
Expand Down
53 changes: 29 additions & 24 deletions src/components/study_details/StudyDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EnumerateSnapshotModel, SnapshotSummaryModel } from 'src/types/tdrModel
import { DatasetSearchFooter } from 'src/components/data_search/DatasetSearchFooter'
import { applyForAccess } from 'src/utils/accessUtils'
import { usePageTitle } from 'src/hooks/usePageTitle'
import { getFlagEsIndexKeyName } from 'src/libs/ajax/FeatureFlag'

interface SectionProps {
style?: React.CSSProperties
Expand Down Expand Up @@ -84,35 +85,39 @@ export const StudyDetails = () => {
}

useEffect(() => {
const query = {
from: 0,
size: 10000,
query: {
bool: {
must: [
{
match: {
_type: 'dataset',
const init = async () => {
const esIndexKeyName = await getFlagEsIndexKeyName()
const query = {
from: 0,
size: 10000,
query: {
bool: {
must: [
{
match: {
[esIndexKeyName]: 'dataset',
},
},
},
{
match: {
'study.studyId': studyId,
{
match: {
'study.studyId': studyId,
},
},
},
{
exists: {
field: 'study',
{
exists: {
field: 'study',
},
},
},
],
],
},
},
},
}
DataSet.searchDatasetIndex(query).then((datasets) => {
setDatasets(datasets)
setLoading(false)
})
}
DataSet.searchDatasetIndex(query).then((datasets) => {
setDatasets(datasets)
setLoading(false)
})
init()
}, [studyId, setDatasets])

useEffect(() => {
Expand Down
24 changes: 18 additions & 6 deletions src/pages/DatasetSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { Metrics } from 'src/libs/ajax/Metrics'
import eventList from 'src/libs/events'
import { useParams, useNavigate } from 'react-router-dom'
import { usePageTitle } from 'src/hooks/usePageTitle'
import { getFlagNhgriDacId } from 'src/libs/ajax/FeatureFlag.ts'
import { getFlagEsIndexKeyName, getFlagNhgriDacId } from 'src/libs/ajax/FeatureFlag'

const assembleFullQuery = (isSigningOfficial, isInstitutionQuery, subQuery, nhgriDacId) => {
const assembleFullQuery = (isSigningOfficial, isInstitutionQuery, subQuery, nhgriDacId, esIndexKeyName) => {
const queryChunks = [
{
match: {
_type: 'dataset',
[esIndexKeyName]: 'dataset',
},
},
{
Expand Down Expand Up @@ -93,6 +93,7 @@ export const DatasetSearch = (props) => {
const [queryState, setQueryState] = useState(query)
const [loading, setLoading] = useState(true)
const [nhgriDacId, setNhgriDacId] = useState(null)
const [esIndexKeyName, setEsIndexKeyName] = useState(null)
const user = Storage.getCurrentUser()

const isSigningOfficial = user.isSigningOfficial
Expand All @@ -112,14 +113,25 @@ export const DatasetSearch = (props) => {

// Memoize fullQuery to prevent recreation on every render
const fullQuery = useMemo(
() => assembleFullQuery(isSigningOfficial, isInstitutionQuery, version.query, nhgriDacId),
[isSigningOfficial, isInstitutionQuery, version.query, nhgriDacId],
() => {
if (!esIndexKeyName) return null
return assembleFullQuery(isSigningOfficial, isInstitutionQuery, version.query, nhgriDacId, esIndexKeyName)
},
[isSigningOfficial, isInstitutionQuery, version.query, nhgriDacId, esIndexKeyName],
)

const isInstitutionSet = institutionId === undefined && isInstitutionQuery

const hasChangedPage = query !== queryState

useEffect(() => {
const init = async () => {
const keyName = await getFlagEsIndexKeyName()
setEsIndexKeyName(keyName)
}
init()
}, [])

useEffect(() => {
const init = async () => {
if (key === '/datalibrary') {
Expand All @@ -137,7 +149,7 @@ export const DatasetSearch = (props) => {

useEffect(() => {
const init = async () => {
if (loading || hasChangedPage) {
if ((loading || hasChangedPage) && fullQuery) {
if (isInstitutionSet) {
Notifications.showError({ text: 'You must set an institution in your profile to view the `myinstitution` data library' })
navigate('/profile')
Expand Down
4 changes: 3 additions & 1 deletion src/pages/DatasetStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getDataLocationLink } from 'src/utils/DataLocationUtils'
import { createDataUseDisplay } from 'src/utils/DataUseUtils'
import { useParams, useNavigate } from 'react-router-dom'
import { usePageTitle } from 'src/hooks/usePageTitle'
import { getFlagEsIndexKeyName } from 'src/libs/ajax/FeatureFlag'

const LINE = <div style={{ borderTop: '1px solid #BABEC1', height: 0 }} />

Expand Down Expand Up @@ -94,12 +95,13 @@ export default function DatasetStatistics() {
useEffect(() => {
const init = async () => {
try {
const esIndexKeyName = await getFlagEsIndexKeyName()
const datasetTerms: DatasetTerm[] = await DataSet.searchDatasetIndex({ query: {
bool: {
must: [
{
match: {
_type: 'dataset',
[esIndexKeyName]: 'dataset',
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion src/pages/researcher_console/DatasetSubmissions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Storage } from 'src/libs/storage'
import styles from './DatasetTerms.module.css'
import TableHeaderSection from 'src/components/TableHeaderSection'
import AddObjectButton from 'src/components/AddObjectButton.tsx'
import { getFlagEsIndexKeyName } from 'src/libs/ajax/FeatureFlag'

export default function DatasetSubmissions() {
const [terms, setTerms] = useState([])
Expand All @@ -23,6 +24,7 @@ export default function DatasetSubmissions() {
const init = async () => {
const user = Storage.getCurrentUser()
setCurrentUser(user)
const esIndexKeyName = await getFlagEsIndexKeyName()
const query = {
from: 0,
size: 10000,
Expand All @@ -31,7 +33,7 @@ export default function DatasetSubmissions() {
must: [
{
match: {
_type: 'dataset',
[esIndexKeyName]: 'dataset',
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion src/utils/BucketUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { Notifications } from 'src/libs/utils'
import { extractError } from 'src/utils/ErrorUtils'
import { ControlledAccessType } from 'src/libs/dataUseTranslation'
import { getFlagEsIndexKeyName } from 'src/libs/ajax/FeatureFlag'

export interface Bucket {
key: string
Expand Down Expand Up @@ -334,6 +335,7 @@ const createRpVoteStructureFromBuckets = (buckets: Bucket[]): Array<{ rp: VoteGr
* data use information so the UI doesn't have to reprocess it.
*/
const getDatasetTerms = async (datasets: Dataset[]): Promise<DatasetTerm[]> => {
const esIndexKeyName = await getFlagEsIndexKeyName()
const datasetQuery = DataSet.searchDatasetIndex({
from: 0,
size: 10000,
Expand All @@ -342,7 +344,7 @@ const getDatasetTerms = async (datasets: Dataset[]): Promise<DatasetTerm[]> => {
must: [
{
match: {
_type: 'dataset',
[esIndexKeyName]: 'dataset',
},
},
{
Expand Down
Loading