Commit 2455d350 authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: hide loading spinner on 404 error on item history page

parent a89421d9
Pipeline #291388 passed with stages
in 15 minutes and 23 seconds
import { ItemHistorySearchResults } from '@/components/item-history/ItemHistorySearchResults'
import type { Dataset } from '@/data/sshoc/api/dataset'
import { useDatasetHistory } from '@/data/sshoc/hooks/dataset'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { QueryMetadata } from '@/lib/core/query/types'
export interface DatasetHistorySearchResultsProps {
persistentId: Dataset['persistentId']
......@@ -9,7 +11,16 @@ export interface DatasetHistorySearchResultsProps {
export function DatasetHistorySearchResults(props: DatasetHistorySearchResultsProps): JSX.Element {
const { persistentId } = props
const items = useDatasetHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const items = useDatasetHistory({ persistentId }, undefined, { meta })
return <ItemHistorySearchResults items={items} />
}
import { HttpError } from '@stefanprobst/request'
import type { UseQueryResult } from 'react-query'
import { NoSearchResultsFound } from '@/components/common/NoSearchResultsFound'
......@@ -14,6 +15,14 @@ export interface ItemHistorySearchResultsProps {
export function ItemHistorySearchResults(props: ItemHistorySearchResultsProps): JSX.Element {
const { items } = props
if (items.isError && items.error instanceof HttpError && items.error.response.status === 404) {
return (
<section className={css['container']} data-state="empty">
<NoSearchResultsFound />
</section>
)
}
if (items.data == null) {
return (
<section className={css['container']} data-state="loading">
......
import { ItemHistorySearchResults } from '@/components/item-history/ItemHistorySearchResults'
import type { Publication } from '@/data/sshoc/api/publication'
import { usePublicationHistory } from '@/data/sshoc/hooks/publication'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { QueryMetadata } from '@/lib/core/query/types'
export interface PublicationHistorySearchResultsProps {
persistentId: Publication['persistentId']
......@@ -11,7 +13,16 @@ export function PublicationHistorySearchResults(
): JSX.Element {
const { persistentId } = props
const items = usePublicationHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const items = usePublicationHistory({ persistentId }, undefined, { meta })
return <ItemHistorySearchResults items={items} />
}
import { ItemHistorySearchResults } from '@/components/item-history/ItemHistorySearchResults'
import type { Tool } from '@/data/sshoc/api/tool-or-service'
import { useToolHistory } from '@/data/sshoc/hooks/tool-or-service'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { QueryMetadata } from '@/lib/core/query/types'
export interface ToolHistorySearchResultsProps {
persistentId: Tool['persistentId']
......@@ -9,7 +11,16 @@ export interface ToolHistorySearchResultsProps {
export function ToolHistorySearchResults(props: ToolHistorySearchResultsProps): JSX.Element {
const { persistentId } = props
const items = useToolHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const items = useToolHistory({ persistentId }, undefined, { meta })
return <ItemHistorySearchResults items={items} />
}
import { ItemHistorySearchResults } from '@/components/item-history/ItemHistorySearchResults'
import type { TrainingMaterial } from '@/data/sshoc/api/training-material'
import { useTrainingMaterialHistory } from '@/data/sshoc/hooks/training-material'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { QueryMetadata } from '@/lib/core/query/types'
export interface TrainingMaterialHistorySearchResultsProps {
persistentId: TrainingMaterial['persistentId']
......@@ -11,7 +13,16 @@ export function TrainingMaterialHistorySearchResults(
): JSX.Element {
const { persistentId } = props
const items = useTrainingMaterialHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const items = useTrainingMaterialHistory({ persistentId }, undefined, { meta })
return <ItemHistorySearchResults items={items} />
}
import { ItemHistorySearchResults } from '@/components/item-history/ItemHistorySearchResults'
import type { Workflow } from '@/data/sshoc/api/workflow'
import { useWorkflowHistory } from '@/data/sshoc/hooks/workflow'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { QueryMetadata } from '@/lib/core/query/types'
export interface WorkflowHistorySearchResultsProps {
persistentId: Workflow['persistentId']
......@@ -11,7 +13,16 @@ export function WorkflowHistorySearchResults(
): JSX.Element {
const { persistentId } = props
const items = useWorkflowHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const items = useWorkflowHistory({ persistentId }, undefined, { meta })
return <ItemHistorySearchResults items={items} />
}
......@@ -18,6 +18,7 @@ import { DatasetHistorySearchResults } from '@/components/item-history/DatasetHi
import { ItemHistoryScreenLayout } from '@/components/item-history/ItemHistoryScreenLayout'
import type { Dataset } from '@/data/sshoc/api/dataset'
import { useDatasetHistory } from '@/data/sshoc/hooks/dataset'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { PageComponent } from '@/lib/core/app/types'
import { getLocale } from '@/lib/core/i18n/getLocale'
import { getLocales } from '@/lib/core/i18n/getLocales'
......@@ -27,6 +28,7 @@ import { useI18n } from '@/lib/core/i18n/useI18n'
import { PageMetadata } from '@/lib/core/metadata/PageMetadata'
import { routes } from '@/lib/core/navigation/routes'
import { PageMainContent } from '@/lib/core/page/PageMainContent'
import type { QueryMetadata } from '@/lib/core/query/types'
import { Breadcrumbs } from '@/lib/core/ui/Breadcrumbs/Breadcrumbs'
import { Centered } from '@/lib/core/ui/Centered/Centered'
import { FullPage } from '@/lib/core/ui/FullPage/FullPage'
......@@ -79,7 +81,16 @@ export async function getStaticProps(
export default function DatasetHistoryPage(props: DatasetHistoryPage.Props): JSX.Element {
const { persistentId } = props.params
const datasetHistory = useDatasetHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const datasetHistory = useDatasetHistory({ persistentId }, undefined, { meta })
const router = useRouter()
const { t } = useI18n<'authenticated' | 'common'>()
......@@ -91,7 +102,7 @@ export default function DatasetHistoryPage(props: DatasetHistoryPage.Props): JSX
const label = dataset?.label ?? t(['common', 'item-categories', category, 'one'])
const title = t(['authenticated', 'item-history', 'item-history'], { values: { item: label } })
if (router.isFallback || datasetHistory.data == null) {
if (router.isFallback) {
return (
<Fragment>
<PageMetadata title={title} />
......
......@@ -18,6 +18,7 @@ import { ItemHistoryScreenLayout } from '@/components/item-history/ItemHistorySc
import { PublicationHistorySearchResults } from '@/components/item-history/PublicationHistorySearchResults'
import type { Publication } from '@/data/sshoc/api/publication'
import { usePublicationHistory } from '@/data/sshoc/hooks/publication'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { PageComponent } from '@/lib/core/app/types'
import { getLocale } from '@/lib/core/i18n/getLocale'
import { getLocales } from '@/lib/core/i18n/getLocales'
......@@ -27,6 +28,7 @@ import { useI18n } from '@/lib/core/i18n/useI18n'
import { PageMetadata } from '@/lib/core/metadata/PageMetadata'
import { routes } from '@/lib/core/navigation/routes'
import { PageMainContent } from '@/lib/core/page/PageMainContent'
import type { QueryMetadata } from '@/lib/core/query/types'
import { Breadcrumbs } from '@/lib/core/ui/Breadcrumbs/Breadcrumbs'
import { Centered } from '@/lib/core/ui/Centered/Centered'
import { FullPage } from '@/lib/core/ui/FullPage/FullPage'
......@@ -79,7 +81,16 @@ export async function getStaticProps(
export default function PublicationHistoryPage(props: PublicationHistoryPage.Props): JSX.Element {
const { persistentId } = props.params
const publicationHistory = usePublicationHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const publicationHistory = usePublicationHistory({ persistentId }, undefined, { meta })
const router = useRouter()
const { t } = useI18n<'authenticated' | 'common'>()
......@@ -91,7 +102,7 @@ export default function PublicationHistoryPage(props: PublicationHistoryPage.Pro
const label = publication?.label ?? t(['common', 'item-categories', category, 'one'])
const title = t(['authenticated', 'item-history', 'item-history'], { values: { item: label } })
if (router.isFallback || publicationHistory.data == null) {
if (router.isFallback) {
return (
<Fragment>
<PageMetadata title={title} />
......
......@@ -18,6 +18,7 @@ import { ItemHistoryScreenLayout } from '@/components/item-history/ItemHistorySc
import { ToolHistorySearchResults } from '@/components/item-history/ToolHistorySearchResults'
import type { Tool } from '@/data/sshoc/api/tool-or-service'
import { useToolHistory } from '@/data/sshoc/hooks/tool-or-service'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { PageComponent } from '@/lib/core/app/types'
import { getLocale } from '@/lib/core/i18n/getLocale'
import { getLocales } from '@/lib/core/i18n/getLocales'
......@@ -27,6 +28,7 @@ import { useI18n } from '@/lib/core/i18n/useI18n'
import { PageMetadata } from '@/lib/core/metadata/PageMetadata'
import { routes } from '@/lib/core/navigation/routes'
import { PageMainContent } from '@/lib/core/page/PageMainContent'
import type { QueryMetadata } from '@/lib/core/query/types'
import { Breadcrumbs } from '@/lib/core/ui/Breadcrumbs/Breadcrumbs'
import { Centered } from '@/lib/core/ui/Centered/Centered'
import { FullPage } from '@/lib/core/ui/FullPage/FullPage'
......@@ -81,7 +83,16 @@ export default function ToolOrServiceHistoryPage(
props: ToolOrServiceHistoryPage.Props,
): JSX.Element {
const { persistentId } = props.params
const toolHistory = useToolHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const toolHistory = useToolHistory({ persistentId }, undefined, { meta })
const router = useRouter()
const { t } = useI18n<'authenticated' | 'common'>()
......@@ -93,7 +104,7 @@ export default function ToolOrServiceHistoryPage(
const label = tool?.label ?? t(['common', 'item-categories', category, 'one'])
const title = t(['authenticated', 'item-history', 'item-history'], { values: { item: label } })
if (router.isFallback || toolHistory.data == null) {
if (router.isFallback) {
return (
<Fragment>
<PageMetadata title={title} />
......
......@@ -18,6 +18,7 @@ import { ItemHistoryScreenLayout } from '@/components/item-history/ItemHistorySc
import { TrainingMaterialHistorySearchResults } from '@/components/item-history/TrainingMaterialHistorySearchResults'
import type { TrainingMaterial } from '@/data/sshoc/api/training-material'
import { useTrainingMaterialHistory } from '@/data/sshoc/hooks/training-material'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { PageComponent } from '@/lib/core/app/types'
import { getLocale } from '@/lib/core/i18n/getLocale'
import { getLocales } from '@/lib/core/i18n/getLocales'
......@@ -27,6 +28,7 @@ import { useI18n } from '@/lib/core/i18n/useI18n'
import { PageMetadata } from '@/lib/core/metadata/PageMetadata'
import { routes } from '@/lib/core/navigation/routes'
import { PageMainContent } from '@/lib/core/page/PageMainContent'
import type { QueryMetadata } from '@/lib/core/query/types'
import { Breadcrumbs } from '@/lib/core/ui/Breadcrumbs/Breadcrumbs'
import { Centered } from '@/lib/core/ui/Centered/Centered'
import { FullPage } from '@/lib/core/ui/FullPage/FullPage'
......@@ -81,7 +83,16 @@ export default function TrainingMaterialHistoryPage(
props: TrainingMaterialHistoryPage.Props,
): JSX.Element {
const { persistentId } = props.params
const trainingMaterialHistory = useTrainingMaterialHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const trainingMaterialHistory = useTrainingMaterialHistory({ persistentId }, undefined, { meta })
const router = useRouter()
const { t } = useI18n<'authenticated' | 'common'>()
......@@ -93,7 +104,7 @@ export default function TrainingMaterialHistoryPage(
const label = trainingMaterial?.label ?? t(['common', 'item-categories', category, 'one'])
const title = t(['authenticated', 'item-history', 'item-history'], { values: { item: label } })
if (router.isFallback || trainingMaterialHistory.data == null) {
if (router.isFallback) {
return (
<Fragment>
<PageMetadata title={title} />
......
......@@ -18,6 +18,7 @@ import { ItemHistoryScreenLayout } from '@/components/item-history/ItemHistorySc
import { WorkflowHistorySearchResults } from '@/components/item-history/WorkflowHistorySearchResults'
import type { Workflow } from '@/data/sshoc/api/workflow'
import { useWorkflowHistory } from '@/data/sshoc/hooks/workflow'
import { isNotFoundError } from '@/data/sshoc/utils/isNotFoundError'
import type { PageComponent } from '@/lib/core/app/types'
import { getLocale } from '@/lib/core/i18n/getLocale'
import { getLocales } from '@/lib/core/i18n/getLocales'
......@@ -27,6 +28,7 @@ import { useI18n } from '@/lib/core/i18n/useI18n'
import { PageMetadata } from '@/lib/core/metadata/PageMetadata'
import { routes } from '@/lib/core/navigation/routes'
import { PageMainContent } from '@/lib/core/page/PageMainContent'
import type { QueryMetadata } from '@/lib/core/query/types'
import { Breadcrumbs } from '@/lib/core/ui/Breadcrumbs/Breadcrumbs'
import { Centered } from '@/lib/core/ui/Centered/Centered'
import { FullPage } from '@/lib/core/ui/FullPage/FullPage'
......@@ -79,7 +81,16 @@ export async function getStaticProps(
export default function WorkflowHistoryPage(props: WorkflowHistoryPage.Props): JSX.Element {
const { persistentId } = props.params
const workflowHistory = useWorkflowHistory({ persistentId })
const meta: QueryMetadata = {
messages: {
error(error) {
if (isNotFoundError(error)) return false
return undefined
},
},
}
const workflowHistory = useWorkflowHistory({ persistentId }, undefined, { meta })
const router = useRouter()
const { t } = useI18n<'authenticated' | 'common'>()
......@@ -91,7 +102,7 @@ export default function WorkflowHistoryPage(props: WorkflowHistoryPage.Props): J
const label = workflow?.label ?? t(['common', 'item-categories', category, 'one'])
const title = t(['authenticated', 'item-history', 'item-history'], { values: { item: label } })
if (router.isFallback || workflowHistory.data == null) {
if (router.isFallback) {
return (
<Fragment>
<PageMetadata title={title} />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment