Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions dashboard/src/components/ImportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import ListItemText from "@mui/material/ListItemText";
import ArrowBackIosNewIcon from "@mui/icons-material/ArrowBackIosNew";
import { postGlossaryImportFormData } from "@utils/glossaryImportFlow";
import { getApiErrorToastMessage } from "@utils/apiErrorToastMessage";
import {
formatImportFailureForDisplay,
getImportFailureToastMessage,
GlossaryImportFailure
} from "@utils/glossaryImportUtils";

const BootstrapDialog = styled(Dialog)(({ theme }) => ({
"& .MuiDialogContent-root": {
Expand Down Expand Up @@ -74,6 +79,7 @@ export const ImportDialog: React.FC<CustomModalProps> = ({
const [errorDetails, setErrorDetails] = useState(false);
const [importData, setImportData] = useState<any>(null);
const toastId: any = useRef(null);
const isGlossaryImport = title !== "Import Business Metadata";

const onUpload = async () => {
if (fileData) {
Expand Down Expand Up @@ -113,7 +119,7 @@ export const ImportDialog: React.FC<CustomModalProps> = ({
if (importResp.data.failedImportInfoList != undefined) {
toast.dismiss(toastId.current);
toastId.current = toast.error(
importResp.data.failedImportInfoList[0].remarks
getImportFailureToastMessage(isGlossaryImport, importResp.data)
);

setErrorDetails(true);
Expand Down Expand Up @@ -200,17 +206,15 @@ export const ImportDialog: React.FC<CustomModalProps> = ({
>
<List>
{importData.failedImportInfoList.map(
(
value: {
index: number;
remarks: string;
},
index: number
) => (
<ListItem key={value.index} disableGutters disablePadding>
(value: GlossaryImportFailure, index: number) => (
<ListItem
key={`${value.childObjectName || "term"}-${index}`}
disableGutters
disablePadding
>
<ListItemText
className="dropzone-listitem"
primary={`${index + 1}. ${value.remarks}`}
primary={`${index + 1}. ${formatImportFailureForDisplay(isGlossaryImport, value)}`}
/>
</ListItem>
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker:

Test Suites: 1 failed, 2 passed, 3 total
Tests: 1 failed, 48 passed, 49 total

Failure: ImportDialog.test.tsx — expectations not updated for new behavior:

Suggestion: (ImportDialog.test.tsx line ~103–122):
Tests must be updated to match new toast summary and formatted error lines. Also add a Business Metadata failure test to ensure glossary formatting is not applied there.

Expand Down
64 changes: 53 additions & 11 deletions dashboard/src/components/__tests__/ImportDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ jest.mock('../muiComponents', () => ({
}))

const uploadMock = jest.fn()
const glossaryMock = jest.fn()
const glossaryImportMock = jest.fn()

jest.mock('../../api/apiMethods/entitiesApiMethods', () => ({
getBusinessMetadataImport: (...args: any[]) => uploadMock(...args)
}))

jest.mock('../../api/apiMethods/glossaryApiMethod', () => ({
getGlossaryImport: (...args: any[]) => glossaryMock(...args)
jest.mock('@utils/glossaryImportFlow', () => ({
postGlossaryImportFormData: (...args: any[]) => glossaryImportMock(...args)
}))

jest.mock('../../views/SideBar/Import/ImportLayout', () => ({
Expand Down Expand Up @@ -100,10 +100,16 @@ describe('ImportDialog', () => {
})
})

it('shows error details when import returns failed info', async () => {
glossaryMock.mockResolvedValue({
it('shows glossary-specific error details when glossary import returns failed info', async () => {
glossaryImportMock.mockResolvedValue({
data: {
failedImportInfoList: [{ index: 1, remarks: 'Bad row' }]
failedImportInfoList: [
{
childObjectName: 'Patient',
parentObjectName: 'Healthcare Glossary',
remarks: 'Bad row'
}
]
}
})

Expand All @@ -113,12 +119,48 @@ describe('ImportDialog', () => {
fireEvent.click(screen.getByText('Upload'))

await waitFor(() => {
expect(glossaryMock).toHaveBeenCalled()
expect(toastError).toHaveBeenCalledWith('Bad row')
expect(glossaryImportMock).toHaveBeenCalled()
expect(toastError).toHaveBeenCalledWith(
'Glossary import completed with 1 failure(s) out of 1 term(s). See error details.'
)
})

expect(screen.getByText('Error Details')).toBeTruthy()
expect(screen.getByText('1. Bad row')).toBeTruthy()
expect(
screen.getByText('1. Patient@Healthcare Glossary: Bad row')
).toBeTruthy()
})

it('shows business metadata errors without glossary formatting', async () => {
uploadMock.mockResolvedValue({
data: {
failedImportInfoList: [
{
parentObjectName: 'guid-123',
childObjectName: 'attr1',
remarks: 'Invalid attribute'
}
]
}
})

render(
<ImportDialog open={true} onClose={jest.fn()} title="Import Business Metadata" />
)

fireEvent.click(screen.getByText('Select File'))
fireEvent.click(screen.getByText('Upload'))

await waitFor(() => {
expect(uploadMock).toHaveBeenCalled()
expect(toastError).toHaveBeenCalledWith('Invalid attribute')
})

expect(screen.getByText('Error Details')).toBeTruthy()
expect(screen.getByText('1. Invalid attribute')).toBeTruthy()
expect(
screen.queryByText('1. attr1@guid-123: Invalid attribute')
).toBeNull()
})

it('handles upload errors', async () => {
Expand Down Expand Up @@ -147,9 +189,9 @@ describe('ImportDialog', () => {
})

it('returns to upload view when back is clicked', async () => {
glossaryMock.mockResolvedValue({
glossaryImportMock.mockResolvedValue({
data: {
failedImportInfoList: [{ index: 1, remarks: 'Bad row' }]
failedImportInfoList: [{ remarks: 'Bad row' }]
}
})

Expand Down
134 changes: 134 additions & 0 deletions dashboard/src/utils/__tests__/glossaryImportUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
buildGenericImportFailureSummary,
buildGlossaryImportFailureSummary,
formatGenericImportFailure,
formatGlossaryImportFailure,
formatImportFailureForDisplay,
getGlossaryImportTermLabel,
getImportFailureToastMessage
} from "../glossaryImportUtils";

describe("glossaryImportUtils", () => {
it("formats failure with glossary term label when both names exist", () => {
expect(
formatGlossaryImportFailure({
childObjectName: "Patient",
parentObjectName: "Healthcare Glossary",
remarks: "Reference not found"
})
).toBe("Patient@Healthcare Glossary: Reference not found");
});

it("formats failure with childObjectName only (same-glossary shorthand)", () => {
expect(
formatGlossaryImportFailure({
childObjectName: "Patient",
remarks: "Invalid relation"
})
).toBe("Patient: Invalid relation");
expect(getGlossaryImportTermLabel({ childObjectName: "Patient" })).toBe(
"Patient"
);
});

it("formats failure with remarks only (no term names)", () => {
expect(
formatGlossaryImportFailure({
remarks: "Bad row"
})
).toBe("Unknown term: Bad row");
});

it("falls back to Import failed when remarks are empty", () => {
expect(formatGlossaryImportFailure({ childObjectName: "Patient" })).toBe(
"Patient: Import failed"
);
expect(formatGenericImportFailure({})).toBe("Import failed");
});

it("builds import summary with success and failure counts", () => {
expect(
buildGlossaryImportFailureSummary({
successImportInfoList: [{ childObjectName: "A" }],
failedImportInfoList: [
{
childObjectName: "Patient",
parentObjectName: "Healthcare Glossary",
remarks: "Invalid relation"
}
]
})
).toBe(
"Glossary import completed with 1 failure(s) out of 2 term(s). See error details."
);
});

it("builds summary with failures only (no successes)", () => {
expect(
buildGlossaryImportFailureSummary({
failedImportInfoList: [{ remarks: "Bad row" }]
})
).toBe(
"Glossary import completed with 1 failure(s) out of 1 term(s). See error details."
);
});

it("builds summary with empty success and failure lists", () => {
expect(buildGlossaryImportFailureSummary({})).toBe(
"Glossary import completed with 0 failure(s) out of 0 term(s). See error details."
);
});

it("uses generic import helpers for business metadata", () => {
const response = {
successImportInfoList: [{ remarks: "ok" }],
failedImportInfoList: [
{
parentObjectName: "guid-123",
childObjectName: "attr1",
remarks: "Invalid attribute"
}
]
};

expect(getImportFailureToastMessage(false, response)).toBe(
"Invalid attribute"
);
expect(formatImportFailureForDisplay(false, response.failedImportInfoList[0])).toBe(
"Invalid attribute"
);
expect(buildGenericImportFailureSummary(response)).toBe(
"Import completed with 1 failure(s) out of 2 item(s). See error details."
);
});

it("uses generic summary toast for multiple business metadata failures", () => {
expect(
getImportFailureToastMessage(false, {
failedImportInfoList: [
{ remarks: "First error" },
{ remarks: "Second error" }
]
})
).toBe(
"Import completed with 2 failure(s) out of 2 item(s). See error details."
);
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing negative / edge cases:

Only remarks (no names)
Only childObjectName
Empty both lists → "0 failure(s) out of 0 term(s)"
Only failures, no successes
Empty remarks → fallback "Import failed"

suggestion:
line 23:
Please add negative/edge tests: remarks-only, child-only, empty lists, failures-only (no successes).

105 changes: 105 additions & 0 deletions dashboard/src/utils/glossaryImportUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export interface GlossaryImportFailure {
childObjectName?: string;
parentObjectName?: string;
remarks?: string;
rowNumber?: number;
}

export interface GlossaryImportResponse {
failedImportInfoList?: GlossaryImportFailure[];
successImportInfoList?: GlossaryImportFailure[];
}

/** Glossary-only: term label for TermName@GlossaryName when both names exist. */
export const getGlossaryImportTermLabel = (
failure: GlossaryImportFailure
): string => {
if (failure.childObjectName && failure.parentObjectName) {
return `${failure.childObjectName}@${failure.parentObjectName}`;
}
if (failure.childObjectName) {
return failure.childObjectName;
}
return "Unknown term";
};

/** Glossary-only: one formatted failure line (term label + reason). */
export const formatGlossaryImportFailure = (
failure: GlossaryImportFailure
): string => {
return `${getGlossaryImportTermLabel(failure)}: ${failure.remarks || "Import failed"}`;
};

/** Glossary-only: summary toast for bulk glossary term import failures. */
export const buildGlossaryImportFailureSummary = (
response: GlossaryImportResponse
): string => {
const failedCount = response.failedImportInfoList?.length || 0;
const successCount = response.successImportInfoList?.length || 0;
const totalCount = failedCount + successCount;

return `Glossary import completed with ${failedCount} failure(s) out of ${totalCount} term(s). See error details.`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary string is hardcoded glossary-specific ("Glossary import completed...")

  • Consider renaming to make scope explicit, e.g. buildGlossaryImportFailureSummary, and do not reuse for Business Metadata

};

/** Generic import (e.g. Business Metadata): use raw remarks, not glossary @ labels. */
export const formatGenericImportFailure = (
failure: GlossaryImportFailure
): string => {
return failure.remarks || "Import failed";
};

/** Generic import summary when multiple failures exist (non-glossary imports). */
export const buildGenericImportFailureSummary = (
response: GlossaryImportResponse
): string => {
const failedCount = response.failedImportInfoList?.length || 0;
const successCount = response.successImportInfoList?.length || 0;
const totalCount = failedCount + successCount;

return `Import completed with ${failedCount} failure(s) out of ${totalCount} item(s). See error details.`;
};

/** Pick toast message based on import type — glossary vs shared/BM dialog. */
export const getImportFailureToastMessage = (
isGlossaryImport: boolean,
response: GlossaryImportResponse
): string => {
if (isGlossaryImport) {
return buildGlossaryImportFailureSummary(response);
}

const failedList = response.failedImportInfoList;
if (failedList && failedList.length === 1) {
return failedList[0]?.remarks ?? "Import failed";
}

return buildGenericImportFailureSummary(response);
};

/** Pick error-detail line based on import type. */
export const formatImportFailureForDisplay = (
isGlossaryImport: boolean,
failure: GlossaryImportFailure
): string => {
if (isGlossaryImport) {
return formatGlossaryImportFailure(failure);
}
return formatGenericImportFailure(failure);
};
Loading