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.

fix: update trigger for quote and part search result

Brad Barbin1999d9156347
diff --git a/apps/carbon/app/components/Search/Search/Search.tsx b/apps/carbon/app/components/Search/Search/Search.tsx
index 74b55dd67a..5c6d182195 100644
--- a/apps/carbon/app/components/Search/Search/Search.tsx
+++ b/apps/carbon/app/components/Search/Search/Search.tsx
@@ -12,6 +12,7 @@ import {
Kbd,
Modal,
ModalContent,
+ VStack,
useDebounce,
useDisclosure,
useKeyboardShortcuts,
@@ -207,8 +208,17 @@ const SearchModal = ({
})
}
>
- <ResultIcon entity={result.entity} />
- <span>{result.name}</span>
+ <HStack>
+ <ResultIcon entity={result.entity} />
+ <VStack spacing={0}>
+ <span>{result.name}</span>
+ {result.description && (
+ <span className="text-xs text-muted-foreground">
+ {result.description}
+ </span>
+ )}
+ </VStack>
+ </HStack>
</CommandItem>
))}
</CommandGroup>
diff --git a/packages/database/supabase/migrations/20240416212554_part-search.sql b/packages/database/supabase/migrations/20240416212554_part-search.sql
new file mode 100644
index 0000000000..b2060058b2
--- /dev/null
+++ b/packages/database/supabase/migrations/20240416212554_part-search.sql
@@ -0,0 +1,42 @@
+CREATE OR REPLACE FUNCTION public.update_quotation_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ IF (old."quoteId" <> new."quoteId" OR old."name" <> new."name") THEN
+ UPDATE public.search SET name = new."quoteId", description = new.name
+ WHERE entity = 'Quotation' AND uuid = new.id;
+ END IF;
+ RETURN new;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE OR REPLACE TRIGGER update_quotation_search_result
+ AFTER UPDATE on public."quote"
+ FOR EACH ROW EXECUTE PROCEDURE public.update_quotation_search_result();
+
+CREATE OR REPLACE FUNCTION public.update_part_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ IF (old.name <> new.name OR old.description <> new.description) THEN
+ UPDATE public.search SET name = new.id, description = new.name || ' ' || COALESCE(new.description, '')
+ WHERE entity = 'Part' AND uuid = new.id;
+ END IF;
+ RETURN new;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE OR REPLACE TRIGGER update_part_search_result
+ AFTER UPDATE on public.part
+ FOR EACH ROW EXECUTE PROCEDURE public.update_part_search_result();
+
+CREATE OR REPLACE FUNCTION public.create_part_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ INSERT INTO public.search(name, description, entity, uuid, link)
+ VALUES (new.id, new.name || ' ' || COALESCE(new.description, ''), 'Part', new.id, '/x/part/' || new.id);
+ RETURN new;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE OR REPLACE TRIGGER create_part_search_result
+ AFTER INSERT on public.part
+ FOR EACH ROW EXECUTE PROCEDURE public.create_part_search_result();
\ No newline at end of file