Skip to content

Commit 889cd89

Browse files
authored
fix(data-preview): Select correct schema (#89)
* chore(bump-npm): Bump npm as it seems to increase start up time locally * fix(preview): Fix bug in preview where we would query the wrong schema
1 parent f886288 commit 889cd89

File tree

4 files changed

+17
-66
lines changed

4 files changed

+17
-66
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"ace-linters": "^0.13.3",
2222
"daisyui": "^3.9.3",
2323
"install": "^0.13.0",
24-
"npm": "^10.2.1",
2524
"react": "^18.2.0",
2625
"react-ace": "^10.1.0",
2726
"react-data-table-component": "^7.5.4",

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@
120120
<goal>install-node-and-npm</goal>
121121
</goals>
122122
<configuration>
123-
<nodeVersion>v18.18.2</nodeVersion>
124-
<npmVersion>9.8.1</npmVersion>
123+
<nodeVersion>v20.10.0</nodeVersion>
124+
<npmVersion>10.2.3</npmVersion>
125125
</configuration>
126126
</execution>
127127
<execution>

src/main/js/routes/content/enhanced-content.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,7 @@ function EnhancedContent() {
2828

2929
// Handler for clickable headers - integrates with query.js
3030
const handleHeaderClick = (headerText) => {
31-
// Navigate to schema page with the header text inserted
32-
// This assumes you have a schema selected - you might need to adjust this logic
33-
const firstSchema = vespaState.content.clusters[0]?.contentData[0]?.schema?.schemaName;
34-
if (firstSchema) {
35-
const queryField = queryFieldFromSearchParam(firstSchema);
36-
const currentQuery = searchParams.get(queryField) || `SELECT * from ${firstSchema} where true`;
37-
38-
// Insert the header text into the query at cursor position
39-
// For demo purposes, we'll append it to the WHERE clause
40-
const updatedQuery = currentQuery.replace(
41-
/where\s+true/i,
42-
`where ${headerText.toLowerCase().replace(/\s+/g, '_')} = "value" AND true`
43-
);
44-
45-
searchParams.set(queryField, updatedQuery);
46-
setSearchParams(searchParams);
47-
navigate(`/app/schema/${firstSchema}?${searchParams.toString()}`);
48-
}
31+
console.log(`Header clicked: ${headerText}. To query this field, please navigate to a specific schema page.`);
4932
};
5033

5134
return (<TabView tabs={tabs}></TabView>);

src/main/js/routes/schema/preview.js

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@ import VispanaApiClient from "../../client/vispana-api-client";
55
import Loading from "../loading/loading";
66
import VispanaError from "../error/vispana-error";
77

8-
function Preview() {
9-
const vispanaState = useOutletContext()
8+
function Preview({ containerUrl, schema }) {
9+
const vispanaClient = new VispanaApiClient();
1010
const [data, setData] = useState({ columns: [], content: [] });
11-
const [loading, setLoading] = useState(true);
11+
const [loading, setLoading] = useState(false);
1212
const [error, setError] = useState({ hasError: false, error: "" });
1313
const [totalRows, setTotalRows] = useState(0);
14-
15-
// pagination state - copied from query-result.js
16-
const [offset, setOffset] = useState(0);
17-
const [perPage, setPerPage] = useState(15); // Will be updated on mount
1814
const [page, setPage] = useState(1);
15+
const [offset, setOffset] = useState(0);
16+
const [perPage, setPerPage] = useState(10);
1917
const [optimalPageSize, setOptimalPageSize] = useState(15); // Store calculated optimal size
20-
const [isOptimalSizeCalculated, setIsOptimalSizeCalculated] = useState(false); // Track calculation completion
2118
const [gridHeight, setGridHeight] = useState('70vh'); // Dynamic grid height
22-
23-
const vispanaClient = new VispanaApiClient();
19+
const [isOptimalSizeCalculated, setIsOptimalSizeCalculated] = useState(false); // Track calculation completion
2420

2521
// Track important pagination changes
2622
React.useEffect(() => {
@@ -102,36 +98,9 @@ function Preview() {
10298

10399
useEffect(() => {
104100
const fetchPreviewData = async () => {
105-
// Try to find schema in different locations
106-
let activeSchema = vispanaState.activeSchema;
107-
let containerUrl = vispanaState.containerUrl;
108-
109-
// Check if schema is in content clusters
110-
if (!activeSchema && vispanaState.content?.clusters?.length > 0) {
111-
const firstCluster = vispanaState.content.clusters[0];
112-
if (firstCluster.contentData?.length > 0) {
113-
activeSchema = firstCluster.contentData[0].schema?.schemaName;
114-
console.log('Found schema in content.clusters:', activeSchema);
115-
}
116-
}
117-
118-
// Use the same logic as other query components to find queryable container
119-
if (!containerUrl && vispanaState.container?.clusters?.length > 0) {
120-
const queryableClusters = vispanaState.container.clusters.filter(cluster => cluster.canSearch === true);
121-
if (queryableClusters.length > 0 && queryableClusters[0].route) {
122-
containerUrl = queryableClusters[0].route;
123-
} else {
124-
console.log('No queryable containers found or no route set');
125-
console.log('Available clusters:', vispanaState.container.clusters.map(c => ({
126-
name: c.name,
127-
canSearch: c.canSearch,
128-
route: c.route
129-
})));
130-
}
131-
}
132-
133-
if (!activeSchema) {
134-
console.log('No active schema found, setting error');
101+
// Use the props directly, just like query.js does
102+
if (!schema) {
103+
console.log('No schema provided');
135104
setError({
136105
hasError: true,
137106
error: "No schema available for preview"
@@ -141,7 +110,7 @@ function Preview() {
141110
}
142111

143112
if (!containerUrl) {
144-
console.log('No container URL found, setting error');
113+
console.log('No container URL provided');
145114
setError({
146115
hasError: true,
147116
error: "Container URL not available"
@@ -155,7 +124,7 @@ function Preview() {
155124

156125
try {
157126
const defaultQuery = {
158-
yql: `SELECT * from ${activeSchema} WHERE true LIMIT ${perPage};`
127+
yql: `SELECT * from ${schema} WHERE true LIMIT ${perPage};`
159128
};
160129

161130
console.log('Executing query:', defaultQuery);
@@ -231,16 +200,16 @@ function Preview() {
231200
if (isOptimalSizeCalculated && perPage > 0) {
232201
fetchPreviewData();
233202
}
234-
}, [vispanaState, offset, perPage, isOptimalSizeCalculated]); // Combined dependencies
203+
}, [schema, containerUrl, offset, perPage, isOptimalSizeCalculated]); // Updated dependencies
235204

236-
// Reset pagination when vispanaState changes (but prevent infinite loop)
205+
// Reset pagination when schema or containerUrl changes
237206
useEffect(() => {
238207
if (page !== 1 || offset !== 0) {
239208
setPage(1);
240209
setOffset(0);
241210
}
242211
setError({ hasError: false, error: "" });
243-
}, [vispanaState]);
212+
}, [schema, containerUrl]);
244213

245214
// Process query results into grid format
246215
const processResult = (result) => {

0 commit comments

Comments
 (0)