Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,248 @@
import { Property } from "@toolctrl/db/prisma-browser";
import clsx from "clsx";
import { useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Link, useSubmit } from "react-router";
import { PropertyType } from "~/application/enums/entities/PropertyType";
import { PropertyWithDetails } from "~/utils/db/entities/entities.db.server";
import EntityHelper from "~/utils/helpers/EntityHelper";
import ButtonTertiary from "../../ui/buttons/ButtonTertiary";
import LockClosedIcon from "../../ui/icons/LockClosedIcon";
import NewFieldIcon from "../../ui/icons/NewFieldIcon";
import PencilIcon from "../../ui/icons/PencilIcon";
import TrashIcon from "../../ui/icons/TrashIcon";
import ConfirmModal, { RefConfirmModal } from "../../ui/modals/ConfirmModal";
import PropertyBadge from "./PropertyBadge";
import OrderListButtons from "../../ui/sort/OrderListButtons";
import { defaultDisplayProperties } from "~/utils/helpers/PropertyHelper";
import EyeIcon from "~/components/ui/icons/EyeIcon";
import EyeLashIcon from "~/components/ui/icons/EyeLashIcon";
import DocumentDuplicateIconFilled from "~/components/ui/icons/DocumentDuplicateIconFilled";
interface Props {
items: PropertyWithDetails[];
className?: string;
}
export default function PropertiesList({ items, className }: Props) {
const { t } = useTranslation();
const submit = useSubmit();
const confirmDelete = useRef<RefConfirmModal>(null);
const [showDefaultFields, setShowDefaultFields] = useState(false);
function deleteField(item: Property) {
confirmDelete.current?.setValue(item);
confirmDelete.current?.show(t("shared.confirmDelete"), t("shared.delete"), t("shared.cancel"), t("shared.warningCannotUndo"));
}
function confirmedDelete(item: Property) {
const form = new FormData();
form.set("action", "delete");
form.set("id", item.id);
submit(form, {
method: "post",
});
}
function onToggleDisplay(item: Property) {
const form = new FormData();
form.set("action", "toggle-display");
form.set("id", item.id);
submit(form, {
method: "post",
});
}
function onDuplicate(item: Property) {
const form = new FormData();
form.set("action", "duplicate");
form.set("id", item.id);
submit(form, {
method: "post",
});
}
return (
<div className={clsx(className, "")}>
<div className="space-y-2">
{showDefaultFields && (
<div className="mb-3 space-y-2">
<div className="flex items-center justify-between">
<h3 className="text-sm font-medium">{t("models.property.defaultProperties.title")}</h3>
{showDefaultFields && (
<div className="flex justify-end">
<ButtonTertiary className="-my-1" onClick={() => setShowDefaultFields(!showDefaultFields)}>
{t("models.property.defaultProperties.hide")}
</ButtonTertiary>
</div>
)}
</div>
{defaultDisplayProperties.map((item, idx) => {
return (
<div key={idx} className="border-border bg-secondary/90 rounded-md border px-4 py-2 shadow-2xs">
<div className="flex items-center justify-between space-x-2">
<div className="flex items-center space-x-2">
<div className="flex items-center space-x-3">
<div className="flex items-center space-x-2">
<LockClosedIcon className="h-4 w-4 text-gray-300" />
{/* <PropertyBadge className="h-4 w-4 text-muted-foreground" /> */}
{/* <div className="truncate text-sm text-muted-foreground">{t("entities.fields." + PropertyType[item.type])}</div> */}
</div>
<div className="text-muted-foreground text-sm">
{/* <PropertyTitle item={item} /> */}
<div className="flex flex-col">
<div>{t(item.title)}</div>
<div className="text-muted-foreground text-xs">{item.name}</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
})}
</div>
)}
</div>
<div className="">
<div className="space-y-4">
<div className="flex items-center justify-between">
<h3 className="text-sm font-medium">{t("models.property.plural")}</h3>
{!showDefaultFields && (
<div className="flex justify-end">
<ButtonTertiary className="-my-1" onClick={() => setShowDefaultFields(!showDefaultFields)}>
{t("models.property.defaultProperties.show")}
</ButtonTertiary>
</div>
)}
</div>
{items
.filter((f) => !f.isDefault)
.sort((a, b) => a.order - b.order)
.map((item, idx) => {
return (
<div key={idx} className="border-border bg-background rounded-md border px-4 py-1 shadow-2xs">
<div className="flex items-center justify-between space-x-2">
<div className="flex items-center space-x-2 truncate">
<div className="flex items-center space-x-3 truncate">
<div className="hidden shrink-0 sm:flex">
<OrderListButtons index={idx} items={items.filter((f) => !f.isDefault)} editable={true} />
</div>
<div className="flex items-center space-x-2">
<PropertyBadge type={item.type} className="text-muted-foreground h-4 w-4" />
</div>
<div className="text-foreground flex items-center space-x-2 truncate text-sm">
<PropertyTitle item={item} />
</div>
</div>
</div>
<div className="flex shrink-0 space-x-1">
<div className="flex items-center space-x-1 truncate p-1">
<button
type="button"
onClick={() => onToggleDisplay(item)}
aria-label={t(item.isDisplay ? "shared.hide" : "shared.show")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:ring-2 focus:ring-gray-400 focus:ring-offset-1 focus:outline-hidden"
>
{item.isDisplay ? (
<EyeIcon className="text-muted-foreground hover:text-muted-foreground h-4 w-4" />
) : (
<EyeLashIcon className="hover:text-muted-foreground h-4 w-4 text-gray-300" />
)}
</button>
<Link
to={item.id}
aria-label={t("shared.edit")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:ring-2 focus:ring-gray-400 focus:ring-offset-1 focus:outline-hidden"
preventScrollReset
// onClick={() => update(idx, item)}
>
<PencilIcon className="group-hover:text-muted-foreground h-4 w-4 text-gray-300" />
</Link>
<button
type="button"
onClick={() => onDuplicate(item)}
aria-label={t("shared.duplicate")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:ring-2 focus:ring-gray-400 focus:ring-offset-1 focus:outline-hidden"
>
<DocumentDuplicateIconFilled className="hover:text-muted-foreground h-4 w-4 text-gray-300" />
</button>
<button
type="button"
aria-label={t("shared.delete")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:ring-2 focus:ring-gray-400 focus:ring-offset-1 focus:outline-hidden"
onClick={() => deleteField(item)}
>
<TrashIcon className="group-hover:text-muted-foreground h-4 w-4 text-gray-300" />
</button>
</div>
</div>
</div>
</div>
);
})}
</div>
</div>
<div className="mt-3">
<Link
to={`new`}
className="focus:ring-ring border-border hover:border-border relative block w-full rounded-lg border-2 border-dashed px-12 py-6 text-center focus:ring-2 focus:ring-offset-2 focus:outline-hidden"
preventScrollReset
>
<NewFieldIcon className="text-muted-foreground mx-auto h-8" />
<span className="text-foreground mt-2 block text-sm font-medium">{t("models.property.actions.add")}</span>
</Link>
</div>
{/* <PropertyForm ref={propertyForm} entityId={entityId} onCreated={created} onUpdated={updated} onDeleted={deleted} /> */}
<ConfirmModal ref={confirmDelete} destructive onYes={confirmedDelete} />
</div>
);
}
const PropertyTitle = ({ item }: { item: PropertyWithDetails }) => {
const { t } = useTranslation();
return (
<>
<div className="flex items-baseline space-x-1 truncate">
<div className="flex flex-col">
<div>
{t(EntityHelper.getFieldTitle(item, item.isDefault))}
{item.isRequired && <span className="text-red-500">*</span>}
</div>
<div className="text-muted-foreground text-xs">
{item.name}
{item.subtype === "phone" && " (phone)"}
{item.subtype === "url" && " (URL)"}
{[PropertyType.MULTI_SELECT, PropertyType.SELECT].includes(item.type) && "[]"}
{[PropertyType.RANGE_NUMBER, PropertyType.RANGE_DATE].includes(item.type) && ` (${t("models.property.badges.range")})`}
{[PropertyType.FORMULA].includes(item.type) && ` (${t("models.property.badges.formula")})`}
</div>
</div>
{/* {item.type === PropertyType.FORMULA && <div className="truncate italic text-muted-foreground">({item.formula})</div>} */}
{[PropertyType.SELECT, PropertyType.MULTI_SELECT].includes(item.type) && (
<div className="text-muted-foreground truncate text-xs">
[
{item.options.length === 0
? t("models.property.noOptions")
: t("models.property.optionsSummary", { options: item.options?.map((f) => f.value).join(", ") })}
]
</div>
)}
{item.attributes.filter((f) => f.value).length > 0 && (
<div className="text-muted-foreground truncate text-xs">
[
{item.attributes
.filter((f) => f.value)
.map((f) => `${f.name}: ${f.value}`)
.join(", ")}
]
</div>
)}
</div>
</>
);
};
@@ -0,0 +1,116 @@
import { useTranslation } from "react-i18next";
import { PropertyAttributeName } from "~/application/enums/entities/PropertyAttributeName";
import InputCheckboxWithDescription from "~/components/ui/input/InputCheckboxWithDescription";
import InputNumber from "~/components/ui/input/InputNumber";
import InputSelector from "~/components/ui/input/InputSelector";
import InputText from "~/components/ui/input/InputText";
import PropertyAttributeHelper from "~/utils/helpers/PropertyAttributeHelper";
interface Props {
name: PropertyAttributeName;
title: string;
value: string | undefined;
setValue: React.Dispatch<React.SetStateAction<string | undefined>>;
className?: string;
}
export default function PropertyAttribute({ name, title, value, setValue, className }: Props) {
const { t } = useTranslation();
function isNumber() {
return [
PropertyAttributeName.Min,
PropertyAttributeName.Max,
PropertyAttributeName.MaxSize,
PropertyAttributeName.Rows,
PropertyAttributeName.Columns,
].includes(name);
}
function isBoolean() {
return [PropertyAttributeName.Uppercase, PropertyAttributeName.Lowercase, PropertyAttributeName.Password].includes(name);
}
function isSelector() {
return PropertyAttributeHelper.getPropertyAttributeOptions(name, t).length > 0;
}
function getPlaceholder() {
if (name === PropertyAttributeName.Step) {
return "0.01";
}
return "";
}
function getDescription() {
if (name === PropertyAttributeName.Uppercase) {
return t("models.entity.propertyAttributes.descriptions.uppercase");
} else if (name === PropertyAttributeName.Lowercase) {
return t("models.entity.propertyAttributes.descriptions.lowercase");
}
return "";
}
return (
<>
{isNumber() ? (
<InputNumber
className={className}
name={name}
title={title}
value={Number(value)}
setValue={(e) => setValue(e?.toString())}
max={name === PropertyAttributeName.Columns ? 12 : undefined}
hint={
<>
{value && (
<button type="button" onClick={() => setValue("")} className="text-muted-foreground text-xs hover:text-red-500">
{t("shared.remove")}
</button>
)}
</>
}
/>
) : isBoolean() ? (
<InputCheckboxWithDescription
className={className}
description={getDescription()}
name={name}
title={title}
value={value === "true" ? true : false}
setValue={(e) => setValue(e ? (Boolean(e) === true ? "true" : "false") : "false")}
/>
) : isSelector() ? (
<InputSelector
className={className}
withSearch={false}
name={name}
title={title}
value={value}
setValue={(e) => setValue(e?.toString())}
options={PropertyAttributeHelper.getPropertyAttributeOptions(name, t)}
hint={
<>
{value && (
<button type="button" onClick={() => setValue("")} className="text-muted-foreground text-xs hover:text-red-500">
{t("shared.remove")}
</button>
)}
</>
}
></InputSelector>
) : (
<InputText
className={className}
name={name}
title={title}
value={value}
setValue={(e) => setValue(e.toString())}
placeholder={getPlaceholder()}
hint={
<>
{value && (
<button type="button" onClick={() => setValue("")} className="text-muted-foreground text-xs hover:text-red-500">
{t("shared.remove")}
</button>
)}
</>
}
/>
)}
</>
);
}
@@ -0,0 +1,113 @@
import clsx from "clsx";
import { PropertyType } from "~/application/enums/entities/PropertyType";
import { Colors } from "~/application/enums/shared/Colors";
import CheckIcon from "~/components/ui/icons/CheckIcon";
import SimpleBadge from "../../ui/badges/SimpleBadge";
import PaperClipIcon from "../../ui/icons/PaperClipIcon";
import ExperimentIconFilled from "~/components/ui/icons/tests/ExperimentIconFilled";
interface Props {
title?: string;
type: PropertyType;
className?: string;
}
export default function PropertyBadge({ title, type, className }: Props) {
return (
<>
{title ? (
<SimpleBadge title={title} color={Colors.ORANGE} />
) : [PropertyType.NUMBER, PropertyType.RANGE_NUMBER].includes(type) ? (
<svg xmlns="http://www.w3.org/2000/svg" className={clsx(className, "h-5 w-5 shrink-0")} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M9 7h6m0 10v-3m-3 3h.01M9 17h.01M9 14h.01M12 14h.01M15 11h.01M12 11h.01M9 11h.01M7 21h10a2 2 0 002-2V5a2 2 0 00-2-2H7a2 2 0 00-2 2v14a2 2 0 002 2z"
/>
</svg>
) : [PropertyType.DATE, PropertyType.RANGE_DATE].includes(type) ? (
<svg xmlns="http://www.w3.org/2000/svg" className={clsx(className, "h-5 w-5 shrink-0")} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
/>
</svg>
) : type === PropertyType.TEXT ? (
<svg
className={clsx(className, "h-5 w-5 shrink-0")}
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
width="24"
height="24"
viewBox="0 0 172 172"
fill="currentColor"
>
<g
fill="none"
fillRule="nonzero"
stroke="none"
strokeWidth="1"
strokeLinecap="butt"
strokeLinejoin="miter"
strokeMiterlimit="10"
strokeDasharray=""
strokeDashoffset="0"
fontFamily="none"
fontWeight="none"
fontSize="none"
// textAnchor="none"
>
<path d="M0,172v-172h172v172z" fill="none"></path>
<g fill="currentColor">
<path d="M146.59473,57.24935c-5.28183,0 -9.90758,1.23715 -13.89941,3.69531c-3.98467,2.451 -7.04629,5.9742 -9.19629,10.56803c-2.14283,4.59384 -3.2194,9.90187 -3.2194,15.92904v3.83528c0,9.44567 2.33353,16.88702 6.9847,22.29785c4.65117,5.41083 11.04261,8.11849 19.16244,8.11849c7.42467,0 13.40816,-1.93175 17.94466,-5.80892c4.5365,-3.87717 7.05009,-9.19203 7.54459,-15.94304v-0.014h-13.03157c-0.29383,3.81983 -1.4442,6.6341 -3.42936,8.45443c-1.98517,1.8275 -4.99348,2.74349 -9.02832,2.74349c-4.46483,0 -7.74101,-1.5573 -9.81218,-4.68913c-2.07117,-3.12467 -3.10742,-8.08556 -3.10742,-14.86523v-4.73112c0.05733,-6.48583 1.16705,-11.2725 3.33138,-14.36133c2.16433,-3.08883 5.40602,-4.63314 9.75618,-4.63314c4.00617,0 6.98784,0.92316 8.94434,2.74349c1.96367,1.82033 3.10686,4.7552 3.42936,8.80436h13.04557c-0.69517,-7.009 -3.27573,-12.4438 -7.74056,-16.32096c-4.46483,-3.87717 -10.36871,-5.82292 -17.67871,-5.82292zM23.58561,58.11719l-23.58561,62.70833h13.88542l4.35319,-12.91959h22.87174l4.40918,12.91959h13.87142l-23.71159,-62.70833zM65.31185,58.11719v62.70833h24.63542c7.19533,-0.05733 12.73058,-1.64195 16.61491,-4.74511c3.8915,-3.10317 5.83691,-7.66229 5.83691,-13.68946c0,-3.53317 -0.94298,-6.52167 -2.81348,-8.95833c-1.8705,-2.43667 -4.43807,-4.06842 -7.68457,-4.87109c2.84517,-1.08933 5.06459,-2.79355 6.66276,-5.13705c1.59816,-2.3435 2.39355,-5.04399 2.39355,-8.11849c0,-5.62583 -1.98539,-9.90478 -5.96289,-12.82161c-3.9775,-2.91683 -9.80692,-4.36719 -17.49675,-4.36719zM78.35742,68.58724h9.1403c3.59767,0 6.2247,0.61465 7.89453,1.86165c1.66983,1.247 2.50553,3.29969 2.50553,6.14486c0,5.08117 -3.29599,7.68189 -9.88216,7.79655h-9.6582zM29.63249,73.96224l7.96452,23.47364h-15.84505zM78.35742,93.5306h11.96777c6.00567,0.086 9.00032,2.99387 9.00032,8.73438c0,2.55133 -0.86235,4.55722 -2.58952,6.00489c-1.72717,1.44767 -4.12016,2.16959 -7.19466,2.16959h-11.18392z"></path>
</g>
</g>
</svg>
) : type === PropertyType.BOOLEAN ? (
<CheckIcon className={clsx(className, "h-5 w-5 shrink-0")} />
) : type === PropertyType.SELECT || type === PropertyType.MULTI_SELECT || type === PropertyType.MULTI_TEXT ? (
<svg
className={clsx(className, "h-5 w-5 shrink-0")}
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
width="24"
height="24"
viewBox="0 0 172 172"
fill="currentColor"
>
<g
fill="none"
fillRule="nonzero"
stroke="none"
strokeWidth="1"
strokeLinecap="butt"
strokeLinejoin="miter"
strokeMiterlimit="10"
strokeDasharray=""
strokeDashoffset="0"
fontFamily="none"
fontWeight="none"
fontSize="none"
// textAnchor="none"
>
<path d="M0,172v-172h172v172z" fill="none"></path>
<g fill="currentColor">
<path d="M21.5,43v14.33333h129v-14.33333zM21.5,71.66667v14.33333h129v-14.33333zM21.5,100.33333v14.33333h129v-14.33333zM64.5,129l21.5,21.5l21.5,-21.5z"></path>
</g>
</g>
</svg>
) : type === PropertyType.MEDIA ? (
<PaperClipIcon className={clsx(className, "h-5 w-5 shrink-0")} />
) : type === PropertyType.FORMULA ? (
<ExperimentIconFilled className={clsx(className, "h-5 w-5 shrink-0")} />
) : (
<div></div>
)}
</>
);
}
@@ -0,0 +1,377 @@
import clsx from "clsx";
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { PropertyType } from "~/application/enums/entities/PropertyType";
import ButtonTertiary from "~/components/ui/buttons/ButtonTertiary";
import FormGroup from "~/components/ui/forms/FormGroup";
import PencilAltIcon from "~/components/ui/icons/PencilAltIcon";
import ViewListIcon from "~/components/ui/icons/ViewListIcon";
import InputCheckboxWithDescription from "~/components/ui/input/InputCheckboxWithDescription";
import InputNumber from "~/components/ui/input/InputNumber";
import InputText from "~/components/ui/input/InputText";
import { PropertyWithDetails, EntitySimple } from "~/utils/db/entities/entities.db.server";
import StringUtils from "~/utils/shared/StringUtils";
import PropertyTypeSelector from "./PropertyTypeSelector";
import PropertyOptionsForm, { OptionValue, RefPropertyOptionsForm } from "./PropertyOptionsForm";
import PropertyAttributeHelper from "~/utils/helpers/PropertyAttributeHelper";
import PropertyAttribute from "./PropertyAttribute";
import PropertySubtypeSelector from "./PropertySubtypeSelector";
import PropertyFormulaSelector from "./PropertyFormulaSelector";
import { FormulaDto } from "~/modules/formulas/dtos/FormulaDto";
import { Link } from "react-router";
interface Props {
item?: PropertyWithDetails;
properties: PropertyWithDetails[];
entities: EntitySimple[];
formulas: FormulaDto[];
formulaListPath?: string;
formulaDetailsPath?: (formulaId: string) => string;
}
export default function PropertyForm({ item, properties, formulas, formulaListPath, formulaDetailsPath }: Props) {
const { t } = useTranslation();
const selectOptionsForm = useRef<RefPropertyOptionsForm>(null);
const [showAdvancedOptions, setShowAdvancedOptions] = useState(true);
const [order, setOrder] = useState<number | undefined>(item?.order ?? Math.max(...properties.map((o) => o.order)) + 1);
const [name, setName] = useState<string>(item?.name ?? "");
const [title, setTitle] = useState<string>(item?.title ?? "");
const [type, setType] = useState<PropertyType>(item?.type ?? PropertyType.TEXT);
const [subtype, setSubtype] = useState<string>(item?.subtype ?? "");
const [formulaId, setFormulaId] = useState(item?.formulaId ?? undefined);
const [options, setOptions] = useState<OptionValue[]>(
item?.options?.map((o) => {
return {
id: o.id,
order: o.order,
value: o.value,
name: o.name,
color: o.color,
};
}) ?? []
);
const [isRequired, setIsRequired] = useState<boolean>(item?.isRequired ?? true);
const [showInCreate, setShowInCreate] = useState<boolean>(item?.showInCreate ?? true);
const [isHidden, setIsHidden] = useState<boolean>(item?.isHidden ?? false);
const [isDisplay, setIsDisplay] = useState<boolean>(item?.isDisplay ?? properties.filter((f) => !f.isDefault).length === 0);
const [isReadOnly, setIsReadOnly] = useState<boolean>(item?.isReadOnly ?? false);
const [canUpdate, setCanUpdate] = useState<boolean>(item ? item.canUpdate : true);
const [attributes, setAttributes] = useState<{ name: string; value: string | undefined }[]>(item?.attributes ?? []);
// const [formula, setFormula] = useState<string>();
const [titleEnabled, setTitleEnabled] = useState(false);
useEffect(() => {
if (!item) {
if (title.includes(".")) {
const keys = title.split(".");
setName(StringUtils.toCamelCase(keys[keys.length - 1].toLowerCase()));
} else {
setName(StringUtils.toCamelCase(title.toLowerCase()));
}
}
}, [item, title, type]);
useEffect(() => {
const formula = formulas.find((f) => f.id === formulaId);
if (!item && formula) {
setTitle(formula.name);
setName(StringUtils.toCamelCase(formula.name.toLowerCase()));
}
}, [item, formulaId, formulas]);
useEffect(() => {
setTitleEnabled(true);
if (!item) {
if (type === PropertyType.TEXT) {
setSubtype("singleLine");
} else if (type === PropertyType.SELECT) {
setSubtype("dropdown");
} else if (type === PropertyType.MULTI_SELECT) {
setSubtype("combobox");
} else {
// setSubtype("");
}
} else {
if (type === PropertyType.TEXT) {
if (!subtype || !["singleLine", "email", "phone", "url"].includes(subtype)) {
setSubtype("singleLine");
}
} else if (type === PropertyType.SELECT) {
if (!subtype || !["dropdown", "radioGroupCards"].includes(subtype)) {
setSubtype("dropdown");
}
} else if (type === PropertyType.MULTI_SELECT) {
if (!subtype || !["combobox", "checkboxCards"].includes(subtype)) {
setSubtype("combobox");
}
} else {
// setSubtype("");
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [item, type]);
useEffect(() => {
if (type === PropertyType.FORMULA) {
setShowAdvancedOptions(false);
setIsRequired(false);
setIsReadOnly(true);
setShowInCreate(false);
}
}, [type]);
return (
<>
<FormGroup
id={item?.id}
editing={true}
canDelete={item !== undefined && !item?.isDefault && showAdvancedOptions}
className="space-y-2 pb-4"
classNameFooter="px-4"
>
<input type="hidden" name="order" value={order} hidden readOnly />
<div className="mt-4">
<div className="space-y-3 px-4">
<div className="w-full">
<label htmlFor="type" className="text-foreground/80 block text-xs font-medium">
{t("models.property.type")}
</label>
<div className="mt-1">
<PropertyTypeSelector selected={type} onSelected={(e) => setType(e)} />
</div>
</div>
{type === PropertyType.TEXT && (
<div>
<label htmlFor="subtype" className="text-foreground/80 block text-xs font-medium">
{t("models.property.subtype")}
</label>
<div className="mt-1">
<PropertySubtypeSelector types={["singleLine", "email", "phone", "url"]} selected={subtype} onSelected={(e) => setSubtype(e)} />
</div>
</div>
)}
{type === PropertyType.SELECT && (
<div>
<label htmlFor="subtype" className="text-foreground/80 block text-xs font-medium">
{t("models.property.subtype")}
</label>
<div className="mt-1">
<PropertySubtypeSelector types={["dropdown", "radioGroupCards"]} selected={subtype} onSelected={(e) => setSubtype(e)} />
</div>
</div>
)}
{type === PropertyType.MULTI_SELECT && (
<div>
<label htmlFor="subtype" className="text-foreground/80 block text-xs font-medium">
{t("models.property.subtype")}
</label>
<div className="mt-1">
<PropertySubtypeSelector types={["combobox", "checkboxCards"]} selected={subtype} onSelected={(e) => setSubtype(e)} />
</div>
</div>
)}
{type === PropertyType.FORMULA && (
<div>
<div className="flex justify-between space-x-2">
<label htmlFor="formula" className="text-foreground/80 block text-xs font-medium">
{t("models.property.formula")}
</label>
{item?.formulaId && formulaDetailsPath ? (
<Link to={formulaDetailsPath(item.formulaId)} className="text-xs text-blue-500 hover:underline">
{t("models.property.goToFormula")}
</Link>
) : formulaListPath ? (
<Link to={formulaListPath} className="text-xs text-blue-500 hover:underline">
{t("models.property.viewFormulas")}
</Link>
) : null}
</div>
<div className="mt-1">
<PropertyFormulaSelector name="formula-id" items={formulas} selected={formulaId} onSelected={(e) => setFormulaId(e)} />
</div>
</div>
)}
{titleEnabled && (
<InputText
name="title"
title={t("models.property.title")}
value={title}
setValue={(e) => setTitle(e)}
disabled={!titleEnabled}
required
withTranslation
placeholder={t("models.property.form.placeholders.title")}
autoFocus
/>
)}
<InputText
name="name"
title={t("models.property.name")}
value={name}
setValue={(e) => setName(e)}
required
placeholder={t("models.property.form.placeholders.name")}
pattern="[a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?"
hint={<span className="text-muted-foreground font-normal italic">{t("models.property.form.hints.camelCase")}</span>}
/>
<div className="border-border w-full rounded-md border border-dotted px-2 py-0">
<InputCheckboxWithDescription
name="is-display"
title={t("models.property.isDisplay")}
description={t("models.property.form.descriptions.isDisplay")}
value={isDisplay}
setValue={setIsDisplay}
/>
</div>
{/* {type === PropertyType.FORMULA && (
<div className="w-full">
<label htmlFor="formula" className="block text-xs font-medium text-foreground/80">
{t("entities.fields.FORMULA")}
</label>
<div className="mt-1">
<InputText
name="formula"
title={t("models.property.formula")}
value={formula}
setValue={(e) => setFormula(e.toString())}
disabled={!titleEnabled}
required
/>
</div>
</div>
)} */}
{[PropertyType.SELECT, PropertyType.MULTI_SELECT].includes(type) && (
<div className="w-full">
<label htmlFor="property-options-display" className="text-foreground/80 block text-sm font-medium">
{t("models.property.options")}
</label>
<div className="mt-1 flex rounded-md shadow-2xs">
<div className="relative flex grow items-stretch focus-within:z-10">
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
<ViewListIcon className="text-muted-foreground h-4 w-4" aria-hidden="true" />
</div>
{options.map((option) => {
return <input key={option.order} hidden readOnly type="text" id="options[]" name="options[]" value={JSON.stringify(option)} />;
})}
<input
id="property-options-display"
disabled
className="focus:border-border focus:ring-ring border-border text-foreground bg-secondary/90 block w-full rounded-none rounded-l-md border pl-10 sm:text-sm"
value={options.length === 0 ? t("models.property.form.noDropdownValues") : options.map((f) => f.value).join(", ")}
/>
</div>
<button
type="button"
onClick={() => selectOptionsForm.current?.set(options)}
className="focus:border-border focus:ring-ring border-border bg-secondary hover:bg-secondary/90 text-foreground/80 relative -ml-px inline-flex items-center space-x-2 rounded-r-md border px-4 py-1.5 text-sm font-medium focus:outline-hidden focus:ring-1"
>
<PencilAltIcon className="text-muted-foreground h-4 w-4" aria-hidden="true" />
<span>{t("models.property.form.setOptions")}</span>
</button>
</div>
</div>
)}
<div className="flex">
<ButtonTertiary onClick={() => setShowAdvancedOptions(!showAdvancedOptions)}>
{!showAdvancedOptions ? t("models.property.form.showAdvancedOptions") : t("models.property.form.hideAdvancedOptions")}
</ButtonTertiary>
</div>
</div>
<div className={clsx("border-border bg-secondary my-2 space-y-3 border border-dashed px-4 py-3", showAdvancedOptions ? "" : "hidden")}>
<div className="w-full">
<InputNumber name="order" title={t("models.property.order")} value={order} setValue={setOrder} />
</div>
<div className="w-full">
<InputCheckboxWithDescription
name="show-in-create"
title={t("models.property.showInCreate")}
description={t("models.property.form.descriptions.showInCreate")}
value={showInCreate}
setValue={setShowInCreate}
/>
</div>
<div className="w-full">
<InputCheckboxWithDescription
name="is-required"
title={t("models.property.isRequired")}
description={t("models.property.form.descriptions.isRequired")}
value={isRequired}
setValue={setIsRequired}
/>
</div>
<div className="w-full">
<InputCheckboxWithDescription
name="is-hidden"
title={t("models.property.isHidden")}
description={t("models.property.form.descriptions.isHidden")}
value={isHidden}
setValue={setIsHidden}
/>
</div>
<div className="w-full">
<InputCheckboxWithDescription
name="is-read-only"
title={t("models.property.isReadOnly")}
description={t("models.property.form.descriptions.isReadOnly")}
value={isReadOnly}
setValue={setIsReadOnly}
/>
</div>
<div className="w-full">
<InputCheckboxWithDescription
name="can-update"
title={t("models.property.canUpdate")}
description={t("models.property.form.descriptions.canUpdate")}
value={canUpdate}
setValue={setCanUpdate}
/>
</div>
{/* <div className="font-bold">{t("models.propertyAttribute.plural")}</div> */}
{attributes.map((attribute) => {
return <input key={attribute.name} hidden readOnly type="text" id="attributes[]" name="attributes[]" value={JSON.stringify(attribute)} />;
})}
{PropertyAttributeHelper.getAttributesByType(type, attributes).map((item) => {
return (
<PropertyAttribute
className="mb-2"
key={item}
name={item}
title={PropertyAttributeHelper.getAttributeTitle(t, item)}
value={attributes.find((f) => f.name === item)?.value ?? undefined}
setValue={(e) => {
const value = { name: item, value: e?.toString() };
const found = attributes.find((f) => f.name === item);
if (found) {
setAttributes([...attributes.filter((f) => f.name !== item), value]);
} else {
setAttributes([...attributes, value]);
}
}}
/>
);
})}
</div>
</div>
</FormGroup>
<PropertyOptionsForm ref={selectOptionsForm} title={title} onSet={(e) => setOptions(e)} />
</>
);
}
@@ -0,0 +1,77 @@
import { Fragment } from "react";
import { Listbox, Transition } from "@headlessui/react";
import { useTranslation } from "react-i18next";
import clsx from "clsx";
import SelectorIcon from "../../ui/icons/SelectorIcon";
import CheckIcon from "../../ui/icons/CheckIcon";
import { FormulaDto } from "~/modules/formulas/dtos/FormulaDto";
// import PropertySubtypeBadge from "./PropertySubtypeBadge";
interface Props {
name: string;
items: FormulaDto[];
className?: string;
selected: string | undefined;
onSelected: (item: string) => void;
}
export default function PropertyFormulaSelector({ name, items, className, selected, onSelected }: Props) {
const { t } = useTranslation();
return (
<Listbox name={name} value={selected} onChange={onSelected}>
{({ open }) => (
<>
<input type="hidden" name="subtype" value={selected} hidden readOnly />
<div className={clsx("relative", className)}>
<Listbox.Button className="focus:border-border focus:ring-ring border-border text-foreground bg-background relative w-full cursor-default rounded-md border py-2 pl-3 pr-10 text-left shadow-2xs focus:outline-hidden focus:ring-1 sm:text-sm">
{selected ? (
<div className="flex items-center space-x-2">
{/* <PropertySubtypeBadge subtype={selected} className="h-4 w-4 text-muted-foreground" /> */}
<div className="truncate">{items.find((item) => item.id === selected)?.name}</div>
</div>
) : (
<div className="text-muted-foreground">{t("shared.select")}...</div>
)}
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
<SelectorIcon className="text-muted-foreground h-5 w-5" aria-hidden="true" />
</span>
</Listbox.Button>
<Transition show={open} as={Fragment} leave="transition ease-in duration-100" leaveFrom="opacity-100" leaveTo="opacity-0">
<Listbox.Options className="border-border bg-background absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md border py-1 text-base shadow-lg focus:outline-hidden sm:text-sm">
{items.length === 0 ? (
<div className=" flex select-none justify-center p-2 text-red-500">{t("models.property.selectors.noFormulas")}</div>
) : (
<>
{items.map((item, idx) => (
<Listbox.Option
key={idx}
className={({ active }) =>
clsx(active ? " bg-secondary " : "", "hover:bg-secondary relative cursor-default select-none py-2 pl-3 pr-9")
}
value={item.id}
>
{({ selected, active }) => (
<>
<div className="flex items-center space-x-2">
<div className="truncate">{item.name}</div>
</div>
{selected ? (
<span className={clsx(active ? "" : "", "absolute inset-y-0 right-0 flex items-center pr-4")}>
<CheckIcon className="h-5 w-5" aria-hidden="true" />
</span>
) : null}
</>
)}
</Listbox.Option>
))}
</>
)}
</Listbox.Options>
</Transition>
</div>
</>
)}
</Listbox>
);
}
@@ -0,0 +1,43 @@
import { PropertyWithDetails } from "~/utils/db/entities/entities.db.server";
import { DateFormatType } from "~/utils/shared/DateUtils";
import { NumberFormatType } from "~/utils/shared/NumberUtils";
import RowNumberCell from "../rows/cells/RowNumberCell";
import RowDateCell from "../rows/cells/RowDateCell";
import { PropertyAttributeName } from "~/application/enums/entities/PropertyAttributeName";
import { FormulaValueType } from "~/modules/formulas/dtos/FormulaDto";
import { BooleanFormatType } from "~/utils/shared/BooleanUtils";
import RowBooleanCell from "../rows/cells/RowBooleanCell";
interface Props {
property: PropertyWithDetails;
value: FormulaValueType;
}
export default function PropertyFormulaValueBadge({ property, value }: Props) {
const getNumberFormat = () => {
return property.attributes.find((f) => f.name === PropertyAttributeName.FormatNumber)?.value as NumberFormatType;
};
const getBooleanFormat = () => {
return property.attributes.find((f) => f.name === PropertyAttributeName.FormatBoolean)?.value as BooleanFormatType;
};
const getDateFormat = () => {
return property.attributes.find((f) => f.name === PropertyAttributeName.FormatDate)?.value as DateFormatType;
};
return (
<div className="flex space-x-1">
{/* <div>
<div>[resultAs:{property.formula?.resultAs}]</div>
<div>[calculationTrigger:{property.formula?.calculationTrigger}]</div>
<div>value: {JSON.stringify(value)}</div>
</div> */}
{property.formula?.resultAs === "number" ? (
<RowNumberCell value={Number(value) ?? undefined} format={getNumberFormat()} />
) : property.formula?.resultAs === "boolean" ? (
<RowBooleanCell value={Boolean(value) ?? undefined} format={getBooleanFormat()} />
) : property.formula?.resultAs === "date" ? (
<RowDateCell value={value ? (value as Date) : undefined} format={getDateFormat()} />
) : (
<div>{value?.toString()}</div>
)}
</div>
);
}
@@ -0,0 +1,84 @@
import { ReactNode, useEffect, useState } from "react";
import InputCombobox from "~/components/ui/input/InputCombobox";
import { RowValueMultipleDto } from "~/application/dtos/entities/RowValueMultipleDto";
import InputCheckboxCards from "~/components/ui/input/InputCheckboxCards";
interface Props {
name: string;
title: string;
options: { value: string; name: string | null; color: number }[];
subtype?: "combobox" | "checkboxCards";
required?: boolean;
disabled?: boolean;
value?: RowValueMultipleDto[];
onSelected?: (item: RowValueMultipleDto[]) => void;
hint?: ReactNode;
help?: string;
icon?: string;
autoFocus?: boolean;
}
const PropertyMultiSelector = ({ name, title, options, subtype, disabled, value, onSelected, required }: Props) => {
const [actualValue, setActualValue] = useState<(string | number)[]>([]);
useEffect(() => {
const selection = value?.map((f) => f.value) ?? [];
if (selection.sort().join(",") !== actualValue.sort().join(",")) {
setActualValue(selection);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]);
useEffect(() => {
// onSelected(actualValue);
}, [actualValue, onSelected]);
return (
<>
{/* actualValue: {JSON.stringify(actualValue)} */}
{!subtype || subtype === "combobox" ? (
<InputCombobox
name={name}
title={title}
value={actualValue}
onChange={setActualValue}
options={options}
disabled={disabled}
withSearch={false}
withLabel={true}
required={required}
/>
) : subtype === "checkboxCards" ? (
<InputCheckboxCards
name={name}
title={title}
value={actualValue}
onChange={setActualValue}
options={options.map((f) => {
return {
value: f.value,
name: f.name ?? f.value,
};
})}
disabled={disabled}
required={required}
/>
) : null}
{actualValue?.map((item, idx) => {
return (
<input
key={idx}
type="hidden"
name={name + `[]`}
value={JSON.stringify({
value: item,
order: idx,
})}
/>
);
})}
</>
);
};
export default PropertyMultiSelector;
@@ -0,0 +1,44 @@
import { RowValueMultipleDto } from "~/application/dtos/entities/RowValueMultipleDto";
import { translateSelectOptionLabel } from "~/utils/i18n/translateLabel";
import { useTranslation } from "react-i18next";
type OptionDto = { value: string; name: string | null };
interface Props {
values: RowValueMultipleDto[] | null;
options?: OptionDto[];
entityName?: string;
propertyName?: string;
}
export default function PropertyMultipleValueBadge({ values, options, entityName, propertyName }: Props) {
const { t, i18n } = useTranslation();
function getSelectedNames() {
let names: string[] = [];
if (values) {
for (const value of values) {
const option = options?.find((f) => f.value === value.value);
if (option && entityName && propertyName) {
names.push(translateSelectOptionLabel(t, i18n, entityName, propertyName, option));
} else {
names.push(option?.name ?? value.value);
}
}
}
return names;
}
return (
<div className="flex space-x-1">
{getSelectedNames().join(", ") ?? <span className="text-gray-300"></span>}
{/* {values?.map((value) => {
return (
<div
key={value.id}
className="relative mx-0.5 inline-flex max-w-sm shrink-0 select-none items-center space-x-0.5 overflow-x-auto rounded-full border border-border bg-secondary px-2 py-0.5"
>
<div className="text-xs font-medium text-muted-foreground">{value.value}</div>
</div>
);
})} */}
</div>
);
}
@@ -0,0 +1,21 @@
import { EntityWithDetails } from "~/utils/db/entities/entities.db.server";
import RowSelectedOptionCell from "../rows/cells/RowSelectedOptionCell";
import { SelectOptionsDisplay } from "~/utils/shared/SelectOptionsUtils";
interface Props {
entity: EntityWithDetails;
property: string;
value: string;
display: SelectOptionsDisplay;
}
export default function PropertyOptionValueBadge({ entity, property, value, display }: Props) {
return (
<RowSelectedOptionCell
value={value}
options={entity.properties.find((f) => f.name === property)?.options ?? []}
display={display}
entityName={entity.name}
propertyName={property}
/>
);
}
@@ -0,0 +1,220 @@
import { Ref, useImperativeHandle, useRef, useState, forwardRef, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { Colors } from "~/application/enums/shared/Colors";
import ColorBadge from "~/components/ui/badges/ColorBadge";
import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
import ButtonSecondary from "~/components/ui/buttons/ButtonSecondary";
import ButtonTertiary from "~/components/ui/buttons/ButtonTertiary";
import TrashIcon from "~/components/ui/icons/TrashIcon";
import InputCheckboxInline from "~/components/ui/input/InputCheckboxInline";
import InputSelector from "~/components/ui/input/InputSelector";
import InputText, { RefInputText } from "~/components/ui/input/InputText";
import ErrorModal, { RefErrorModal } from "~/components/ui/modals/ErrorModal";
import SlideOverWideEmpty from "~/components/ui/slideOvers/SlideOverWideEmpty";
import { getColors } from "~/utils/shared/ColorUtils";
import { updateItemByIdx } from "~/utils/shared/ObjectUtils";
export type OptionValue = {
id?: string | null;
parentId?: string | null;
order: number;
value: string;
name: string | null;
color?: Colors;
options?: OptionValue[];
};
export interface RefPropertyOptionsForm {
set: (options: OptionValue[]) => void;
}
interface Props {
title: string;
onSet: (items: OptionValue[]) => void;
}
const PropertyOptionsForm = ({ title, onSet }: Props, ref: Ref<RefPropertyOptionsForm>) => {
useImperativeHandle(ref, () => ({ set }));
const { t } = useTranslation();
const errorModal = useRef<RefErrorModal>(null);
const inputOption = useRef<RefInputText>(null);
const [withColors, setWithColors] = useState(false);
const [withDescriptions, setWithDescriptions] = useState(false);
const [open, setOpen] = useState(false);
const [items, setItems] = useState<OptionValue[]>([]);
useEffect(() => {
if (!withDescriptions) {
setItems((items) => items.map((f) => ({ ...f, name: null })));
}
}, [withDescriptions]);
useEffect(() => {
if (!withColors) {
setItems((items) => items.map((f) => ({ ...f, color: undefined })));
}
}, [withColors]);
function set(options: OptionValue[]) {
setItems(options);
if (options.length === 0 && items.length === 0) {
addOption();
}
setWithColors(options.some((f) => f.color));
setWithDescriptions(options.some((f) => f.name));
setOpen(true);
}
function close() {
setOpen(false);
}
function save() {
const emptyItems = items.filter((f) => !f.value || f.value.trim() === "");
if (emptyItems.length > 0) {
errorModal.current?.show(t("entities.errors.selectOptionCannotBeEmpty"));
return;
}
onSet(items);
close();
}
function addOption() {
const maxOrder = items.length === 0 ? 1 : Math.max(...items.map((o) => o.order));
setItems([
...items,
{
id: null,
parentId: null,
order: maxOrder + 1,
value: "",
name: null,
color: Colors.UNDEFINED,
options: [],
},
]);
setTimeout(() => {
inputOption.current?.input.current?.focus();
}, 1);
}
return (
<SlideOverWideEmpty title={t("models.property.optionEditor.titleWithProperty", { property: t(title) })} open={open} onClose={() => setOpen(false)}>
<div className="">
<div>
<div className="mt-3 sm:mt-5">
<div className="mt-4 space-y-3">
<div className="flex space-x-3">
<InputCheckboxInline name="with-colors" title={t("models.property.optionEditor.withColors")} description="" value={withColors} setValue={setWithColors} />
<InputCheckboxInline
name="with-descriptions"
title={t("models.property.optionEditor.withDescriptions")}
description=""
value={withDescriptions}
setValue={setWithDescriptions}
/>
</div>
<div className="w-full">
<div className="flex items-center justify-between space-x-2">
<label htmlFor="select" className="text-foreground/80 block text-sm font-medium">{t("models.property.options")}</label>
<div className="flex space-x-2">
<ButtonTertiary onClick={addOption}>
<div className="-mx-1 text-xs">{t("models.property.optionEditor.add")}</div>
</ButtonTertiary>
</div>
</div>
<div className="border-border bg-secondary mt-1 space-y-2 rounded-md border-2 border-dashed p-2">
{items.map((option, idx) => {
return (
<div key={option.order} className="mt-1 flex items-center space-x-1 rounded-md">
<InputText
ref={inputOption}
type="text"
title="shared.value"
withLabel={false}
name={"select-option-" + idx}
value={option.value}
placeholder={t("shared.value")}
setValue={(e) =>
updateItemByIdx(items, setItems, idx, {
value: e,
})
}
className="flex-auto"
/>
{withDescriptions && (
<InputText
type="text"
title=""
withLabel={false}
name={"select-option-name-" + idx}
placeholder={t("shared.name")}
value={option.name ?? undefined}
setValue={(e) =>
updateItemByIdx(items, setItems, idx, {
name: e,
})
}
className="flex-auto"
/>
)}
{withColors && (
<div className="w-32">
<InputSelector
name="color"
title={t("models.group.color")}
withSearch={false}
value={option.color ?? Colors.UNDEFINED}
withLabel={false}
setValue={(e) =>
updateItemByIdx(items, setItems, idx, {
color: Number(e),
})
}
selectPlaceholder={""}
className="w-32"
options={
getColors().map((color) => {
return {
name: <ColorBadge color={color} />,
value: color,
};
}) ?? []
}
></InputSelector>
</div>
)}
<ButtonSecondary disabled={items.length === 1} type="button" onClick={() => setItems([...items.filter((_, index) => index !== idx)])}>
<TrashIcon className="text-muted-foreground h-4 w-4" aria-hidden="true" />
</ButtonSecondary>
</div>
);
})}
<div className="w-full"></div>
</div>
</div>
</div>
</div>
</div>
<div className="border-border mt-5 border-t pt-3 sm:mt-6">
<div className="flex items-center justify-end space-x-2">
<ButtonSecondary onClick={close}>{t("shared.cancel")}</ButtonSecondary>
<ButtonPrimary onClick={save}>{t("shared.save")}</ButtonPrimary>
</div>
</div>
<ErrorModal ref={errorModal} />
</div>
</SlideOverWideEmpty>
);
};
export default forwardRef(PropertyOptionsForm);
@@ -0,0 +1,24 @@
import EmailIcon from "~/components/ui/icons/EmailIcon";
import LinkIcon from "~/components/ui/icons/crud/LinkIcon";
import { PhoneIcon } from "~/components/ui/icons/vendor";
interface Props {
subtype?: string;
className?: string;
}
export default function PropertySubtypeBadge({ subtype, className }: Props) {
return (
<>
{subtype === "email" ? (
<EmailIcon className="h-4 w-4 shrink-0" />
) : subtype === "phone" ? (
<PhoneIcon className="h-4 w-4 shrink-0" />
) : subtype === "url" ? (
<LinkIcon className="h-4 w-4 shrink-0" />
) : (
<div></div>
)}
</>
);
}
@@ -0,0 +1,76 @@
import { Fragment } from "react";
import { Listbox, Transition } from "@headlessui/react";
import { useTranslation } from "react-i18next";
import clsx from "clsx";
import SelectorIcon from "../../ui/icons/SelectorIcon";
import CheckIcon from "../../ui/icons/CheckIcon";
// import PropertySubtypeBadge from "./PropertySubtypeBadge";
interface Props {
types: string[];
className?: string;
selected: string | undefined;
onSelected: (item: string) => void;
}
export default function PropertySubtypeSelector({ types, className, selected, onSelected }: Props) {
const { t } = useTranslation();
return (
<Listbox name="formula" value={selected} onChange={onSelected}>
{({ open }) => (
<>
<input type="hidden" name="subtype" value={selected} hidden readOnly />
<div className={clsx("relative", className)}>
<Listbox.Button className="focus:border-border focus:ring-ring border-border text-foreground bg-background relative w-full cursor-default rounded-md border py-2 pl-3 pr-10 text-left shadow-2xs focus:outline-hidden focus:ring-1 sm:text-sm">
{selected ? (
<div className="flex items-center space-x-2">
{/* <PropertySubtypeBadge subtype={selected} className="h-4 w-4 text-muted-foreground" /> */}
<div className="truncate">{t("entities.subtypes." + selected)}</div>
</div>
) : (
<div className="text-muted-foreground">{t("shared.select")}...</div>
)}
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
<SelectorIcon className="text-muted-foreground h-5 w-5" aria-hidden="true" />
</span>
</Listbox.Button>
<Transition show={open} as={Fragment} leave="transition ease-in duration-100" leaveFrom="opacity-100" leaveTo="opacity-0">
<Listbox.Options className="border-border bg-background absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md border py-1 text-base shadow-lg focus:outline-hidden sm:text-sm">
{types.length === 0 ? (
<div className=" flex select-none justify-center p-2 text-red-500">{t("models.property.selectors.noSubtypes")}</div>
) : (
<>
{types.map((item, idx) => (
<Listbox.Option
key={idx}
className={({ active }) =>
clsx(active ? " bg-secondary " : "", "hover:bg-secondary relative cursor-default select-none py-2 pl-3 pr-9")
}
value={item}
>
{({ selected, active }) => (
<>
<div className="flex items-center space-x-2">
{/* <PropertySubtypeBadge subtype={item} className={clsx(active ? "" : "", "h-4 w-4")} /> */}
<div className="truncate">{t("entities.subtypes." + item)}</div>
</div>
{selected ? (
<span className={clsx(active ? "" : "", "absolute inset-y-0 right-0 flex items-center pr-4")}>
<CheckIcon className="h-5 w-5" aria-hidden="true" />
</span>
) : null}
</>
)}
</Listbox.Option>
))}
</>
)}
</Listbox.Options>
</Transition>
</div>
</>
)}
</Listbox>
);
}
@@ -0,0 +1,89 @@
import { Fragment } from "react";
import { Listbox, Transition } from "@headlessui/react";
import { useTranslation } from "react-i18next";
import clsx from "clsx";
import PropertyBadge from "./PropertyBadge";
import { PropertyType } from "~/application/enums/entities/PropertyType";
import SelectorIcon from "../../ui/icons/SelectorIcon";
import CheckIcon from "../../ui/icons/CheckIcon";
interface Props {
className?: string;
selected: PropertyType;
onSelected: (item: PropertyType) => void;
}
export default function PropertyTypeSelector({ className, selected, onSelected }: Props) {
const items: PropertyType[] = [
PropertyType.TEXT,
PropertyType.NUMBER,
PropertyType.DATE,
// PropertyType.USER,
// PropertyType.ROLE,
PropertyType.SELECT,
PropertyType.BOOLEAN,
PropertyType.MEDIA,
// PropertyType.ENTITY,
// PropertyType.FORMULA,
PropertyType.MULTI_SELECT,
PropertyType.MULTI_TEXT,
PropertyType.RANGE_NUMBER,
PropertyType.RANGE_DATE,
PropertyType.FORMULA,
];
const { t } = useTranslation();
return (
<Listbox value={selected} onChange={onSelected}>
{({ open }) => (
<>
<input type="hidden" name="type" value={selected} hidden readOnly />
<div className={clsx("relative", className)}>
<Listbox.Button className="focus:border-border focus:ring-ring border-border text-foreground bg-background relative w-full cursor-default rounded-md border py-2 pl-3 pr-10 text-left shadow-2xs focus:outline-hidden focus:ring-1 sm:text-sm">
<div className="flex items-center space-x-2">
<PropertyBadge type={selected} className="text-muted-foreground h-4 w-4" />
<div className="truncate">{t("entities.fields." + PropertyType[selected])}</div>
</div>
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
<SelectorIcon className="text-muted-foreground h-5 w-5" aria-hidden="true" />
</span>
</Listbox.Button>
<Transition show={open} as={Fragment} leave="transition ease-in duration-100" leaveFrom="opacity-100" leaveTo="opacity-0">
<Listbox.Options className="border-border bg-background absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md border py-1 text-base shadow-lg focus:outline-hidden sm:text-sm">
{items.length === 0 ? (
<div className=" flex select-none justify-center p-2 text-red-500">{t("models.property.selectors.noFields")}</div>
) : (
<>
{items.map((item, idx) => (
<Listbox.Option
key={idx}
className={({ active }) =>
clsx(active ? " bg-secondary " : "", "hover:bg-secondary relative cursor-default select-none py-2 pl-3 pr-9")
}
value={item}
>
{({ selected, active }) => (
<>
<div className="flex items-center space-x-2">
<PropertyBadge type={item} className={clsx(active ? "" : "", "h-4 w-4")} />
<div className="truncate">{t("entities.fields." + PropertyType[item])}</div>
</div>
{selected ? (
<span className={clsx(active ? "" : "", "absolute inset-y-0 right-0 flex items-center pr-4")}>
<CheckIcon className="h-5 w-5" aria-hidden="true" />
</span>
) : null}
</>
)}
</Listbox.Option>
))}
</>
)}
</Listbox.Options>
</Transition>
</div>
</>
)}
</Listbox>
);
}
@@ -0,0 +1,259 @@
import { Property } from "@toolctrl/db/prisma-browser";
import clsx from "clsx";
import { useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Link, useSubmit } from "react-router";
import { PropertyType } from "~/application/enums/entities/PropertyType";
import { PropertyWithDetails } from "~/utils/db/entities/entities.db.server";
import EntityHelper from "~/utils/helpers/EntityHelper";
import ButtonTertiary from "../../ui/buttons/ButtonTertiary";
import LockClosedIcon from "../../ui/icons/LockClosedIcon";
import NewFieldIcon from "../../ui/icons/NewFieldIcon";
import PencilIcon from "../../ui/icons/PencilIcon";
import TrashIcon from "../../ui/icons/TrashIcon";
import ConfirmModal, { RefConfirmModal } from "../../ui/modals/ConfirmModal";
import PropertyBadge from "./PropertyBadge";
import OrderListButtons from "../../ui/sort/OrderListButtons";
import EyeIcon from "~/components/ui/icons/EyeIcon";
import EyeLashIcon from "~/components/ui/icons/EyeLashIcon";
import DocumentDuplicateIconFilled from "~/components/ui/icons/DocumentDuplicateIconFilled";
import { useRootData } from "~/utils/data/useRootData";
interface Props {
tenantId: string | null;
items: PropertyWithDetails[];
className?: string;
}
export default function TenantPropertiesList({ tenantId, items, className }: Props) {
const { t } = useTranslation();
const submit = useSubmit();
const rootData = useRootData();
const confirmDelete = useRef<RefConfirmModal>(null);
const [showDefaultFields, setShowDefaultFields] = useState(false);
function deleteField(item: Property) {
confirmDelete.current?.setValue(item);
confirmDelete.current?.show(t("shared.confirmDelete"), t("shared.delete"), t("shared.cancel"), t("shared.warningCannotUndo"));
}
function confirmedDelete(item: Property) {
const form = new FormData();
form.set("action", "delete");
form.set("id", item.id);
if (rootData.csrf) {
form.set("csrf", rootData.csrf);
}
submit(form, {
method: "post",
});
}
function onToggleDisplay(item: Property) {
const form = new FormData();
form.set("action", "toggle-display");
form.set("id", item.id);
if (rootData.csrf) {
form.set("csrf", rootData.csrf);
}
submit(form, {
method: "post",
});
}
function onDuplicate(item: Property) {
const form = new FormData();
form.set("action", "duplicate");
form.set("id", item.id);
if (rootData.csrf) {
form.set("csrf", rootData.csrf);
}
submit(form, {
method: "post",
});
}
return (
<div className={clsx(className, "")}>
<div className="space-y-2">
{showDefaultFields && (
<div className="mb-3 space-y-2">
<div className="flex items-center justify-between">
<h3 className="text-sm font-medium">{t("models.property.defaultProperties.title")}</h3>
{showDefaultFields && (
<div className="flex justify-end">
<ButtonTertiary className="-my-1" onClick={() => setShowDefaultFields(!showDefaultFields)}>
{t("models.property.defaultProperties.hide")}
</ButtonTertiary>
</div>
)}
</div>
{items
.filter((f) => f.tenantId === null)
.map((item, idx) => {
return (
<div key={idx} className="border-border bg-secondary/90 rounded-md border px-4 py-2 shadow-2xs">
<div className="flex items-center justify-between space-x-2">
<div className="flex items-center space-x-2">
<div className=" flex items-center space-x-3">
<div className=" flex items-center space-x-2">
<LockClosedIcon className="h-4 w-4 text-gray-300" />
{/* <PropertyBadge className="h-4 w-4 text-muted-foreground" /> */}
{/* <div className="truncate text-sm text-muted-foreground">{t("entities.fields." + PropertyType[item.type])}</div> */}
</div>
<div className="text-muted-foreground text-sm">
{/* <PropertyTitle item={item} /> */}
<div className="flex flex-col">
<div>{t(item.title)}</div>
<div className="text-muted-foreground text-xs">{item.name}</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
})}
</div>
)}
</div>
<div className="">
<div className="space-y-4">
<div className="flex items-center justify-between">
<h3 className="text-sm font-medium">{t("models.property.plural")}</h3>
{!showDefaultFields && (
<div className="flex justify-end">
<ButtonTertiary className="-my-1" onClick={() => setShowDefaultFields(!showDefaultFields)}>
{t("models.property.defaultProperties.show")}
</ButtonTertiary>
</div>
)}
</div>
{items
.filter((f) => !f.isDefault && f.tenantId === tenantId)
.sort((a, b) => a.order - b.order)
.map((item, idx) => {
return (
<div key={idx} className="border-border bg-background rounded-md border px-4 py-1 shadow-2xs">
<div className="flex items-center justify-between space-x-2">
<div className="flex items-center space-x-2 truncate">
<div className=" flex items-center space-x-3 truncate">
<div className="hidden shrink-0 sm:flex">
<OrderListButtons index={idx} items={items.filter((f) => !f.isDefault)} editable={true} />
</div>
<div className=" flex items-center space-x-2">
<PropertyBadge type={item.type} className="text-muted-foreground h-4 w-4" />
</div>
<div className="text-foreground flex items-center space-x-2 truncate text-sm">
<PropertyTitle item={item} />
</div>
</div>
</div>
<div className="flex shrink-0 space-x-1">
<div className="flex items-center space-x-1 truncate p-1">
<button
type="button"
onClick={() => onToggleDisplay(item)}
aria-label={t(item.isDisplay ? "shared.hide" : "shared.show")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:outline-hidden focus:ring-2 focus:ring-gray-400 focus:ring-offset-1"
>
{item.isDisplay ? (
<EyeIcon className="text-muted-foreground hover:text-muted-foreground h-4 w-4" />
) : (
<EyeLashIcon className="hover:text-muted-foreground h-4 w-4 text-gray-300" />
)}
</button>
<Link
to={item.id}
aria-label={t("shared.edit")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:outline-hidden focus:ring-2 focus:ring-gray-400 focus:ring-offset-1"
// onClick={() => update(idx, item)}
>
<PencilIcon className="group-hover:text-muted-foreground h-4 w-4 text-gray-300" />
</Link>
<button
type="button"
onClick={() => onDuplicate(item)}
aria-label={t("shared.duplicate")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:outline-hidden focus:ring-2 focus:ring-gray-400 focus:ring-offset-1"
>
<DocumentDuplicateIconFilled className="hover:text-muted-foreground h-4 w-4 text-gray-300" />
</button>
<button
type="button"
aria-label={t("shared.delete")}
className="hover:bg-secondary/90 focus:bg-secondary/90 group flex items-center rounded-md border border-transparent p-2 focus:outline-hidden focus:ring-2 focus:ring-gray-400 focus:ring-offset-1"
onClick={() => deleteField(item)}
>
<TrashIcon className="group-hover:text-muted-foreground h-4 w-4 text-gray-300" />
</button>
</div>
</div>
</div>
</div>
);
})}
</div>
</div>
<div className="mt-3">
<Link
to={`new`}
className="focus:ring-ring border-border hover:border-border relative block w-full rounded-lg border-2 border-dashed px-12 py-6 text-center focus:outline-hidden focus:ring-2 focus:ring-offset-2"
>
<NewFieldIcon className="text-muted-foreground mx-auto h-8" />
<span className="text-foreground mt-2 block text-sm font-medium">{t("models.property.actions.add")}</span>
</Link>
</div>
{/* <PropertyForm ref={propertyForm} entityId={entityId} onCreated={created} onUpdated={updated} onDeleted={deleted} /> */}
<ConfirmModal ref={confirmDelete} destructive onYes={confirmedDelete} />
</div>
);
}
const PropertyTitle = ({ item }: { item: PropertyWithDetails }) => {
const { t } = useTranslation();
return (
<>
<div className="flex items-baseline space-x-1 truncate">
<div className="flex flex-col">
<div>
{t(EntityHelper.getFieldTitle(item, item.isDefault))}
{item.isRequired && <span className="text-red-500">*</span>}
</div>
<div className="text-muted-foreground text-xs">
{item.name}
{item.subtype === "phone" && " (phone)"}
{item.subtype === "url" && " (URL)"}
{[PropertyType.MULTI_SELECT, PropertyType.SELECT].includes(item.type) && "[]"}
{[PropertyType.RANGE_NUMBER, PropertyType.RANGE_DATE].includes(item.type) && ` (${t("models.property.badges.range")})`}
{[PropertyType.FORMULA].includes(item.type) && ` (${t("models.property.badges.formula")})`}
</div>
</div>
{/* {item.type === PropertyType.FORMULA && <div className="truncate italic text-muted-foreground">({item.formula})</div>} */}
{[PropertyType.SELECT, PropertyType.MULTI_SELECT].includes(item.type) && (
<div className="text-muted-foreground truncate text-xs">
[
{item.options.length === 0
? t("models.property.noOptions")
: t("models.property.optionsSummary", { options: item.options?.map((f) => f.value).join(", ") })}
]
</div>
)}
{item.attributes.filter((f) => f.value).length > 0 && (
<div className="text-muted-foreground truncate text-xs">
[
{item.attributes
.filter((f) => f.value)
.map((f) => `${f.name}: ${f.value}`)
.join(", ")}
]
</div>
)}
</div>
</>
);
};
@@ -0,0 +1,20 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
const sourcePath = path.resolve(process.cwd(), "apps/web/app/components/entities/properties/PropertiesList.tsx");
describe("properties list i18n", () => {
it("uses semantic translation keys for option summaries", () => {
const source = fs.readFileSync(sourcePath, "utf8");
expect(source).toContain("models.property.noOptions");
expect(source).toContain("models.property.optionsSummary");
expect(source).toContain("models.property.badges.range");
expect(source).toContain("models.property.badges.formula");
expect(source).not.toContain('"No options"');
expect(source).not.toContain('"Options: "');
expect(source).not.toContain('" (range)"');
expect(source).not.toContain("` (formula)`");
});
});
@@ -0,0 +1,26 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
const selectorRoot = path.resolve(process.cwd(), "apps/web/app/components/entities/properties");
function readSelector(relativePath: string) {
return fs.readFileSync(path.join(selectorRoot, relativePath), "utf8");
}
describe("property selector empty states i18n", () => {
it("uses semantic translation keys for empty dropdown states", () => {
const sources = [
readSelector("PropertySubtypeSelector.tsx"),
readSelector("PropertyTypeSelector.tsx"),
readSelector("PropertyFormulaSelector.tsx"),
].join("\n");
expect(sources).toContain("models.property.selectors.noSubtypes");
expect(sources).toContain("models.property.selectors.noFields");
expect(sources).toContain("models.property.selectors.noFormulas");
expect(sources).not.toContain("there_are_no_subtypes");
expect(sources).not.toContain("there_are_no_fields");
expect(sources).not.toContain("there_are_no_formulas");
});
});
@@ -0,0 +1,119 @@
import { Fragment } from "react";
import { Colors } from "~/application/enums/shared/Colors";
import ColorBadge from "~/components/ui/badges/ColorBadge";
import { SelectOptionsDisplay } from "~/utils/shared/SelectOptionsUtils";
export default function RenderOption({
option,
hasColors,
display,
}: {
option:
| {
name?: string | null;
value: string;
color?: Colors | number;
}
| undefined;
hasColors: boolean;
display?: SelectOptionsDisplay;
}) {
return (
<Fragment>
{!option ? (
<></>
) : (
<Fragment>
{!display ? (
<Fragment>
{option.name ? (
option.name
) : (
<>
{option.value}
{option.name && option.value && " - "}
{option.name}
</>
)}
</Fragment>
) : (
<Fragment>
<div className="flex space-x-2 truncate">
{display === "Name" && (option.name ?? option.value)}
{display === "Value" && option.value}
{display === "Color" && (
<Fragment>
<ColorBadge color={option.color} />
</Fragment>
)}
{display === "ColorWithTitle" && (
<Fragment>
<div>
<ColorBadge color={option.color} />
</div>
{option.color !== undefined && option.color !== null && <div className="capitalize">{Colors[option.color]?.toLowerCase()}</div>}
</Fragment>
)}
{display === "NameAndValue" && (
<Fragment>
{option.name}
{option.name && option.value && " - "}
{option.value}
</Fragment>
)}
{display === "ValueAndName" && (
<Fragment>
{option.value}
{option.name && option.value && " - "}
{option.name}
</Fragment>
)}
{display === "NameValueAndColor" && (
<Fragment>
<div>
<ColorBadge color={option.color} />
</div>
<div>
{option.name}
{option.name && option.value && " - "}
{option.value}
</div>
</Fragment>
)}
{display === "ValueNameAndColor" && (
<Fragment>
<div>
<ColorBadge color={option.color} />
</div>
<div>
{option.value}
{option.name && option.value && " - "}
{option.name}
</div>
</Fragment>
)}
{display === "NameAndColor" && (
<Fragment>
<div>
<ColorBadge color={option.color} />
</div>
<div>{option.name}</div>
</Fragment>
)}
{display === "ValueAndColor" && (
<Fragment>
<div>
<ColorBadge color={option.color} />
</div>
<div>{option.value}</div>
</Fragment>
)}
</div>
</Fragment>
)}
</Fragment>
)}
</Fragment>
);
}
@@ -0,0 +1,20 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
const sourcePath = path.resolve(process.cwd(), "apps/web/app/components/entities/properties/TenantPropertiesList.tsx");
describe("tenant properties list i18n", () => {
it("uses semantic translation keys for option summaries", () => {
const source = fs.readFileSync(sourcePath, "utf8");
expect(source).toContain("models.property.noOptions");
expect(source).toContain("models.property.optionsSummary");
expect(source).toContain("models.property.badges.range");
expect(source).toContain("models.property.badges.formula");
expect(source).not.toContain('"No options"');
expect(source).not.toContain('"Options: "');
expect(source).not.toContain('" (range)"');
expect(source).not.toContain("` (formula)`");
});
});