Skip to content

Commit

Permalink
Merge pull request #304 from commercelayer/avoid-useless-api-resource…
Browse files Browse the repository at this point in the history
…stags

Avoid useless api requests in `ResourceTags`
  • Loading branch information
pfferrari authored Aug 18, 2023
2 parents c28f664 + 38c8e50 commit 979ac96
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/app-elements/src/ui/resources/ResourceTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ export const ResourceTags = withSkeletonTemplate<{
]
)

const { data: organizationTags } = useCoreApi('tags', 'list', [
{
fields: ['id', 'name'],
sort: ['updated_at'],
pageSize: 10
}
])
const { sdkClient } = useCoreSdkProvider()

const tagsToSelectOptions = useCallback(
Expand Down Expand Up @@ -93,7 +86,7 @@ export const ResourceTags = withSkeletonTemplate<{
tagsToSelectOptions(resourceTags ?? [])
)

if (resourceTags == null || organizationTags == null) return <></>
if (resourceTags == null) return <></>

return (
<div>
Expand Down Expand Up @@ -189,9 +182,12 @@ export const ResourceTags = withSkeletonTemplate<{
isClearable={false}
isOptionDisabled={() => selectedTags.length >= 10}
loadAsyncValues={async (hint) => {
return await sdkClient.tags
.list(makeTagQuery(hint))
.then(tagsToSelectOptions)
if (hint.length > 0) {
return await sdkClient.tags
.list(makeTagQuery(hint))
.then(tagsToSelectOptions)
}
return []
}}
initialValues={[]}
defaultValue={tagsToSelectOptions(resourceTags)}
Expand Down

0 comments on commit 979ac96

Please sign in to comment.