Skip to content

Commit

Permalink
fixed warnings in myems-web
Browse files Browse the repository at this point in the history
  • Loading branch information
nengyuanzhang committed Feb 20, 2024
1 parent f0defe9 commit cf4c728
Showing 1 changed file with 59 additions and 58 deletions.
117 changes: 59 additions & 58 deletions myems-web/src/components/MyEMS/KnowledgeBase/KnowledgeBase.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React, { useEffect, useState} from 'react';
import { Alert, Card, CardBody, Col, Row, Spinner, } from 'reactstrap';
import React, { useEffect, useState } from 'react';
import { Alert, Card, CardBody, Col, Row, Spinner } from 'reactstrap';
import Summary from './Summary';
import FalconCardHeader from '../../common/FalconCardHeader';
import createMarkup from '../../../helpers/createMarkup';
import { isIterableArray } from '../../../helpers/utils'
import { isIterableArray } from '../../../helpers/utils';
import { getCookieValue, createCookie } from '../../../helpers/utils';
import withRedirect from '../../../hoc/withRedirect';
import { withTranslation } from 'react-i18next';
import { APIBaseURL, settings } from '../../../config';



const KnowledgeBase = ({ setRedirect, setRedirectUrl, t }) => {

const [fetchSuccess, setFetchSuccess] = useState(false);

//Results
Expand All @@ -39,73 +36,77 @@ const KnowledgeBase = ({ setRedirect, setRedirectUrl, t }) => {

let isResponseOK = false;
if (!fetchSuccess) {
fetch(
APIBaseURL +
'/knowledgefiles', {
fetch(APIBaseURL + '/knowledgefiles', {
method: 'GET',
headers: {
'Content-type': 'application/json',
'User-UUID': getCookieValue('user_uuid'),
Token: getCookieValue('token')
},
body: null,

}).then(response => {
if (response.ok) {
isResponseOK = true;
}
return response.json();
}).then(json => {
if (isResponseOK) {
console.log(json);
setFetchSuccess(true);

let reportList = []

if (json.length > 0) {
json.forEach((currentValue, index) => {
let report = {}
report['id'] = json[index]['id'];
report['calendar'] = { month: json[index]['upload_datetime'].substring(5, 7),
day: json[index]['upload_datetime'].substring(8, 10) };
report['title'] = json[index]['file_name'];
report['additional'] = t('Created Datetime') + ': ' + json[index]['upload_datetime'] + '<br/>' +
t('File Size') + ': ' + (json[index]['file_size_bytes']/(1024*1024)).toFixed(2) + ' MB';
report['to'] = '#';
report['file_bytes_base64'] = json[index]['file_bytes_base64'];

reportList.push(report);
});
body: null
})
.then(response => {
if (response.ok) {
isResponseOK = true;
}

setReports(reportList);
setSpinnerHidden(true);
}
});
return response.json();
})
.then(json => {
if (isResponseOK) {
console.log(json);
setFetchSuccess(true);
let reportList = [];
if (json.length > 0) {
json.forEach((currentValue, index) => {
let report = {};
report['id'] = json[index]['id'];
report['calendar'] = {
month: json[index]['upload_datetime'].substring(5, 7),
day: json[index]['upload_datetime'].substring(8, 10)
};
report['title'] = json[index]['file_name'];
report['additional'] =
t('Created Datetime') +
': ' +
json[index]['upload_datetime'] +
'<br/>' +
t('File Size') +
': ' +
(json[index]['file_size_bytes'] / (1024 * 1024)).toFixed(2) +
' MB';
report['to'] = '#';
report['file_bytes_base64'] = json[index]['file_bytes_base64'];
reportList.push(report);
});
}
setReports(reportList);
setSpinnerHidden(true);
}
});
}
}
}, );
});

return (
<Card>
<FalconCardHeader title={t('Knowledge Base')} titleClass="text-lightSlateGray mb-0" />
<CardBody className="fs--1">
<Spinner color="primary" hidden={spinnerHidden} />
<Spinner color="primary" hidden={spinnerHidden} />
{isIterableArray(reports) ? (
<Row>
{reports.map(({ additional, ...rest }, index) => (
<Col md={6} className="h-100" key={index}>
<Summary divider={reports.length !== index + 1} {...rest}>
<p className="text-1000 mb-0" dangerouslySetInnerHTML={createMarkup(additional)} />
</Summary>
</Col>
))}
</Row>
) : (
<Alert color="info" className="mb-0">
{t('No data found')}
</Alert>
)}
<Row>
{reports.map(({ additional, ...rest }, index) => (
<Col md={6} className="h-100" key={index}>
<Summary divider={reports.length !== index + 1} {...rest}>
<p className="text-1000 mb-0" dangerouslySetInnerHTML={createMarkup(additional)} />
</Summary>
</Col>
))}
</Row>
) : (
<Alert color="info" className="mb-0">
{t('No data found')}
</Alert>
)}
</CardBody>
</Card>
);
Expand Down

0 comments on commit cf4c728

Please sign in to comment.