-
Notifications
You must be signed in to change notification settings - Fork 38
[MDS-5758] Dam History #3463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[MDS-5758] Dam History #3463
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f257bad
set up versioning on BE, put in a button that doesn't do anything yet
taraepp 32c973a
add dam diff modal, tweak some of the existing code
taraepp b066f4a
clean up models on BE a bit
taraepp 577ac19
upstream changes
taraepp 7630d51
add tests, fix things found in tests
taraepp 4689ef9
text changes
taraepp 540067f
quick hookification
taraepp 87e7a33
make red lines go away
taraepp e683bed
convert a file to tsx
taraepp 589efbc
remove obsolete test
taraepp fbafa31
fix BE test issues
taraepp c48c543
upstream changes
taraepp 064c43e
it was the enums
taraepp 0749a6c
little tidy up
taraepp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
migrations/sql/V2025.03.10.18.46__add_dam_version_history_table.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- This file was generated by the generate_history_table_ddl command | ||
-- The file contains the corresponding history table definition for the {table} table | ||
CREATE TABLE dam_version ( | ||
create_user VARCHAR(60), | ||
create_timestamp TIMESTAMP WITHOUT TIME ZONE, | ||
update_user VARCHAR(60), | ||
update_timestamp TIMESTAMP WITHOUT TIME ZONE, | ||
deleted_ind BOOLEAN, | ||
dam_guid UUID NOT NULL, | ||
mine_tailings_storage_facility_guid UUID, | ||
dam_type dam_type, | ||
dam_name VARCHAR(200), | ||
latitude NUMERIC(9, 7), | ||
longitude NUMERIC(11, 7), | ||
operating_status operating_status, | ||
consequence_classification consequence_classification, | ||
permitted_dam_crest_elevation NUMERIC(10, 2), | ||
current_dam_height NUMERIC(10, 2), | ||
current_elevation NUMERIC(10, 2), | ||
max_pond_elevation NUMERIC(10, 2), | ||
min_freeboard_required NUMERIC(10, 2), | ||
transaction_id BIGINT NOT NULL, | ||
end_transaction_id BIGINT, | ||
operation_type SMALLINT NOT NULL, | ||
PRIMARY KEY (dam_guid, transaction_id) | ||
); | ||
CREATE INDEX ix_dam_version_operation_type ON dam_version (operation_type); | ||
CREATE INDEX ix_dam_version_transaction_id ON dam_version (transaction_id); | ||
CREATE INDEX ix_dam_version_end_transaction_id ON dam_version (end_transaction_id); |
6 changes: 6 additions & 0 deletions
6
migrations/sql/V2025.03.10.18.47__add_dam_version_history_table_backfill.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- This file was generated by the generate_history_table_ddl command | ||
-- The file contains the data migration to backfill history records for the {table} table | ||
with transaction AS (insert into transaction(id) values(DEFAULT) RETURNING id) | ||
insert into dam_version (transaction_id, operation_type, end_transaction_id, "create_user", "create_timestamp", "update_user", "update_timestamp", "deleted_ind", "dam_guid", "mine_tailings_storage_facility_guid", "dam_type", "dam_name", "latitude", "longitude", "operating_status", "consequence_classification", "permitted_dam_crest_elevation", "current_dam_height", "current_elevation", "max_pond_elevation", "min_freeboard_required") | ||
select t.id, '0', null, "create_user", "create_timestamp", "update_user", "update_timestamp", "deleted_ind", "dam_guid", "mine_tailings_storage_facility_guid", "dam_type", "dam_name", "latitude", "longitude", "operating_status", "consequence_classification", "permitted_dam_crest_elevation", "current_dam_height", "current_elevation", "max_pond_elevation", "min_freeboard_required" | ||
from dam,transaction t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { FC } from "react"; | ||
import { DiffColumnValueMapper, IDiffColumn, IDiffEntry } from "./DiffColumn.interface"; | ||
import CoreTable from "../common/CoreTable"; | ||
import DiffColumn from "./DiffColumn"; | ||
import { renderDateColumn } from "../common/CoreTableCommonColumns"; | ||
import { ColumnsType } from "antd/lib/table"; | ||
|
||
interface DiffTableProps { | ||
history: IDiffEntry[]; | ||
loading?: boolean; | ||
valueMapper?: DiffColumnValueMapper; | ||
columns?: ColumnsType; | ||
} | ||
|
||
const DiffTable: FC<DiffTableProps> = ({ history, valueMapper, columns = [], loading = false }) => { | ||
|
||
const commonColumns = [ | ||
{ | ||
title: "Updated by", | ||
dataIndex: "updated_by" | ||
}, | ||
{ ...renderDateColumn("updated_at", "Date", true), defaultSortOrder: "descend" }, | ||
{ | ||
title: "Changes", | ||
dataIndex: "changeset", | ||
render: (differences: IDiffColumn[]) => <DiffColumn differences={differences} valueMapper={valueMapper} /> | ||
} | ||
]; | ||
|
||
return <CoreTable | ||
className="diff-table" | ||
rowClassName="diff-table-row" | ||
rowKey="updated_at" | ||
columns={[...columns, ...commonColumns]} | ||
dataSource={history ?? []} | ||
loading={loading} | ||
/> | ||
}; | ||
|
||
export default DiffTable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
services/common/src/components/tailings/dam/DamDiffModal.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper"; | ||
import { DAM_WITH_HISTORY } from "@mds/common/tests/mocks/dataMocks"; | ||
import { damReducerType } from "@mds/common/redux/slices/damSlice"; | ||
import DamDiffModal from "./DamDiffModal"; | ||
|
||
|
||
const initialState = { | ||
[damReducerType]: { | ||
dams: { | ||
[DAM_WITH_HISTORY.dam_guid]: DAM_WITH_HISTORY | ||
} | ||
} | ||
}; | ||
|
||
describe("Dam History Modal", () => { | ||
it("renders properly", () => { | ||
const { container } = render( | ||
<ReduxWrapper initialState={initialState}> | ||
<DamDiffModal damGuid={DAM_WITH_HISTORY.dam_guid} /> | ||
</ReduxWrapper> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
services/common/src/components/tailings/dam/DamDiffModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { FC, useEffect, useState } from "react"; | ||
import { useAppDispatch, useAppSelector } from "@mds/common/redux/rootState"; | ||
import { fetchDamHistory, getDamByGuid } from "@mds/common/redux/slices/damSlice"; | ||
import DiffTable from "../../history/DiffTable"; | ||
import { CONSEQUENCE_CLASSIFICATION_CODE_HASH, DAM_OPERATING_STATUS_HASH, DAM_TYPES_HASH } from "@mds/common/constants/strings"; | ||
import { formatDateTimeUserTz } from "@mds/common/redux/utils/helpers"; | ||
import { Typography } from "antd"; | ||
|
||
interface DamDiffModalProps { | ||
damGuid: string; | ||
} | ||
|
||
const DamDiffModal: FC<DamDiffModalProps> = ({ damGuid }) => { | ||
const dispatch = useAppDispatch(); | ||
const dam = useAppSelector(getDamByGuid(damGuid)); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const fetchData = () => { | ||
setLoading(true); | ||
dispatch(fetchDamHistory(damGuid)).then(() => { | ||
setLoading(false); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!dam?.history && !loading) { | ||
fetchData(); | ||
} | ||
}, [dam?.history]); | ||
|
||
const dateTransform = { transform: (dateString: string) => formatDateTimeUserTz(dateString) || null }; | ||
|
||
const valueMapper = { | ||
dam_type: { hash: DAM_TYPES_HASH }, | ||
operating_status: { hash: DAM_OPERATING_STATUS_HASH }, | ||
consequence_classification: { hash: CONSEQUENCE_CLASSIFICATION_CODE_HASH }, | ||
create_timestamp: dateTransform, | ||
update_timestamp: dateTransform, | ||
}; | ||
|
||
return <> | ||
<Typography.Title level={3}>View History</Typography.Title> | ||
<Typography.Paragraph> | ||
You are viewing the past history of <b>{dam.dam_name}</b> | ||
</Typography.Paragraph> | ||
<DiffTable history={dam?.history} loading={loading} valueMapper={valueMapper} /> | ||
</> | ||
}; | ||
|
||
export default DamDiffModal; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Autobots, TRANFORM! 😆