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.

style: order calibration records by created at in gauge drawer

Brad Barbine07df83d753b
diff --git a/apps/erp/app/modules/quality/quality.service.ts b/apps/erp/app/modules/quality/quality.service.ts
index 1baa243920..ca9f006429 100644
--- a/apps/erp/app/modules/quality/quality.service.ts
+++ b/apps/erp/app/modules/quality/quality.service.ts
@@ -279,7 +279,8 @@ export async function getGaugeCalibrationRecordsByGaugeId(
return client
.from("gaugeCalibrationRecords")
.select("*")
- .eq("gaugeId", gaugeId);
+ .eq("gaugeId", gaugeId)
+ .order("createdAt", { ascending: false });
}
export async function getGaugeTypesList(
@@ -1073,6 +1074,10 @@ export async function upsertGaugeCalibrationRecord(
customFields?: Json;
})
) {
+ const userId =
+ "updatedBy" in gaugeCalibrationRecord
+ ? gaugeCalibrationRecord.updatedBy
+ : gaugeCalibrationRecord.createdBy;
const gauge = await client
.from("gauge")
.select("*")
@@ -1106,6 +1111,8 @@ export async function upsertGaugeCalibrationRecord(
gaugeCalibrationRecord.inspectionStatus === "Pass"
? "In-Calibration"
: gauge.data.lastCalibrationStatus,
+ updatedBy: userId,
+ updatedAt: new Date().toISOString(),
})
.eq("id", gaugeCalibrationRecord.gaugeId);
@@ -1125,7 +1132,13 @@ export async function upsertGaugeCalibrationRecord(
}
return client
.from("gaugeCalibrationRecord")
- .update(sanitize(gaugeCalibrationRecord))
+ .update(
+ sanitize({
+ ...gaugeCalibrationRecord,
+ updatedBy: userId,
+ updatedAt: new Date().toISOString(),
+ })
+ )
.eq("id", gaugeCalibrationRecord.id);
}
diff --git a/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx b/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx
index 63506f39ce..361e638424 100644
--- a/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx
+++ b/apps/erp/app/modules/quality/ui/Gauge/GaugeForm.tsx
@@ -11,6 +11,7 @@ import {
ModalDrawer,
ModalDrawerBody,
ModalDrawerContent,
+ ModalDrawerDescription,
ModalDrawerFooter,
ModalDrawerHeader,
ModalDrawerProvider,
@@ -26,6 +27,7 @@ import { formatRelativeTime } from "@carbon/utils";
import { getLocalTimeZone, parseDate, today } from "@internationalized/date";
import { Await, Link, useFetcher } from "@remix-run/react";
import type { PostgrestResponse } from "@supabase/supabase-js";
+import { nanoid } from "nanoid";
import { Suspense, useState } from "react";
import {
LuCalendar,
@@ -119,9 +121,14 @@ const GaugeForm = ({
>
<ModalDrawerHeader className="flex flex-col gap-4">
<HStack className="w-full justify-between pr-8">
- <ModalDrawerTitle>
- {isEditing ? `${initialValues.gaugeId}` : "New Gauge"}
- </ModalDrawerTitle>
+ <VStack>
+ <ModalDrawerTitle>
+ {isEditing ? `${initialValues.gaugeId}` : "New Gauge"}
+ </ModalDrawerTitle>
+ <ModalDrawerDescription>
+ {isEditing ? initialValues.description : undefined}
+ </ModalDrawerDescription>
+ </VStack>
{isEditing && (
<div>
@@ -312,8 +319,9 @@ const GaugeForm = ({
</ModalDrawerProvider>
{newRecordDisclosure.isOpen && (
<GaugeCalibrationRecordForm
+ files={[]}
initialValues={{
- id: undefined,
+ id: nanoid(),
gaugeId: initialValues.id!,
dateCalibrated: today(getLocalTimeZone()).toString(),
requiresAction: false,