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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger
} from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
import { LuBuilding2 } from "react-icons/lu";
import { useUrlParams } from "~/hooks";
type Company = {
id: string;
name: string;
};
type CompanySelectorProps = {
companies: Company[];
selectedCompanyIds: string[];
/** Offers "All Companies"; off for reports that read one company only */
allowAll?: boolean;
};
const ALL = "__all__";
const CompanySelector = ({
companies,
selectedCompanyIds,
allowAll = true
}: CompanySelectorProps) => {
const { t } = useLingui();
const [, setParams] = useUrlParams();
if (companies.length <= 1) return null;
const allSelected = selectedCompanyIds.length === companies.length;
const value = allSelected ? ALL : selectedCompanyIds[0];
const label = allSelected
? t`All Companies`
: (companies.find((c) => c.id === value)?.name ?? t`All Companies`);
const onChange = (next: string) => {
setParams({ companies: next === ALL ? "all" : next });
};
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="secondary" leftIcon={<LuBuilding2 />}>
{label}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuRadioGroup value={value} onValueChange={onChange}>
{allowAll && (
<DropdownMenuRadioItem value={ALL}>
<Trans>All Companies</Trans>
</DropdownMenuRadioItem>
)}
{companies.map((company) => (
<DropdownMenuRadioItem key={company.id} value={company.id}>
{company.name}
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
);
};
export default CompanySelector;