Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import { ActionFunction, LoaderFunctionArgs, redirect, useLoaderData } from "react-router";
|
||||
import EntityRelationshipForm from "~/components/entities/relationships/EntityRelationshipForm";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { EntityWithDetails, getAllEntities, getEntityBySlug } from "~/utils/db/entities/entities.db.server";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import {
|
||||
deleteScopedEntityRelationship,
|
||||
EntityRelationshipWithCount,
|
||||
findEntityRelationship,
|
||||
getScopedEntityRelationship,
|
||||
updateScopedEntityRelationship,
|
||||
} from "~/utils/db/entities/entityRelationships.db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
|
||||
type LoaderData = {
|
||||
entity: EntityWithDetails;
|
||||
entities: EntityWithDetails[];
|
||||
item: EntityRelationshipWithCount;
|
||||
};
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
await verifyUserHasPermission(request, "admin.entities.view");
|
||||
const entity = await getEntityBySlug({ tenantId: null, slug: params.entity! });
|
||||
const item = await getScopedEntityRelationship({ id: params.id ?? "", entityId: entity.id });
|
||||
if (!item) {
|
||||
return redirect(adminPath(`entities/${params.entity}/relationships`, { mode: "host-aware" }));
|
||||
}
|
||||
const data: LoaderData = {
|
||||
entity,
|
||||
entities: await getAllEntities({ tenantId: null }),
|
||||
item,
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
type ActionData = {
|
||||
error?: string;
|
||||
};
|
||||
const badRequest = (data: ActionData) => Response.json(data, { status: 400 });
|
||||
export const action: ActionFunction = async ({ request, params }) => {
|
||||
await verifyUserHasPermission(request, "admin.entities.update");
|
||||
const { t } = await getTranslations(request);
|
||||
const entity = await getEntityBySlug({ tenantId: null, slug: params.entity! });
|
||||
const relationshipScope = { id: params.id ?? "", entityId: entity.id };
|
||||
let existing = await getScopedEntityRelationship(relationshipScope);
|
||||
if (!existing) {
|
||||
return badRequest({ error: t("shared.notFound") });
|
||||
}
|
||||
|
||||
await validateCSRFToken(request);
|
||||
const form = await request.formData();
|
||||
const action = form.get("action")?.toString() ?? "";
|
||||
// const order = Number(form.get("order"));
|
||||
let title = form.get("title")?.toString() ?? null;
|
||||
const type = form.get("relationshipType")?.toString() ?? "one-to-many";
|
||||
const required = Boolean(form.get("required"));
|
||||
const cascade = Boolean(form.get("cascade"));
|
||||
const readOnly = Boolean(form.get("readOnly"));
|
||||
const hiddenIfEmpty = Boolean(form.get("hiddenIfEmpty"));
|
||||
const childEntityViewId = form.get("childEntityViewId")?.toString() ?? null;
|
||||
const parentEntityViewId = form.get("parentEntityViewId")?.toString() ?? null;
|
||||
|
||||
if (title?.trim() === "") {
|
||||
title = null;
|
||||
}
|
||||
if (action === "edit") {
|
||||
existing = await findEntityRelationship({ parentId: existing.parentId, childId: existing.childId, title, notIn: [existing.id] });
|
||||
if (existing) {
|
||||
return badRequest({ error: t("models.relationship.errors.alreadyExists") });
|
||||
}
|
||||
try {
|
||||
await updateScopedEntityRelationship(relationshipScope, {
|
||||
// order,
|
||||
title,
|
||||
type,
|
||||
required,
|
||||
cascade,
|
||||
readOnly,
|
||||
hiddenIfEmpty,
|
||||
childEntityViewId: childEntityViewId?.length ? childEntityViewId : null,
|
||||
parentEntityViewId: parentEntityViewId?.length ? parentEntityViewId : null,
|
||||
});
|
||||
return redirect(adminPath(`entities/${params.entity}/relationships`, { mode: "host-aware" }));
|
||||
} catch (e: any) {
|
||||
return badRequest({ error: e.message });
|
||||
}
|
||||
} else if (action === "delete") {
|
||||
await verifyUserHasPermission(request, "admin.entities.delete");
|
||||
if (existing._count.rows > 0) {
|
||||
return badRequest({ error: t("models.relationship.errors.cannotDeleteWithRows", { id: existing.id }) });
|
||||
}
|
||||
await deleteScopedEntityRelationship(relationshipScope);
|
||||
return redirect(adminPath(`entities/${params.entity}/relationships`, { mode: "host-aware" }));
|
||||
}
|
||||
return badRequest({ error: t("shared.invalidForm") });
|
||||
};
|
||||
|
||||
export default function EditEntityRelationshipRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
return (
|
||||
<div>
|
||||
<EntityRelationshipForm entity={data.entity} entities={data.entities} item={data.item} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { ActionFunction, LoaderFunctionArgs, redirect, useLoaderData } from "react-router";
|
||||
import EntityRelationshipForm from "~/components/entities/relationships/EntityRelationshipForm";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { EntityWithDetails, getAllEntities, getEntityBySlug } from "~/utils/db/entities/entities.db.server";
|
||||
import { createEntityRelationship, getEntityRelationships, findEntityRelationship } from "~/utils/db/entities/entityRelationships.db.server";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
entity: EntityWithDetails;
|
||||
entities: EntityWithDetails[];
|
||||
};
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
const entity = await getEntityBySlug({ tenantId: null, slug: params.entity! });
|
||||
const data: LoaderData = {
|
||||
title: t("models.relationship.metaTitle", { appName: process.env.APP_NAME }),
|
||||
entity,
|
||||
entities: await getAllEntities({ tenantId: null }),
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
type ActionData = {
|
||||
error?: string;
|
||||
};
|
||||
const badRequest = (data: ActionData) => Response.json(data, { status: 400 });
|
||||
export const action: ActionFunction = async ({ request, params }) => {
|
||||
const { t } = await getTranslations(request);
|
||||
|
||||
const entity = await getEntityBySlug({ tenantId: null, slug: params.entity! });
|
||||
if (!entity) {
|
||||
return redirect(adminPath("entities", { mode: "host-aware" }));
|
||||
}
|
||||
|
||||
await validateCSRFToken(request);
|
||||
const form = await request.formData();
|
||||
const action = form.get("action")?.toString() ?? "";
|
||||
const parentId = form.get("parentId")?.toString() ?? entity.id;
|
||||
const childId = form.get("childId")?.toString() ?? entity.id;
|
||||
let title = form.get("title")?.toString().trim() ?? null;
|
||||
const type = form.get("relationshipType")?.toString() ?? "one-to-many";
|
||||
const required = Boolean(form.get("required"));
|
||||
const cascade = Boolean(form.get("cascade"));
|
||||
const readOnly = Boolean(form.get("readOnly"));
|
||||
const hiddenIfEmpty = Boolean(form.get("hiddenIfEmpty"));
|
||||
const childEntityViewId = form.get("childEntityViewId")?.toString() ?? null;
|
||||
const parentEntityViewId = form.get("parentEntityViewId")?.toString() ?? null;
|
||||
|
||||
if (title?.trim() === "") {
|
||||
title = null;
|
||||
}
|
||||
if (action === "create") {
|
||||
const adminEntityIds = new Set((await getAllEntities({ tenantId: null })).map((candidate) => candidate.id));
|
||||
if (!adminEntityIds.has(parentId) || !adminEntityIds.has(childId) || (parentId !== entity.id && childId !== entity.id)) {
|
||||
return badRequest({ error: t("shared.notFound") });
|
||||
}
|
||||
const existing = await findEntityRelationship({ parentId, childId, title });
|
||||
if (existing) {
|
||||
return badRequest({ error: t("models.relationship.errors.alreadyExists") });
|
||||
}
|
||||
const allRelationships = await getEntityRelationships(entity.id);
|
||||
let maxOrder = 0;
|
||||
if (allRelationships.length > 0) {
|
||||
maxOrder = Math.max(...allRelationships.map((f) => f.order ?? 0));
|
||||
}
|
||||
try {
|
||||
await createEntityRelationship({
|
||||
parentId,
|
||||
childId,
|
||||
order: maxOrder + 1,
|
||||
title,
|
||||
type,
|
||||
required,
|
||||
cascade,
|
||||
readOnly,
|
||||
hiddenIfEmpty,
|
||||
childEntityViewId: childEntityViewId?.length ? childEntityViewId : null,
|
||||
parentEntityViewId: parentEntityViewId?.length ? parentEntityViewId : null,
|
||||
});
|
||||
return redirect(adminPath(`entities/${params.entity}/relationships`, { mode: "host-aware" }));
|
||||
} catch (e: any) {
|
||||
return badRequest({ error: e.message });
|
||||
}
|
||||
}
|
||||
return badRequest({ error: t("shared.invalidForm") });
|
||||
};
|
||||
|
||||
export default function NewEntityRelationshipRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
return (
|
||||
<div>
|
||||
<EntityRelationshipForm entity={data.entity} entities={data.entities} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user