Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6d8ac067

Přidáno uživatelem Michal Schwob před asi 2 roky(ů)

Page for external sources created
re #9812

Zobrazit rozdíly:

frontend/src/App.tsx
18 18
import { Fragment } from 'react'
19 19
import Administration from "./features/Administration/Administration"
20 20
import Register from "./features/Auth/Register"
21
import ExternalSources from "./features/ExternalSources/ExternalSources"
21 22

  
22 23
const App = () => {
23 24
    return (
......
39 40
                            <Route path="/logout" element={<Logout />} />
40 41
                            <Route path="/map" element={<TrackingTool />} />
41 42
                            <Route path="/administration" element={<Administration />}/>
43
                            <Route path="/externalSources" element={<ExternalSources />}/>
42 44
                            <Route path="*" element={<NotFound />} />
43 45
                        </Routes>
44 46
                    </Box>
frontend/src/features/Catalog/CatalogTable.tsx
80 80
    // Name of columns in the header
81 81
    const columns = [
82 82
        'Name',
83
        'Alternative Names',
83
        'All Names',
84 84
        'Written form',
85 85
        'Type',
86 86
        'State or Territory',
frontend/src/features/ExternalSources/ExternalSources.tsx
1
import {Button, Container, Paper, Typography} from '@mui/material'
2
import {Fragment, useEffect, useState} from 'react'
3
import { useDispatch, useSelector } from 'react-redux'
4
import { RootState } from '../redux/store'
5
import axiosInstance from "../../api/api"
6
import 'react-quill/dist/quill.snow.css'
7
import NotAuthorized from "../NotAuthorized/NotAuthorized"
8
import SingleFileSelectionForm from "../Reusables/SingleFileSelectionForm"
9
import * as yup from "yup"
10
import {useFormik} from "formik"
11

  
12

  
13
interface UploadValues {
14
    file?: File
15
}
16

  
17
const initialValues: UploadValues = {}
18

  
19

  
20
const ExternalSources = () => {
21

  
22
    const [filename, setFilename] = useState<string | undefined>(undefined)
23
    const [fileProcessing, setFileProcessing] = useState(false)
24

  
25
    const validationSchema = yup.object().shape({
26
        file: yup.mixed().required('File is required'),
27
    })
28

  
29
    const formik = useFormik({
30
        initialValues,
31
        validationSchema,
32
        onSubmit: async (values) => {
33
            setFileProcessing(true)
34
            const reader = new FileReader()
35
            reader.readAsText(values.file as File)
36
            reader.onload = async () => {
37
                const {data, status} = await axiosInstance.post(
38
                   '/external-catalog-item',
39
                   { file: reader.result as string }
40
                )
41
                if (status !== 200) {
42
                    console.log("Error in updating catalog")
43
                }
44
            }
45
        },
46
    })
47

  
48
    // Callback when user selects the file
49
    const onFileSelected = (event: any) => {
50
        const file = event.currentTarget.files[0]
51
        if (file) {
52
            setFilename(file.name)
53
            formik.setFieldValue('file', file)
54
        }
55
    }
56

  
57
    const onClose = () => {
58
        if (fileProcessing) {
59
            return
60
        }
61
        setFilename(undefined)
62
        formik.resetForm()
63
    }
64

  
65
    const onClearSelectedFile = () => {
66
        setFilename(undefined)
67
        formik.setFieldValue('file', undefined)
68
    }
69

  
70

  
71
    const isAdmin = useSelector(
72
        (state: RootState) => state.user.roles.includes("ROLE_ADMIN")
73
    )
74
    const handleClick = () => {
75

  
76
    }
77

  
78
    return (
79
        <Fragment>
80
            <Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
81
                External Sources
82
            </Typography>
83
            {isAdmin ? (
84
            <Paper style={{ minHeight: '80vh' }} variant="outlined">
85
                <Container sx={{ mt: 4 }}>
86
                    <Typography sx={{ mb: 2 }}>
87
                        Select file with sources from ... source and then click submit to update all external sources.
88
                    </Typography>
89
                    <SingleFileSelectionForm
90
                        onFileSelected={onFileSelected}
91
                        onClearSelectedFile={onClearSelectedFile}
92
                        filename={filename}
93
                        formik={formik}
94
                    />
95
                </Container>
96
            </Paper>
97
            ) : <NotAuthorized />}
98
        </Fragment>
99
    )
100
}
101

  
102
export default ExternalSources
frontend/src/features/Navigation/navigationMenuItems.ts
80 80
        icon: DataSaverOffIcon,
81 81
        position: 4,
82 82
    },
83
    {
84
        name: 'External Catalog Sources',
85
        path: '/externalSources',
86
        accessibleTo: loggedInAccess,
87
        icon: SupervisorAccountIcon,
88
        position: 6,
89
    },
83 90
    {
84 91
        name: 'Administration',
85 92
        path: '/administration',

Také k dispozici: Unified diff