-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev-tools): improve support for non-store recs components (#1302)
- Loading branch information
Showing
8 changed files
with
106 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@latticexyz/dev-tools": patch | ||
"@latticexyz/store-sync": patch | ||
--- | ||
|
||
Improves support for internal/client-only RECS components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useEntityQuery } from "@latticexyz/react"; | ||
import { Component, Has, Schema, getComponentValueStrict } from "@latticexyz/recs"; | ||
import { StoreComponentMetadata, decodeEntity } from "@latticexyz/store-sync/recs"; | ||
|
||
// TODO: use react-table or similar for better perf with lots of logs | ||
|
||
type Props = { | ||
component: Component<Schema, StoreComponentMetadata>; | ||
}; | ||
|
||
export function StoreComponentDataTable({ component }: Props) { | ||
// TODO: this breaks when navigating because its state still has entity IDs from prev page | ||
const entities = useEntityQuery([Has(component)]); | ||
|
||
return ( | ||
<table className="w-full -mx-1"> | ||
<thead className="sticky top-0 z-10 bg-slate-800 text-left"> | ||
<tr className="text-amber-200/80 font-mono"> | ||
{Object.keys(component.metadata.keySchema).map((name) => ( | ||
<th key={name} className="px-1 pt-1.5 font-normal"> | ||
{name} | ||
</th> | ||
))} | ||
{Object.keys(component.metadata.valueSchema).map((name) => ( | ||
<th key={name} className="px-1 pt-1.5 font-normal"> | ||
{name} | ||
</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody className="font-mono text-xs"> | ||
{entities.map((entity) => { | ||
const key = decodeEntity(component.metadata.keySchema, entity); | ||
const value = getComponentValueStrict(component, entity); | ||
return ( | ||
<tr key={entity}> | ||
{Object.keys(component.metadata.keySchema).map((name) => ( | ||
<td key={name} className="px-1 whitespace-nowrap overflow-hidden text-ellipsis"> | ||
{String(key[name])} | ||
</td> | ||
))} | ||
{Object.keys(component.metadata.valueSchema).map((name) => { | ||
const fieldValue = value[name]; | ||
return ( | ||
<td key={name} className="px-1 whitespace-nowrap overflow-hidden text-ellipsis"> | ||
{Array.isArray(fieldValue) ? fieldValue.map(String).join(", ") : String(fieldValue)} | ||
</td> | ||
); | ||
})} | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Component } from "@latticexyz/recs"; | ||
|
||
export function getComponentName(component: Component): string { | ||
return String(component.metadata?.componentName ?? component.id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters