Skip to content

Commit

Permalink
CORE-4990: add error view
Browse files Browse the repository at this point in the history
  • Loading branch information
ekachxaidze98 committed Sep 9, 2024
1 parent 54cab8a commit 9d1b663
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 23 deletions.
1 change: 1 addition & 0 deletions pages/data-providers/[data-provider-id]/deduplication.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const DeduplicationPage = ({ store, ...props }) => (
getDeduplicationData={store.dataProvider?.getDeduplicationData}
duplicateDataLoading={store.dataProvider?.duplicateDataLoading}
harvestingStatus={store.dataProvider?.issues?.harvestingStatus}
harvestingError={store.dataProvider?.issues?.harvestingError}
duplicateList={store.dataProvider?.duplicateList}
getDeduplicationInfo={store.dataProvider?.getDeduplicationInfo}
duplicateListDetails={store.dataProvider?.duplicateListDetails}
Expand Down
1 change: 1 addition & 0 deletions pages/data-providers/[data-provider-id]/indexing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { withGlobalStore } from 'store'
const HarvestingPage = ({ store, store: { dataProvider }, ...props }) => (
<HarvestingPageTemplate
harvestingStatus={dataProvider?.issues?.harvestingStatus}
harvestingError={store.dataProvider?.issues?.harvestingError}
aggregation={dataProvider?.issues?.aggregation}
issuesByType={dataProvider?.issues?.issuesByType}
errorsCount={dataProvider?.issues?.aggregation?.errorsCount}
Expand Down
16 changes: 13 additions & 3 deletions store/issues.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// store/issues.js
import { action, observable } from 'mobx'

import Store from './store'
Expand All @@ -6,6 +7,8 @@ import { Pages } from './helpers/pages'
class Issues extends Store {
@observable harvestingStatus = null

@observable harvestingError = false

@observable aggregation = null

@observable issuesByType = new Map()
Expand All @@ -26,12 +29,19 @@ class Issues extends Store {

const options = refresh ? { cache: 'reload' } : {}

const { data } = await this.request(url, options)
this.harvestingStatus = data
return data
const response = await this.request(url, options)
if (response.status === 200) {
this.harvestingStatus = response.data
this.harvestingError = false
} else {
this.harvestingStatus = null
this.harvestingError = true
}
return response.data
} catch (error) {
console.error('Error fetching harvesting status:', error)
this.harvestingStatus = null
this.harvestingError = true
throw error
}
}
Expand Down
22 changes: 15 additions & 7 deletions templates/deduplication/cards/deduplicationInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import React from 'react'
import styles from '../styles.module.css'
import texts from '../../../texts/deduplication/deduplication.yml'
import { formatDate, valueOrDefault } from '../../../utils/helpers'
import info from '../../../components/upload/assets/info.svg'

import { Card } from 'design'

const DeduplicationInfoCard = ({ harvestingStatus }) => (
const DeduplicationInfoCard = ({ harvestingStatus, harvestingError }) => (
<Card
className={styles.deduplicationInfoCardWrapper}
tag="section"
Expand All @@ -18,12 +19,19 @@ const DeduplicationInfoCard = ({ harvestingStatus }) => (
</Card.Title>
</div>
<div className={styles.innerWrapper}>
<span className={styles.text}>
{valueOrDefault(
formatDate(harvestingStatus?.lastHarvestingDate),
'Loading...'
)}
</span>
{harvestingError ? (
<div className={styles.errorsWrapper}>
<img className={styles.infoIcon} src={info} alt="riox" />
<p className={styles.errorText}>This data is not available now. </p>
</div>
) : (
<span className={styles.text}>
{valueOrDefault(
formatDate(harvestingStatus?.lastHarvestingDate),
'Loading...'
)}
</span>
)}
</div>
<Card.Description className={styles.cardDescription}>
{texts.info.description}
Expand Down
7 changes: 6 additions & 1 deletion templates/deduplication/index.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// templates/deduplication/index.jsx
import React, { useEffect, useState } from 'react'
import { classNames } from '@oacore/design/lib/utils'
import { useRouter } from 'next/router'
Expand All @@ -20,6 +21,7 @@ const DeduplicationPageTemplate = observer(
getDeduplicationInfo,
duplicateListDetails,
harvestingStatus,
harvestingError,
getOutputsData,
outputData,
getWorksData,
Expand Down Expand Up @@ -85,7 +87,10 @@ const DeduplicationPageTemplate = observer(
}
/>
<div className={styles.cardsWrapper}>
<DeduplicationInfoCard harvestingStatus={harvestingStatus} />
<DeduplicationInfoCard
harvestingError={harvestingError}
harvestingStatus={harvestingStatus}
/>
<DeduplicationStatistics
duplicateList={duplicateList}
duplicatesUrl={duplicatesUrl}
Expand Down
14 changes: 14 additions & 0 deletions templates/deduplication/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@
margin-right: 55px;
}

.errors-wrapper {
background: #f5f5f5;
display: flex;
height: 48px;
padding: 12px 16px;
align-items: center;
gap: 10px;
width: max-content;
}

.error-text {
margin-top: unset;
}

.inner-sub-title {
margin: 4px 0 12px;
font-size: 14px;
Expand Down
44 changes: 33 additions & 11 deletions templates/harvesting/cards/harvesting-progress.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useContext, useState } from 'react'
import React, { useContext, useState, useEffect } from 'react'
import { classNames } from '@oacore/design/lib/utils'
import { Popover } from '@oacore/design'
import { observer } from 'mobx-react-lite'

import info from '../../../components/upload/assets/info.svg'
import { GlobalContext } from '../../../store'
import styles from '../styles.module.css'
import { Button, ProgressSpinner } from '../../../design'
Expand All @@ -15,12 +16,14 @@ import { Card } from 'design'
import texts from 'texts/issues'

const HarvestingProgressCard = observer(
({ harvestingStatus, sendHarvestingRequest }) => {
({ harvestingStatus, sendHarvestingRequest, harvestingError }) => {
const { ...globalStore } = useContext(GlobalContext)
const [loading, setLoading] = useState(false)
const [success, setSuccess] = useState(false)
const [modalOpen, setModalOpen] = useState(false)
const [errorMessage, setErrorMessage] = useState(null)
const [renderedContent, setRenderedContent] = useState(null)

const dayInterval = (lastHarvestingDateString) => {
const lastHarvestingDate = new Date(lastHarvestingDateString)
const currentDate = new Date()
Expand Down Expand Up @@ -105,6 +108,32 @@ const HarvestingProgressCard = observer(
}
}

const getContent = () => {
if (harvestingError) {
return (
<div className={styles.errorsWrapper}>
<img className={styles.infoIcon} src={info} alt="riox" />
<p className={styles.errorText}>
Request reindexing is not available at the moment.
</p>
</div>
)
}
if (!harvestingStatus) {
return (
<div className={styles.dataSpinnerWrapper}>
<ProgressSpinner className={styles.spinner} />
<p className={styles.spinnerText}>Loading...</p>
</div>
)
}
return <div className={styles.buttonWrapper}>{renderView()}</div>
}

useEffect(() => {
setRenderedContent(getContent())
}, [harvestingError, harvestingStatus])

return (
<Card className={styles.progressWrapper}>
<div
Expand All @@ -120,7 +149,7 @@ const HarvestingProgressCard = observer(
<div className={styles.requestDateWrapper}>
{modalOpen &&
harvestingStatus?.scheduledState === 'IN_DOWNLOAD_METADATA_QUEUE' &&
!result(
!result && (
<HarvestingModal
title={texts.modal.scheduled.title}
description={texts.modal.scheduled.description}
Expand Down Expand Up @@ -232,14 +261,7 @@ const HarvestingProgressCard = observer(
<div className={styles.statusDescription}>
{texts.progress.description}
</div>
{!harvestingStatus ? (
<div className={styles.dataSpinnerWrapper}>
<ProgressSpinner className={styles.spinner} />
<p className={styles.spinnerText}>Loading</p>
</div>
) : (
<div className={styles.buttonWrapper}>{renderView()}</div>
)}
{renderedContent}
</Card>
)
}
Expand Down
15 changes: 14 additions & 1 deletion templates/harvesting/cards/harvesting-status-card.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'

import styles from '../styles.module.css'
import info from '../../../components/upload/assets/info.svg'

import { Card } from 'design'
import { valueOrDefault, formatDate, patchValueFull } from 'utils/helpers'
Expand All @@ -15,13 +16,25 @@ const HarvestingStatusCard = ({
lastHarvestingDate,
metadataCount,
total,
harvestingError,
}) => (
<Card className={styles.harvestingCardWrapper}>
<Card.Title tag="h2">{texts.genInfo.title}</Card.Title>
<div className={styles.metadata}>
<div className={styles.metadataItems}>
<NumericValue
value={valueOrDefault(formatDate(lastHarvestingDate), 'Loading...')}
value={
harvestingError ? (
<div className={styles.errorsWrapper}>
<img className={styles.infoIcon} src={info} alt="riox" />
<p className={styles.errorText}>
This data is not available now.{' '}
</p>
</div>
) : (
valueOrDefault(formatDate(lastHarvestingDate), 'Loading...')
)
}
title="Last successful updating"
tag="div"
bold
Expand Down
3 changes: 3 additions & 0 deletions templates/harvesting/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const HarvestingPageTemplate = observer(
issues,
typesCount,
responseData,
harvestingError,
...restProps
}) => {
const { ...globalStore } = useContext(GlobalContext)
Expand Down Expand Up @@ -60,6 +61,7 @@ const HarvestingPageTemplate = observer(
)}
<div className={styles.harvestingWrapper}>
<HarvestingStatusCard
harvestingError={harvestingError}
metadataCount={metadataCount}
lastHarvestingDate={harvestingStatus?.lastHarvestingDate || 0}
fullTextCount={fullTextCount}
Expand All @@ -70,6 +72,7 @@ const HarvestingPageTemplate = observer(
harvestingStatus={harvestingStatus}
sendHarvestingRequest={sendHarvestingRequest}
responseData={responseData}
harvestingError={harvestingError}
/>
</div>
<Card className={styles.issuesCard}>
Expand Down
15 changes: 15 additions & 0 deletions templates/harvesting/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
width: 50%;
}

.errors-wrapper {
background: #f5f5f5;
display: flex;
height: 48px;
padding: 12px 16px;
align-items: center;
gap: 10px;
width: 100%;
font-size: 14px;
}

.error-text {
margin-top: unset;
}

.chart {
max-width: 12.5rem;
background-color: var(--white);
Expand Down

0 comments on commit 9d1b663

Please sign in to comment.