• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CSCfi / metadata-submitter-frontend / 15132822209

20 May 2025 08:35AM UTC coverage: 47.784% (-0.08%) from 47.859%
15132822209

push

github

Hang Le
Feature/fix formatting (merge commit)

Merge branch 'feature/fix-formatting' into 'main'
* Format all files missed by incorrect format script

* Update precommit for husky v9

* Fix formatting script to include all files

Closes #1033
See merge request https://gitlab.ci.csc.fi/sds-dev/sd-submit/metadata-submitter-frontend/-/merge_requests/1114

Approved-by: Hang Le <lhang@csc.fi>
Co-authored-by: Monika Radaviciute <mradavic@csc.fi>
Merged by Hang Le <lhang@csc.fi>

656 of 963 branches covered (68.12%)

Branch coverage included in aggregate %.

150 of 326 new or added lines in 48 files covered. (46.01%)

5 existing lines in 4 files now uncovered.

6353 of 13705 relevant lines covered (46.36%)

4.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.82
/src/components/SubmissionWizard/WizardComponents/WizardDataFolderTable.tsx
1
import React, { useState, useEffect } from "react"
1✔
2

3
import FolderIcon from "@mui/icons-material/Folder"
1✔
4
import Box from "@mui/material/Box"
1✔
5
import Radio from "@mui/material/Radio"
1✔
6
import Typography from "@mui/material/Typography"
1✔
7
import { GridColDef } from "@mui/x-data-grid"
8
import type { GridSortDirection } from "@mui/x-data-grid"
9
import { upperFirst } from "lodash"
1✔
10
import { useTranslation } from "react-i18next"
1✔
11

12
import { files } from "../../../../playwright/fixtures/files_response" // MOCK files array
1✔
13

14
import DataTable from "components/DataTable"
1✔
15
import { ResponseStatus } from "constants/responseStatus"
1✔
16
import { updateStatus } from "features/statusMessageSlice"
1✔
17
import { useAppSelector, useAppDispatch } from "hooks"
1✔
18
import filesAPIService from "services/filesAPI"
1✔
19
import type { DataFolderRow } from "types"
20

21
type DataFolderTableProps = {
22
  selectedFolder: string
23
  linkedFolder: string
24
  handleFolderChange: (e: React.ChangeEvent<HTMLInputElement>) => void
25
  handleFilesView: (folderName: string) => void
26
}
27

28
const WizardDataFolderTable: React.FC<DataFolderTableProps> = props => {
1✔
29
  const { selectedFolder, linkedFolder, handleFolderChange, handleFilesView } = props
×
30
  const projectId = useAppSelector(state => state.projectId)
×
31
  const dispatch = useAppDispatch()
×
32

33
  const { t } = useTranslation()
×
34

35
  const columns: GridColDef[] = [
×
36
    {
×
37
      field: "name",
×
38
      headerName: t("dataTable.name"),
×
39
      sortable: true,
×
40
      renderCell: params => {
×
41
        return (
×
42
          <Box display="flex" alignItems="center" height="100%">
×
43
            {!linkedFolder && (
×
44
              <Radio
×
45
                checked={selectedFolder === params.row.name}
×
46
                onChange={handleFolderChange}
×
47
                value={params.row.name}
×
48
                name="radio-buttons"
×
49
                inputProps={{ "aria-label": params.row.name }}
×
50
              />
51
            )}
52
            <FolderIcon
×
53
              color="primary"
×
54
              fontSize="medium"
×
55
              sx={{ ml: "1rem", mr: "0.5rem" }}
×
56
              onClick={() => handleFilesView(params.row.name)}
×
57
            />
58
            <Typography component="span" onClick={() => handleFilesView(params.row.name)}>
×
59
              {upperFirst(params.row.name)}
×
60
            </Typography>
×
61
          </Box>
×
62
        )
63
      },
×
64
    },
×
65
    {
×
66
      field: "items",
×
67
      headerName: t("dataTable.totalItems"),
×
68
      type: "number",
×
69
    },
×
70
    {
×
71
      field: "size",
×
72
      headerName: t("dataTable.size"),
×
73
      sortable: true, // TODO: need to convert sizes to humanreadable bytes
×
74
    },
×
75
  ]
76

77
  useEffect(() => {
×
78
    let isMounted = true
×
79
    const getFiles = async () => {
×
80
      if (isMounted) {
×
81
        try {
×
82
          const response = await filesAPIService.getProjectFiles(projectId)
×
83
          const files = response.data
×
84
          sessionStorage.setItem("files", JSON.stringify(files))
×
85
          // TODO: consider saving files in redux instead of sessionStorage if needed
86
        } catch (error) {
×
87
          dispatch(
×
88
            updateStatus({
×
89
              status: ResponseStatus.error,
×
90
              response: error,
×
91
              helperText: "",
×
92
            })
×
93
          )
×
94
        }
×
95
      }
×
96
    }
×
97
    getFiles()
×
98
    return () => {
×
99
      isMounted = false
×
100
    }
×
101
  }, [])
×
102

103
  useEffect(() => {
×
104
    !linkedFolder ? setTotalItems(getFolderNames().length) : setTotalItems(1)
×
105
  }, [linkedFolder])
×
106

107
  const getRows = (): DataFolderRow[] => {
×
108
    const folderNames = getFolderNames()
×
109
    return folderNames
×
110
      .filter(folderName => (!!linkedFolder ? folderName === linkedFolder : folderName))
×
NEW
111
      .map(folderName => {
×
112
        const currentFiles = files.filter(file => file.path.includes(`/${folderName}/`))
×
113
        const totalSize = currentFiles.reduce((acc, currentFile) => acc + currentFile["bytes"], 0)
×
114
        return {
×
115
          id: folderName,
×
116
          name: folderName,
×
117
          size: totalSize,
×
118
          items: currentFiles.length,
×
119
        }
×
120
      })
×
121
  }
×
122

123
  const getFolderNames = () => [...new Set(files.map(file => file["path"].split("/")[1]))]
×
124

125
  const sortingModel = [
×
126
    {
×
127
      field: "name",
×
128
      sort: "asc" as GridSortDirection,
×
129
    },
×
130
  ]
131

132
  const [page, setPage] = useState<number>(0)
×
133
  const [totalItems, setTotalItems] = useState<number>(0)
×
134

135
  const fetchPageOnChange = (page: number) => {
×
136
    setPage(page)
×
137
  }
×
138

139
  return (
×
140
    <DataTable
×
141
      rows={getRows()}
×
142
      columns={columns}
×
143
      page={page}
×
144
      sortingModel={sortingModel}
×
145
      totalItems={totalItems}
×
146
      fetchPageOnChange={fetchPageOnChange}
×
147
    />
148
  )
149
}
×
150

151
export default WizardDataFolderTable
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc