Improve `useItem` API to accept collection and item IDs instead of full URL
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- react, typescript
Direzione di ricerca
Inizia leggendo gli hook useItem e useCollection esistenti, quindi esamina StacApiProvider e useStacApiContext per capire come viene esposto l'URL di base. Definisci la nuova firma degli ID di collection e item, aggiorna i chiamanti dell'hook, la documentazione, gli esempi e le indicazioni per la migrazione, quindi verifica che la query utilizzi il percorso collection-item costruito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The current useItem hook requires users to pass the full URL of an item, which is redundant and inconsistent with other hooks in the library:
// Current API
const { item } = useItem('https://stac-catalog.com/collections/sentinel-2/items/abc123');
This design has several issues:
- Redundancy: The
StacApiProvideralready knows the base API URL, yet users must construct the full URL themselves - Error-prone: Manual URL construction can lead to mistakes (typos, wrong separators, encoding issues)
- Not portable: Hardcoded URLs make switching between environments (dev/staging/prod) difficult
- Inconsistent API:
useCollectiontakes just acollectionId, butuseItemrequires a full URL
Proposed Solution
Refactor useItem to accept collectionId and itemId parameters, then construct the URL internally using the stacApi from context:
// Proposed API
const { item } = useItem('sentinel-2', 'abc123');
// Or with an object for clarity:
const { item } = useItem({ collectionId: 'sentinel-2', itemId: 'abc123' });
This follows the STAC API spec pattern: /collections/{collectionId}/items/{itemId}
Benefits
- Consistency: Matches the pattern used by
useCollection - Simplicity: No manual URL construction required
- Portability: Environment-agnostic (base URL comes from context)
- Type safety: Parameters are clearly defined
- Less error-prone: Reduces chance of URL construction mistakes
Implementation Details
The hook would:
- Accept
collectionIdanditemIdas parameters - Get
stacApifromuseStacApiContext() - Construct the URL using
stacApi.baseUrl+/collections/${collectionId}/items/${itemId} - Use this constructed URL for the query
Breaking Change
⚠️ This is a breaking change that would require a major version bump.
The hook could detect which signature is being used based on the number/type of arguments.
Related
- Consider whether other hooks might benefit from similar improvements
- Update documentation and examples
- Add migration guide if this is a breaking change
- Lingua principale
- TypeScript
- Stelle
- 34
- Fork
- 4
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di developmentseed/stac-react
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Add Flexible Search Hook Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Add File Upload Support Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
Tutte le issue di developmentseed/stac-react
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
copse-dev/agent-pane#2953 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
[Bug]: Matrix progress drafts fail with "Matrix runtime not initialized" during tool activity Apertabug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
calcite-components needs triage refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Esri/calcite-design-system#15203 ·