Skip to content

Commit

Permalink
fix rowy run buildFunction endpoint expecting old pathname for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
notsidney committed Jun 28, 2022
1 parent ff608ab commit 96abb36
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/components/ColumnModals/ColumnConfigModal/ColumnConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import { useSnackLogContext } from "@src/contexts/SnackLogContext";
import { FieldType } from "@src/constants/fields";
import { runRoutes } from "@src/constants/runRoutes";
import { useSnackbar } from "notistack";
import { getTableSchemaPath } from "@src/utils/table";
import {
getTableSchemaPath,
getTableBuildFunctionPathname,
} from "@src/utils/table";

export default function ColumnConfigModal({
onClose,
Expand Down Expand Up @@ -193,9 +196,10 @@ export default function ColumnConfigModal({
body: {
tablePath: tableSettings.collection,
// pathname must match old URL format
pathname: `/table/${encodeURIComponent(
tableSettings.collection
)}`,
pathname: getTableBuildFunctionPathname(
tableSettings.id,
tableSettings.tableType
),
tableConfigPath: getTableSchemaPath(tableSettings),
},
});
Expand Down
11 changes: 9 additions & 2 deletions src/components/TableModals/ExtensionsModal/ExtensionsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import { useSnackLogContext } from "@src/contexts/SnackLogContext";
import { emptyExtensionObject, IExtension, ExtensionType } from "./utils";
import { runRoutes } from "@src/constants/runRoutes";
import { analytics, logEvent } from "@src/analytics";
import { getTableSchemaPath } from "@src/utils/table";
import {
getTableSchemaPath,
getTableBuildFunctionPathname,
} from "@src/utils/table";

export default function ExtensionsModal({ onClose }: ITableModalProps) {
const [currentUser] = useAtom(currentUserAtom, globalScope);
Expand Down Expand Up @@ -91,7 +94,11 @@ export default function ExtensionsModal({ onClose }: ITableModalProps) {
route: runRoutes.buildFunction,
body: {
tablePath: tableSettings.collection,
pathname: `/table/${encodeURIComponent(tableSettings.collection)}`,
// pathname must match old URL format
pathname: getTableBuildFunctionPathname(
tableSettings.id,
tableSettings.tableType
),
tableConfigPath: getTableSchemaPath(tableSettings),
},
});
Expand Down
15 changes: 9 additions & 6 deletions src/components/TableSettingsDialog/TableSettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import { runRoutes } from "@src/constants/runRoutes";
import { CONFIG } from "@src/config/dbPaths";
import { ROUTES } from "@src/constants/routes";
import { useSnackLogContext } from "@src/contexts/SnackLogContext";
import { getTableSchemaPath } from "@src/utils/table";
import {
getTableSchemaPath,
getTableBuildFunctionPathname,
} from "@src/utils/table";

const customComponents = {
tableName: {
Expand Down Expand Up @@ -128,11 +131,11 @@ export default function TableSettingsDialog() {
route: runRoutes.buildFunction,
body: {
tablePath,
pathname: `/${
data.tableType === "collectionGroup"
? "tableGroup"
: "table"
}/${data.id}`,
// pathname must match old URL format
pathname: getTableBuildFunctionPathname(
data.id,
data.tableType
),
tableConfigPath,
},
});
Expand Down
22 changes: 22 additions & 0 deletions src/utils/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,25 @@ export const getTableSchemaPath = (
*/
export const formatSubTableName = (id?: string) =>
id ? id.replace(formatPathRegex, "/subTables/$1").replace(/\//g, "_") : "";

/**
* Gets the pathname of the table or sub-table
* for Rowy Run `buildFunction` endpoint.
* Rowy Run expects the previous URL format for sub-tables.
* @param id - Table ID (or sub-table ID from tableIdAtom)
* @param tableType - primaryCollection (default) or collectionGroup
* @returns - pathname
*/
export const getTableBuildFunctionPathname = (
id: string,
tableType: "primaryCollection" | "collectionGroup" = "primaryCollection"
) => {
const root =
"/" + (tableType === "collectionGroup" ? "tableGroup" : "table") + "/";

if (!id.includes("/")) return root + id;

const split = id.split("/");
const rootTableId = split.shift();
return root + rootTableId + encodeURIComponent("/" + split.join("/"));
};

0 comments on commit 96abb36

Please sign in to comment.