-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/1342 rejseplanen rewrite to fit new api WIP #243
Changes from 11 commits
64e7763
2c13edc
9d3e4d2
097fdd0
3cf36aa
0665bb5
f4b9f55
8b775c8
481b80b
3bfafa8
de0e7cb
a307b6b
2b9db2c
c78354b
d25c135
d7224aa
f6e2816
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"api": "/", | ||
"touchButtonRegions": false, | ||
"rejseplanenApiKey": "abc", | ||
"loginMethods": [ | ||
{ | ||
"type": "oidc", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ body, | |
display: flex; | ||
justify-content: center; | ||
padding: 5em; | ||
z-index: 10; | ||
z-index: 1021; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.spinner-container { | ||
display: flex; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,37 +49,47 @@ function MultiSelectComponent({ | |
const nothingSelectedLabel = | ||
noSelectedString || t("multi-dropdown.nothing-selected"); | ||
|
||
/** Map data to fit component. */ | ||
useEffect(() => { | ||
const localMappedOptions = | ||
options?.map((item) => { | ||
return { | ||
label: item.title || item.name, | ||
value: item["@id"] || item.id, | ||
disabled: false, | ||
}; | ||
}) ?? []; | ||
let localMappedSelected = []; | ||
/** | ||
* @param {Array} arrayWithDuplicates - Array of objects to make unique | ||
* @param {string} key - The key to make array unique by. | ||
* @returns {Array} Unique array | ||
*/ | ||
function removeDuplicatesByKey(arrayWithDuplicates, key) { | ||
return [ | ||
...new Map(arrayWithDuplicates.map((item) => [item[key], item])).values(), | ||
]; | ||
} | ||
|
||
if (selected.length > 0) { | ||
localMappedSelected = selected.map((item) => { | ||
/** | ||
* @param {Array} dataToMap - The data to map to {label, value, disabled} | ||
* @returns {Array} An array of {label, value, disabled} | ||
*/ | ||
function mapDataToFitMultiselect(dataToMap) { | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why ( ) around the return value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the linter does it |
||
dataToMap.map((item) => { | ||
return { | ||
label: item.title || item.name, | ||
value: item["@id"] || item.id, | ||
disabled: false, | ||
}; | ||
}); | ||
} | ||
}) ?? [] | ||
); | ||
} | ||
|
||
/** Map data to fit component. */ | ||
useEffect(() => { | ||
const localMappedOptions = | ||
options.length > 0 ? mapDataToFitMultiselect(options) : []; | ||
|
||
const localMappedSelected = | ||
selected.length > 0 ? mapDataToFitMultiselect(selected) : []; | ||
|
||
const optionsWithSelected = Object.values( | ||
[...localMappedOptions, ...localMappedSelected].reduce((a, c) => { | ||
const aCopy = { ...a }; | ||
aCopy[c.value] = c; | ||
return aCopy; | ||
}, {}) | ||
const optionsWithSelected = removeDuplicatesByKey( | ||
[...localMappedOptions, ...localMappedSelected], | ||
"value" | ||
); | ||
setMappedOptions(optionsWithSelected); | ||
|
||
setMappedOptions(optionsWithSelected); | ||
setMappedSelected(localMappedSelected); | ||
}, [selected, selected.length, options]); | ||
|
||
|
@@ -103,29 +113,39 @@ function MultiSelectComponent({ | |
); | ||
}; | ||
|
||
/** | ||
* Filter to replace the default filter in multi-select. It matches the label name. | ||
* | ||
* @param {Array} multiselectData Data from the multiselect component | ||
* @returns {Array} Array of selected values without duplicates | ||
*/ | ||
const addOrRemoveNewEntryToSelected = (multiselectData) => { | ||
let selectedOptions = []; | ||
const idsOfSelectedEntries = multiselectData.map(({ value }) => value); | ||
|
||
selectedOptions = removeDuplicatesByKey( | ||
[...selected, ...options].filter((option) => | ||
idsOfSelectedEntries.includes(option["@id"] || option.id) | ||
), | ||
"id" | ||
); | ||
|
||
if (singleSelect) { | ||
selectedOptions = [selectedOptions[selectedOptions.length - 1]]; | ||
} | ||
|
||
return selectedOptions; | ||
}; | ||
|
||
/** | ||
* A callback on changed data. | ||
* | ||
* @param {Array} data The data to call back with | ||
*/ | ||
const changeData = (data) => { | ||
let selectedOptions = []; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New lines around if statements increase the readability of the code. |
||
if (data.length > 0) { | ||
const ids = data.map(({ value }) => value); | ||
selectedOptions = Object.values( | ||
[...selected, ...options] | ||
.filter((option) => ids.includes(option["@id"] || option.id)) | ||
.reduce((a, c) => { | ||
const aCopy = { ...a }; | ||
aCopy[c["@id"] || c.id] = c; | ||
return aCopy; | ||
}, {}) | ||
); | ||
|
||
if (singleSelect) { | ||
selectedOptions = [selectedOptions[selectedOptions.length - 1]]; | ||
} | ||
selectedOptions = addOrRemoveNewEntryToSelected(data); | ||
} | ||
|
||
const target = { value: selectedOptions, id: name }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be added to the infrastructure templates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value should be null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "the infrastructure templates"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/os2display/display-admin-client/blob/develop/infrastructure/itkdev/etc/confd/templates/config.tmpl
https://github.com/os2display/display-admin-client/blob/develop/infrastructure/os2display/etc/confd/templates/config.tmpl