Skip to content

Commit

Permalink
tasotarkistus: change type and attribute naming
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Dec 2, 2024
1 parent 5d00b97 commit f70e6bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { flowRight } from 'lodash';
import { connect } from 'react-redux';
import type {
OldDwellingsInHousingCompaniesPriceIndex as OldDwellingsInHousingCompaniesPriceIndexProps,
IndexNumberYearly as IndexNumberYearlyProps,
IndexPointFigureYearly as IndexPointFigureYearlyProps,
} from '@/leases/types';
import BoxItemContainer from '@/components/content/BoxItemContainer';
import { withWindowResize } from '@/components/resize/WindowResizeHandler';
Expand All @@ -15,36 +15,38 @@ import { LeaseFieldTitles, LeaseRentOldDwellingsInHousingCompaniesPriceIndexFiel
import Authorization from '@/components/authorization/Authorization';
import { getUiDataLeaseKey } from '@/uiData/helpers';
import { formatDate } from '../../../../util/helpers';
import { OldDwellingsInHousingCompaniesPriceIndex } from '../../../types';

type Props = {
oldDwellingsInHousingCompaniesPriceIndex: OldDwellingsInHousingCompaniesPriceIndexProps;
leaseStartDate: string;
};

const getLastYearsIndexPointNumber = (annualIndexNumbers: IndexNumberYearlyProps[]): string => {
const getLastYearsIndexPointNumber = (pointFigures: IndexPointFigureYearlyProps[]): string => {
const lastYear = new Date().getFullYear() - 1;
const lastYearIndex = annualIndexNumbers.find((x: IndexNumberYearlyProps) => x.year == lastYear);
return lastYearIndex ? `${lastYearIndex.year} * ${lastYearIndex.number}` : '';
const lastYearIndex = pointFigures?.find((x: IndexPointFigureYearlyProps) => x.year == lastYear) || null;
return lastYearIndex ? `${lastYearIndex.year} * ${lastYearIndex.value}` : 'Indeksipisteluvut puuttuvat';
}

const getReviewDaysSorted = (annualIndexNumbers: IndexNumberYearlyProps[]): IndexNumberYearlyProps[] => {
const getReviewDaysSorted = (pointFigures: IndexPointFigureYearlyProps[]): IndexPointFigureYearlyProps[] => {
// deep copy
const sortedNumbers = JSON.parse(JSON.stringify(annualIndexNumbers));
const sortedNumbers = JSON.parse(JSON.stringify(pointFigures));

sortedNumbers.sort((a: IndexNumberYearlyProps, b: IndexNumberYearlyProps) => a.year - b.year);
sortedNumbers.sort((a: IndexPointFigureYearlyProps, b: IndexPointFigureYearlyProps) => a.year - b.year);
return sortedNumbers;
}

class OldDwellingsInHousingCompaniesPriceIndex extends PureComponent<Props> {
class OldDwellingsInHousingCompaniesPriceIndexView extends PureComponent<Props> {
render() {
const {
oldDwellingsInHousingCompaniesPriceIndex: {
name,
numbers,
source_table_label: sourceTableLabel,
},
oldDwellingsInHousingCompaniesPriceIndex,
leaseStartDate
} = this.props;
const {
name,
point_figures: pointFigures,
source_table_label: sourceTableLabel
} = oldDwellingsInHousingCompaniesPriceIndex || {};
return <Fragment>
<BoxItemContainer>
<Row>
Expand Down Expand Up @@ -74,7 +76,7 @@ class OldDwellingsInHousingCompaniesPriceIndex extends PureComponent<Props> {
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS)}>
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.NUMBERS}
</FormTextTitle>
<FormText>{getLastYearsIndexPointNumber(numbers)}</FormText>
<FormText>{getLastYearsIndexPointNumber(pointFigures)}</FormText>
<FormText>{sourceTableLabel}</FormText>
</>
</Authorization>
Expand All @@ -87,9 +89,9 @@ class OldDwellingsInHousingCompaniesPriceIndex extends PureComponent<Props> {
{LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldTitles.REVIEW_DAYS}
</FormTextTitle>
<>
{numbers && !!numbers.length ?
getReviewDaysSorted(numbers).map(
(number: IndexNumberYearlyProps, index: number) => {
{pointFigures && !!pointFigures.length ?
getReviewDaysSorted(pointFigures).map(
(number: IndexPointFigureYearlyProps, index: number) => {
return <FormText key={LeaseRentOldDwellingsInHousingCompaniesPriceIndexFieldPaths.NUMBERS + `[${index}]`}>
{`1.1.${number.year}`}
</FormText>
Expand All @@ -111,4 +113,4 @@ export default flowRight(withWindowResize, connect(state => {
leaseAttributes: getLeaseAttributes(state),
leaseStartDate: getCurrentLeaseStartDate(state)
};
}))(OldDwellingsInHousingCompaniesPriceIndex);
}))(OldDwellingsInHousingCompaniesPriceIndexView);
7 changes: 4 additions & 3 deletions src/leases/components/leaseSections/rent/RentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { formatDateRange, getFieldOptions, getLabelOfOption, isActive, isArchive
import { getAttributes as getLeaseAttributes, getCollapseStateByKey } from "@/leases/selectors";
import type { Attributes } from "types";
import type { ServiceUnit } from "@/serviceUnits/types";
import OldDwellingsInHousingCompaniesPriceIndex from "./OldDwellingsInHousingCompaniesPriceIndex";
import OldDwellingsInHousingCompaniesPriceIndexView from "./OldDwellingsInHousingCompaniesPriceIndex";

const formName = FormNames.LEASE_RENTS;
type Props = {
Expand Down Expand Up @@ -117,9 +117,10 @@ const RentItem = ({
</Authorization>} onToggle={handleRentCollapseToggle}>

{/* TODO: Add authorization for OldDwellingsInHousingCompaniesPriceIndex */}
{/* <Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX)}> */}
{ oldDwellingsInHousingCompaniesPriceIndex &&
/* <Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX)}> */
<Collapse className='collapse__secondary' defaultOpen={true} headerTitle='Tasotarkistus'>
<OldDwellingsInHousingCompaniesPriceIndex oldDwellingsInHousingCompaniesPriceIndex={oldDwellingsInHousingCompaniesPriceIndex} />
<OldDwellingsInHousingCompaniesPriceIndexView oldDwellingsInHousingCompaniesPriceIndex={oldDwellingsInHousingCompaniesPriceIndex} />
</Collapse>
{/* </Authorization> */}
<BasicInfo rent={rent} rentType={rentType} serviceUnit={serviceUnit} />
Expand Down
11 changes: 5 additions & 6 deletions src/leases/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Action, ApiResponse, Attributes, Methods } from "@/types";
import type { ServiceUnit } from "@/serviceUnits/types";
import { year } from '../components/form/validations';
import commentSaga from '@/comments/saga';

export type LeaseState = {
attributes: Attributes;
byId: Record<string, any>;
Expand All @@ -13,7 +12,7 @@ export type LeaseState = {
isEditMode: boolean;
isFetching: boolean;
isFetchingByBBox: boolean;
isFetchingById: {};
isFetchingById: Record<string, any>;
isFetchingAttributes: boolean;
isSaveClicked: boolean;
isSaving: boolean;
Expand Down Expand Up @@ -51,8 +50,8 @@ export type IntendedUse = {
name: string;
service_unit: ServiceUnit["id"];
};
export type IndexNumberYearly = {
number: number;
export type IndexPointFigureYearly = {
value: number;
year: number;
region: string;
comment: string;
Expand All @@ -65,7 +64,7 @@ export type OldDwellingsInHousingCompaniesPriceIndex = {
source_table_updated?: string;
source_table_label: string;
url: string;
numbers: IndexNumberYearly[];
point_figures: IndexPointFigureYearly[];
}
export type FetchAttributesAction = Action<string, void>;
export type ReceiveAttributesAction = Action<string, Attributes>;
Expand Down

0 comments on commit f70e6bf

Please sign in to comment.