From f7cce06320112a9dd4145eeca934956833c774c2 Mon Sep 17 00:00:00 2001 From: Bobby Wang Date: Sat, 7 Jan 2023 04:20:16 +1300 Subject: [PATCH] requires cloud function setup before creating related columns --- src/atoms/projectScope/rowyRun.ts | 2 - .../ColumnModals/FieldsDropdown.tsx | 46 +++++++++++++++++-- src/components/fields/Action/index.tsx | 1 + src/components/fields/Connector/index.tsx | 1 + src/components/fields/Derivative/index.tsx | 1 + src/components/fields/types.ts | 1 + 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/atoms/projectScope/rowyRun.ts b/src/atoms/projectScope/rowyRun.ts index bc6d35cd..bb66d8f2 100644 --- a/src/atoms/projectScope/rowyRun.ts +++ b/src/atoms/projectScope/rowyRun.ts @@ -73,7 +73,6 @@ export const rowyRunAtom = atom((get) => { handleNotSetUp, }: IRowyRunRequestProps): Promise => { if (!currentUser) { - console.log("Rowy Run: Not signed in", route.path); if (handleNotSetUp) handleNotSetUp(); return false; } @@ -85,7 +84,6 @@ export const rowyRunAtom = atom((get) => { ? rowyRunServices?.[service] : rowyRunUrl; if (!serviceUrl) { - console.log("Rowy Run: Not set up", route.path); if (handleNotSetUp) handleNotSetUp(); return false; } diff --git a/src/components/ColumnModals/FieldsDropdown.tsx b/src/components/ColumnModals/FieldsDropdown.tsx index 8257292c..a3fdd4c6 100644 --- a/src/components/ColumnModals/FieldsDropdown.tsx +++ b/src/components/ColumnModals/FieldsDropdown.tsx @@ -5,12 +5,20 @@ import { FIELDS } from "@src/components/fields"; import { FieldType } from "@src/constants/fields"; import { getFieldProp } from "@src/components/fields"; +import { useSetAtom, useAtom } from "jotai"; +import { + projectScope, + projectSettingsAtom, + rowyRunModalAtom, +} from "@src/atoms/projectScope"; + export interface IFieldsDropdownProps { value: FieldType | ""; onChange: (value: FieldType) => void; hideLabel?: boolean; label?: string; options?: FieldType[]; + [key: string]: any; } @@ -25,13 +33,21 @@ export default function FieldsDropdown({ options: optionsProp, ...props }: IFieldsDropdownProps) { + const [projectSettings] = useAtom(projectSettingsAtom, projectScope); + const openRowyRunModal = useSetAtom(rowyRunModalAtom, projectScope); const fieldTypesToDisplay = optionsProp ? FIELDS.filter((fieldConfig) => optionsProp.indexOf(fieldConfig.type) > -1) : FIELDS; - const options = fieldTypesToDisplay.map((fieldConfig) => ({ - label: fieldConfig.name, - value: fieldConfig.type, - })); + const options = fieldTypesToDisplay.map((fieldConfig) => { + const requireCloudFunctionSetup = + fieldConfig.requireCloudFunction && !projectSettings.rowyRunUrl; + return { + label: fieldConfig.name, + value: fieldConfig.type, + disabled: requireCloudFunctionSetup, + requireCloudFunctionSetup, + }; + }); return ( {getFieldProp("icon", option.value as FieldType)} - {option.label} + {option.label}{" "} + {option.requireCloudFunctionSetup && ( + <> + (requires + { + e.stopPropagation(); + openRowyRunModal({ feature: option.label }); + }} + > + Cloud Function + + ) + + )} )} label={label || "Field type"} diff --git a/src/components/fields/Action/index.tsx b/src/components/fields/Action/index.tsx index e2e8c1bd..7ab899e2 100644 --- a/src/components/fields/Action/index.tsx +++ b/src/components/fields/Action/index.tsx @@ -30,6 +30,7 @@ export const config: IFieldConfig = { SideDrawerField, settings: Settings, requireConfiguration: true, + requireCloudFunction: true, sortKey: "status", }; export default config; diff --git a/src/components/fields/Connector/index.tsx b/src/components/fields/Connector/index.tsx index a0e239d1..7c72963b 100644 --- a/src/components/fields/Connector/index.tsx +++ b/src/components/fields/Connector/index.tsx @@ -34,6 +34,7 @@ export const config: IFieldConfig = { }), SideDrawerField, requireConfiguration: true, + requireCloudFunction: true, settings: Settings, }; export default config; diff --git a/src/components/fields/Derivative/index.tsx b/src/components/fields/Derivative/index.tsx index d046b4d3..4c18a0f3 100644 --- a/src/components/fields/Derivative/index.tsx +++ b/src/components/fields/Derivative/index.tsx @@ -21,5 +21,6 @@ export const config: IFieldConfig = { settings: Settings, settingsValidator, requireConfiguration: true, + requireCloudFunction: true, }; export default config; diff --git a/src/components/fields/types.ts b/src/components/fields/types.ts index 63374d81..a11e1e10 100644 --- a/src/components/fields/types.ts +++ b/src/components/fields/types.ts @@ -19,6 +19,7 @@ export interface IFieldConfig { dataType: string; initializable?: boolean; requireConfiguration?: boolean; + requireCloudFunction?: boolean; initialValue: any; icon?: React.ReactNode; description?: string;