@malloy-publisher/sdk 0.0.126 → 0.0.128

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.0.126",
4
+ "version": "0.0.128",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -162,6 +162,11 @@ export const connectionFieldsByType: Record<
162
162
  name: "password",
163
163
  type: "password",
164
164
  },
165
+ {
166
+ label: "Peaka Key",
167
+ name: "peakaKey",
168
+ type: "password",
169
+ },
165
170
  ],
166
171
  mysql: [
167
172
  {
@@ -22,13 +22,18 @@ import { useModelData } from "./useModelData";
22
22
  interface ModelProps {
23
23
  onChange?: (query: QueryExplorerResult) => void;
24
24
  resourceUri: string;
25
+ runOnDemand?: boolean;
25
26
  }
26
27
 
27
28
  // Note: For this to properly render outside of publisher,
28
29
  // you must explicitly import the styles from the package:
29
30
  // import "@malloy-publisher/sdk/malloy-explorer.css";
30
31
 
31
- export default function Model({ onChange, resourceUri }: ModelProps) {
32
+ export default function Model({
33
+ onChange,
34
+ resourceUri,
35
+ runOnDemand = false,
36
+ }: ModelProps) {
32
37
  const { modelPath } = parseResourceUri(resourceUri);
33
38
  const { data, isError, isLoading, error } = useModelData(resourceUri);
34
39
  const [dialogOpen, setDialogOpen] = React.useState(false);
@@ -184,6 +189,7 @@ export default function Model({ onChange, resourceUri }: ModelProps) {
184
189
  queryName={query.name}
185
190
  annotations={query.annotations}
186
191
  resourceUri={resourceUri}
192
+ runOnDemand={runOnDemand}
187
193
  />
188
194
  ))}
189
195
  </Stack>
@@ -1,5 +1,6 @@
1
+ import PlayArrowIcon from "@mui/icons-material/PlayArrow";
1
2
  import SearchIcon from "@mui/icons-material/Search";
2
- import { Box, IconButton, Typography } from "@mui/material";
3
+ import { Box, Button, IconButton, Typography } from "@mui/material";
3
4
  import React, { useEffect } from "react";
4
5
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
5
6
  import { parseResourceUri } from "../../utils/formatting";
@@ -15,16 +16,19 @@ interface ModelCellProps {
15
16
  noView?: boolean;
16
17
  annotations?: string[];
17
18
  resourceUri: string;
19
+ runOnDemand?: boolean;
18
20
  }
19
21
 
20
22
  export function ModelCell({
21
23
  queryName,
22
24
  annotations,
23
25
  resourceUri,
26
+ runOnDemand = false,
24
27
  }: ModelCellProps) {
25
28
  const [highlightedAnnotations, setHighlightedAnnotations] =
26
29
  React.useState<string>();
27
30
  const [resultsDialogOpen, setResultsDialogOpen] = React.useState(false);
31
+ const [hasRun, setHasRun] = React.useState(false);
28
32
 
29
33
  const { packageName, projectName, versionId, modelPath } =
30
34
  parseResourceUri(resourceUri);
@@ -48,7 +52,7 @@ export function ModelCell({
48
52
  versionId: versionId,
49
53
  },
50
54
  ),
51
- enabled: true, // Always execute
55
+ enabled: runOnDemand ? hasRun : true, // Execute on demand or always
52
56
  });
53
57
 
54
58
  useEffect(() => {
@@ -126,19 +130,54 @@ export function ModelCell({
126
130
  position: "relative",
127
131
  }}
128
132
  >
129
- {isLoading && (
133
+ {runOnDemand && !hasRun && (
134
+ <Box
135
+ sx={{
136
+ padding: "40px 20px",
137
+ textAlign: "center",
138
+ display: "flex",
139
+ flexDirection: "column",
140
+ alignItems: "center",
141
+ gap: "16px",
142
+ }}
143
+ >
144
+ <Typography variant="body2" color="text.secondary">
145
+ Click Run to execute the query
146
+ </Typography>
147
+ <Button
148
+ variant="contained"
149
+ startIcon={<PlayArrowIcon />}
150
+ onClick={() => setHasRun(true)}
151
+ sx={{
152
+ backgroundColor: "#1976d2",
153
+ "&:hover": {
154
+ backgroundColor: "#1565c0",
155
+ },
156
+ textTransform: "none",
157
+ fontSize: "14px",
158
+ fontWeight: 600,
159
+ padding: "8px 24px",
160
+ }}
161
+ >
162
+ Run Query
163
+ </Button>
164
+ </Box>
165
+ )}
166
+ {(!runOnDemand || hasRun) && isLoading && (
130
167
  <Box sx={{ padding: "20px", textAlign: "center" }}>
131
168
  <Typography>Loading results...</Typography>
132
169
  </Box>
133
170
  )}
134
- {isSuccess && queryData?.data?.result && (
135
- <ResultContainer
136
- result={queryData.data.result}
137
- minHeight={300}
138
- maxHeight={600}
139
- hideToggle={false}
140
- />
141
- )}
171
+ {(!runOnDemand || hasRun) &&
172
+ isSuccess &&
173
+ queryData?.data?.result && (
174
+ <ResultContainer
175
+ result={queryData.data.result}
176
+ minHeight={300}
177
+ maxHeight={600}
178
+ hideToggle={false}
179
+ />
180
+ )}
142
181
  </CleanMetricCard>
143
182
 
144
183
  {/* Results Dialog */}
@@ -36,7 +36,7 @@ type ConnectionProps = {
36
36
  connection: ApiConnection;
37
37
  onClick: () => void;
38
38
  onEdit: (connection: ApiConnection) => Promise<unknown>;
39
- onDelete: (connection: ApiConnection) => Promise<unknown>;
39
+ onDelete: (connection: ApiConnection) => Promise<unknown> | void;
40
40
  isMutating: boolean;
41
41
  mutable: boolean;
42
42
  };
@@ -274,9 +274,19 @@ export default function Connections({ resourceUri }: ConnectionsProps) {
274
274
  onEdit={(payload) =>
275
275
  updateConnection.mutateAsync(payload)
276
276
  }
277
- onDelete={(payload) =>
278
- deleteConnection.mutateAsync(payload)
279
- }
277
+ onDelete={(payload) => {
278
+ if (
279
+ !selectedConnectionResourceUri.startsWith(
280
+ "publisher:",
281
+ )
282
+ ) {
283
+ deleteConnection.mutateAsync(payload);
284
+ } else {
285
+ setNotificationMessage(
286
+ "Cannot delete this connection (publisher: resource)",
287
+ );
288
+ }
289
+ }}
280
290
  isMutating={
281
291
  updateConnection.isPending ||
282
292
  deleteConnection.isPending