fix(intake): 保存实时供应商目录映射

This commit is contained in:
WuYongJie 2026-09-17 17:25:52 +08:00
parent ca6e22ac66
commit be9f844c5a
7 changed files with 76 additions and 1 deletions

View File

@ -0,0 +1,63 @@
import {
createEmptyNonIntegratedOpeningReference,
createEmptyNonIntegratedPatentApplication,
createEmptyNonIntegratedProjectReview,
} from "./core/nonIntegratedStorage";
import { createFactoryRow } from "./NonIntegratedDetailClient.testFixtures";
import { buildProductPayload } from "./nonIntegratedProductPayload";
import { createFormValuesFromProduct } from "./workspaces/basic-info/productFormValueHelpers";
import { EMPTY_DOCUMENT_WORKSPACE_NOTES } from "./workspaces/documents/documentWorkspaceHelpers";
describe("buildProductPayload", () => {
it("keeps a factory supplier that exists only in the live supplier directory", () => {
const payload = buildProductPayload(
"product-1",
createFormValuesFromProduct(null),
[],
{},
{},
[],
{ rows: [] },
[
createFactoryRow({
supplierName: "木际",
supplierCode: "",
}),
],
[],
[],
[],
[],
[],
[],
[],
EMPTY_DOCUMENT_WORKSPACE_NOTES,
{},
{},
{},
{},
createEmptyNonIntegratedOpeningReference(),
createEmptyNonIntegratedPatentApplication(),
createEmptyNonIntegratedProjectReview(),
"draft",
1,
{},
{},
{},
undefined,
undefined,
undefined,
undefined,
undefined,
"product",
"",
undefined,
new Map([["木际", "N3580"]]),
);
expect(payload.factoryRows[0]).toMatchObject({
supplierName: "木际",
supplierCode: "N3580",
});
});
});

View File

@ -85,6 +85,7 @@ export function buildProductPayload(
productDevelopmentKind: ProductDevelopmentKind = "product",
productTag = "",
metadata?: Record<string, unknown>,
supplierCodeByName?: ReadonlyMap<string, string>,
): NonIntegratedProductRecord {
const now = new Date().toISOString();
const derivedSkuItems = skuItems.map((item, index) => {
@ -116,7 +117,7 @@ export function buildProductPayload(
factoryRows: factoryRowsForPayload,
} = normalizeNonIntegratedPackageSetCounts(
derivedSkuItems,
normalizeFactoryRowsForPayload(factoryRows),
normalizeFactoryRowsForPayload(factoryRows, supplierCodeByName),
);
const normalizedStyleDetails = Object.entries(styleDetails)
.filter(([styleKey]) => Boolean(styleKey))

View File

@ -103,6 +103,7 @@ export type UseNonIntegratedSaveControllerParams = {
SetStateAction<NonIntegratedProductRecord["metadata"]>
>;
};
supplierCodeByName: ReadonlyMap<string, string>;
workflow: ProductWorkflowState;
};

View File

@ -123,6 +123,7 @@ export function useNonIntegratedDetailDomainControllers(
projectState,
refreshSpuEstimate: spuEstimate.refreshSpuEstimate,
skuState,
supplierCodeByName: directoryOptions.supplierCodeByName,
workflowRows: workflow.workflowRows,
workflowState,
});

View File

@ -23,6 +23,7 @@ describe("useNonIntegratedPersistenceCoordinator", () => {
const setSaveMessage = jest.fn();
const setSaveMessageType = jest.fn();
const onProductSavedRef = { current: jest.fn() };
const supplierCodeByName = new Map([["木际", "N3580"]]);
jest.mocked(useNonIntegratedAssetStorageNormalizer).mockReturnValue({
normalizeProductAssetsForStorage,
@ -115,6 +116,7 @@ describe("useNonIntegratedPersistenceCoordinator", () => {
skuBatchFlowNos: {},
skuItems: [],
},
supplierCodeByName,
workflowRows: {
displayedProductFactoryRows: productFactoryRows,
productFactoryRows,
@ -149,6 +151,7 @@ describe("useNonIntegratedPersistenceCoordinator", () => {
normalizeProductAssetsForStorage,
onProductSavedRef,
}),
supplierCodeByName,
workflow: expect.objectContaining({ productFactoryRows }),
}),
);

View File

@ -46,6 +46,7 @@ type PersistenceCoordinatorProps = Pick<
typeof useSpuEstimateRefreshToken
>["refreshSpuEstimate"];
skuState: ReturnType<typeof useNonIntegratedSkuState>;
supplierCodeByName: ReadonlyMap<string, string>;
workflowRows: WorkflowDerivedState["workflowRows"];
workflowState: ReturnType<typeof useNonIntegratedWorkflowState>;
};
@ -66,6 +67,7 @@ export function useNonIntegratedPersistenceCoordinator({
projectState,
refreshSpuEstimate,
skuState,
supplierCodeByName,
workflowRows,
workflowState,
}: PersistenceCoordinatorProps) {
@ -143,6 +145,7 @@ export function useNonIntegratedPersistenceCoordinator({
setOpeningReferenceAndRef: projectState.setOpeningReferenceAndRef,
setProductMetadata: workflowState.setProductMetadata,
},
supplierCodeByName,
workflow: {
displayedProductFactoryRows: workflowRows.displayedProductFactoryRows,
planningLayoutRows: workflowState.planningLayoutRows,

View File

@ -64,6 +64,7 @@ export function useNonIntegratedSaveController({
persistence,
state,
stateActions,
supplierCodeByName,
workflow,
}: UseNonIntegratedSaveControllerParams) {
const lastPersistErrorMessageRef = useRef("");
@ -219,6 +220,7 @@ export function useNonIntegratedSaveController({
identity.effectiveProductDevelopmentKind,
identity.productTag,
nextProductMetadata,
supplierCodeByName,
),
);
@ -346,6 +348,7 @@ export function useNonIntegratedSaveController({
documents.skuBatchWorkflowConfirmations,
state.skuItems,
state.styleDetails,
supplierCodeByName,
documents.uploadFiles,
persistence.compactStoredProducts,
],