@malloy-publisher/sdk 0.0.81 → 0.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -235,7 +235,7 @@ function SourceExplorerComponentInner({
235
235
 
236
236
  const onQueryChange = React.useCallback(
237
237
  (malloyQuery: Malloy.Query) => {
238
- setQuery({ ...query, malloyQuery });
238
+ setQuery({ ...query, malloyQuery, malloyResult: undefined });
239
239
  },
240
240
  [query],
241
241
  );
@@ -243,88 +243,75 @@ function SourceExplorerComponentInner({
243
243
  if (oldSourceInfo !== sourceAndPath.sourceInfo.name) {
244
244
  return <div>Loading...</div>;
245
245
  }
246
-
247
246
  return (
248
- <StyledExplorerPage key={sourceAndPath.sourceInfo.name}>
249
- <StyledExplorerContent>
250
- <MalloyExplorerProvider
251
- source={sourceAndPath.sourceInfo}
252
- query={query?.malloyQuery}
253
- onQueryChange={onQueryChange}
254
- focusedNestViewPath={focusedNestViewPath}
255
- onFocusedNestViewPathChange={setFocusedNestViewPath}
256
- onDrill={(params) => {
257
- console.info(params);
247
+ <StyledExplorerContent key={sourceAndPath.sourceInfo.name}>
248
+ <MalloyExplorerProvider
249
+ source={sourceAndPath.sourceInfo}
250
+ query={query?.malloyQuery}
251
+ onQueryChange={onQueryChange}
252
+ focusedNestViewPath={focusedNestViewPath}
253
+ onFocusedNestViewPathChange={setFocusedNestViewPath}
254
+ onDrill={(params) => {
255
+ console.info(params);
256
+ }}
257
+ >
258
+ <div
259
+ style={{
260
+ display: "flex",
261
+ height: "100%",
262
+ overflowY: "auto",
258
263
  }}
259
264
  >
260
- <div
261
- style={{
262
- display: "flex",
263
- flexDirection: "column",
264
- height: "100%",
265
- }}
265
+ <ResizableCollapsiblePanel
266
+ isInitiallyExpanded={true}
267
+ initialWidth={180}
268
+ minWidth={180}
269
+ icon="database"
270
+ title={sourceAndPath.sourceInfo.name}
266
271
  >
267
- <div
268
- style={{
269
- display: "flex",
270
- height: "100%",
271
- overflowY: "auto",
272
+ <SourcePanel
273
+ onRefresh={() => setQuery(emptyQueryExplorerResult())}
274
+ />
275
+ </ResizableCollapsiblePanel>
276
+ <ResizableCollapsiblePanel
277
+ isInitiallyExpanded={true}
278
+ initialWidth={280}
279
+ minWidth={280}
280
+ icon="filterSliders"
281
+ title="Query"
282
+ >
283
+ <QueryPanel
284
+ runQuery={() => {
285
+ mutation.mutate();
272
286
  }}
273
- >
274
- <ResizableCollapsiblePanel
275
- isInitiallyExpanded={true}
276
- initialWidth={180}
277
- minWidth={180}
278
- icon="database"
279
- title={sourceAndPath.sourceInfo.name}
280
- >
281
- <SourcePanel
282
- onRefresh={() =>
283
- setQuery(emptyQueryExplorerResult())
284
- }
285
- />
286
- </ResizableCollapsiblePanel>
287
- <ResizableCollapsiblePanel
288
- isInitiallyExpanded={true}
289
- initialWidth={280}
290
- minWidth={280}
291
- icon="filterSliders"
292
- title="Query"
293
- >
294
- <QueryPanel
295
- runQuery={() => {
296
- mutation.mutate();
297
- }}
298
- />
299
- </ResizableCollapsiblePanel>
300
- <ResultPanel
301
- source={sourceAndPath.sourceInfo}
302
- draftQuery={query?.malloyQuery}
303
- setDraftQuery={(malloyQuery) =>
304
- setQuery({ ...query, malloyQuery: malloyQuery })
305
- }
306
- submittedQuery={
307
- query?.malloyQuery
308
- ? {
309
- executionState: mutation.isPending
310
- ? "running"
311
- : "finished",
312
- response: {
313
- result: query.malloyResult,
314
- },
315
- query: query.malloyQuery,
316
- queryResolutionStartMillis: Date.now(),
317
- onCancel: mutation.reset,
318
- }
319
- : undefined
320
- }
321
- options={{ showRawQuery: true }}
322
- />
323
- </div>
324
- </div>
325
- </MalloyExplorerProvider>
326
- </StyledExplorerContent>
327
- </StyledExplorerPage>
287
+ />
288
+ </ResizableCollapsiblePanel>
289
+ <ResultPanel
290
+ source={sourceAndPath.sourceInfo}
291
+ draftQuery={query?.malloyQuery}
292
+ setDraftQuery={(malloyQuery) =>
293
+ setQuery({ ...query, malloyQuery: malloyQuery })
294
+ }
295
+ submittedQuery={
296
+ query?.malloyQuery
297
+ ? {
298
+ executionState: mutation.isPending
299
+ ? "running"
300
+ : "finished",
301
+ response: {
302
+ result: query.malloyResult,
303
+ },
304
+ query: query.malloyQuery,
305
+ queryResolutionStartMillis: Date.now(),
306
+ onCancel: mutation.reset,
307
+ }
308
+ : undefined
309
+ }
310
+ options={{ showRawQuery: true }}
311
+ />
312
+ </div>
313
+ </MalloyExplorerProvider>
314
+ </StyledExplorerContent>
328
315
  );
329
316
  }
330
317
 
@@ -366,7 +353,6 @@ export function SourceExplorerComponent(props: SourceExplorerComponentProps) {
366
353
  <StyledExplorerContent>
367
354
  <div
368
355
  style={{
369
- display: "flex",
370
356
  alignItems: "center",
371
357
  justifyContent: "center",
372
358
  height: "200px",
@@ -1,4 +1,7 @@
1
1
  export { default as Model } from "./Model";
2
+ export { ModelExplorer } from "./ModelExplorer";
2
3
  export { SourcesExplorer } from "./SourcesExplorer";
3
4
  export { SourceExplorerComponent } from "./SourcesExplorer";
4
5
  export type { SourceAndPath } from "./SourcesExplorer";
6
+ export { useModelData } from "./useModelData";
7
+ export type { ModelExplorerProps } from "./ModelExplorer";
@@ -0,0 +1,38 @@
1
+ import { Configuration, ModelsApi, CompiledModel } from "../../client";
2
+ import { usePackage } from "../Package/PackageProvider";
3
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
4
+
5
+ const modelsApi = new ModelsApi(new Configuration());
6
+
7
+ /**
8
+ * Custom hook for fetching model data. Combines usePackage context with
9
+ * useQueryWithApiError to fetch a compiled model.
10
+ */
11
+ export function useModelData(modelPath: string, versionId?: string) {
12
+ const {
13
+ projectName,
14
+ packageName,
15
+ versionId: packageVersionId,
16
+ } = usePackage();
17
+ const effectiveVersionId = versionId || packageVersionId;
18
+
19
+ return useQueryWithApiError<CompiledModel>({
20
+ queryKey: [
21
+ "package",
22
+ projectName,
23
+ packageName,
24
+ modelPath,
25
+ effectiveVersionId,
26
+ ],
27
+ queryFn: async (config) => {
28
+ const response = await modelsApi.getModel(
29
+ projectName,
30
+ packageName,
31
+ modelPath,
32
+ effectiveVersionId,
33
+ config,
34
+ );
35
+ return response.data;
36
+ },
37
+ });
38
+ }
@@ -18,8 +18,6 @@ export const StyledCardMedia = styled(CardMedia)({
18
18
  });
19
19
 
20
20
  export const StyledExplorerPage = styled("div")({
21
- display: "flex",
22
- flexDirection: "column",
23
21
  height: "100%",
24
22
  });
25
23
 
@@ -32,7 +30,6 @@ export const StyledExplorerBanner = styled("div")({
32
30
  });
33
31
 
34
32
  export const StyledExplorerContent = styled("div")({
35
- display: "flex",
36
33
  height: "75vh",
37
34
  width: "100%",
38
35
  overflowY: "auto",