mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 15:18:11 +00:00
add migration file when the app is starting
This commit is contained in:
@@ -14,6 +14,7 @@ import type {
|
||||
} from "@/types/rule-engine";
|
||||
|
||||
const CARGO_TYPE_PARENT_PAGE_SIZE = 500;
|
||||
const CONTAINER_TYPE_OPTIONS_PAGE_SIZE = 500;
|
||||
|
||||
export const useRuleEngineList = (
|
||||
resource: RuleEngineResourceSlug,
|
||||
@@ -52,6 +53,36 @@ export const useCargoTypeParentOptions = (excludeId?: string, enabled = true) =>
|
||||
},
|
||||
});
|
||||
|
||||
export const useContainerTypeOptions = (enabled = true) =>
|
||||
useQuery({
|
||||
queryKey: [
|
||||
...QUERY_KEYS.RULE_ENGINE.list("container-types"),
|
||||
"select-options",
|
||||
],
|
||||
queryFn: () =>
|
||||
ruleEngineService.list<RuleEngineRecord>("container-types", {
|
||||
page: 1,
|
||||
pageSize: CONTAINER_TYPE_OPTIONS_PAGE_SIZE,
|
||||
}),
|
||||
enabled,
|
||||
select: (result) => {
|
||||
const noneOption = { label: "None", value: RULE_ENGINE_SELECT_NONE };
|
||||
const options = (result.data ?? []).map((row) => {
|
||||
const label = String(row.label ?? "").trim();
|
||||
const code = String(row.code ?? "").trim();
|
||||
const size = row.sizeFt ? `${String(row.sizeFt)}ft` : "";
|
||||
const parts = [label || code || String(row.id), size].filter(Boolean);
|
||||
|
||||
return {
|
||||
label: parts.join(" - "),
|
||||
value: String(row.id),
|
||||
};
|
||||
});
|
||||
|
||||
return [noneOption, ...options];
|
||||
},
|
||||
});
|
||||
|
||||
export const useApprovalChain = (enabled: boolean) =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEYS.RULE_ENGINE.chain,
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import {
|
||||
useApprovalChain,
|
||||
useCargoTypeParentOptions,
|
||||
useContainerTypeOptions,
|
||||
useRateWorkflow,
|
||||
useRuleEngineList,
|
||||
useRuleEngineMutations,
|
||||
@@ -104,16 +105,31 @@ const RuleEngineResourcePage = () => {
|
||||
const editingId = editing?.id ? String(editing.id) : undefined;
|
||||
const { data: cargoParentOptions, isLoading: cargoParentOptionsLoading } =
|
||||
useCargoTypeParentOptions(editingId, config?.slug === "cargo-types");
|
||||
const { data: containerTypeOptions, isLoading: containerTypeOptionsLoading } =
|
||||
useContainerTypeOptions(config?.slug === "rates");
|
||||
|
||||
const formFields = useMemo(() => {
|
||||
if (!config || config.slug !== "cargo-types") return config?.formFields ?? [];
|
||||
const fallback = [{ label: "None", value: RULE_ENGINE_SELECT_NONE }];
|
||||
if (!config) return [];
|
||||
return config.formFields.map((field) =>
|
||||
field.name === "parentGroupId"
|
||||
? { ...field, options: cargoParentOptions ?? fallback }
|
||||
: field,
|
||||
config.slug === "cargo-types" && field.name === "parentGroupId"
|
||||
? {
|
||||
...field,
|
||||
options:
|
||||
cargoParentOptions ?? [
|
||||
{ label: "None", value: RULE_ENGINE_SELECT_NONE },
|
||||
],
|
||||
}
|
||||
: config.slug === "rates" && field.name === "containerTypeId"
|
||||
? {
|
||||
...field,
|
||||
options:
|
||||
containerTypeOptions ?? [
|
||||
{ label: "None", value: RULE_ENGINE_SELECT_NONE },
|
||||
],
|
||||
}
|
||||
: field,
|
||||
);
|
||||
}, [config, cargoParentOptions]);
|
||||
}, [config, cargoParentOptions, containerTypeOptions]);
|
||||
|
||||
const rows = data?.data ?? [];
|
||||
const meta = data?.meta;
|
||||
@@ -320,7 +336,8 @@ const RuleEngineResourcePage = () => {
|
||||
initialRecord={editing}
|
||||
isSubmitting={create.isPending || update.isPending}
|
||||
selectOptionsLoading={
|
||||
config.slug === "cargo-types" && cargoParentOptionsLoading
|
||||
(config.slug === "cargo-types" && cargoParentOptionsLoading) ||
|
||||
(config.slug === "rates" && containerTypeOptionsLoading)
|
||||
}
|
||||
onSubmit={handleFormSubmit}
|
||||
/>
|
||||
|
||||
@@ -333,7 +333,13 @@ export const RULE_ENGINE_RESOURCES: RuleEngineResourceConfig[] = [
|
||||
],
|
||||
formFields: [
|
||||
{ name: "rateType", label: "Rate type", type: "select", required: true, options: RATE_TYPES },
|
||||
{ name: "containerTypeId", label: "Container type ID", type: "text", placeholder: "Optional UUID" },
|
||||
{
|
||||
name: "containerTypeId",
|
||||
label: "Container type",
|
||||
type: "select",
|
||||
optional: true,
|
||||
placeholder: "Select container type (optional)",
|
||||
},
|
||||
{
|
||||
name: "tradeDirection",
|
||||
label: "Trade direction",
|
||||
|
||||
Reference in New Issue
Block a user