diff --git a/package.json b/package.json index ad8cf3cc..759a315a 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "react-router-hash-link": "^2.4.3", "react-scripts": "^4.0.3", "react-usestateref": "^1.0.5", + "semver": "^7.3.5", "serve": "^11.3.2", "swr": "^1.0.1", "tinymce": "^5.9.2", diff --git a/src/components/Table/TableHeader/Webhooks/index.tsx b/src/components/Table/TableHeader/Webhooks/index.tsx index 22a3437f..d9832855 100644 --- a/src/components/Table/TableHeader/Webhooks/index.tsx +++ b/src/components/Table/TableHeader/Webhooks/index.tsx @@ -20,7 +20,8 @@ import { analytics } from "@src/analytics"; import { useSnackbar } from "notistack"; export default function Webhooks() { - const { tableState, tableActions, rowyRun } = useProjectContext(); + const { tableState, tableActions, rowyRun, compatibleRowyRunVersion } = + useProjectContext(); const appContext = useAppContext(); const { requestConfirmation } = useConfirmation(); const { enqueueSnackbar } = useSnackbar(); @@ -35,7 +36,7 @@ export default function Webhooks() { index?: number; } | null>(null); const [webhookLogs, setWebhookLogs] = useState(); - + if (!compatibleRowyRunVersion?.({ minVersion: "1.1.1" })) return <>; const edited = !_isEqual(currentWebhooks, localWebhooksObjects); const tablePathTokens = diff --git a/src/contexts/ProjectContext.tsx b/src/contexts/ProjectContext.tsx index 44cdb175..52b3ab19 100644 --- a/src/contexts/ProjectContext.tsx +++ b/src/contexts/ProjectContext.tsx @@ -16,11 +16,10 @@ import { ColumnMenuRef } from "@src/components/Table/ColumnMenu"; import { ImportWizardRef } from "@src/components/Wizards/ImportWizard"; import { rowyRun, IRowyRunRequestProps } from "@src/utils/rowyRun"; -import { FieldType } from "@src/constants/fields"; import { rowyUser } from "@src/utils/fns"; import { WIKI_LINKS } from "@src/constants/externalLinks"; import { runRoutes } from "@src/constants/runRoutes"; - +import semver from "semver"; export type Table = { id: string; collection: string; @@ -76,6 +75,10 @@ interface IProjectContext { deleteTable: (id: string) => void; }; + compatibleRowyRunVersion: (args: { + minVersion?: string; + maxVersion?: string; + }) => boolean; // A ref to the data grid. Contains data grid functions dataGridRef: React.RefObject; // A ref to the side drawer state. Prevents unnecessary re-renders @@ -104,6 +107,17 @@ export const ProjectContextProvider: React.FC = ({ children }) => { const [settings, settingsActions] = useSettings(); const table = _find(tables, (table) => table.id === tableState.config.id); + const [rowyRunVersion, setRowyRunVersion] = useState(""); + useEffect(() => { + if (settings?.doc?.rowyRunUrl) { + _rowyRun({ + route: runRoutes.version, + }).then((resp) => { + if (resp.version) setRowyRunVersion(resp.version); + }); + } + }, [settings?.doc?.rowyRunUrl]); + useEffect(() => { const { tables } = settings; if (tables && userRoles) { @@ -268,6 +282,21 @@ export const ProjectContextProvider: React.FC = ({ children }) => { } }; + const compatibleRowyRunVersion = ({ + minVersion, + maxVersion, + }: { + minVersion?: string; + maxVersion?: string; + }) => { + // example: "1.0.0", "1.0.0-beta.1", "1.0.0-rc.1+1" + const version = rowyRunVersion.split("-")[0]; + console.log(version, minVersion, maxVersion); + if (!version) return false; + if (minVersion && semver.lt(version, minVersion)) return false; + if (maxVersion && semver.gt(version, maxVersion)) return false; + return true; + }; // A ref to the data grid. Contains data grid functions const dataGridRef = useRef(null); const sideDrawerRef = useRef(); @@ -292,6 +321,7 @@ export const ProjectContextProvider: React.FC = ({ children }) => { columnMenuRef, importWizardRef, rowyRun: _rowyRun, + compatibleRowyRunVersion, }} > {children}