@quillsql/react 2.16.24 → 2.16.25

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.
Files changed (3) hide show
  1. package/dist/index.cjs +24 -103
  2. package/dist/index.js +24 -103
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -17028,22 +17028,6 @@ function getSelectFromAST(ast) {
17028
17028
  return ast;
17029
17029
  }
17030
17030
  }
17031
- function processStarColumn(ast, columns) {
17032
- if (ast.columns === "*") {
17033
- ast.columns = columns.map((column) => {
17034
- return {
17035
- type: "expr",
17036
- expr: {
17037
- type: "column_ref",
17038
- table: null,
17039
- column: column.field
17040
- },
17041
- as: null
17042
- };
17043
- });
17044
- }
17045
- return ast;
17046
- }
17047
17031
  function createTableNameToTableAliasMap(ast) {
17048
17032
  const tableNameToTableAliasMap = {};
17049
17033
  if (ast.from) {
@@ -17077,21 +17061,6 @@ function createTableNameToTableAliasMap(ast) {
17077
17061
  }
17078
17062
  return tableNameToTableAliasMap;
17079
17063
  }
17080
- function processApostrophe(node, searchKeys) {
17081
- if (!node || typeof node !== "object") {
17082
- return;
17083
- }
17084
- const nodeKeys = Object.keys(node);
17085
- if (searchKeys.every((key) => nodeKeys.includes(key))) {
17086
- if (node.type === "single_quote_string") {
17087
- node.value = node.value.replace("''", "'").replace("\\'", "'");
17088
- }
17089
- }
17090
- for (const key of nodeKeys) {
17091
- processApostrophe(node[key], searchKeys);
17092
- }
17093
- return;
17094
- }
17095
17064
  function recursiveSearchByKeysFindAllOccurances(node, searchKeys, results) {
17096
17065
  if (!node || typeof node !== "object") {
17097
17066
  return;
@@ -17304,7 +17273,7 @@ function getTablesHelper(ast, allTables, skipStar) {
17304
17273
  });
17305
17274
  return { referencedTablesAndColumns, dateFields };
17306
17275
  }
17307
- var isSubquery, createSelectStarFromAst, fetchAndProcessASTFromPrompt, fetchASTFromQuillReport, POSTGRES_DATE_TYPES;
17276
+ var isSubquery, createSelectStarFromAst, fetchAndProcessASTFromPrompt, POSTGRES_DATE_TYPES;
17308
17277
  var init_astProcessing = __esm({
17309
17278
  "src/utils/astProcessing.ts"() {
17310
17279
  "use strict";
@@ -17492,63 +17461,6 @@ var init_astProcessing = __esm({
17492
17461
  }
17493
17462
  return { ast: newAst, pivot, whereAST };
17494
17463
  };
17495
- fetchASTFromQuillReport = async (report, client, schema, getToken, eventTracking) => {
17496
- let newAst;
17497
- let groupByPivot = null;
17498
- let schemaInfo = [];
17499
- try {
17500
- if (!report) {
17501
- throw new Error("Report not found");
17502
- }
17503
- const { data: resp } = await quillFetch({
17504
- client,
17505
- task: "astify",
17506
- metadata: {
17507
- query: report.queryString,
17508
- useNewNodeSql: true
17509
- },
17510
- getToken
17511
- });
17512
- if (resp.success === false) {
17513
- throw new Error(resp.message || "Couldn't process report query.");
17514
- }
17515
- const ast = getSelectFromAST(resp.ast);
17516
- let convertedAst = processStarColumn(ast, report.columns);
17517
- convertedAst = convertWildcardColumns(convertedAst, schema);
17518
- convertedAst = convertBigQuery(convertedAst);
17519
- schemaInfo = schema;
17520
- processApostrophe(convertedAst, ["type", "value"]);
17521
- convertedAst = convertBigQuery(convertedAst);
17522
- ({ ast: newAst, pivot: groupByPivot } = convertGroupBy(
17523
- convertedAst,
17524
- schemaInfo,
17525
- report.pivot ? report.pivot : void 0
17526
- ));
17527
- newAst = convertedAst;
17528
- } catch (e) {
17529
- console.log(e);
17530
- eventTracking?.logError?.({
17531
- type: "bug",
17532
- // TODO: determine type
17533
- severity: "high",
17534
- message: "Error fetching AST from report",
17535
- errorMessage: e.message,
17536
- errorStack: e.stack,
17537
- errorData: {
17538
- caller: "fetchASTFromQuillReport",
17539
- function: "fetchASTFromQuillReport"
17540
- }
17541
- });
17542
- if (e instanceof Error) {
17543
- return {
17544
- error: e.message,
17545
- ast: null,
17546
- pivot: null
17547
- };
17548
- }
17549
- }
17550
- return { ast: newAst, pivot: groupByPivot, schema: schemaInfo };
17551
- };
17552
17464
  POSTGRES_DATE_TYPES = [
17553
17465
  "timestamp",
17554
17466
  "date",
@@ -51038,7 +50950,7 @@ var useReportBuilderInternal = ({
51038
50950
  isLoading: dashboardIsLoading,
51039
50951
  reload
51040
50952
  } = useDashboardInternal(destinationDashboard);
51041
- const { getToken } = (0, import_react49.useContext)(FetchContext);
50953
+ const { getToken, quillFetchWithToken } = (0, import_react49.useContext)(FetchContext);
51042
50954
  const { eventTracking } = (0, import_react49.useContext)(EventTrackingContext);
51043
50955
  const destinationDashboardConfig = (0, import_react49.useMemo)(() => {
51044
50956
  return dashboards?.find((d) => d.name === destinationDashboard);
@@ -52250,29 +52162,38 @@ var useReportBuilderInternal = ({
52250
52162
  clearAllState();
52251
52163
  }
52252
52164
  }, [client]);
52165
+ const fetchReportBuilderStateByReportId = async (reportId2) => {
52166
+ if (!client) {
52167
+ throw new Error("Client not found");
52168
+ }
52169
+ const { data: resp, error } = await quillFetchWithToken({
52170
+ client,
52171
+ task: "report-builder-state",
52172
+ metadata: {
52173
+ reportId: reportId2
52174
+ }
52175
+ });
52176
+ if (error) {
52177
+ throw new Error(error);
52178
+ }
52179
+ const state = resp?.reportBuilderState;
52180
+ if (!state) {
52181
+ throw new Error("ReportBuilder state not found for report");
52182
+ }
52183
+ return state;
52184
+ };
52253
52185
  (0, import_react49.useEffect)(() => {
52254
52186
  const loadChart = async () => {
52255
52187
  if (!client || !reportId) return;
52256
52188
  const report = allReportsById[reportId];
52257
52189
  if (!report) return;
52258
52190
  try {
52259
- const { ast: newAst, pivot: newPivot } = await fetchASTFromQuillReport(
52260
- report,
52261
- client,
52262
- filteredSchema,
52263
- getToken,
52264
- eventTracking
52265
- );
52266
- const initialState = astToReportBuilderState(
52267
- newAst,
52268
- client.databaseType || "postgresql",
52269
- filteredSchema
52270
- );
52191
+ const initialState = report.reportBuilderState ?? await fetchReportBuilderStateByReportId(report.id || reportId);
52271
52192
  setTempReport(report);
52272
52193
  handleMultiStateChange({
52273
52194
  state: {
52274
52195
  ...initialState,
52275
- pivot: newPivot ?? null
52196
+ pivot: initialState.pivot ?? report.pivot ?? null
52276
52197
  },
52277
52198
  fetchData: true,
52278
52199
  report,
package/dist/index.js CHANGED
@@ -17070,22 +17070,6 @@ function getSelectFromAST(ast) {
17070
17070
  return ast;
17071
17071
  }
17072
17072
  }
17073
- function processStarColumn(ast, columns) {
17074
- if (ast.columns === "*") {
17075
- ast.columns = columns.map((column) => {
17076
- return {
17077
- type: "expr",
17078
- expr: {
17079
- type: "column_ref",
17080
- table: null,
17081
- column: column.field
17082
- },
17083
- as: null
17084
- };
17085
- });
17086
- }
17087
- return ast;
17088
- }
17089
17073
  function createTableNameToTableAliasMap(ast) {
17090
17074
  const tableNameToTableAliasMap = {};
17091
17075
  if (ast.from) {
@@ -17119,21 +17103,6 @@ function createTableNameToTableAliasMap(ast) {
17119
17103
  }
17120
17104
  return tableNameToTableAliasMap;
17121
17105
  }
17122
- function processApostrophe(node, searchKeys) {
17123
- if (!node || typeof node !== "object") {
17124
- return;
17125
- }
17126
- const nodeKeys = Object.keys(node);
17127
- if (searchKeys.every((key) => nodeKeys.includes(key))) {
17128
- if (node.type === "single_quote_string") {
17129
- node.value = node.value.replace("''", "'").replace("\\'", "'");
17130
- }
17131
- }
17132
- for (const key of nodeKeys) {
17133
- processApostrophe(node[key], searchKeys);
17134
- }
17135
- return;
17136
- }
17137
17106
  function recursiveSearchByKeysFindAllOccurances(node, searchKeys, results) {
17138
17107
  if (!node || typeof node !== "object") {
17139
17108
  return;
@@ -17346,7 +17315,7 @@ function getTablesHelper(ast, allTables, skipStar) {
17346
17315
  });
17347
17316
  return { referencedTablesAndColumns, dateFields };
17348
17317
  }
17349
- var isSubquery, createSelectStarFromAst, fetchAndProcessASTFromPrompt, fetchASTFromQuillReport, POSTGRES_DATE_TYPES;
17318
+ var isSubquery, createSelectStarFromAst, fetchAndProcessASTFromPrompt, POSTGRES_DATE_TYPES;
17350
17319
  var init_astProcessing = __esm({
17351
17320
  "src/utils/astProcessing.ts"() {
17352
17321
  "use strict";
@@ -17534,63 +17503,6 @@ var init_astProcessing = __esm({
17534
17503
  }
17535
17504
  return { ast: newAst, pivot, whereAST };
17536
17505
  };
17537
- fetchASTFromQuillReport = async (report, client, schema, getToken, eventTracking) => {
17538
- let newAst;
17539
- let groupByPivot = null;
17540
- let schemaInfo = [];
17541
- try {
17542
- if (!report) {
17543
- throw new Error("Report not found");
17544
- }
17545
- const { data: resp } = await quillFetch({
17546
- client,
17547
- task: "astify",
17548
- metadata: {
17549
- query: report.queryString,
17550
- useNewNodeSql: true
17551
- },
17552
- getToken
17553
- });
17554
- if (resp.success === false) {
17555
- throw new Error(resp.message || "Couldn't process report query.");
17556
- }
17557
- const ast = getSelectFromAST(resp.ast);
17558
- let convertedAst = processStarColumn(ast, report.columns);
17559
- convertedAst = convertWildcardColumns(convertedAst, schema);
17560
- convertedAst = convertBigQuery(convertedAst);
17561
- schemaInfo = schema;
17562
- processApostrophe(convertedAst, ["type", "value"]);
17563
- convertedAst = convertBigQuery(convertedAst);
17564
- ({ ast: newAst, pivot: groupByPivot } = convertGroupBy(
17565
- convertedAst,
17566
- schemaInfo,
17567
- report.pivot ? report.pivot : void 0
17568
- ));
17569
- newAst = convertedAst;
17570
- } catch (e) {
17571
- console.log(e);
17572
- eventTracking?.logError?.({
17573
- type: "bug",
17574
- // TODO: determine type
17575
- severity: "high",
17576
- message: "Error fetching AST from report",
17577
- errorMessage: e.message,
17578
- errorStack: e.stack,
17579
- errorData: {
17580
- caller: "fetchASTFromQuillReport",
17581
- function: "fetchASTFromQuillReport"
17582
- }
17583
- });
17584
- if (e instanceof Error) {
17585
- return {
17586
- error: e.message,
17587
- ast: null,
17588
- pivot: null
17589
- };
17590
- }
17591
- }
17592
- return { ast: newAst, pivot: groupByPivot, schema: schemaInfo };
17593
- };
17594
17506
  POSTGRES_DATE_TYPES = [
17595
17507
  "timestamp",
17596
17508
  "date",
@@ -51214,7 +51126,7 @@ var useReportBuilderInternal = ({
51214
51126
  isLoading: dashboardIsLoading,
51215
51127
  reload
51216
51128
  } = useDashboardInternal(destinationDashboard);
51217
- const { getToken } = useContext30(FetchContext);
51129
+ const { getToken, quillFetchWithToken } = useContext30(FetchContext);
51218
51130
  const { eventTracking } = useContext30(EventTrackingContext);
51219
51131
  const destinationDashboardConfig = useMemo24(() => {
51220
51132
  return dashboards?.find((d) => d.name === destinationDashboard);
@@ -52426,29 +52338,38 @@ var useReportBuilderInternal = ({
52426
52338
  clearAllState();
52427
52339
  }
52428
52340
  }, [client]);
52341
+ const fetchReportBuilderStateByReportId = async (reportId2) => {
52342
+ if (!client) {
52343
+ throw new Error("Client not found");
52344
+ }
52345
+ const { data: resp, error } = await quillFetchWithToken({
52346
+ client,
52347
+ task: "report-builder-state",
52348
+ metadata: {
52349
+ reportId: reportId2
52350
+ }
52351
+ });
52352
+ if (error) {
52353
+ throw new Error(error);
52354
+ }
52355
+ const state = resp?.reportBuilderState;
52356
+ if (!state) {
52357
+ throw new Error("ReportBuilder state not found for report");
52358
+ }
52359
+ return state;
52360
+ };
52429
52361
  useEffect26(() => {
52430
52362
  const loadChart = async () => {
52431
52363
  if (!client || !reportId) return;
52432
52364
  const report = allReportsById[reportId];
52433
52365
  if (!report) return;
52434
52366
  try {
52435
- const { ast: newAst, pivot: newPivot } = await fetchASTFromQuillReport(
52436
- report,
52437
- client,
52438
- filteredSchema,
52439
- getToken,
52440
- eventTracking
52441
- );
52442
- const initialState = astToReportBuilderState(
52443
- newAst,
52444
- client.databaseType || "postgresql",
52445
- filteredSchema
52446
- );
52367
+ const initialState = report.reportBuilderState ?? await fetchReportBuilderStateByReportId(report.id || reportId);
52447
52368
  setTempReport(report);
52448
52369
  handleMultiStateChange({
52449
52370
  state: {
52450
52371
  ...initialState,
52451
- pivot: newPivot ?? null
52372
+ pivot: initialState.pivot ?? report.pivot ?? null
52452
52373
  },
52453
52374
  fetchData: true,
52454
52375
  report,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/react",
3
- "version": "2.16.24",
3
+ "version": "2.16.25",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {