[Feature request] Resolve directives in conditions (visible, $cond)
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- frontend
Direzione di ricerca
Start with resolveComparisonValue and resolveConditionValue in @json-render/core, then trace the visibility condition types and VisibilityConditionSchema and VisibilityConditionStrictSchema. Check the conditions section of catalog.prompt({ directives }) for the prompt update. Done means registered directives resolve on either side of comparisons, accepted types and schemas validate them, and runtime behavior is covered for visible and $cond.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! Thanks for json-render, directives have been really useful for us. Here's a small feature request around conditions.
Context
Directives (defineDirective) are resolved in props and action params (via resolvePropValue), but not in conditions. In @json-render/core 0.20:
resolveComparisonValue(the right side ofeq,neq,gt,lt…) only resolves{ "$state" }; any other object is compared as is.resolveConditionValue(the left side) only accepts$state,$itemor$index.
Use case
Comparing against a value computed at render time, with the standard directives or a custom one:
{ "visible": { "$count": { "$state": "/cart/items" }, "gt": 0 } }
{
"visible": {
"$state": "/product/stock",
"lt": { "$math": "multiply", "a": { "$state": "/product/minStock" }, "b": 2 }
}
}
{ "visible": { "$item": "dueDate", "eq": { "$today": true } } }
($today would be a custom directive that returns today's date.)
Current behavior
- On the right side, the directive is compared as a literal object: the condition never matches, with no warning.
- On the left side, the condition has no
$state,$itemor$index: its value isundefined, andvalidateSpecrejects it (VisibilityConditionStrictSchema).
The workaround today is to save the value to state first (a setState on some event) and compare against { "$state" }. It's more verbose for whoever writes the spec (or the model generating it), and the value goes stale until that event runs again.
Proposal
Resolve a registered directive on both sides of a comparison. The ctx already carries directives both in an element's visible (the renderer builds the full context) and in $cond (resolvePropValue):
function resolveComparisonValue(value, ctx) {
if (typeof value === "object" && value !== null) {
if ("$state" in value && typeof value.$state === "string") {
return getByPath(ctx.stateModel, value.$state);
}
const directive = findDirective(value, ctx.directives);
if (directive) return directive.resolve(value, ctx);
}
return value;
}
function resolveConditionValue(cond, ctx) {
// … $index and $item as today
const directive = findDirective(cond, ctx.directives);
if (directive) return directive.resolve(cond, ctx);
return getByPath(ctx.stateModel, cond.$state);
}
On the left side, the directive gets the object with its operator included (gt, eq…), which its resolve ignores.
To be consistent, this would also need:
- Types:
gt/gte/lt/lteaccepting a directive, and aSingleConditionvariant whose value is a directive. - Schemas:
VisibilityConditionSchemaandVisibilityConditionStrictSchemaaccepting those forms, sovalidateSpecdoesn't flag them as invalid. - Prompt: a line in the conditions section of
catalog.prompt({ directives }), so the model knows it can use a directive on either side.
We tested it with a local patch of @json-render/core 0.20, covering runtime and types. Happy to open a PR if this sounds good, thanks!
- Lingua principale
- TypeScript
- Stelle
- 20k
- Fork
- 1.1k
- Merge medio
- 1g 18h
- PR unite (30g)
- 25
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
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 vercel-labs/json-render
-
React Quick Start examples fail at runtime: Renderer must be wrapped in JSONUIProviderForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
vercel-labs/json-render#443 ·
I maintainer di solito rispondono entro 2 giorni
-
shadcn Grid/Stack are not responsive (fixed grid-cols-N, no min-w-0)Forse già presa @sushanshakya77 l’ha presa 67 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
vercel-labs/json-render#355 ·
I maintainer di solito rispondono entro 2 giorni
-
Array path helpers accept malformed RFC 6902 indexesForse già presa @simonyang08 l’ha presa 106 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
vercel-labs/json-render#326 ·
I maintainer di solito rispondono entro 2 giorni
-
Support zod 4.4+ — _zod.version.minor type check prevents upgradeForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
vercel-labs/json-render#297 · 2 reazioni ·
I maintainer di solito rispondono entro 2 giorni
-
feat: Generic `Spec` type supportForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
vercel-labs/json-render#275 · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di vercel-labs/json-render
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ClickHouse/clickhouse-js#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
agent/quality testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno