diff --git a/nginx/nginx.conf b/nginx/nginx.conf index e3c6319bf6d02236da9783965614cc9cac5aeb7c..3ed620d20b90e99365f4078061fcf0619613e11d 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -5,9 +5,6 @@ server { listen 80; server_name -; - ssl_certificate /etc/ssl/fullchain.pem; - ssl_certificate_key /etc/ssl/fullchain.pem.key; - proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/package.json b/package.json index e3f8cc457211452a7eea10e9ee5a97056db6a78b..e4a846ac36372bc0f9717148c0c6a1b85b714ff9 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,7 @@ }, "extends": [ "plugin:react/recommended", - "plugin:prettier/recommended", - "airbnb" + "plugin:prettier/recommended" ], "parserOptions": { "ecmaFeatures": { diff --git a/src/pages/fields/Fields.js b/src/pages/fields/Fields.js index 46f766abc590a8ba71e3465474a0efebe564445a..d6d52d00453bdd11de3749b1fa27c21bd400e4c8 100644 --- a/src/pages/fields/Fields.js +++ b/src/pages/fields/Fields.js @@ -12,6 +12,7 @@ import { EuiFilePicker, EuiButton, EuiInMemoryTable, + EuiSpacer, } from '@elastic/eui'; import { ShowAlert } from '../../components/Common'; import Papa from 'papaparse'; @@ -40,6 +41,7 @@ const renderFiles = (files) => { const NewFieldsForm = memo(({ files, onFilePickerChange, onSaveField }) => { return ( <> + <EuiSpacer /> <EuiForm component="form"> <EuiFormRow label="Standard field file(s)"> <EuiFilePicker @@ -52,18 +54,16 @@ const NewFieldsForm = memo(({ files, onFilePickerChange, onSaveField }) => { display={'large'} /> </EuiFormRow> - <EuiFormRow label=""> + <EuiFormRow> <EuiText> <h3>Files attached</h3> {renderFiles(files)} </EuiText> </EuiFormRow> - <EuiFormRow label=""> - { - <EuiButton fill onClick={onSaveField}> - Load - </EuiButton> - } + <EuiFormRow> + <EuiButton fill onClick={onSaveField} disabled={!files}> + Load + </EuiButton> </EuiFormRow> </EuiForm> </> @@ -73,28 +73,23 @@ const NewFieldsForm = memo(({ files, onFilePickerChange, onSaveField }) => { const StdFields = memo(({ stdFields, stdFieldColumns }) => { return ( <> - <EuiForm component="form"> - <EuiFormRow label="Uploaded standard fields" fullWidth> - <EuiInMemoryTable - items={stdFields} - columns={stdFieldColumns} - search={{ - box: { - incremental: true, - }, - }} - pagination={true} - sorting={true} - /> - </EuiFormRow> - </EuiForm> + <EuiSpacer /> + <EuiInMemoryTable + items={stdFields} + columns={stdFieldColumns} + search={{ + box: { + incremental: true, + }, + }} + pagination={true} + sorting={true} + /> </> ); }); -let debounceTimeoutId; -let requestTimeoutId; -const Fields = (props) => { +const Fields = () => { const [selectedTabNumber, setSelectedTabNumber] = useState(0); const [open, setOpen] = useState(false); const [alertMessage, setAlertMessage] = useState(''); @@ -102,13 +97,11 @@ const Fields = (props) => { const [files, setFiles] = useState(); const [loadedFields, setLoadedFields] = useState([]); const [stdFields, setStdFields] = useState([]); - const [filteredFields, setFilteredFields] = useState([]); const loadStdFields = useCallback(async () => { const fields = await getPublicFields(); if (fields) { setStdFields(fields); - setFilteredFields(fields); } }, []); @@ -122,23 +115,6 @@ const Fields = (props) => { return () => (isSubscribed = false); }, [loadStdFields]); - const onQueryChange = ({ query }) => { - clearTimeout(debounceTimeoutId); - debounceTimeoutId = setTimeout(() => { - const items = stdFields.filter((field) => { - const normalizedFieldName = - `${field.field_name} ${field.Definition_and_comment}`.toLowerCase(); - const normalizedQuery = query.text.toLowerCase(); - return normalizedFieldName.indexOf(normalizedQuery) !== -1; - }); - if (query.text !== '') { - setFilteredFields(items); - } else { - setFilteredFields([]); - } - }, 300); - }; - const onFilePickerChange = async (files) => { setFiles(files); await handleSelectedFile(files); @@ -155,18 +131,7 @@ const Fields = (props) => { const handleData = (file) => { if (file) { const result = Papa.parse(file, { header: true }); - const columns = []; const rows = []; - result.meta.fields.forEach((item) => { - const column = { - name: item, - options: { - display: true, - }, - }; - columns.push(column); - }); - result.data.forEach((item) => { // lowercase the key Object.keys(item).forEach((key) => { @@ -179,7 +144,7 @@ const Fields = (props) => { rows.push(item); }); - if (columns && rows) { + if (rows) { setLoadedFields((preRows) => [...preRows, ...rows]); } } @@ -203,13 +168,12 @@ const Fields = (props) => { obligation_or_condition, values, list_url, - default_display_fields + default_display_fields, } = field; - console.log("fields: ", field); const isOptional = isoptional || is_optional; const isPublic = ispublic || is_public; - const response = await createStdField( + await createStdField( cardinality, category, definition_and_comment, @@ -219,13 +183,12 @@ const Fields = (props) => { isPublic?.toString().toLowerCase() === 'true', obligation_or_condition, values, - list_url, - default_display_fields + list_url, + default_display_fields ); } - // Reload fields after processing - loadStdFields(); + await loadStdFields(); } catch (error) { console.error('Unexpected error during field saving:', error); setOpen(true); @@ -239,40 +202,56 @@ const Fields = (props) => { { field: 'field_name', name: 'Field name', + align: 'left', + valign: 'center', sortable: true, - truncateText: true, }, { field: 'field_type', name: 'Field type', + align: 'left', + valign: 'center', + width: '5%', }, { field: 'definition_and_comment', - name: 'Definition And comment', - // truncateText: true, + name: 'Definition and comment', + align: 'left', + valign: 'center', }, { - field: 'Obligation_or_condition', + field: 'obligation_or_condition', name: 'Obligation or condition', + align: 'left', + valign: 'center', }, { field: 'cardinality', name: 'Cardinality', + align: 'left', + valign: 'center', + width: '5%', }, { field: 'default_display_fields', name: 'Default display fields', + align: 'left', + valign: 'center', + width: '5%', }, { field: 'list_url', name: 'List URL', + align: 'left', + valign: 'center', }, { field: 'values', name: 'Values', + align: 'left', + valign: 'center', sortable: true, truncateText: true, - // render: date => formatDate(date, 'dobLong'), }, ]; @@ -281,25 +260,17 @@ const Fields = (props) => { id: 'tab1', name: 'Upload fields', content: ( - <> - <br /> - <NewFieldsForm - files={files} - onFilePickerChange={onFilePickerChange} - onSaveField={onSaveField} - /> - </> + <NewFieldsForm + files={files} + onFilePickerChange={onFilePickerChange} + onSaveField={onSaveField} + /> ), }, { id: 'tab2', name: 'Fields', - content: ( - <> - <br /> - <StdFields stdFields={stdFields} stdFieldColumns={stdFieldColumns} /> - </> - ), + content: <StdFields stdFields={stdFields} stdFieldColumns={stdFieldColumns} />, }, ]; diff --git a/src/pages/sources/Sources.js b/src/pages/sources/Sources.js index 11a8d3d7ca0d5b1c18ced34ed1b84b3814a69db5..10957cdeab9232954fac4c7ee20e1693033af8ba 100644 --- a/src/pages/sources/Sources.js +++ b/src/pages/sources/Sources.js @@ -1,6 +1,5 @@ import React, { useState, useCallback, useEffect, memo, useRef } from 'react'; import { - EuiForm, EuiPageContent, EuiPageContentHeader, EuiPageContentHeaderSection, @@ -19,13 +18,6 @@ import { EuiHealth, EuiConfirmModal, EuiOverlayMask, - EuiModal, - EuiModalHeader, - EuiModalHeaderTitle, - EuiModalBody, - EuiModalFooter, - EuiButtonEmpty, - EuiCallOut, } from '@elastic/eui'; import { ShowAlert } from '../../components/Common'; @@ -52,8 +44,7 @@ const NewSourceForm = memo( }) => { return ( <> - <br /> - <EuiForm component="form"> + <EuiSpacer /> <EuiFlexGroup> <EuiFlexItem grow={3}> <EuiFormRow label="Source or file name"> @@ -101,18 +92,14 @@ const NewSourceForm = memo( </EuiFormRow> </EuiFlexItem> <EuiFlexItem grow={3}> - <> - <br /> <ReactJson name="Metadata records" collapsed={true} iconStyle={'triangle'} src={metaUrfms} /> - </> </EuiFlexItem> </EuiFlexGroup> - </EuiForm> </> ); } @@ -126,31 +113,19 @@ const SourcesForm = memo( tableref, pagination, sorting, - selection, - mergeButton, }) => { return ( <> - <br /> - <EuiForm component="form"> - <EuiFlexGroup alignItems="center">{mergeButton}</EuiFlexGroup> - - <EuiSpacer size="l" /> - - <EuiFormRow label="Uploaded sources" fullWidth> - <EuiBasicTable - itemId="id" - isSelectable={true} - items={sources} - columns={metaUrfmColumns} - onChange={onTableChange} - ref={tableref} - pagination={pagination} - sorting={sorting} - selection={selection} - /> - </EuiFormRow> - </EuiForm> + <EuiSpacer /> + <EuiBasicTable + itemId="id" + items={sources} + columns={metaUrfmColumns} + onChange={onTableChange} + ref={tableref} + pagination={pagination} + sorting={sorting} + /> </> ); } @@ -168,9 +143,10 @@ const renderFiles = (files) => { </ul> ); } else { - return <p>Please, add some files to upload.</p>; + return <p>Upload files to continue.</p>; } }; + const Sources = () => { const [metaUrfms, setMetaUrfms] = useState([]); const [selectedTabNumber, setSelectedTabNumber] = useState(0); @@ -184,59 +160,27 @@ const Sources = () => { const [pageIndex, setPageIndex] = useState(0); const [pageSize, setPageSize] = useState(5); const [sortDirection, setSortDirection] = useState('asc'); - const [selectedSources, setSelectedSources] = useState([]); const [sortField, setSortField] = useState('name'); - const tableref = useRef(); const [source, setSource] = useState({}); const [isModalVisible, setIsModalVisible] = useState(false); - const [isMergeModalVisible, setIsMergeModalVisible] = useState(false); - const [sourceName, setSourceName] = useState(''); - const [sourceDescription, setSourceDescription] = useState(''); - - const onClickMergeSource = () => { - openMergeSourceModal(); - }; - - const renderMergeButton = () => { - if (selectedSources.length === 0 || selectedSources.length === 1) { - return; - } - - return ( - <EuiButton color="secondary" iconType="merge" onClick={onClickMergeSource}> - Merge and Send {selectedSources.length} Source File(s) - </EuiButton> - ); - }; + const tableref = useRef(); const onTableChange = ({ page = {}, sort = {} }) => { const { index: pageIndex, size: pageSize } = page; - const { field: sortField, direction: sortDirection } = sort; - setPageIndex(pageIndex); setPageSize(pageSize); setSortField(sortField); setSortDirection(sortDirection); }; - const onSelectionChange = (selectedItems) => { - setSelectedSources(selectedItems); - }; - const totalItemCount = typeof sources === ([] || null) ? 0 : sources.length; - const pagination = { pageIndex: pageIndex, pageSize: pageSize, - totalItemCount: totalItemCount, + totalItemCount: typeof sources === ([] || null) ? 0 : sources.length, pageSizeOptions: [3, 5, 8], }; - const selection = { - selectable: (source) => !source.is_send, - onSelectionChange: onSelectionChange, - }; - const sorting = { sort: { field: sortField, @@ -247,9 +191,6 @@ const Sources = () => { const closeModal = () => setIsModalVisible(false); const showModal = () => setIsModalVisible(true); - const closeMergeSourceModal = () => setIsMergeModalVisible(false); - const openMergeSourceModal = () => setIsMergeModalVisible(true); - // delete source from db, elasticsearch and mongodb const onDeleteSource = async (source) => { setSource(source); @@ -259,77 +200,19 @@ const Sources = () => { const onDeleteSourceConfirm = async () => { closeModal(); if (source.id) { - const response = await deleteSource(source.id); - setAlertMessage('Source is deleted successfully'); + await deleteSource(source.id); + setAlertMessage('Source deleted.'); setSeverity('success'); setOpen(true); - await loadSources(); } else { setOpen(true); - setAlertMessage( - 'While deletion the sources to elastic stack, unexpected error has been occurred.' - ); + setAlertMessage('An error occurred while deleting this source.'); setSeverity('error'); } }; - const onMergeAndSendSourcesConfirmed = async () => { - if (sourceName && sourceDescription && selectedSources) { - //const kcId = sessionStorage.getItem('userId'); - // const result = await globalActions.source.mergeAndSendSource( - // kcId, - // sourceName, - // sourceDescription, - // selectedSources - // ); - // if (result.status === 201) { - // setOpen(true); - // setAlertMessage('Sources are merged and send to elasticsearch successfully !'); - // setSeverity('success'); - // await loadSources(); - // } else { - // setOpen(true); - // setAlertMessage('While merging the sources, unexpected error has been occurred.'); - // setSeverity('error'); - // } - // closeMergeSourceModal(); - } - }; - - // const updateSource = async (kc_id, source_id) => { - // await globalActions.source.updateSource(kc_id, source_id); - // }; - // import source document to elasticsearch - const onSendSource = async (source) => { - if (sessionStorage.getItem('userId') && source) { - // const kc_id = sessionStorage.getItem('userId'); - // const source_id = source.id; - // const updatedSource = await updateSource(kc_id, source_id); - // if (updatedSource) { - // setOpen(true); - // setAlertMessage('Source imported to elastic stack successfully'); - // setSeverity('success'); - // await loadSources(); - // } else { - // setOpen(true); - // setAlertMessage( - // 'While importation the sources to elastic stack, unexpected error has been occurred.' - // ); - // setSeverity('error'); - // } - } - }; - const metaUrfmActions = [ - { - name: 'Send', - description: 'Send this source', - icon: 'aggregate', - type: 'icon', - enabled: (value) => !value.is_send, - onClick: onSendSource, - }, { name: 'Delete', description: 'Delete this source', @@ -448,7 +331,6 @@ const Sources = () => { } setOpen(false); }; - const mergeButton = renderMergeButton(); const tabContents = [ { @@ -482,63 +364,12 @@ const Sources = () => { tableref={tableref} pagination={pagination} sorting={sorting} - selection={selection} - mergeButton={mergeButton} /> </> ), }, ]; - const mergeModalForm = ( - <EuiForm> - <EuiCallOut title="Proceed with caution!" color="warning" iconType="help"> - <p>Source / File Name is unique field for the In-Sylva Search App.</p> - </EuiCallOut>{' '} - <br /> - <EuiFormRow label="Source or file name"> - <EuiFieldText - name="sourceName" - value={sourceName} - onChange={(e) => setSourceName(e.target.value)} - /> - </EuiFormRow> - <EuiFormRow label="Source description"> - <EuiFieldText - name="sourceDescription" - value={sourceDescription} - onChange={(e) => setSourceDescription(e.target.value)} - /> - </EuiFormRow> - <EuiSpacer /> - </EuiForm> - ); - - let mergeSourceModal; - if (isMergeModalVisible) { - mergeSourceModal = ( - <EuiOverlayMask> - <EuiModal onClose={closeMergeSourceModal} initialFocus="[name=popswitch]"> - <EuiModalHeader> - <EuiModalHeaderTitle> - Merge and send selected source files - </EuiModalHeaderTitle> - </EuiModalHeader> - - <EuiModalBody>{mergeModalForm}</EuiModalBody> - - <EuiModalFooter> - <EuiButtonEmpty onClick={closeMergeSourceModal}>Cancel</EuiButtonEmpty> - - <EuiButton onClick={onMergeAndSendSourcesConfirmed} fill> - Save - </EuiButton> - </EuiModalFooter> - </EuiModal> - </EuiOverlayMask> - ); - } - let Warningmodal; if (isModalVisible) { Warningmodal = ( @@ -569,22 +400,17 @@ const Sources = () => { </EuiPageContentHeaderSection> </EuiPageContentHeader> <EuiPageContentBody> - <EuiForm> - <EuiForm> - <EuiTabbedContent - tabs={tabContents} - selectedTab={tabContents[selectedTabNumber]} - onTabClick={(tab) => { - setSelectedTabNumber(tabContents.indexOf(tab)); - }} - /> - </EuiForm> - </EuiForm> + <EuiTabbedContent + tabs={tabContents} + selectedTab={tabContents[selectedTabNumber]} + onTabClick={(tab) => { + setSelectedTabNumber(tabContents.indexOf(tab)); + }} + /> </EuiPageContentBody> </EuiPageContent> {ShowAlert(open, handleClose, alertMessage, severity)} {Warningmodal} - {mergeSourceModal} </> ); };