• 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

57.23
/src/components/SubmissionWizard/WizardHooks/WizardMapObjectsToStepsHook.tsx
1
import type { TFunction } from "i18next"
1✔
2
import { startCase } from "lodash"
1✔
3

4
import { ObjectTypes } from "constants/wizardObject"
1✔
5
import { WorkflowTypes } from "constants/wizardWorkflow"
1✔
6
import {
7
  Schema,
8
  SubmissionFolder,
9
  Workflow,
10
  WorkflowStep,
11
  MappedSteps,
12
  WorkflowSchema,
13
} from "types"
14

15
const mapObjectsToStepsHook = (
1✔
16
  submission: SubmissionFolder,
6✔
17
  objectTypesArray: Schema[],
6✔
18
  currentWorkflow: Workflow | Record<string, unknown>,
6✔
19
  t: TFunction,
6✔
20
  remsInfo: Record<string, unknown>[]
6✔
21
): { mappedSteps: MappedSteps[] } => {
6✔
22
  // Group objects by schema and status of the object
23
  // Sort newest first by reversing array order
24
  const groupedObjects = objectTypesArray
6✔
25
    .map((schema: Schema) => {
6✔
26
      const mapItem = item => ({
64✔
27
        id: item.accessionId,
×
28
        displayTitle: item.tags.displayTitle,
×
29
        objectData: { ...item },
×
30
      })
×
31
      return {
64✔
32
        [schema]: {
64✔
33
          drafts: submission.drafts
64✔
34
            .filter(
64✔
35
              (object: { schema: string }) =>
64✔
36
                object.schema.toLowerCase() === `draft-${schema.toLowerCase()}`
×
37
            )
64✔
38
            .map(item => mapItem(item))
64✔
39
            .reverse(),
64✔
40
          ready: submission.metadataObjects
64✔
41
            .filter(
64✔
42
              (object: { schema: string }) => object.schema.toLowerCase() === schema.toLowerCase()
64✔
43
            )
64✔
44
            .map(item => mapItem(item))
64✔
45
            .reverse(),
64✔
46
        },
64✔
47
      }
64✔
48
    })
6✔
49
    .reduce((map, obj) => {
6✔
50
      const key = Object.keys(obj)[0]
64✔
51
      map[key] = obj[key]
64✔
52
      return map
64✔
53
    }, {})
6✔
54

55
  // Test if object type has ready or draft objects
56
  const checkSchemaReady = (objectTypes: string[]) => {
6✔
57
    const foundObjects: string[] = []
×
58
    objectTypes.forEach(type => {
×
59
      if (groupedObjects[type]?.drafts?.length || groupedObjects[type]?.ready?.length) {
×
60
        foundObjects.push(type)
×
61
      }
×
62
    })
×
63

64
    return foundObjects.length === objectTypes.length
×
65
  }
×
66

67
  const workflowSteps: WorkflowStep[] = currentWorkflow?.steps as WorkflowStep[]
6✔
68

69
  const schemaSteps =
6✔
70
    workflowSteps?.length > 0
6!
71
      ? workflowSteps.map((step: WorkflowStep, index: number) => {
×
72
          /*
73
           * Filter previous steps and check whether their required schemas
74
            have been saved/submitted before enabling next step
75
          */
76
          const previousSteps = workflowSteps.filter((step, ind) => ind < index)
×
77

78
          const requiredSchemas = previousSteps
×
79
            .flatMap(step => step.schemas)
×
80
            .reduce((result: string[], schema: WorkflowSchema) => {
×
81
              if (schema.required && schema.name !== "file") {
×
82
                result.push(schema.name)
×
83
              }
×
84
              return result
×
85
            }, [])
×
86

87
          return {
×
88
            ...step,
×
89
            title: step.title.toLowerCase().includes(ObjectTypes.file)
×
90
              ? t("datafolder.datafolder")
×
91
              : step.title,
×
92
            ["schemas"]: step.schemas.map(schema => ({
×
93
              ...schema,
×
94
              name: schema.name.toLowerCase().includes(ObjectTypes.file)
×
95
                ? t("datafolder.datafolder")
×
96
                : schema.name === ObjectTypes.dac
×
NEW
97
                  ? schema.name.toUpperCase()
×
NEW
98
                  : startCase(schema.name),
×
99
              objectType: schema.name,
×
100
              objects: groupedObjects[schema.name],
×
101
            })),
×
102
            disabled: index > 0 && !checkSchemaReady(requiredSchemas),
×
103
          }
×
104
        })
×
105
      : []
6✔
106
  /*
107
   * List of accordion steps and configurations.
108
   * Steps are disabled by checking if previous step has been filled.
109
   * First step is always enabled.
110
   */
111
  const createSubmissionStep = {
6✔
112
    title: t("submissionDetails"),
6✔
113
    schemas: [
6✔
114
      {
6✔
115
        objectType: "submissionDetails",
6✔
116
        name: t("newSubmission.nameSubmission"),
6✔
117
        objects: {
6✔
118
          ready: submission.submissionId
6✔
119
            ? [{ id: submission.submissionId, displayTitle: submission.name }]
3✔
120
            : [],
3✔
121
        },
6✔
122
        required: true,
6✔
123
      },
6✔
124
    ],
125
  }
6✔
126

127
  const getRemsObject = () => {
6✔
128
    if (submission.rems) {
6!
129
      const selectedRems = submission.rems
×
130
      const remsObj = remsInfo.reduce(
×
131
        (
×
132
          arr: { id: number | string; displayTitle: string }[],
×
133
          organization: Record<string, unknown>
×
134
        ) => {
×
135
          if (organization["id"] === selectedRems["organizationId"]) {
×
136
            const workflow = (organization["workflows"] as Record<string, unknown>[]).filter(
×
137
              wf => wf["id"] === selectedRems["workflowId"]
×
138
            )[0]
×
139
            arr.push({
×
140
              id: selectedRems["workflowId"],
×
141
              displayTitle: `${workflow["title"]} DAC`,
×
142
            })
×
143
            const numberOfLicenses = (organization["licenses"] as Record<string, unknown>[]).length
×
144
            if (numberOfLicenses > 0) {
×
145
              arr.push({
×
146
                id: "",
×
147
                displayTitle: numberOfLicenses > 1 ? `${numberOfLicenses} policies` : "1 policy",
×
148
              })
×
149
            }
×
150
          }
×
151
          return arr
×
152
        },
×
153
        []
×
154
      )
×
155
      return remsObj
×
156
    }
×
157
  }
6✔
158

159
  const dacPoliciesStep = {
6✔
160
    title: t("dacPolicies.title"),
6✔
161
    schemas: [
6✔
162
      {
6✔
163
        objectType: "dacPolicies",
6✔
164
        name: t("dacPolicies.title"),
6✔
165
        objects: {
6✔
166
          ready: getRemsObject(),
6✔
167
        },
6✔
168
        required: true,
6✔
169
      },
6✔
170
    ],
171
  }
6✔
172

173
  const mappedSteps = (
6✔
174
    currentWorkflow?.name === WorkflowTypes.sdsx
6!
175
      ? [createSubmissionStep, dacPoliciesStep]
×
176
      : [createSubmissionStep]
6✔
177
  ).concat(schemaSteps)
6✔
178

179
  const summaryStep = {
6✔
180
    title: t("setIdentifierPublish"),
6✔
181
    schemas: [
6✔
182
      {
6✔
183
        objectType: t("summary"), // REPLACE "Add" by "view" with objectype as text to the button (Add summary) inside accordion
6✔
184
        name: t("summary"), // Text inside accordion by isActive ChevronRightIcon
6✔
185
        objects: {
6✔
186
          ready: [],
6✔
187
        },
6✔
188
        required: true,
6✔
189
      },
6✔
190
    ],
191
    actionButtonText: t("summaryButtonText"), // This does place the text in the button
6✔
192
    disabled: submission.name === "",
6✔
193
  }
6✔
194
  if (submission.name !== "") mappedSteps.push(summaryStep)
6✔
195

196
  return { mappedSteps }
6✔
197
}
6✔
198

199
export default mapObjectsToStepsHook
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