Skip to content

Commit

Permalink
feat: assessment hh included in count
Browse files Browse the repository at this point in the history
  • Loading branch information
AntBush committed May 16, 2024
1 parent 54db93b commit 3acfad5
Show file tree
Hide file tree
Showing 11 changed files with 537 additions and 3 deletions.
34 changes: 34 additions & 0 deletions app/components/Analyst/History/HistoryContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { diff } from 'json-diff';
import conditionalApprovalSchema from 'formSchema/uiSchema/history/conditionalApproval';
import screeningSchema from 'formSchema/uiSchema/history/screening';
import gis from 'formSchema/uiSchema/history/gis';
import gisAssessmentHhSchema from 'formSchema/uiSchema/history/gisAssessmentHh';
import StatusPill from '../../StatusPill';
import HistoryDetails from './HistoryDetails';
import HistoryAttachment from './HistoryAttachment';
Expand Down Expand Up @@ -512,6 +513,39 @@ const HistoryContent = ({ historyItem, prevHistoryItem }) => {
);
}

if (tableName === 'application_gis_assessment_hh') {
return (
<div>
<StyledContent data-testid="history-content-form-data">
<span>
{displayName}
{' updated the '}
<b>GIS Analysis </b>
</span>
on {createdAtFormatted}
</StyledContent>
{showHistoryDetails && (
<HistoryDetails
json={record}
prevJson={prevHistoryItem?.record || {}}
excludedKeys={[
'id',
'updated_at',
'created_at',
'created_by',
'updated_by',
'archived_at',
'archived_by',
]}
diffSchema={gisAssessmentHhSchema}
overrideParent="gis"
/>
)}
{reasonForChange && <ChangeReason reason={reasonForChange} />}
</div>
);
}

if (tableName === 'project_information_data') {
// Generate a diff for all the file arrays
// will return undefined if no changes
Expand Down
14 changes: 14 additions & 0 deletions app/formSchema/uiSchema/history/gisAssessmentHh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const gisAssessmentHh = {
gis: {
properties: {
eligible: {
title: 'Eligible',
},
eligible_indigenous: {
title: 'Eligible Indigenous',
},
},
},
};

export default gisAssessmentHh;
9 changes: 9 additions & 0 deletions db/deploy/computed_columns/application_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ returns setof ccbc_public.history_item as $$
where v.op='INSERT' and v.table_name='application_gis_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'history_operation' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by = u.id
where (v.op='INSERT' or v.op='UPDATE') and v.table_name='application_gis_assessment_hh'
and v.record->>'archived_by' is null and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'history_operation' as item,
Expand Down
224 changes: 224 additions & 0 deletions db/deploy/computed_columns/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
-- Deploy ccbc:computed_columns/application_history to pg

begin;

create or replace function ccbc_public.application_history(application ccbc_public.application)
returns setof ccbc_public.history_item as $$

select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record, 'application' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application' and v.record->>'id'=application.id::varchar(10)
union all

select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record, v.record->>'status' as item,
COALESCE(u.family_name,'Automated process'), COALESCE(u.given_name,''), COALESCE(u.session_sub,'robot@idir'), COALESCE(u.external_analyst,null)
from ccbc_public.record_version as v
left join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_status'
and v.record->>'application_id'=application.id::varchar(10)
union all

select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record, v.record->>'file_name' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='attachment'
and v.record->>'application_id'=application.id::varchar(10) and v.record->>'archived_by' is null

union all

select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record, v.record->>'assessment_data_type' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='assessment_data'
and v.record->>'application_id'=application.id::varchar(10) and v.record->>'archived_by' is null

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record-> 'json_data' ->>'rfiType' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='rfi_data' and v.record->>'archived_by' is null
and v.record->>'id' in (select rd.id::varchar(10) from ccbc_public.rfi_data as rd
inner join ccbc_public.application_rfi_data arf
on arf.rfi_data_id = rd.id
where arf.application_id = application.id)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record-> 'json_data' ->>'rfiType' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on (v.record->>'updated_by')::integer=u.id
where v.op='UPDATE' and v.table_name='rfi_data' and v.record->>'archived_by' is null
and v.record->>'id' in (select rd.id::varchar(10) from ccbc_public.rfi_data as rd
inner join ccbc_public.application_rfi_data arf
on arf.rfi_data_id = rd.id
where arf.application_id = application.id)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
concat_ws(' ', a.given_name, a.family_name) as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
left join ccbc_public.analyst a on v.record->>'analyst_id' = a.id::varchar(10)
where v.op='INSERT' and v.table_name='application_analyst_lead' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'package' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_package' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'conditional_approval_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='conditional_approval_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record-> 'json_data' ->>'reason_for_change' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='form_data' and v.record->>'archived_by' is null
and v.record->>'id' in (
select fd.id::varchar(10) from ccbc_public.form_data as fd,
ccbc_public.form as f, ccbc_public.application_form_data as af
where
fd.form_schema_id = f.id and
f.form_type = 'intake' and
af.application_id = application.id and
fd.id = af.form_data_id )

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'conditional_approval_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_gis_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'history_operation' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_announcement' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'history_operation' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='project_information_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all

select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'history_operation' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where (v.op='INSERT' or v.op='UPDATE') and v.table_name='change_request_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'history_operation' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.table_name='application_announcement' and v.record->>'history_operation'='deleted'
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'application_community_progress_report_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_community_progress_report_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)


union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'application_community_progress_report_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on (v.record->>'updated_by')::integer=u.id
where v.op='UPDATE' and v.table_name='application_community_progress_report_data' and v.record->>'history_operation'='deleted'
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'application_claims_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on (v.record->>'updated_by')::integer=u.id
where v.op='UPDATE' and v.table_name='application_claims_data' and v.record->>'history_operation'='deleted'
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'application_community_claims_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_claims_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'application_milestone_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_milestone_data' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'application_milestone_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on (v.record->>'updated_by')::integer=u.id
where v.op='UPDATE' and v.table_name='application_milestone_data' and v.record->>'history_operation'='deleted'
and v.record->>'application_id'=application.id::varchar(10)

union all
select application.id, v.created_at, v.op, v.table_name, v.record_id, v.record, v.old_record,
v.record->>'application_project_type' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
where v.op='INSERT' and v.table_name='application_project_type' and v.record->>'archived_by' is null
and v.record->>'application_id'=application.id::varchar(10);

$$ language sql stable;

grant execute on function ccbc_public.application_history to ccbc_admin;
grant execute on function ccbc_public.application_history to ccbc_analyst;

comment on function ccbc_public.application_history is 'Computed column that returns list of audit records for application';

commit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Deploy ccbc:extensions/application_gis_assessment_hh_history to pg

begin;

select audit.enable_tracking('ccbc_public.application_gis_assessment_hh'::regclass);

commit;
7 changes: 7 additions & 0 deletions db/deploy/tables/application_gis_assessment_hh_001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Deploy ccbc:tables/application_gis_assessment_hh_001 to pg

BEGIN;

select ccbc_private.upsert_timestamp_columns('ccbc_public', 'application_gis_assessment_hh');

COMMIT;
6 changes: 3 additions & 3 deletions db/revert/computed_columns/application_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ returns setof ccbc_public.history_item as $$
v.record->>'application_community_progress_report_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
inner join ccbc_public.ccbc_user u on (v.record->>'updated_by')::integer=u.id
where v.op='UPDATE' and v.table_name='application_community_progress_report_data' and v.record->>'history_operation'='deleted'
and v.record->>'application_id'=application.id::varchar(10)

Expand All @@ -174,7 +174,7 @@ returns setof ccbc_public.history_item as $$
v.record->>'application_claims_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
inner join ccbc_public.ccbc_user u on (v.record->>'updated_by')::integer=u.id
where v.op='UPDATE' and v.table_name='application_claims_data' and v.record->>'history_operation'='deleted'
and v.record->>'application_id'=application.id::varchar(10)

Expand All @@ -201,7 +201,7 @@ returns setof ccbc_public.history_item as $$
v.record->>'application_milestone_data' as item,
u.family_name, u.given_name, u.session_sub, u.external_analyst
from ccbc_public.record_version as v
inner join ccbc_public.ccbc_user u on v.created_by=u.id
inner join ccbc_public.ccbc_user u on (v.record->>'updated_by')::integer=u.id
where v.op='UPDATE' and v.table_name='application_milestone_data' and v.record->>'history_operation'='deleted'
and v.record->>'application_id'=application.id::varchar(10)

Expand Down
Loading

0 comments on commit 3acfad5

Please sign in to comment.