Skip to content

Commit f80a92e

Browse files
Merge pull request #262 from os2display/feature/2807-template-layout-selected-validation
2807 template layout selected validation
2 parents 2ce8303 + 1cb200c commit f80a92e

8 files changed

Lines changed: 60 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ All notable changes to this project will be documented in this file.
55

66
## [Unreleased]
77

8+
- [#265](https://github.com/os2display/display-admin-client/pull/265)
9+
- Add no-cache directive
10+
811
- [#263](https://github.com/os2display/display-admin-client/pull/263)
912
- Added prefix to local storage keys.
13+
14+
- [#262](https://github.com/os2display/display-admin-client/pull/262)
15+
- Add multi select styling for `invalid` state
16+
- Add possibility of sending error via props to multiselect component
17+
- Add validation checking if layout is selected on screen before save
18+
- Add validation checking if template is selected on slide before save
19+
1020
- [#260](https://github.com/os2display/display-admin-client/pull/260)
1121
- Bug in multiselect, fixed by removing duplicates by key both `@id`and `id`
1222
- [#265](https://github.com/os2display/display-admin-client/pull/265)
1323
- Bug in multiselect, fixed by removing duplicates by key both `@id`and `id`
24+
1425
- [#259](https://github.com/os2display/display-admin-client/pull/259)
1526
- Add saving of playlists/groups with screen (as opposed to _after_)
1627
- Clean up `screen-manager.jsx`

e2e/slides.spec.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ test.describe("Create slide page works", () => {
145145
page.locator(".Toastify").locator(".Toastify__toast--error")
146146
).toBeVisible();
147147
await expect(
148-
page
149-
.locator(".Toastify")
150-
.locator(".Toastify__toast--error")
151-
.getByText(/An error occurred/)
152-
.first()
148+
page.locator(".Toastify").locator(".Toastify__toast--error").first()
153149
).toBeVisible();
154150
await expect(page).toHaveURL(/slide\/create/);
155151
});

src/components/screen/screen-form.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function ScreenForm({
5050
const { t } = useTranslation("common", { keyPrefix: "screen-form" });
5151
const navigate = useNavigate();
5252
const dispatch = useDispatch();
53+
const [layoutError, setLayoutError] = useState(false);
5354
const [selectedLayout, setSelectedLayout] = useState();
5455
const [layoutOptions, setLayoutOptions] = useState();
5556
const [bindKey, setBindKey] = useState("");
@@ -59,6 +60,21 @@ function ScreenForm({
5960
order: { createdAt: "desc" },
6061
});
6162

63+
/** Check if published is set */
64+
const checkInputsHandleSubmit = () => {
65+
setLayoutError(false);
66+
let submit = true;
67+
if (!selectedLayout) {
68+
displayError(t("remember-layout-error"));
69+
setLayoutError(true);
70+
submit = false;
71+
}
72+
73+
if (submit) {
74+
handleSubmit();
75+
}
76+
};
77+
6278
useEffect(() => {
6379
if (layouts) {
6480
setLayoutOptions(layouts["hydra:member"]);
@@ -283,6 +299,7 @@ function ScreenForm({
283299
helpText={t("search-to-se-possible-selections")}
284300
selected={selectedLayout ? [selectedLayout] : []}
285301
name="layout"
302+
error={layoutError}
286303
singleSelect
287304
/>
288305
</div>
@@ -327,7 +344,7 @@ function ScreenForm({
327344
type="button"
328345
id="save_screen"
329346
size="lg"
330-
onClick={handleSubmit}
347+
onClick={checkInputsHandleSubmit}
331348
>
332349
{t("save-button")}
333350
</Button>

src/components/screen/screen-manager.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function ScreenManager({
257257
regions: mapPlaylistsWithRegion(),
258258
}),
259259
};
260-
debugger;
260+
261261
setLoadingMessage(t("loading-messages.saving-screen"));
262262

263263
if (saveMethod === "POST") {

src/components/slide/slide-form.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function SlideForm({
7272
const [searchTextTheme, setSearchTextTheme] = useState("");
7373
const [selectedTemplates, setSelectedTemplates] = useState([]);
7474
const [themesOptions, setThemesOptions] = useState();
75+
const [templateError, setTemplateError] = useState(false);
7576

7677
// Load templates.
7778
const { data: templates, isLoading: loadingTemplates } =
@@ -87,6 +88,21 @@ function SlideForm({
8788
order: { createdAt: "desc" },
8889
});
8990

91+
/** Check if published is set */
92+
const checkInputsHandleSubmit = () => {
93+
setTemplateError(false);
94+
let submit = true;
95+
if (!selectedTemplate) {
96+
setTemplateError(true);
97+
submit = false;
98+
displayError(t("slide-form.remember-template-error"));
99+
}
100+
101+
if (submit) {
102+
handleSubmit();
103+
}
104+
};
105+
90106
/**
91107
* For closing overlay on escape key.
92108
*
@@ -227,6 +243,7 @@ function SlideForm({
227243
handleSelection={selectTemplate}
228244
options={templateOptions}
229245
selected={selectedTemplates}
246+
error={templateError}
230247
name="templateInfo"
231248
filterCallback={onFilterTemplate}
232249
singleSelect
@@ -484,7 +501,7 @@ function SlideForm({
484501
<Button
485502
variant="primary"
486503
type="button"
487-
onClick={handleSubmit}
504+
onClick={checkInputsHandleSubmit}
488505
id="save_slide"
489506
size="lg"
490507
>

src/components/util/forms/multiselect-dropdown/multi-dropdown.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import "./multi-dropdown.scss";
2626
* @param {Function} props.filterCallback - The callback on search filter.
2727
* @param {boolean} props.singleSelect - If the dropdown is single select.
2828
* @param {boolean} props.disableSearch - Disable search option.
29+
* @param props.error
2930
* @returns {object} - The multidropdown
3031
*/
3132
function MultiSelectComponent({
@@ -35,6 +36,7 @@ function MultiSelectComponent({
3536
noSelectedString = null,
3637
isLoading = false,
3738
errorText = "",
39+
error = false,
3840
helpText = null,
3941
selected = [],
4042
options = [],
@@ -43,7 +45,6 @@ function MultiSelectComponent({
4345
filterCallback = () => {},
4446
}) {
4547
const { t } = useTranslation("common");
46-
const [error] = useState();
4748
const [mappedOptions, setMappedOptions] = useState();
4849
const [mappedSelected, setMappedSelected] = useState();
4950
const textOnError = errorText || t("multi-dropdown.validation-text");
@@ -224,6 +225,7 @@ MultiSelectComponent.propTypes = {
224225
name: PropTypes.string.isRequired,
225226
isLoading: PropTypes.bool,
226227
errorText: PropTypes.string,
228+
error: PropTypes.bool,
227229
label: PropTypes.string.isRequired,
228230
helpText: PropTypes.string,
229231
singleSelect: PropTypes.bool,

src/components/util/forms/multiselect-dropdown/multi-dropdown.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
@import "bootstrap/scss/bootstrap";
2+
13
.rmsc {
4+
&.invalid {
5+
border: 1px solid $red;
6+
}
7+
28
&.single-select {
39
input[type="checkbox"] {
410
opacity: 0;

src/translations/da/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
"slide-form": {
306306
"slide-template-selected": "Skabelon",
307307
"template-error": "Der skete en fejl da skabelonen skulle hentes:",
308+
"remember-template-error": "Husk at tilknytte en skabelon til dit slide",
308309
"touch-region": "Touch region",
309310
"touch-region-button-text-label": "Knaptekst i touch region",
310311
"touch-region-button-text-helptext": "Her kan du sætte knapteksten, hvis slidet indgår i en touch region, hvor slides bliver vist som knapper der kan åbnes.",
@@ -670,6 +671,7 @@
670671
}
671672
},
672673
"screen-form": {
674+
"remember-layout-error": "Husk at tilknytte et layout til din skærm",
673675
"enable-color-scheme-change-headline": "Farveskema",
674676
"enable-color-scheme-change": "Aktivér farveskema skift",
675677
"enable-color-scheme-change-helptext": "Hvis dette aktiveres vil skærmen skifte til \"dark mode\" når solen går ned og skifte til normal visning når solen står op. Dette påvirker kun skabeloner der understøtter \"dark mode\".",

0 commit comments

Comments
 (0)