Skip to content

Commit 1bc159e

Browse files
authored
Remove field group (#539)
* Add x button for field group * Fix formatter issues * Add x icon * Run formatter * Translate alt tag * Use splice instead of loop * Run formatter
1 parent f1c82f1 commit 1bc159e

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

frontend/.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
"react/forbid-prop-types": "off",
2121
"jsx-a11y/click-events-have-key-events": "off",
2222
"jsx-a11y/no-static-element-interactions": "off",
23+
"jsx-a11y/no-noninteractive-element-interactions": "off",
2324
"no-use-before-define": "off",
2425
"no-plusplus": "off",
26+
"no-continue": "off",
2527
"no-underscore-dangle": ["error", { "allow": ["_id"] }],
2628
"import/order": [
2729
"warn",

frontend/src/assets/x-icon.png

19.9 KB
Loading

frontend/src/components/Fields/FieldGroup.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/* eslint import/no-cycle: "off" */
22
// Unfortunately, there has to be an import cycle, because this is by nature, recursive
3-
import React from 'react';
4-
import PropTypes from 'prop-types';
53
import { Button } from '@material-ui/core';
4+
import _ from 'lodash';
5+
import PropTypes from 'prop-types';
6+
import React from 'react';
7+
import swal from 'sweetalert';
68

9+
import XIcon from '../../assets/x-icon.png';
10+
import { useTranslations } from '../../hooks/useTranslations';
711
import StepField from '../StepField/StepField';
812
import './Fields.scss';
9-
import { useTranslations } from '../../hooks/useTranslations';
1013

1114
const FieldGroup = ({
1215
isDisabled,
@@ -53,6 +56,29 @@ const FieldGroup = ({
5356
handleSimpleUpdate(getKeyBase(getNumFields()), {});
5457
};
5558

59+
const onRemoveGroup = (groupNumber) => {
60+
if (isDisabled) return;
61+
62+
swal({
63+
title: translations.components.button.discard.question,
64+
text: translations.components.button.discard.warningMessage,
65+
icon: 'warning',
66+
dangerMode: true,
67+
buttons: [
68+
translations.components.button.discard.cancelButton,
69+
translations.components.button.discard.confirmButton,
70+
],
71+
}).then((isDeleteConfirmed) => {
72+
if (isDeleteConfirmed) doRemoveGroup(groupNumber);
73+
});
74+
};
75+
76+
const doRemoveGroup = (groupNumber) => {
77+
const newData = _.cloneDeep(value);
78+
newData.splice(groupNumber, 1);
79+
handleSimpleUpdate(metadata.key, newData);
80+
};
81+
5682
const generateSingleGroup = (index) => {
5783
return metadata?.subFields?.map((field) => {
5884
return (
@@ -85,6 +111,24 @@ const FieldGroup = ({
85111
});
86112
};
87113

114+
const generateHeader = (groupNumber, displayName) => {
115+
const buttonClass = `button-${isDisabled ? 'disabled' : 'active'}`;
116+
117+
return (
118+
<div
119+
className={`group-title-container-base group-title-container-${selectedLang}`}
120+
>
121+
<img
122+
src={XIcon}
123+
alt={translations.components.button.discard}
124+
className={`xicon-base xicon-${selectedLang} ${buttonClass}`}
125+
onClick={() => onRemoveGroup(groupNumber)}
126+
/>
127+
<h3 key={displayName}>{displayName}</h3>
128+
</div>
129+
);
130+
};
131+
88132
const generateAllGroups = () => {
89133
const numFieldGroups = getNumFields();
90134
const groups = [];
@@ -93,7 +137,7 @@ const FieldGroup = ({
93137
const displayName = `${metadata?.displayName[selectedLang]} ${
94138
i + 1
95139
}`;
96-
groups.push(<h3 key={displayName}>{displayName}</h3>);
140+
groups.push(generateHeader(i, displayName));
97141
groups.push(generateSingleGroup(i));
98142
}
99143

frontend/src/components/Fields/Fields.scss

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
@import '../../styles/colors.scss';
22
@import '../../styles/variables.scss';
33

4+
.xicon-base {
5+
width: 20px;
6+
height: 20px;
7+
align-self: flex-end;
8+
}
9+
10+
.button-disabled {
11+
opacity: 0.5;
12+
}
13+
14+
.button-active:hover {
15+
opacity: 0.5;
16+
}
17+
18+
.xicon-EN {
19+
margin-right: 10px;
20+
}
21+
22+
.xicon-AR {
23+
margin-left: 10px;
24+
}
25+
26+
.group-title-container-base {
27+
display: flex;
28+
margin-left: -30px;
29+
}
30+
31+
.group-title-container-AR {
32+
margin-left: -30px;
33+
}
34+
35+
.group-title-container-EN {
36+
margin-right: -30px;
37+
}
38+
439
.datepicker {
540
padding: 18.5px 14px;
641
font-size: 1em;

0 commit comments

Comments
 (0)