From f53b4e46dfb0bb99085b3bfa055633a68ad39731 Mon Sep 17 00:00:00 2001 From: ev <4164774+ev-sc@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:20:17 +0000 Subject: [PATCH] Revert query changes --- nextjs/src/__generated__/gql.ts | 9 ++- nextjs/src/__generated__/graphql.ts | 14 +++- .../[id]/addCountByGssToMapboxLayer.ts | 3 +- nextjs/src/app/reports/[id]/gql_queries.ts | 37 ++++++++++- .../app/reports/[id]/useBoundaryAnalytics.ts | 66 +++++++++++-------- 5 files changed, 90 insertions(+), 39 deletions(-) diff --git a/nextjs/src/__generated__/gql.ts b/nextjs/src/__generated__/gql.ts index 0a16cc24e..8099a69b4 100644 --- a/nextjs/src/__generated__/gql.ts +++ b/nextjs/src/__generated__/gql.ts @@ -54,10 +54,11 @@ const documents = { "\n query GetPage($hostname: String!, $path: String) {\n hubPageByPath(hostname: $hostname, path: $path) {\n id\n title\n path\n puckJsonContent\n seoTitle\n searchDescription\n hub {\n faviconUrl\n seoTitle\n seoImageUrl\n searchDescription\n primaryColour\n secondaryColour\n customCss\n navLinks {\n link\n label\n }\n }\n }\n }\n": types.GetPageDocument, "\n query ConstituencyStatsOverview(\n $reportID: ID!\n $analyticalAreaType: AnalyticalAreaType!\n ) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByConstituency: importedDataCountByArea(\n analyticalAreaType: $analyticalAreaType\n ) {\n label\n gss\n count\n gssArea {\n id\n name\n fitBounds\n mp: person(filters: { personType: \"MP\" }) {\n id\n name\n photo {\n url\n }\n party: personDatum(filters: { dataType_Name: \"party\" }) {\n name: data\n }\n }\n lastElection {\n stats {\n date\n majority\n electorate\n firstPartyResult {\n party\n shade\n votes\n }\n secondPartyResult {\n party\n shade\n votes\n }\n }\n }\n }\n }\n }\n }\n": types.ConstituencyStatsOverviewDocument, "\n query GetConstituencyData(\n $analyticalAreaType: AnalyticalAreaType!\n $gss: String!\n $reportID: ID!\n ) {\n constituency: area(gss: $gss, analyticalAreaType: $analyticalAreaType) {\n id\n name\n mp: person(filters: { personType: \"MP\" }) {\n id\n name\n photo {\n url\n }\n party: personDatum(filters: { dataType_Name: \"party\" }) {\n name: data\n shade\n }\n }\n lastElection {\n stats {\n date\n electorate\n validVotes\n majority\n firstPartyResult {\n party\n shade\n votes\n }\n secondPartyResult {\n party\n shade\n votes\n }\n }\n }\n }\n mapReport(pk: $reportID) {\n id\n importedDataCountForConstituency: importedDataCountForArea(\n analyticalAreaType: $analyticalAreaType\n gss: $gss\n ) {\n gss\n count\n }\n layers {\n id\n name\n source {\n id\n importedDataCountForConstituency: importedDataCountForArea(\n analyticalAreaType: $analyticalAreaType\n gss: $gss\n ) {\n gss\n count\n }\n }\n }\n }\n }\n": types.GetConstituencyDataDocument, + "\n query MapReportWardStats($reportID: ID!) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByWard {\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.MapReportWardStatsDocument, "\n query 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 address\n json\n remoteUrl\n dataType {\n dataSet {\n externalDataSource {\n name\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 dataType\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 MapReportAreaStats(\n $reportID: ID!\n $analyticalAreaType: AnalyticalAreaType!\n ) {\n mapReport(pk: $reportID) {\n id\n 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.MapReportAreaStatsDocument, + "\n query MapReportConstituencyStats(\n $reportID: ID!\n $analyticalAreaType: AnalyticalAreaType!\n ) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByConstituency: importedDataCountByArea(\n analyticalAreaType: $analyticalAreaType\n ) {\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, "\n query GetMapReport($id: ID!) {\n mapReport(pk: $id) {\n id\n name\n slug\n displayOptions\n organisation {\n id\n slug\n name\n }\n ...MapReportPage\n }\n }\n \n": types.GetMapReportDocument, "\n mutation UpdateMapReport($input: MapReportInput!) {\n updateMapReport(data: $input) {\n id\n name\n displayOptions\n layers {\n id\n name\n source {\n id\n name\n }\n }\n }\n }\n": types.UpdateMapReportDocument, "\n mutation DeleteMapReport($id: IDObject!) {\n deleteMapReport(data: $id) {\n id\n }\n }\n": types.DeleteMapReportDocument, @@ -264,6 +265,10 @@ export function gql(source: "\n query ConstituencyStatsOverview(\n $reportID * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function gql(source: "\n query GetConstituencyData(\n $analyticalAreaType: AnalyticalAreaType!\n $gss: String!\n $reportID: ID!\n ) {\n constituency: area(gss: $gss, analyticalAreaType: $analyticalAreaType) {\n id\n name\n mp: person(filters: { personType: \"MP\" }) {\n id\n name\n photo {\n url\n }\n party: personDatum(filters: { dataType_Name: \"party\" }) {\n name: data\n shade\n }\n }\n lastElection {\n stats {\n date\n electorate\n validVotes\n majority\n firstPartyResult {\n party\n shade\n votes\n }\n secondPartyResult {\n party\n shade\n votes\n }\n }\n }\n }\n mapReport(pk: $reportID) {\n id\n importedDataCountForConstituency: importedDataCountForArea(\n analyticalAreaType: $analyticalAreaType\n gss: $gss\n ) {\n gss\n count\n }\n layers {\n id\n name\n source {\n id\n importedDataCountForConstituency: importedDataCountForArea(\n analyticalAreaType: $analyticalAreaType\n gss: $gss\n ) {\n gss\n count\n }\n }\n }\n }\n }\n"): (typeof documents)["\n query GetConstituencyData(\n $analyticalAreaType: AnalyticalAreaType!\n $gss: String!\n $reportID: ID!\n ) {\n constituency: area(gss: $gss, analyticalAreaType: $analyticalAreaType) {\n id\n name\n mp: person(filters: { personType: \"MP\" }) {\n id\n name\n photo {\n url\n }\n party: personDatum(filters: { dataType_Name: \"party\" }) {\n name: data\n shade\n }\n }\n lastElection {\n stats {\n date\n electorate\n validVotes\n majority\n firstPartyResult {\n party\n shade\n votes\n }\n secondPartyResult {\n party\n shade\n votes\n }\n }\n }\n }\n mapReport(pk: $reportID) {\n id\n importedDataCountForConstituency: importedDataCountForArea(\n analyticalAreaType: $analyticalAreaType\n gss: $gss\n ) {\n gss\n count\n }\n layers {\n id\n name\n source {\n id\n importedDataCountForConstituency: importedDataCountForArea(\n analyticalAreaType: $analyticalAreaType\n gss: $gss\n ) {\n gss\n count\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. + */ +export function gql(source: "\n query MapReportWardStats($reportID: ID!) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByWard {\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"): (typeof documents)["\n query MapReportWardStats($reportID: ID!) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByWard {\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"]; /** * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ @@ -279,7 +284,7 @@ export function gql(source: "\n query MapReportRegionStats($reportID: ID!) {\n /** * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function gql(source: "\n query MapReportAreaStats(\n $reportID: ID!\n $analyticalAreaType: AnalyticalAreaType!\n ) {\n mapReport(pk: $reportID) {\n id\n 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"): (typeof documents)["\n query MapReportAreaStats(\n $reportID: ID!\n $analyticalAreaType: AnalyticalAreaType!\n ) {\n mapReport(pk: $reportID) {\n id\n 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"]; +export function gql(source: "\n query MapReportConstituencyStats(\n $reportID: ID!\n $analyticalAreaType: AnalyticalAreaType!\n ) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByConstituency: importedDataCountByArea(\n analyticalAreaType: $analyticalAreaType\n ) {\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"): (typeof documents)["\n query MapReportConstituencyStats(\n $reportID: ID!\n $analyticalAreaType: AnalyticalAreaType!\n ) {\n mapReport(pk: $reportID) {\n id\n importedDataCountByConstituency: importedDataCountByArea(\n analyticalAreaType: $analyticalAreaType\n ) {\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"]; /** * 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 4f7cb0577..e420a1a26 100644 --- a/nextjs/src/__generated__/graphql.ts +++ b/nextjs/src/__generated__/graphql.ts @@ -3137,6 +3137,13 @@ export type GetConstituencyDataQueryVariables = Exact<{ export type GetConstituencyDataQuery = { __typename?: 'Query', constituency?: { __typename?: 'Area', id: string, name: string, mp?: { __typename?: 'Person', id: string, name: string, photo?: { __typename?: 'DjangoImageType', url: string } | null, party?: { __typename?: 'PersonData', shade?: string | null, name: string } | null } | null, lastElection?: { __typename?: 'ConstituencyElectionResult', stats: { __typename?: 'ConstituencyElectionStats', date: string, electorate: number, validVotes: number, majority: number, firstPartyResult: { __typename?: 'PartyResult', party: string, shade: string, votes: number }, secondPartyResult: { __typename?: 'PartyResult', party: string, shade: string, votes: number } } } | null } | null, mapReport: { __typename?: 'MapReport', id: any, importedDataCountForConstituency?: { __typename?: 'GroupedDataCount', gss?: string | null, count: number } | null, layers: Array<{ __typename?: 'MapLayer', id: string, name: string, source: { __typename?: 'SharedDataSource', id: any, importedDataCountForConstituency?: { __typename?: 'GroupedDataCount', gss?: string | null, count: number } | null } }> } }; +export type MapReportWardStatsQueryVariables = Exact<{ + reportID: Scalars['ID']['input']; +}>; + + +export type MapReportWardStatsQuery = { __typename?: 'Query', mapReport: { __typename?: 'MapReport', id: any, importedDataCountByWard: Array<{ __typename?: 'GroupedDataCount', label?: string | null, gss?: string | null, count: number, gssArea?: { __typename?: 'Area', point?: { __typename?: 'PointFeature', id?: string | null, type: GeoJsonTypes, geometry: { __typename?: 'PointGeometry', type: GeoJsonTypes, coordinates: Array } } | null } | null }> } }; + export type MapReportLayerGeoJsonPointQueryVariables = Exact<{ genericDataId: Scalars['String']['input']; }>; @@ -3158,13 +3165,13 @@ export type MapReportRegionStatsQueryVariables = Exact<{ export type MapReportRegionStatsQuery = { __typename?: 'Query', mapReport: { __typename?: 'MapReport', id: any, importedDataCountByRegion: Array<{ __typename?: 'GroupedDataCount', label?: string | null, gss?: string | null, count: number, gssArea?: { __typename?: 'Area', point?: { __typename?: 'PointFeature', id?: string | null, type: GeoJsonTypes, geometry: { __typename?: 'PointGeometry', type: GeoJsonTypes, coordinates: Array } } | null } | null }> } }; -export type MapReportAreaStatsQueryVariables = Exact<{ +export type MapReportConstituencyStatsQueryVariables = Exact<{ reportID: Scalars['ID']['input']; analyticalAreaType: AnalyticalAreaType; }>; -export type MapReportAreaStatsQuery = { __typename?: 'Query', mapReport: { __typename?: 'MapReport', id: any, importedDataCountByArea: Array<{ __typename?: 'GroupedDataCount', label?: string | null, gss?: string | null, count: number, gssArea?: { __typename?: 'Area', point?: { __typename?: 'PointFeature', id?: string | null, type: GeoJsonTypes, geometry: { __typename?: 'PointGeometry', type: GeoJsonTypes, coordinates: Array } } | null } | null }> } }; +export type MapReportConstituencyStatsQuery = { __typename?: 'Query', mapReport: { __typename?: 'MapReport', id: any, importedDataCountByConstituency: Array<{ __typename?: 'GroupedDataCount', label?: string | null, gss?: string | null, count: number, gssArea?: { __typename?: 'Area', point?: { __typename?: 'PointFeature', id?: string | null, type: GeoJsonTypes, geometry: { __typename?: 'PointGeometry', type: GeoJsonTypes, coordinates: Array } } | null } | null }> } }; export type GetMapReportQueryVariables = Exact<{ id: Scalars['ID']['input']; @@ -3402,10 +3409,11 @@ export const GetEventDataDocument = {"kind":"Document","definitions":[{"kind":"O export const GetPageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetPage"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"hostname"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"path"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hubPageByPath"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"hostname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"hostname"}}},{"kind":"Argument","name":{"kind":"Name","value":"path"},"value":{"kind":"Variable","name":{"kind":"Name","value":"path"}}}],"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":"puckJsonContent"}},{"kind":"Field","name":{"kind":"Name","value":"seoTitle"}},{"kind":"Field","name":{"kind":"Name","value":"searchDescription"}},{"kind":"Field","name":{"kind":"Name","value":"hub"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"faviconUrl"}},{"kind":"Field","name":{"kind":"Name","value":"seoTitle"}},{"kind":"Field","name":{"kind":"Name","value":"seoImageUrl"}},{"kind":"Field","name":{"kind":"Name","value":"searchDescription"}},{"kind":"Field","name":{"kind":"Name","value":"primaryColour"}},{"kind":"Field","name":{"kind":"Name","value":"secondaryColour"}},{"kind":"Field","name":{"kind":"Name","value":"customCss"}},{"kind":"Field","name":{"kind":"Name","value":"navLinks"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"link"}},{"kind":"Field","name":{"kind":"Name","value":"label"}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const ConstituencyStatsOverviewDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ConstituencyStatsOverview"},"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":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"fitBounds"}},{"kind":"Field","alias":{"kind":"Name","value":"mp"},"name":{"kind":"Name","value":"person"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"personType"},"value":{"kind":"StringValue","value":"MP","block":false}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"photo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"url"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"party"},"name":{"kind":"Name","value":"personDatum"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"dataType_Name"},"value":{"kind":"StringValue","value":"party","block":false}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"name"},"name":{"kind":"Name","value":"data"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"lastElection"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"stats"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"date"}},{"kind":"Field","name":{"kind":"Name","value":"majority"}},{"kind":"Field","name":{"kind":"Name","value":"electorate"}},{"kind":"Field","name":{"kind":"Name","value":"firstPartyResult"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"party"}},{"kind":"Field","name":{"kind":"Name","value":"shade"}},{"kind":"Field","name":{"kind":"Name","value":"votes"}}]}},{"kind":"Field","name":{"kind":"Name","value":"secondPartyResult"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"party"}},{"kind":"Field","name":{"kind":"Name","value":"shade"}},{"kind":"Field","name":{"kind":"Name","value":"votes"}}]}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const GetConstituencyDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetConstituencyData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"analyticalAreaType"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AnalyticalAreaType"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"gss"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"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","alias":{"kind":"Name","value":"constituency"},"name":{"kind":"Name","value":"area"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"gss"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gss"}}},{"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":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","alias":{"kind":"Name","value":"mp"},"name":{"kind":"Name","value":"person"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"personType"},"value":{"kind":"StringValue","value":"MP","block":false}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"photo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"url"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"party"},"name":{"kind":"Name","value":"personDatum"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"dataType_Name"},"value":{"kind":"StringValue","value":"party","block":false}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"name"},"name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"shade"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"lastElection"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"stats"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"date"}},{"kind":"Field","name":{"kind":"Name","value":"electorate"}},{"kind":"Field","name":{"kind":"Name","value":"validVotes"}},{"kind":"Field","name":{"kind":"Name","value":"majority"}},{"kind":"Field","name":{"kind":"Name","value":"firstPartyResult"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"party"}},{"kind":"Field","name":{"kind":"Name","value":"shade"}},{"kind":"Field","name":{"kind":"Name","value":"votes"}}]}},{"kind":"Field","name":{"kind":"Name","value":"secondPartyResult"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"party"}},{"kind":"Field","name":{"kind":"Name","value":"shade"}},{"kind":"Field","name":{"kind":"Name","value":"votes"}}]}}]}}]}}]}},{"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":"importedDataCountForConstituency"},"name":{"kind":"Name","value":"importedDataCountForArea"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"analyticalAreaType"},"value":{"kind":"Variable","name":{"kind":"Name","value":"analyticalAreaType"}}},{"kind":"Argument","name":{"kind":"Name","value":"gss"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gss"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"gss"}},{"kind":"Field","name":{"kind":"Name","value":"count"}}]}},{"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","alias":{"kind":"Name","value":"importedDataCountForConstituency"},"name":{"kind":"Name","value":"importedDataCountForArea"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"analyticalAreaType"},"value":{"kind":"Variable","name":{"kind":"Name","value":"analyticalAreaType"}}},{"kind":"Argument","name":{"kind":"Name","value":"gss"},"value":{"kind":"Variable","name":{"kind":"Name","value":"gss"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"gss"}},{"kind":"Field","name":{"kind":"Name","value":"count"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; +export const MapReportWardStatsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MapReportWardStats"},"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":"importedDataCountByWard"},"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 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":"address"}},{"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 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":"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 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 MapReportAreaStatsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MapReportAreaStats"},"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","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; +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; export const GetMapReportDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetMapReport"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"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":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"slug"}},{"kind":"Field","name":{"kind":"Name","value":"displayOptions"}},{"kind":"Field","name":{"kind":"Name","value":"organisation"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"slug"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"MapReportPage"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MapReportLayersSummary"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MapReport"}},"selectionSet":{"kind":"SelectionSet","selections":[{"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":"sharingPermission"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"visibilityRecordDetails"}},{"kind":"Field","name":{"kind":"Name","value":"visibilityRecordCoordinates"}},{"kind":"Field","name":{"kind":"Name","value":"organisation"},"selectionSet":{"kind":"SelectionSet","selections":[{"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":"name"}},{"kind":"Field","name":{"kind":"Name","value":"isImportScheduled"}},{"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"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MapReportPage"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MapReport"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"MapReportLayersSummary"}}]}}]} as unknown as DocumentNode; export const UpdateMapReportDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateMapReport"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"MapReportInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateMapReport"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"data"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"displayOptions"}},{"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":"name"}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const DeleteMapReportDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteMapReport"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IDObject"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteMapReport"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"data"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode; diff --git a/nextjs/src/app/reports/[id]/addCountByGssToMapboxLayer.ts b/nextjs/src/app/reports/[id]/addCountByGssToMapboxLayer.ts index 50341b68f..4f3853d1e 100644 --- a/nextjs/src/app/reports/[id]/addCountByGssToMapboxLayer.ts +++ b/nextjs/src/app/reports/[id]/addCountByGssToMapboxLayer.ts @@ -1,12 +1,11 @@ import { MAPBOX_LOAD_INTERVAL } from '@/lib/map/useLoadedMap' import { MapRef } from 'react-map-gl' -import { BoundaryAnalytics } from './useBoundaryAnalytics' // GSS (Geographic Statistical System) codes are unique identifiers // used in the UK to reference geographic areas for statistical purposes. // The data prop needs to contain the gss code and the count export function addCountByGssToMapboxLayer( - data: BoundaryAnalytics, + data: { gss?: string | null; count: number }[], mapboxSourceId: string, sourceLayerId?: string, mapbox?: MapRef | null diff --git a/nextjs/src/app/reports/[id]/gql_queries.ts b/nextjs/src/app/reports/[id]/gql_queries.ts index 5f1baf54b..c0d2fcf9d 100644 --- a/nextjs/src/app/reports/[id]/gql_queries.ts +++ b/nextjs/src/app/reports/[id]/gql_queries.ts @@ -4,6 +4,35 @@ import { gql } from '@apollo/client' import { MAP_REPORT_FRAGMENT } from '@/lib/map' +// TODO: In general, make these query names more consistent with their actual function and return data +// for example, "_STATS" is ambiguous now that we're moving into the phase +// of not just returning row counts for every geographic query. +// Also, "MAP_REPORT" is redundant, since the queries take a report ID as an argument. +// These should be replaced by e.g. DATA_SOURCE_ROW_COUNT_BY_WARD + +export const MAP_REPORT_WARD_STATS = gql` + query MapReportWardStats($reportID: ID!) { + mapReport(pk: $reportID) { + id + importedDataCountByWard { + label + gss + count + gssArea { + point { + id + type + geometry { + type + coordinates + } + } + } + } + } + } +` + export const MAP_REPORT_LAYER_POINT = gql` query MapReportLayerGeoJSONPoint($genericDataId: String!) { importedDataGeojsonPoint(genericDataId: $genericDataId) { @@ -77,14 +106,16 @@ export const MAP_REPORT_REGION_STATS = gql` } } ` -export const MAP_REPORT_AREA_STATS = gql` - query MapReportAreaStats( +export const MAP_REPORT_CONSTITUENCY_STATS = gql` + query MapReportConstituencyStats( $reportID: ID! $analyticalAreaType: AnalyticalAreaType! ) { mapReport(pk: $reportID) { id - importedDataCountByArea(analyticalAreaType: $analyticalAreaType) { + importedDataCountByConstituency: importedDataCountByArea( + analyticalAreaType: $analyticalAreaType + ) { label gss count diff --git a/nextjs/src/app/reports/[id]/useBoundaryAnalytics.ts b/nextjs/src/app/reports/[id]/useBoundaryAnalytics.ts index 16a94eda6..557e4c2d5 100644 --- a/nextjs/src/app/reports/[id]/useBoundaryAnalytics.ts +++ b/nextjs/src/app/reports/[id]/useBoundaryAnalytics.ts @@ -1,40 +1,48 @@ -import { - AnalyticalAreaType, - MapReportAreaStatsQuery, - MapReportAreaStatsQueryVariables, -} from '@/__generated__/graphql' +import { AnalyticalAreaType } from '@/__generated__/graphql' import { useQuery } from '@apollo/client' -import { MAP_REPORT_AREA_STATS } from './gql_queries' +import { useEffect, useState } from 'react' +import { + MAP_REPORT_CONSTITUENCY_STATS, + MAP_REPORT_WARD_STATS, +} from './gql_queries' import { MapReportExtended } from './reportContext' -export default function useBoundaryAnalytics( +const useBoundaryAnalytics = ( report: MapReportExtended | undefined, boundaryType: AnalyticalAreaType -) { - if (!ENABLED_ANALYTICAL_AREA_TYPES.includes(boundaryType)) { - throw new Error('Invalid boundary type') +) => { + const [canQuery, setCanQuery] = useState(false) + + useEffect(() => { + if (report) { + setCanQuery(true) + } + }, [report]) + + let query + let variables: any = { + reportID: report?.id, } + let dataOutputKey - const canQuery = !!report + // TODO: This is where we can implement arithmetic operations on data from multiple + // sources, such as the sum of member count per political boundary from two different + // organisation's membership lists - const boundaryAnalytics = useQuery< - MapReportAreaStatsQuery, - MapReportAreaStatsQueryVariables - >(MAP_REPORT_AREA_STATS, { - variables: { - reportID: report?.id, - analyticalAreaType: boundaryType, - }, - skip: !canQuery, - }) + // All the queries below do is return membership counts by boundary type + if (boundaryType === 'parliamentary_constituency_2024') { + query = MAP_REPORT_CONSTITUENCY_STATS + variables.analyticalAreaType = + AnalyticalAreaType.ParliamentaryConstituency_2024 + dataOutputKey = 'importedDataCountByConstituency' + } else if (boundaryType === 'admin_ward') { + query = MAP_REPORT_WARD_STATS + dataOutputKey = 'importedDataCountByWard' + } else throw new Error('Invalid boundary type') - return boundaryAnalytics.data?.mapReport.importedDataCountByArea || [] -} + const boundaryAnalytics = useQuery(query, { variables, skip: !canQuery }) -export type BoundaryAnalytics = ReturnType + return boundaryAnalytics.data?.mapReport[dataOutputKey] +} -const ENABLED_ANALYTICAL_AREA_TYPES = [ - AnalyticalAreaType.ParliamentaryConstituency_2024, - AnalyticalAreaType.AdminWard, - AnalyticalAreaType.AdminDistrict, -] +export default useBoundaryAnalytics