Skip to content

Commit

Permalink
authorization and collapse state
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
NC-jsAhonen committed Dec 2, 2024
1 parent f70e6bf commit 2341533
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import { withWindowResize } from '@/components/resize/WindowResizeHandler';
import FormText from "@/components/form/FormText";
import FormTextTitle from '@/components/form/FormTextTitle';
import { LeaseFieldTitles, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles } from '@/leases/enums';
import Authorization from '@/components/authorization/Authorization';
import { getUiDataLeaseKey } from '@/uiData/helpers';
import { formatDate } from '../../../../util/helpers';
import { OldDwellingsInHousingCompaniesPriceIndex } from '../../../types';
import { formatDate } from '@/util/helpers';

type Props = {
oldDwellingsInHousingCompaniesPriceIndex: OldDwellingsInHousingCompaniesPriceIndexProps;
Expand Down Expand Up @@ -51,40 +49,25 @@ class OldDwellingsInHousingCompaniesPriceIndexView extends PureComponent<Props>
<BoxItemContainer>
<Row>
<Column>
<Authorization allow={true/*isFieldAllowedToRead(leaseAttributes, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME)*/}>
<>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME)}>
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NAME}
</FormTextTitle>
<FormText>{name}</FormText>
</>
</Authorization>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME)}>
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NAME}
</FormTextTitle>
<FormText>{name}</FormText>
</Column>
<Column>
<Authorization allow={true/*isFieldAllowedToRead(leaseAttributes, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME)*/}>
<>
<FormTextTitle>
{LeaseFieldTitles.START_DATE}
</FormTextTitle>
<FormText>{formatDate(leaseStartDate)}</FormText>
</>
</Authorization>
<FormTextTitle>
{LeaseFieldTitles.START_DATE}
</FormTextTitle>
<FormText>{formatDate(leaseStartDate)}</FormText>
</Column>
<Column>
<Authorization allow={true/*isFieldAllowedToRead(leaseAttributes, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME)*/}>
<>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS)}>
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NUMBERS}
</FormTextTitle>
<FormText>{getLastYearsIndexPointNumber(pointFigures)}</FormText>
<FormText>{sourceTableLabel}</FormText>
</>
</Authorization>

<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS)}>
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NUMBERS}
</FormTextTitle>
<FormText>{getLastYearsIndexPointNumber(pointFigures)}</FormText>
<FormText>{sourceTableLabel}</FormText>
</Column>
<Column>
<Authorization allow={true/*isFieldAllowedToRead(leaseAttributes, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NAME)*/}>
<>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS)}>
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.REVIEW_DAYS}
</FormTextTitle>
Expand All @@ -99,8 +82,6 @@ class OldDwellingsInHousingCompaniesPriceIndexView extends PureComponent<Props>
)
: ""}
</>
</>
</Authorization>
</Column>
</Row>
</BoxItemContainer>
Expand Down
15 changes: 9 additions & 6 deletions src/leases/components/leaseSections/rent/RentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const formName = FormNames.LEASE_RENTS;
type Props = {
contractRentsCollapseState: boolean;
equalizedRentsCollapseState: boolean;
oldDwellingsInHousingCompaniesPriceIndexCollapseState: boolean;
fixedInitialYearRentsCollapseState: boolean;
indexAdjustedRentsCollapseState: boolean;
leaseAttributes: Attributes;
Expand All @@ -41,6 +42,7 @@ type Props = {
const RentItem = ({
contractRentsCollapseState,
equalizedRentsCollapseState,
oldDwellingsInHousingCompaniesPriceIndexCollapseState,
fixedInitialYearRentsCollapseState,
indexAdjustedRentsCollapseState,
leaseAttributes,
Expand Down Expand Up @@ -117,12 +119,12 @@ const RentItem = ({
</Authorization>} onToggle={handleRentCollapseToggle}>

{/* TODO: Add authorization for OldDwellingsInHousingCompaniesPriceIndex */}
{ oldDwellingsInHousingCompaniesPriceIndex &&
/* <Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX)}> */
<Collapse className='collapse__secondary' defaultOpen={true} headerTitle='Tasotarkistus'>
<OldDwellingsInHousingCompaniesPriceIndexView oldDwellingsInHousingCompaniesPriceIndex={oldDwellingsInHousingCompaniesPriceIndex} />
</Collapse>
{/* </Authorization> */}
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX)}>
{oldDwellingsInHousingCompaniesPriceIndex &&
<Collapse className='collapse__secondary' defaultOpen={oldDwellingsInHousingCompaniesPriceIndexCollapseState !== undefined ? oldDwellingsInHousingCompaniesPriceIndexCollapseState : true} headerTitle='Tasotarkistus'>
<OldDwellingsInHousingCompaniesPriceIndexView oldDwellingsInHousingCompaniesPriceIndex={oldDwellingsInHousingCompaniesPriceIndex} />
</Collapse>}
</Authorization>
<BasicInfo rent={rent} rentType={rentType} serviceUnit={serviceUnit} />

<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentFixedInitialYearRentsFieldPaths.FIXED_INITIAL_YEAR_RENTS)}>
Expand Down Expand Up @@ -168,6 +170,7 @@ export default connect((state, props) => {
return {
contractRentsCollapseState: getCollapseStateByKey(state, `${ViewModes.READONLY}.${formName}.${id}.contract_rents`),
equalizedRentsCollapseState: getCollapseStateByKey(state, `${ViewModes.READONLY}.${formName}.${id}.equalized_rents`),
oldDwellingsInHousingCompaniesPriceIndexCollapseState: getCollapseStateByKey(state, `${ViewModes.READONLY}.${formName}.${id}.old_dwellings_in_housing_companies_price_index`),
fixedInitialYearRentsCollapseState: getCollapseStateByKey(state, `${ViewModes.READONLY}.${formName}.${id}.fixed_initial_year_rents`),
indexAdjustedRentsCollapseState: getCollapseStateByKey(state, `${ViewModes.READONLY}.${formName}.${id}.index_adjusted_rents`),
leaseAttributes: getLeaseAttributes(state),
Expand Down

0 comments on commit 2341533

Please sign in to comment.