Skip to content

Commit

Permalink
feat: use label property to render info in search inputs and to sort …
Browse files Browse the repository at this point in the history
…elements (#210)
  • Loading branch information
rboixaderg authored Jan 20, 2024
1 parent f1ed752 commit 0f6913b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.25.2
------
- feat: use label property to render info in search inputs and to sort elements

0.25.1
------
- chore: export generic Messages
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.25.1",
"version": "0.25.2",
"repository": {
"type": "git",
"url": "[email protected]:guillotinaweb/guillotina_react.git"
Expand Down
7 changes: 2 additions & 5 deletions src/guillo-gmi/components/input/search_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const SearchInput = ({
const wrapperRef = React.useRef(null)
const { PageSize, SearchEngine } = useConfig()
const [valueLabel, setValueLabel] = useState(undefined)
const [isLoadingData, setIsLoadingData] = useState(false)
const [uid] = useState(generateUID('search_input'))

useClickAway(wrapperRef, () => {
Expand All @@ -85,7 +84,6 @@ export const SearchInput = ({

const inicializeLabels = async () => {
if (labelProperty !== 'id' && value) {
setIsLoadingData(true)
let searchTermQs = []
const searchTermParsed = [`id`, value]
const { get: getSearch } = traversal.registry
Expand Down Expand Up @@ -124,7 +122,6 @@ export const SearchInput = ({
return result
}, {})
setValueLabel(newValuesLabel)
setIsLoadingData(false)
}
}

Expand All @@ -143,7 +140,7 @@ export const SearchInput = ({
pageSize: PageSize,
withDepth: false,
})
let sortParsed = parser(`_sort_des=title`)
let sortParsed = parser(`_sort_des=${labelProperty}`)
let typeNameParsed = []
if (typeNameQuery) {
typeNameParsed = parser(`type_name__in=${typeNameQuery}`)
Expand Down Expand Up @@ -185,7 +182,7 @@ export const SearchInput = ({
if (renderTextItemOption) {
return renderTextItemOption(item)
}
return item.title || item['@name']
return get(item, labelProperty, item.title) || item['@name']
}

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/guillo-gmi/components/input/search_input_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const SearchInputList = ({
pageSize: PageSize,
withDepth: false,
})
let sortParsed = parser(`_sort_des=title`)
let sortParsed = parser(`_sort_des=${labelProperty}`)
let typeNameParsed = []
if (typeNameQuery) {
typeNameParsed = parser(`type_name__in=${typeNameQuery}`)
Expand Down Expand Up @@ -188,7 +188,7 @@ export const SearchInputList = ({
if (renderTextItemOption) {
return renderTextItemOption(item)
}
return item.title || item['@name']
return get(item, labelProperty, item.title) || item['@name']
}

React.useEffect(() => {
Expand Down

0 comments on commit 0f6913b

Please sign in to comment.