Skip to content
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

MVJ-245_paikkatietovipunen-urls-broken-fix #487

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { LeasePlanUnitsFieldPaths, LeasePlanUnitsFieldTitles, LeaseAreaUsageDist
import { getUiDataLeaseKey } from "uiData/helpers";
import { formatDate, formatNumber, getFieldOptions, getLabelOfOption, getSearchQuery, getUrlParams, isEmptyValue, isFieldAllowedToRead } from "util/helpers";
import { getAttributes } from "leases/selectors";
import { createPaikkatietovipunenUrl } from "util/helpers";
import { createPTPPlanReportUrl, createPTPPlotDivisionUrl } from "util/helpers";
import type { Attributes } from "types";
import SubTitle from "components/content/SubTitle";
type OwnProps = {
Expand Down Expand Up @@ -99,7 +99,7 @@ const PlanUnitItem = ({
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeasePlanUnitsFieldPaths.DETAILED_PLAN_IDENTIFIER)}>
{LeasePlanUnitsFieldTitles.DETAILED_PLAN_IDENTIFIER}
</FormTextTitle>
{planUnit.detailed_plan_identifier ? <ExternalLink href={createPaikkatietovipunenUrl(`helreport/planpdfloader/?id=${planUnit.detailed_plan_identifier}`)} text={planUnit.detailed_plan_identifier} /> : <FormText>-</FormText>}
{planUnit.detailed_plan_identifier ? <ExternalLink href={createPTPPlanReportUrl(planUnit.detailed_plan_identifier)} text={planUnit.detailed_plan_identifier} /> : <FormText>-</FormText>}
</Authorization>
</Column>
<Column small={12} medium={6} large={3}>
Expand Down Expand Up @@ -127,7 +127,7 @@ const PlanUnitItem = ({
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeasePlanUnitsFieldPaths.PLOT_DIVISION_IDENTIFIER)}>
{LeasePlanUnitsFieldTitles.PLOT_DIVISION_IDENTIFIER}
</FormTextTitle>
{planUnit.plot_division_identifier ? <ExternalLink href={createPaikkatietovipunenUrl(`helreport/plotdivision/?id=${planUnit.plot_division_identifier}`)} text={planUnit.plot_division_identifier} /> : <FormText>-</FormText>}
{planUnit.plot_division_identifier ? <ExternalLink href={createPTPPlotDivisionUrl(planUnit.plot_division_identifier)} text={planUnit.plot_division_identifier} /> : <FormText>-</FormText>}
</Authorization>
</Column>
<Column small={12} medium={6} large={3}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Collapse from "components/collapse/Collapse";
import FormText from "components/form/FormText";
import FormTextTitle from "components/form/FormTextTitle";
import ExternalLink from "components/links/ExternalLink";
import { createPaikkatietovipunenUrl } from "util/helpers";
import { createPTPPlanReportUrl } from "util/helpers";
import { formatDate, getFieldOptions, getLabelOfOption } from "util/helpers";
import { getAttributes, getCollapseStateByKey, getIsFetchingCustomDetailedPlanAttributes, getRelatedApplications } from "plotSearch/selectors";
import type { Attributes } from "types";
Expand Down Expand Up @@ -125,7 +125,7 @@ class PlotSearchSiteCustomDetailedPlan extends PureComponent<Props, State> {
<FormTextTitle>
{PlotSearchFieldTitles.DETAILED_PLAN}
</FormTextTitle>
{get(currentCustomDetailedPlan, 'detailed_plan') ? <ExternalLink href={createPaikkatietovipunenUrl(`helreport/planpdfloader/?id=${get(currentCustomDetailedPlan, 'detailed_plan')}`)} text={get(currentCustomDetailedPlan, 'detailed_plan')} /> : <FormText>-</FormText>}
{get(currentCustomDetailedPlan, 'detailed_plan') ? <ExternalLink href={createPTPPlanReportUrl(get(currentCustomDetailedPlan, 'detailed_plan'))} text={get(currentCustomDetailedPlan, 'detailed_plan')} /> : <FormText>-</FormText>}
</Column>
<Column small={6} medium={4} large={3}>
<FormTextTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import FormTextTitle from "components/form/FormTextTitle";
import { getUsersPermissions } from "usersPermissions/selectors";
import WarningContainer from "components/content/WarningContainer";
import WarningField from "components/form/WarningField";
import { createPaikkatietovipunenUrl } from "util/helpers";
import { createPTPPlanReportUrl } from "util/helpers";
import { receiveCollapseStates, receiveIsSaveClicked, fetchPlanUnit, fetchCustomDetailedPlan } from "plotSearch/actions";
import { PlotSearchFieldTitles } from "plotSearch/enums";
import { formatDate, getFieldOptions, getLabelOfOption } from "util/helpers";
Expand Down Expand Up @@ -571,7 +571,7 @@ class PlotSearchSiteEdit extends Component<Props, State> {
<FormTextTitle>
{PlotSearchFieldTitles.DETAILED_PLAN}
</FormTextTitle>
{planUnitByValue ? <ExternalLink href={createPaikkatietovipunenUrl(`helreport/planpdfloader/?id=${get(planUnitByValue, 'detailed_plan_identifier')}`)} text={get(planUnitByValue, 'detailed_plan_identifier')} /> : <FormText>-</FormText>}
{planUnitByValue ? <ExternalLink href={createPTPPlanReportUrl(get(planUnitByValue, 'detailed_plan_identifier'))} text={get(planUnitByValue, 'detailed_plan_identifier')} /> : <FormText>-</FormText>}
</Column>
<Column small={6} medium={4} large={3}>
<FormTextTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LoaderWrapper from "components/loader/LoaderWrapper";
import ExternalLink from "components/links/ExternalLink";
import Loader from "components/loader/Loader";
import PlanUnitSelectInput from "components/inputs/PlanUnitSelectInput";
import { createPaikkatietovipunenUrl } from "util/helpers";
import { createPTPPlanReportUrl } from "util/helpers";
import { PlotSearchFieldTitles } from "plotSearch/enums";
import { formatDate, getFieldOptions, getLabelOfOption } from "util/helpers";
import { getInfoLinkLanguageDisplayText } from "plotSearch/helpers";
Expand Down Expand Up @@ -105,7 +105,7 @@ class PlotSearchSiteEditCustomDetailedPlan extends Component<Props, State> {
<FormTextTitle>
{PlotSearchFieldTitles.DETAILED_PLAN}
</FormTextTitle>
{get(currentCustomDetailedPlan, 'detailed_plan') ? <ExternalLink href={createPaikkatietovipunenUrl(`helreport/planpdfloader/?id=${get(currentCustomDetailedPlan, 'detailed_plan')}`)} text={get(currentCustomDetailedPlan, 'detailed_plan')} /> : <FormText>-</FormText>}
{get(currentCustomDetailedPlan, 'detailed_plan') ? <ExternalLink href={createPTPPlanReportUrl(get(currentCustomDetailedPlan, 'detailed_plan'))} text={get(currentCustomDetailedPlan, 'detailed_plan')} /> : <FormText>-</FormText>}
</Column>
<Column small={6} medium={4} large={3}>
<FormTextTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FormTextTitle from "components/form/FormTextTitle";
import ExternalLink from "components/links/ExternalLink";
import WarningContainer from "components/content/WarningContainer";
import WarningField from "components/form/WarningField";
import { createPaikkatietovipunenUrl } from "util/helpers";
import { createPTPPlanReportUrl } from "util/helpers";
import { Routes, getRouteById } from "root/routes";
import { formatDate, getFieldOptions, getLabelOfOption } from "util/helpers";
import { getAttributes, getCollapseStateByKey, getIsFetchingPlanUnitAttributes, getRelatedApplications } from "plotSearch/selectors";
Expand Down Expand Up @@ -214,7 +214,7 @@ class PlotSearchSitePlanUnit extends PureComponent<Props, State> {
<FormTextTitle>
{PlotSearchFieldTitles.DETAILED_PLAN}
</FormTextTitle>
{get(currentPlanUnit, 'detailed_plan_identifier') ? <ExternalLink href={createPaikkatietovipunenUrl(`helreport/planpdfloader/?id=${get(currentPlanUnit, 'detailed_plan_identifier')}`)} text={get(currentPlanUnit, 'detailed_plan_identifier')} /> : <FormText>-</FormText>}
{get(currentPlanUnit, 'detailed_plan_identifier') ? <ExternalLink href={createPTPPlanReportUrl(get(currentPlanUnit, 'detailed_plan_identifier'))} text={get(currentPlanUnit, 'detailed_plan_identifier')} /> : <FormText>-</FormText>}
</Column>
<Column small={6} medium={4} large={3}>
<FormTextTitle>
Expand Down
4 changes: 2 additions & 2 deletions src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const MAX_ZOOM = 12;
export const MAP_COLORS = ['#0078C0', '#FF9800', '#1976D2', '#D32F2F', '#E040FB', '#FF4081', '#512DA8', '#536DFE', '#F57C00', '#E64A19', '#8BC34A', '#689F38', '#FFC107', '#CDDC39'];

/**
* Url of the paikkatietovipunen
* Url of the ptp.hel.fi API
* @readonly
* @const {string}
*/
export const PAIKKATIETOVIPUNEN_URL = 'http://paikkatietovipunen.hel.fi:10058';
export const PTP_URL = 'https://ptp.hel.fi';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it would be really nice if we could figure out what PTP stands for and write it out in the variable to describe what this is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed PTP_URL to PAIKKATIETOPALVELU_URL


/**
* Delete modal button text
Expand Down
15 changes: 11 additions & 4 deletions src/util/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import isEmpty from "lodash/isEmpty";
import isNumber from "lodash/isNumber";
import { toastr } from "react-redux-toastr";
import ToastrIcons from "components/toastr/ToastrIcons";
import { PAIKKATIETOVIPUNEN_URL } from "util/constants";
import { PTP_URL } from "util/constants";
import { Breakpoints } from "foundation/enums";
import type { ApiResponse, Attributes, Methods } from "types";
import type { UsersPermissions } from "usersPermissions/types";
Expand Down Expand Up @@ -633,11 +633,18 @@ export const findFromOcdString = (ocd: string, key: string): string | null | und
};

/**
* Create url to paikkatietovipunen
* @param {string} url
* Create url to ptp.hel.fi
* @param {string} reportId
* @returns {string}
*/
export const createPaikkatietovipunenUrl = (url: string): string => `${PAIKKATIETOVIPUNEN_URL}/${url}`;
export const createPTPPlanReportUrl = (reportId: string): string => `${PTP_URL}/DataForms/planreport/?id=${reportId}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really like this approach, nice!


/**
* Create url to ptp.hel.fi
* @param {string} plotDivisionId
* @returns {string}
*/
export const createPTPPlotDivisionUrl = (plotDivisionId: string): string => `${PTP_URL}/DataHandlers/Tonttijaot/?q=${plotDivisionId}`;

/**
* Get count of results from api response
Expand Down
9 changes: 6 additions & 3 deletions src/util/spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { isValidDate, getDayMonth, getCurrentYear, sortByStartAndEndDateAsc, sortByStartAndEndDateDesc, isDateRangesCollapsing, splitDateRanges, getSplittedDateRanges, getSplittedDateRangesWithItems } from "./date";
import { composePageTitle, getSearchQuery, getUrlParams, fixedLengthNumber, getEpochTime, isEmptyValue, formatNumberWithThousandSeparator, formatDecimalNumber, formatNumber, isDecimalNumberStr, convertStrToDecimalNumber, formatDate, formatDateRange, getReferenceNumberLink, findItemById, getLabelOfOption, sortNumberByKeyAsc, sortNumberByKeyDesc, sortStringAsc, sortStringDesc, sortStringByKeyAsc, sortStringByKeyDesc, sortByOptionsAsc, sortByOptionsDesc, addEmptyOption, isFieldRequired, isFieldAllowedToEdit, isFieldAllowedToRead, isMethodAllowed, hasPermissions, getFieldAttributeOptions, getFieldOptions, humanReadableByteCount, hasNumber, findFromOcdString, createPaikkatietovipunenUrl, getApiResponseCount, getApiResponseMaxPage, getApiResponseResults, isActive, isActiveOrFuture, isArchived } from "./helpers";
import { composePageTitle, getSearchQuery, getUrlParams, fixedLengthNumber, getEpochTime, isEmptyValue, formatNumberWithThousandSeparator, formatDecimalNumber, formatNumber, isDecimalNumberStr, convertStrToDecimalNumber, formatDate, formatDateRange, getReferenceNumberLink, findItemById, getLabelOfOption, sortNumberByKeyAsc, sortNumberByKeyDesc, sortStringAsc, sortStringDesc, sortStringByKeyAsc, sortStringByKeyDesc, sortByOptionsAsc, sortByOptionsDesc, addEmptyOption, isFieldRequired, isFieldAllowedToEdit, isFieldAllowedToRead, isMethodAllowed, hasPermissions, getFieldAttributeOptions, getFieldOptions, humanReadableByteCount, hasNumber, findFromOcdString, createPTPPlanReportUrl, createPTPPlotDivisionUrl, getApiResponseCount, getApiResponseMaxPage, getApiResponseResults, isActive, isActiveOrFuture, isArchived } from "./helpers";
import { getCoordinatesOfGeometry, getCenterFromCoordinates } from "./map";

describe('utils', () => {
Expand Down Expand Up @@ -1133,8 +1133,11 @@ describe('utils', () => {
it('should not find property from ocd string', () => {
expect(findFromOcdString('property1:test/property2:test2', 'property3')).to.deep.equal(null);
});
it('should return paikkatietovipunen url', () => {
expect(createPaikkatietovipunenUrl('123')).to.deep.equal('http://paikkatietovipunen.hel.fi:10058/123');
it('should return PTP plan report url', () => {
expect(createPTPPlanReportUrl('123')).to.deep.equal('https://ptp.hel.fi/DataForms/planreport/?id=123');
});
it('should return PTP plot division url', () => {
expect(createPTPPlotDivisionUrl('123')).to.deep.equal('https://ptp.hel.fi/DataHandlers/Tonttijaot/?q=123');
});
it('should return api response count', () => {
const apiResponse = {
Expand Down