Skip to content

Commit

Permalink
[MDS-5049]fix tsf mapping null error (#2839)
Browse files Browse the repository at this point in the history
fix tsf mapping null error
  • Loading branch information
asinn134 authored Dec 8, 2023
1 parent c33a8ca commit e761c66
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 117 deletions.
1 change: 1 addition & 0 deletions services/common/src/constants/strings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const NOTICE_OF_DEPARTURE_STATUS_VALUES = {
determined_non_substantial: "determined_non_substantial",
determined_substantial: "determined_substantial",
withdrawn: "withdrawn",
self_authorized: "self_authorized",
};

export const NOD_TYPE_FIELD_VALUE = {
Expand Down
48 changes: 22 additions & 26 deletions services/core-web/common/components/tailings/AssociatedDams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,28 @@ const AssociatedDams: FC<AssociatedDamsProps> = (props) => {
history.push(url);
};

const renderDamActions = () => {
let actions = [
{
key: "view",
label: "View Dam",
icon: <EyeOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, false);
},
},
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, true);
},
const actions = [
{
key: "view",
label: "View Dam",
icon: <EyeOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, false);
},
];

if (!isEditMode) {
actions = actions.filter((a) => a.key !== "edit");
}

return renderActionsColumn(actions);
};
},
...(isEditMode
? [
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, true);
},
},
]
: []),
];

const columns: ColumnsType<IDam> = [
{
Expand Down Expand Up @@ -118,7 +114,7 @@ const AssociatedDams: FC<AssociatedDamsProps> = (props) => {
dataIndex: "max_pond_elevation",
key: "max_pond_elevation",
},
...[renderDamActions()],
renderActionsColumn({ actions }),
];

const mostRecentUpdatedDate = moment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,25 @@ const MineTailingsTable: FC<RouteComponentProps & MineTailingsTableProps> = (pro
});
},
},
{
key: "edit",
label: "Edit TSF",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
props.history.push({
pathname: MINE_TAILINGS_DETAILS.dynamicRoute(
record.mine_tailings_storage_facility_guid,
record.mine_guid,
"basic-information",
true
),
});
},
},
...(canEditTSF
? [
{
key: "edit",
label: "Edit TSF",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
props.history.push({
pathname: MINE_TAILINGS_DETAILS.dynamicRoute(
record.mine_tailings_storage_facility_guid,
record.mine_guid,
"basic-information",
true
),
});
},
},
]
: []),
];

const damActions = [
Expand All @@ -152,26 +156,21 @@ const MineTailingsTable: FC<RouteComponentProps & MineTailingsTableProps> = (pro
handleEditDam(event, record, false, false);
},
},
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleEditDam(event, record, true, true);
},
},
...(canEditTSF
? [
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleEditDam(event, record, true, true);
},
},
]
: []),
];

const renderActions = (actions) => {
let filteredActions = actions;
if (!canEditTSF) {
filteredActions = actions.filter((a) => a.key !== "edit");
}

return renderActionsColumn(filteredActions);
};

const columns: ColumnsType<ITailingsStorageFacility> = [
const columns = [
{
title: "Name",
dataIndex: "mine_tailings_storage_facility_name",
Expand Down Expand Up @@ -227,7 +226,7 @@ const MineTailingsTable: FC<RouteComponentProps & MineTailingsTableProps> = (pro
dataIndex: "longitude",
render: (text) => <div title="Longitude">{text || EMPTY_FIELD}</div>,
},
...(tsfV2Enabled ? [renderActions(newTSFActions)] : [renderOldTSFActions()]),
...(tsfV2Enabled ? [renderActionsColumn({ actions: newTSFActions })] : [renderOldTSFActions()]),
];

const damColumns = [
Expand All @@ -238,14 +237,14 @@ const MineTailingsTable: FC<RouteComponentProps & MineTailingsTableProps> = (pro
"Consequence Classification",
CONSEQUENCE_CLASSIFICATION_CODE_HASH
),
...[renderActions(damActions)],
renderActionsColumn({ actions: damActions }),
];

return (
<CoreTable
condition={props.isLoaded}
dataSource={transformRowData(props.tailings)}
columns={columns}
columns={columns as ColumnsType<ITailingsStorageFacility>}
rowKey="mine_tailings_storage_facility_guid"
classPrefix="tailings"
expandProps={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,28 @@ const AssociatedDams: FC<AssociatedDamsProps> = (props) => {
history.push(url);
};

const renderDamActions = () => {
let actions = [
{
key: "view",
label: "View Dam",
icon: <EyeOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, false);
},
},
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, true);
},
const actions = [
{
key: "view",
label: "View Dam",
icon: <EyeOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, false);
},
];

if (!isEditMode) {
actions = actions.filter((a) => a.key !== "edit");
}

return renderActionsColumn(actions);
};
},
...(isEditMode
? [
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleNavigateToEdit(event, record, true);
},
},
]
: []),
];

const columns: ColumnsType<IDam> = [
{
Expand Down Expand Up @@ -118,7 +114,7 @@ const AssociatedDams: FC<AssociatedDamsProps> = (props) => {
dataIndex: "max_pond_elevation",
key: "max_pond_elevation",
},
...[renderDamActions()],
renderActionsColumn({ actions }),
];

const mostRecentUpdatedDate = moment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const TailingsTable = (props) => {
};
};

let newTSFActions = [
const newTSFActions = [
{
key: "view",
label: "View TSF",
Expand All @@ -105,17 +105,21 @@ export const TailingsTable = (props) => {
editTailings(event, record, false);
},
},
{
key: "edit",
label: "Edit TSF",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
editTailings(event, record, true);
},
},
...(canEditTSF
? [
{
key: "edit",
label: "Edit TSF",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
editTailings(event, record, true);
},
},
]
: []),
];

let damActions = [
const damActions = [
{
key: "view",
label: "View Dam",
Expand All @@ -124,25 +128,20 @@ export const TailingsTable = (props) => {
handleEditDam(event, record, false, false);
},
},
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleEditDam(event, record, true, true);
},
},
...(canEditTSF
? [
{
key: "edit",
label: "Edit Dam",
icon: <EditOutlined />,
clickFunction: (_event, record) => {
handleEditDam(event, record, true, true);
},
},
]
: []),
];

const renderActions = (actions) => {
let filteredActions = actions;
if (!canEditTSF) {
filteredActions = actions.filter((a) => a.key !== "edit");
}

return renderActionsColumn(filteredActions);
};

// const handleRowExpand = (record) => {
// const key = record.mine_tailings_storage_facility_guid;
// const expandedRowKeys = expandedRows.includes(key)
Expand Down Expand Up @@ -224,7 +223,7 @@ export const TailingsTable = (props) => {
render: (text) => <div title="Notes">{text || EMPTY_FIELD}</div>,
sorter: (a, b) => (a.notes > b.notes ? -1 : 1),
},
...(tsfV2Enabled ? [renderActions(newTSFActions)] : [renderOldTSFActions()]),
...(tsfV2Enabled ? [renderActionsColumn({ actions: newTSFActions })] : [renderOldTSFActions()]),
];

const expandedColumns = [
Expand All @@ -245,7 +244,7 @@ export const TailingsTable = (props) => {
</Typography.Text>
),
},
...[renderActions(damActions)],
renderActionsColumn({ actions: damActions }),
];

return (
Expand Down

0 comments on commit e761c66

Please sign in to comment.