-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show added and removed communities in history
- Loading branch information
Showing
13 changed files
with
248 additions
and
71 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
app/components/Analyst/CBC/History/CbcHistoryCommunitiesTable.tsx
This file contains 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,80 @@ | ||
import styled from 'styled-components'; | ||
|
||
interface Props { | ||
heading: string; | ||
communities: any[]; | ||
} | ||
|
||
const StyledCommunitiesContainer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
const StyledLeftContainer = styled.div` | ||
padding-right: 2%; | ||
width: 250px; | ||
`; | ||
|
||
const StyledTable = styled.table` | ||
th { | ||
border: none; | ||
} | ||
tbody > tr { | ||
border-bottom: thin dashed; | ||
border-color: ${(props) => props.theme.color.borderGrey}; | ||
td { | ||
width: 200px; | ||
max-width: 200px; | ||
border: none; | ||
} | ||
} | ||
`; | ||
|
||
const StyledIdCell = styled.td` | ||
width: 100px !important; | ||
max-width: 100px; | ||
`; | ||
|
||
const CbcHistoryCommunitiesTable: React.FC<Props> = ({ | ||
heading, | ||
communities, | ||
}) => { | ||
return ( | ||
<StyledCommunitiesContainer | ||
style={{ display: 'flex', alignItems: 'center' }} | ||
> | ||
<StyledLeftContainer>{heading}</StyledLeftContainer> | ||
<div> | ||
<StyledTable> | ||
<thead> | ||
<tr> | ||
<th>Economic Region</th> | ||
<th>Regional District</th> | ||
<th>Geographic Name</th> | ||
<th>Type</th> | ||
<th>ID</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{communities?.map((community, index) => ( | ||
<tr | ||
// eslint-disable-next-line react/no-array-index-key | ||
key={`${community.bc_geographic_name}-${index}`} | ||
> | ||
<td>{community.economic_region}</td> | ||
<td>{community.regional_district}</td> | ||
<td>{community.bc_geographic_name}</td> | ||
<td>{community.geographic_type}</td> | ||
<StyledIdCell> | ||
{community.communities_source_data_id} | ||
</StyledIdCell> | ||
</tr> | ||
))} | ||
</tbody> | ||
</StyledTable> | ||
</div> | ||
</StyledCommunitiesContainer> | ||
); | ||
}; | ||
|
||
export default CbcHistoryCommunitiesTable; |
This file contains 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 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 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 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 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 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 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,27 @@ | ||
-- Deploy ccbc:computed_columns/cbc_history to pg | ||
|
||
begin; | ||
|
||
create or replace function ccbc_public.cbc_history(_cbc_project ccbc_public.cbc) returns setof ccbc_public.record_version as $$ | ||
|
||
select id, record_id, old_record_id, op, ts, table_oid, table_schema, table_name, | ||
-- if the operation is an update, use the updated_by field in the record | ||
-- because created_by is listed as the person who initially created the record | ||
case when op = 'UPDATE'::audit.operation then (record->>'updated_by')::int else created_by end as created_by, | ||
created_at, record, old_record | ||
from ccbc_public.record_version | ||
where table_name = 'cbc_data' and record->>'cbc_id' = _cbc_project.id::text | ||
-- order by record->>'updated_at' since created_at is filled with the initial record creation date | ||
-- could be replaced by id desc, should give the same result | ||
order by record->>'updated_at' desc; | ||
|
||
|
||
$$ language sql stable; | ||
|
||
grant execute on function ccbc_public.cbc_history to ccbc_admin; | ||
grant execute on function ccbc_public.cbc_history to cbc_admin; | ||
grant execute on function ccbc_public.cbc_history to ccbc_analyst; | ||
|
||
comment on function ccbc_public.cbc_history is 'Get the history of a cbc record'; | ||
|
||
commit; |
7 changes: 7 additions & 0 deletions
7
db/deploy/tables/cbc_project_communities_001_enable_tracking.sql
This file contains 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,7 @@ | ||
-- Deploy ccbc:tables/cbc_project_communities_001_enable_tracking to pg | ||
|
||
BEGIN; | ||
|
||
select audit.enable_tracking('ccbc_public.cbc_project_communities'::regclass); | ||
|
||
COMMIT; |
Oops, something went wrong.