From 6e17032d3383779b2c1c891087983c4077ea82da Mon Sep 17 00:00:00 2001 From: Jan Baykara Date: Tue, 12 Mar 2024 14:55:19 +0000 Subject: [PATCH] Disable custom data source mapping for now --- hub/models.py | 24 +++++++------- nextjs/src/components/UpdateMappingForm.tsx | 36 ++++++++++++--------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/hub/models.py b/hub/models.py index 8f90127d6..9de04500f 100644 --- a/hub/models.py +++ b/hub/models.py @@ -1057,17 +1057,19 @@ async def map_one(self, member: Union[str, dict], loaders: Loaders) -> MappedMem if postcode_data is not None: update_fields[destination_column] = get(postcode_data, source_path) else: - print("Custom enrichment layer requested", source, source_path, destination_column) - update_value = await loaders['source_loaders'][source].load( - self.EnrichmentLookup( - member_id=self.get_record_id(member), - postcode_data=postcode_data, - source_id=source, - source_path=source_path - ) - ) - print("Custom mapping", source, source_path, update_value) - update_fields[destination_column] = get(update_value['source_data'], source_path) + pass + # TODO: fix this — there's an async error when making Django requests inside the source_loader DataLoaders — then re-enable. + # print("Custom enrichment layer requested", source, source_path, destination_column) + # update_value = await loaders['source_loaders'][source].load( + # self.EnrichmentLookup( + # member_id=self.get_record_id(member), + # postcode_data=postcode_data, + # source_id=source, + # source_path=source_path + # ) + # ) + # print("Custom mapping", source, source_path, update_value) + # update_fields[destination_column] = get(update_value['source_data'], source_path) # Return the member and config data return self.MappedMember( member=member, diff --git a/nextjs/src/components/UpdateMappingForm.tsx b/nextjs/src/components/UpdateMappingForm.tsx index ce0febc35..5d26c5ebc 100644 --- a/nextjs/src/components/UpdateMappingForm.tsx +++ b/nextjs/src/components/UpdateMappingForm.tsx @@ -26,6 +26,7 @@ import { SelectValue, } from "@/components/ui/select" import { gql, useQuery } from "@apollo/client"; +import { useMemo } from "react"; const ENRICHMENT_LAYERS = gql` query EnrichmentLayers { @@ -67,7 +68,25 @@ export function UpdateMappingForm({ }, ); - const customEnrichmentLayers = useQuery(ENRICHMENT_LAYERS) + // TODO: Fix source_loader code in API, then re-enable this + // const customEnrichmentLayers = useQuery(ENRICHMENT_LAYERS) + // const sources: EnrichmentDataSource[] = useMemo(() => { + // return enrichmentDataSources.concat( + // customEnrichmentLayers.data?.externalDataSources + // .filter(source => !!source.geographyColumn) + // .map((source) => ({ + // slug: source.id, + // name: source.name, + // author: "", + // description: "", + // descriptionURL: "", + // colour: "", + // builtIn: false, + // sourcePaths: source.fieldDefinitions || [] + // })) || [] + // ) + // }, [enrichmentDataSources, customEnrichmentLayers.data?.externalDataSources]) + const sources = enrichmentDataSources return ( @@ -135,20 +154,7 @@ export function UpdateMappingForm({ !!source.geographyColumn) - .map((source) => ({ - slug: source.id, - name: source.name, - author: "", - description: "", - descriptionURL: "", - colour: "", - builtIn: false, - sourcePaths: source.fieldDefinitions || [] - })) || [] - )} + sources={sources} value={{ source: form.watch(`updateMapping.${index}.source`), sourcePath: form.watch(`updateMapping.${index}.sourcePath`),