diff --git a/hub/graphql/types/model_types.py b/hub/graphql/types/model_types.py index 2a0db0583..ded967c6d 100644 --- a/hub/graphql/types/model_types.py +++ b/hub/graphql/types/model_types.py @@ -21,6 +21,10 @@ from hub import models from hub.enrichment.sources import builtin_mapping_sources +from hub.enrichment.sources.electoral_commission_postcode_lookup import ( + electoral_commision_address_lookup, + electoral_commision_postcode_lookup, +) from hub.graphql.context import HubDataLoaderContext from hub.graphql.dataloaders import ( FieldDataLoaderFactory, @@ -28,6 +32,7 @@ ReverseFKWithFiltersDataLoaderFactory, filterable_dataloader_resolver, ) +from hub.graphql.types.electoral_commission import ElectoralCommissionPostcodeLookup from hub.graphql.types.geojson import MultiPolygonFeature, PointFeature from hub.graphql.types.postcodes import PostcodesIOResult from hub.graphql.utils import attr_field, dict_key_field, fn_field @@ -660,6 +665,17 @@ class MapReportMemberFeature(PointFeature): id: Optional[str] properties: Optional[GenericData] + # TODO: move this somewhere more rational + @strawberry_django.field + async def electoral_commission( + self, address_slug: Optional[str] = None + ) -> Optional[ElectoralCommissionPostcodeLookup]: + if address_slug: + return await electoral_commision_address_lookup(address_slug) + if self.properties: + return await electoral_commision_postcode_lookup(self.properties.postcode) + return None + @strawberry.enum class AnalyticalAreaType(Enum): diff --git a/nextjs/src/__generated__/gql.ts b/nextjs/src/__generated__/gql.ts index 497c5452e..584a35f52 100644 --- a/nextjs/src/__generated__/gql.ts +++ b/nextjs/src/__generated__/gql.ts @@ -74,7 +74,7 @@ const documents = { "\n query GetPageEditorData($pageId: ID!) {\n hubPage(pk: $pageId) {\n id\n title\n path\n slug\n puckJsonContent\n modelName\n liveUrl\n # For breadcrumbs\n ancestors(inclusive: true) {\n id\n title\n path\n slug\n modelName\n }\n }\n }\n": types.GetPageEditorDataDocument, "\n query GetHubContext($hostname: String!) {\n hubByHostname(hostname: $hostname) {\n id\n customCss\n primaryColour\n secondaryColour\n }\n }\n": types.GetHubContextDocument, "\n query GetMemberList($currentOrganisationId: ID!) {\n myOrganisations(filters: { id: $currentOrganisationId }) {\n externalDataSources {\n id\n name\n importedDataCount\n crmType\n dataType\n }\n sharingPermissionsFromOtherOrgs {\n externalDataSource {\n id\n name\n importedDataCount\n crmType\n dataType\n organisation {\n name\n }\n }\n }\n }\n }\n": types.GetMemberListDocument, - "\nquery MapReportLayerGeoJSONPoint($genericDataId: String!) {\n importedDataGeojsonPoint(genericDataId: $genericDataId) {\n id\n type\n geometry {\n type\n coordinates\n }\n properties {\n id\n lastUpdate\n name\n phone\n email\n postcodeData {\n postcode\n }\n json\n remoteUrl\n dataType {\n dataSet {\n externalDataSource {\n name\n }\n }\n }\n }\n }\n}\n": types.MapReportLayerGeoJsonPointDocument, + "\nquery MapReportLayerGeoJSONPoint($genericDataId: String!) {\n importedDataGeojsonPoint(genericDataId: $genericDataId) {\n id\n type\n geometry {\n type\n coordinates\n }\n properties {\n id\n lastUpdate\n name\n phone\n email\n postcodeData {\n postcode\n }\n json\n remoteUrl\n dataType {\n dataSet {\n externalDataSource {\n name\n }\n }\n }\n }\n electoralCommission {\n addresses\n dates {\n pollingStation {\n station {\n properties {\n address\n postcode\n }\n }\n }\n }\n }\n }\n}\n": types.MapReportLayerGeoJsonPointDocument, "\n query MapReportLayerAnalytics($reportID: ID!) {\n mapReport(pk: $reportID) {\n id\n layers {\n id\n name\n source {\n id\n organisation {\n name\n }\n }\n }\n }\n }\n": types.MapReportLayerAnalyticsDocument, "\n query MapReportRegionStats($reportID: ID!) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByRegion {\n label\n gss\n count\n gssArea {\n point {\n id\n type\n geometry {\n type\n coordinates\n }\n }\n }\n }\n }\n }\n": types.MapReportRegionStatsDocument, "\n query MapReportConstituencyStats($reportID: ID!, $analyticalAreaType: AnalyticalAreaType!) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByConstituency: importedDataCountByArea(analyticalAreaType: $analyticalAreaType){\n label\n gss\n count\n gssArea {\n point {\n id\n type\n geometry {\n type\n coordinates\n }\n }\n }\n }\n }\n }\n": types.MapReportConstituencyStatsDocument, @@ -350,7 +350,7 @@ export function gql(source: "\n query GetMemberList($currentOrganisationId: ID! /** * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function gql(source: "\nquery MapReportLayerGeoJSONPoint($genericDataId: String!) {\n importedDataGeojsonPoint(genericDataId: $genericDataId) {\n id\n type\n geometry {\n type\n coordinates\n }\n properties {\n id\n lastUpdate\n name\n phone\n email\n postcodeData {\n postcode\n }\n json\n remoteUrl\n dataType {\n dataSet {\n externalDataSource {\n name\n }\n }\n }\n }\n }\n}\n"): (typeof documents)["\nquery MapReportLayerGeoJSONPoint($genericDataId: String!) {\n importedDataGeojsonPoint(genericDataId: $genericDataId) {\n id\n type\n geometry {\n type\n coordinates\n }\n properties {\n id\n lastUpdate\n name\n phone\n email\n postcodeData {\n postcode\n }\n json\n remoteUrl\n dataType {\n dataSet {\n externalDataSource {\n name\n }\n }\n }\n }\n }\n}\n"]; +export function gql(source: "\nquery MapReportLayerGeoJSONPoint($genericDataId: String!) {\n importedDataGeojsonPoint(genericDataId: $genericDataId) {\n id\n type\n geometry {\n type\n coordinates\n }\n properties {\n id\n lastUpdate\n name\n phone\n email\n postcodeData {\n postcode\n }\n json\n remoteUrl\n dataType {\n dataSet {\n externalDataSource {\n name\n }\n }\n }\n }\n electoralCommission {\n addresses\n dates {\n pollingStation {\n station {\n properties {\n address\n postcode\n }\n }\n }\n }\n }\n }\n}\n"): (typeof documents)["\nquery MapReportLayerGeoJSONPoint($genericDataId: String!) {\n importedDataGeojsonPoint(genericDataId: $genericDataId) {\n id\n type\n geometry {\n type\n coordinates\n }\n properties {\n id\n lastUpdate\n name\n phone\n email\n postcodeData {\n postcode\n }\n json\n remoteUrl\n dataType {\n dataSet {\n externalDataSource {\n name\n }\n }\n }\n }\n electoralCommission {\n addresses\n dates {\n pollingStation {\n station {\n properties {\n address\n postcode\n }\n }\n }\n }\n }\n }\n}\n"]; /** * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/nextjs/src/__generated__/graphql.ts b/nextjs/src/__generated__/graphql.ts index aeaee207e..ffd55fb41 100644 --- a/nextjs/src/__generated__/graphql.ts +++ b/nextjs/src/__generated__/graphql.ts @@ -1640,12 +1640,18 @@ export type MapReportInput = { export type MapReportMemberFeature = Feature & { __typename?: 'MapReportMemberFeature'; + electoralCommission?: Maybe; geometry: PointGeometry; id?: Maybe; properties?: Maybe; type: GeoJsonTypes; }; + +export type MapReportMemberFeatureElectoralCommissionArgs = { + addressSlug?: InputMaybe; +}; + export type MappingSource = { __typename?: 'MappingSource'; author?: Maybe; @@ -3229,7 +3235,7 @@ export type MapReportLayerGeoJsonPointQueryVariables = Exact<{ }>; -export type MapReportLayerGeoJsonPointQuery = { __typename?: 'Query', importedDataGeojsonPoint?: { __typename?: 'MapReportMemberFeature', id?: string | null, type: GeoJsonTypes, geometry: { __typename?: 'PointGeometry', type: GeoJsonTypes, coordinates: Array }, properties?: { __typename?: 'GenericData', id: string, lastUpdate: any, name?: string | null, phone?: string | null, email?: string | null, json?: any | null, remoteUrl: string, postcodeData?: { __typename?: 'PostcodesIOResult', postcode: string } | null, dataType: { __typename?: 'DataType', dataSet: { __typename?: 'DataSet', externalDataSource: { __typename?: 'ExternalDataSource', name: string } } } } | null } | null }; +export type MapReportLayerGeoJsonPointQuery = { __typename?: 'Query', importedDataGeojsonPoint?: { __typename?: 'MapReportMemberFeature', id?: string | null, type: GeoJsonTypes, geometry: { __typename?: 'PointGeometry', type: GeoJsonTypes, coordinates: Array }, properties?: { __typename?: 'GenericData', id: string, lastUpdate: any, name?: string | null, phone?: string | null, email?: string | null, json?: any | null, remoteUrl: string, postcodeData?: { __typename?: 'PostcodesIOResult', postcode: string } | null, dataType: { __typename?: 'DataType', dataSet: { __typename?: 'DataSet', externalDataSource: { __typename?: 'ExternalDataSource', name: string } } } } | null, electoralCommission?: { __typename?: 'ElectoralCommissionPostcodeLookup', addresses: any, dates: Array<{ __typename?: 'ElectionDate', pollingStation: { __typename?: 'PollingStation', station?: { __typename?: 'ElectoralCommissionStation', properties?: { __typename?: 'ElectoralCommissionStationProperties', address: string, postcode: string } | null } | null } }> } | null } | null }; export type MapReportLayerAnalyticsQueryVariables = Exact<{ reportID: Scalars['ID']['input']; @@ -3367,7 +3373,7 @@ export const GetHubPagesDocument = {"kind":"Document","definitions":[{"kind":"Op export const GetPageEditorDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetPageEditorData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"pageId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hubPage"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"pk"},"value":{"kind":"Variable","name":{"kind":"Name","value":"pageId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"slug"}},{"kind":"Field","name":{"kind":"Name","value":"puckJsonContent"}},{"kind":"Field","name":{"kind":"Name","value":"modelName"}},{"kind":"Field","name":{"kind":"Name","value":"liveUrl"}},{"kind":"Field","name":{"kind":"Name","value":"ancestors"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"inclusive"},"value":{"kind":"BooleanValue","value":true}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"slug"}},{"kind":"Field","name":{"kind":"Name","value":"modelName"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetHubContextDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetHubContext"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"hostname"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hubByHostname"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"hostname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"hostname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"customCss"}},{"kind":"Field","name":{"kind":"Name","value":"primaryColour"}},{"kind":"Field","name":{"kind":"Name","value":"secondaryColour"}}]}}]}}]} as unknown as DocumentNode; export const GetMemberListDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetMemberList"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentOrganisationId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myOrganisations"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentOrganisationId"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"externalDataSources"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"importedDataCount"}},{"kind":"Field","name":{"kind":"Name","value":"crmType"}},{"kind":"Field","name":{"kind":"Name","value":"dataType"}}]}},{"kind":"Field","name":{"kind":"Name","value":"sharingPermissionsFromOtherOrgs"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"externalDataSource"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"importedDataCount"}},{"kind":"Field","name":{"kind":"Name","value":"crmType"}},{"kind":"Field","name":{"kind":"Name","value":"dataType"}},{"kind":"Field","name":{"kind":"Name","value":"organisation"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; -export const MapReportLayerGeoJsonPointDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MapReportLayerGeoJSONPoint"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"genericDataId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"importedDataGeojsonPoint"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"genericDataId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"genericDataId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"geometry"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"coordinates"}}]}},{"kind":"Field","name":{"kind":"Name","value":"properties"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdate"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"phone"}},{"kind":"Field","name":{"kind":"Name","value":"email"}},{"kind":"Field","name":{"kind":"Name","value":"postcodeData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"postcode"}}]}},{"kind":"Field","name":{"kind":"Name","value":"json"}},{"kind":"Field","name":{"kind":"Name","value":"remoteUrl"}},{"kind":"Field","name":{"kind":"Name","value":"dataType"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"dataSet"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"externalDataSource"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; +export const MapReportLayerGeoJsonPointDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MapReportLayerGeoJSONPoint"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"genericDataId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"importedDataGeojsonPoint"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"genericDataId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"genericDataId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"geometry"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"coordinates"}}]}},{"kind":"Field","name":{"kind":"Name","value":"properties"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdate"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"phone"}},{"kind":"Field","name":{"kind":"Name","value":"email"}},{"kind":"Field","name":{"kind":"Name","value":"postcodeData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"postcode"}}]}},{"kind":"Field","name":{"kind":"Name","value":"json"}},{"kind":"Field","name":{"kind":"Name","value":"remoteUrl"}},{"kind":"Field","name":{"kind":"Name","value":"dataType"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"dataSet"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"externalDataSource"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"electoralCommission"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"addresses"}},{"kind":"Field","name":{"kind":"Name","value":"dates"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pollingStation"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"station"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"properties"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"postcode"}}]}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const MapReportLayerAnalyticsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MapReportLayerAnalytics"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"reportID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"mapReport"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"pk"},"value":{"kind":"Variable","name":{"kind":"Name","value":"reportID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"layers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"source"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"organisation"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const MapReportRegionStatsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MapReportRegionStats"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"reportID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"mapReport"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"pk"},"value":{"kind":"Variable","name":{"kind":"Name","value":"reportID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"importedDataCountByRegion"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"gss"}},{"kind":"Field","name":{"kind":"Name","value":"count"}},{"kind":"Field","name":{"kind":"Name","value":"gssArea"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"point"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"geometry"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"coordinates"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const MapReportConstituencyStatsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MapReportConstituencyStats"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"reportID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"analyticalAreaType"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AnalyticalAreaType"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"mapReport"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"pk"},"value":{"kind":"Variable","name":{"kind":"Name","value":"reportID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","alias":{"kind":"Name","value":"importedDataCountByConstituency"},"name":{"kind":"Name","value":"importedDataCountByArea"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"analyticalAreaType"},"value":{"kind":"Variable","name":{"kind":"Name","value":"analyticalAreaType"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"gss"}},{"kind":"Field","name":{"kind":"Name","value":"count"}},{"kind":"Field","name":{"kind":"Name","value":"gssArea"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"point"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"geometry"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"coordinates"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; diff --git a/nextjs/src/components/hub/ConstituencyView.tsx b/nextjs/src/components/hub/ConstituencyView.tsx index c22288ef9..2f47a3dcc 100644 --- a/nextjs/src/components/hub/ConstituencyView.tsx +++ b/nextjs/src/components/hub/ConstituencyView.tsx @@ -45,6 +45,8 @@ export function ConstituencyView({ electoralCommission?.dates[0]?.pollingStation.station?.properties ) + const pollingAddresses = electoralCommission?.addresses || [] + if (!data?.name) { return (
@@ -209,7 +211,7 @@ export function ConstituencyView({ )} - {electoralCommission?.addresses ? ( + {pollingAddresses.length ? (

Select one of these addresses:

- ) : ( -
-

- No polling station found for your postcode - your council may - not have shared its data yet. You can also try  - - wheredoivote.co.uk - - . -

-
- )} + ) : null} {pollingStation ? (
@@ -259,7 +246,9 @@ export function ConstituencyView({
- ) : addressQuery.data ? ( + ) : null} + {/* Display "No polling station" message if none found and address chosen or no addresses to choose */} + {!pollingStation && (addressQuery.data || !pollingAddresses.length) ? (

No polling station found for this address - your council may diff --git a/nextjs/src/components/report/ReportMap.tsx b/nextjs/src/components/report/ReportMap.tsx index 11357635b..9835ea817 100644 --- a/nextjs/src/components/report/ReportMap.tsx +++ b/nextjs/src/components/report/ReportMap.tsx @@ -3,6 +3,8 @@ import { AnalyticalAreaType, DataSourceType, + GetElectoralCommissionDataQuery, + GetElectoralCommissionDataQueryVariables, MapReportConstituencyStatsQuery, MapReportConstituencyStatsQueryVariables, MapReportLayerAnalyticsQuery, @@ -29,6 +31,7 @@ import { layerColour, useLoadedMap, isConstituencyPanelOpenAtom, MAP_REPORT_LAYE import { constituencyPanelTabAtom } from "@/app/reports/[id]/ConstituenciesPanel"; import { authenticationHeaders } from "@/lib/auth"; import { BACKEND_URL } from "@/env"; +import { GET_ELECTORAL_COMMISSION_DATA } from "@/app/hub/render/[hostname]/map/queries"; const MAX_REGION_ZOOM = 8 export const MAX_CONSTITUENCY_ZOOM = 10 @@ -253,6 +256,26 @@ export function ReportMap () { ] const loading = loadingLayers.some((query) => query.execution.loading) + const [addressSlug, setAddressSlug] = useState(""); + + // TODO: Remove this query after the election + const addressQuery = useQuery< + GetElectoralCommissionDataQuery, + GetElectoralCommissionDataQueryVariables + >(GET_ELECTORAL_COMMISSION_DATA, { + variables: { + postcode: selectedPointData?.importedDataGeojsonPoint?.properties?.postcodeData?.postcode!, + addressSlug + }, + skip: !addressSlug || !selectedPointData?.importedDataGeojsonPoint?.properties?.postcodeData?.postcode, + }); + + const pollingStation = ( + addressQuery.data?.postcodeSearch.electoralCommission?.dates[0]?.pollingStation.station?.properties || + selectedPointData?.importedDataGeojsonPoint?.electoralCommission?.dates[0]?.pollingStation.station?.properties + ) + const pollingAddresses = selectedPointData?.importedDataGeojsonPoint?.electoralCommission?.addresses || [] + return ( <> {loading && ( @@ -280,10 +303,7 @@ export function ReportMap () { } onClick={() => setSelectedSourceMarker(null)} transformRequest={(url, resourceType) => { - if ( - url.includes(BACKEND_URL) && - !url.includes("tiles.json") - ) { + if (url.includes(BACKEND_URL) && !url.includes("tiles.json")) { return { url, headers: authenticationHeaders(), @@ -589,6 +609,66 @@ export function ReportMap () { } )} + {/* TODO: Remove this