Skip to content
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

feat: use label property to render info in search inputs and to sort elements #210

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading