Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

refactor: trigger initial onshape requests

Brad Barbin0ed67e5c431b
diff --git a/apps/erp/app/components/OnshapeSync.tsx b/apps/erp/app/components/OnshapeSync.tsx
index 537c8eb893..09f1894b0f 100644
--- a/apps/erp/app/components/OnshapeSync.tsx
+++ b/apps/erp/app/components/OnshapeSync.tsx
@@ -1,5 +1,5 @@
import { useCarbon } from "@carbon/auth";
-import { OnshapeLogo } from "@carbon/integrations";
+import { OnshapeLogo } from "@carbon/ee";
import {
Badge,
Button,
@@ -59,6 +59,7 @@ export const OnshapeSync = ({
makeMethodId: string;
isDisabled: boolean;
}) => {
+ const [initialized, setInitialized] = useState(false);
const [documentId, setDocumentId] = useState<string | null>(null);
const [versionId, setVersionId] = useState<string | null>(null);
const [elementId, setElementId] = useState<string | null>(null);
@@ -92,11 +93,12 @@ export const OnshapeSync = ({
| { data: null; error: string }
>({});
- useMount(() => {
- if (!isDisabled) {
+ useEffect(() => {
+ if (!isDisabled && initialized) {
documentsFetcher.load(path.to.api.onShapeDocuments);
}
- });
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [initialized]);
useEffect(() => {
if (documentsFetcher.data?.error) {
@@ -122,11 +124,11 @@ export const OnshapeSync = ({
>({});
useEffect(() => {
- if (documentId && !isDisabled) {
+ if (documentId && !isDisabled && initialized) {
versionsFetcher.load(path.to.api.onShapeVersions(documentId));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [documentId]);
+ }, [documentId, initialized]);
const versionOptions =
useMemo(() => {
@@ -146,11 +148,11 @@ export const OnshapeSync = ({
>({});
useEffect(() => {
- if (documentId && versionId && !isDisabled) {
+ if (documentId && versionId && !isDisabled && initialized) {
elementsFetcher.load(path.to.api.onShapeElements(documentId, versionId));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [documentId, versionId]);
+ }, [documentId, versionId, initialized]);
const elementOptions =
useMemo(() => {
@@ -347,17 +349,32 @@ export const OnshapeSync = ({
{isDataLoading ? (
<Spinner className="size-3" />
) : (
- <Button
- variant={bomRows.length > 0 ? "secondary" : "primary"}
- isLoading={bomFetcher.state !== "idle"}
- isDisabled={
- isDisabled || !isReadyForSync || bomFetcher.state !== "idle"
- }
- size="sm"
- onClick={loadBom}
- >
- {bomRows.length > 0 ? "Refresh" : "Sync"}
- </Button>
+ <div className="flex gap-2">
+ {!initialized && (
+ <Button
+ variant="secondary"
+ size="sm"
+ onClick={() => setInitialized(true)}
+ isDisabled={isDisabled}
+ >
+ Fetch
+ </Button>
+ )}
+ <Button
+ variant={bomRows.length > 0 ? "secondary" : "primary"}
+ isLoading={bomFetcher.state !== "idle"}
+ isDisabled={
+ isDisabled ||
+ !isReadyForSync ||
+ bomFetcher.state !== "idle" ||
+ !initialized
+ }
+ size="sm"
+ onClick={loadBom}
+ >
+ {bomRows.length > 0 ? "Refresh" : "Sync"}
+ </Button>
+ </div>
)}
</div>
</div>
diff --git a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts
index 0f03e4e8a0..288a0a4b1b 100644
--- a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts
+++ b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts
@@ -1,6 +1,6 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { Onshape as OnshapeConfig } from "@carbon/ee";
-import { OnshapeClient } from "@carbon/ee/onshape/lib";
+import { OnshapeClient } from "@carbon/ee/onshape";
import type { ShouldRevalidateFunction } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { json } from "@vercel/remix";
diff --git a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.ts b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.ts
index c2429cbb41..70dfddb949 100644
--- a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.ts
+++ b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.ts
@@ -1,6 +1,6 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { Onshape as OnshapeConfig } from "@carbon/ee";
-import { OnshapeClient } from "@carbon/ee/onshape/lib";
+import { OnshapeClient } from "@carbon/ee/onshape";
import type { ShouldRevalidateFunction } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { json } from "@vercel/remix";
diff --git a/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.ts b/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.ts
index db3e4f80f6..ed5fa0c66e 100644
--- a/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.ts
+++ b/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.ts
@@ -1,6 +1,6 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { Onshape as OnshapeConfig } from "@carbon/ee";
-import { OnshapeClient } from "@carbon/ee/onshape/lib";
+import { OnshapeClient } from "@carbon/ee/onshape";
import type { ShouldRevalidateFunction } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { json } from "@vercel/remix";
diff --git a/apps/erp/app/routes/api+/integrations.onshape.documents.ts b/apps/erp/app/routes/api+/integrations.onshape.documents.ts
index a0a8c45e5a..42c379b3ec 100644
--- a/apps/erp/app/routes/api+/integrations.onshape.documents.ts
+++ b/apps/erp/app/routes/api+/integrations.onshape.documents.ts
@@ -1,6 +1,6 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { Onshape as OnshapeConfig } from "@carbon/ee";
-import { OnshapeClient } from "@carbon/ee/onshape/lib";
+import { OnshapeClient } from "@carbon/ee/onshape";
import type { ShouldRevalidateFunction } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { json } from "@vercel/remix";
diff --git a/apps/erp/app/routes/api+/integrations.onshape.sync.ts b/apps/erp/app/routes/api+/integrations.onshape.sync.ts
index 47ec9b5acd..4d7ca8a1e7 100644
--- a/apps/erp/app/routes/api+/integrations.onshape.sync.ts
+++ b/apps/erp/app/routes/api+/integrations.onshape.sync.ts
@@ -1,6 +1,6 @@
import { getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
-import { onShapeDataValidator } from "@carbon/ee/onshape/lib";
+import { onShapeDataValidator } from "@carbon/ee/onshape";
import { FunctionRegion } from "@supabase/supabase-js";
import { json, type ActionFunctionArgs } from "@vercel/remix";