Skip to content

Commit 27014f6

Browse files
Copilothotlong
andcommitted
fix: address code review feedback - WidgetHost lifecycle, ReportRenderer null safety, page-renderer pattern extraction
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 02f578c commit 27014f6

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

components/renderers/ReportRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function SummaryReport({
181181
{col.label ?? col.field} ({col.aggregate})
182182
</Text>
183183
<Text className="text-sm font-semibold text-primary">
184-
{computeAggregate(rows, col.field, col.aggregate!).toLocaleString()}
184+
{computeAggregate(rows, col.field, col.aggregate ?? "count").toLocaleString()}
185185
</Text>
186186
</View>
187187
))}

components/renderers/WidgetHost.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function WidgetHost({ type, props = {}, fallback }: WidgetHostProps) {
3434
const mountedRef = useRef(false);
3535

3636
useEffect(() => {
37-
if (!entry) return;
37+
if (!getWidget(type)) return;
3838
if (!mountedRef.current) {
3939
mountedRef.current = true;
4040
emitWidgetLifecycle({
@@ -50,7 +50,7 @@ export function WidgetHost({ type, props = {}, fallback }: WidgetHostProps) {
5050
timestamp: Date.now(),
5151
});
5252
};
53-
}, [entry, type]);
53+
}, [type]);
5454

5555
if (!entry) {
5656
if (fallback) return <>{fallback}</>;

lib/page-renderer.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ export function validatePageSchema(
8787
return raw as PageSchema;
8888
}
8989

90+
/* ------------------------------------------------------------------ */
91+
/* Constants */
92+
/* ------------------------------------------------------------------ */
93+
94+
const VARIABLE_PATTERN = /^\{\{(.+)\}\}$/;
95+
9096
/* ------------------------------------------------------------------ */
9197
/* Resolution */
9298
/* ------------------------------------------------------------------ */
@@ -101,12 +107,15 @@ function resolveProps(
101107
if (!props) return {};
102108
const resolved: Record<string, unknown> = {};
103109
for (const [key, value] of Object.entries(props)) {
104-
if (typeof value === "string" && value.startsWith("{{") && value.endsWith("}}")) {
105-
const varName = value.slice(2, -2).trim();
106-
resolved[key] = variables[varName] ?? value;
107-
} else {
108-
resolved[key] = value;
110+
if (typeof value === "string") {
111+
const match = VARIABLE_PATTERN.exec(value);
112+
if (match) {
113+
const varName = match[1].trim();
114+
resolved[key] = variables[varName] ?? value;
115+
continue;
116+
}
109117
}
118+
resolved[key] = value;
110119
}
111120
return resolved;
112121
}

0 commit comments

Comments
 (0)