rowyRun version requirement

This commit is contained in:
shamsmosowi
2021-11-04 12:49:36 +11:00
parent 4a8122c88c
commit 745e5d96de
3 changed files with 36 additions and 4 deletions

View File

@@ -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",

View File

@@ -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<IWebhook | null>();
if (!compatibleRowyRunVersion?.({ minVersion: "1.1.1" })) return <></>;
const edited = !_isEqual(currentWebhooks, localWebhooksObjects);
const tablePathTokens =

View File

@@ -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<DataGridHandle>;
// 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<DataGridHandle>(null);
const sideDrawerRef = useRef<SideDrawerRef>();
@@ -292,6 +321,7 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
columnMenuRef,
importWizardRef,
rowyRun: _rowyRun,
compatibleRowyRunVersion,
}}
>
{children}