diff --git a/met-api/src/met_api/resources/survey.py b/met-api/src/met_api/resources/survey.py index c96175120..47ada3f64 100644 --- a/met-api/src/met_api/resources/survey.py +++ b/met-api/src/met_api/resources/survey.py @@ -97,11 +97,14 @@ def get(): published_date_to=args.get('published_date_to', None, type=str), ) + reduce_data = args.get('reduce_data', default=False, type=lambda v: v.lower() == 'true') + survey_records = SurveyService()\ .get_surveys_paginated( user_id, pagination_options, search_options, + reduce_data, ) return survey_records, HTTPStatus.OK except ValueError as err: diff --git a/met-api/src/met_api/services/survey_service.py b/met-api/src/met_api/services/survey_service.py index 61cc05acc..9010105c1 100644 --- a/met-api/src/met_api/services/survey_service.py +++ b/met-api/src/met_api/services/survey_service.py @@ -69,7 +69,7 @@ def get_open(cls, survey_id): return survey @staticmethod - def get_surveys_paginated(user_id, pagination_options: PaginationOptions, search_options: SurveySearchOptions): + def get_surveys_paginated(user_id, pagination_options: PaginationOptions, search_options: SurveySearchOptions, reduce_data: bool): """Get engagements paginated.""" # check if user has view all surveys access to view hidden surveys as well user_roles = TokenInfo.get_user_roles() @@ -87,7 +87,12 @@ def get_surveys_paginated(user_id, pagination_options: PaginationOptions, search pagination_options, search_options, ) - surveys_schema = SurveySchema(many=True) + # surveys_schema = ReducedSurveySchema(many=True) if reduced_data else SurveySchema(many=True) + + if reduce_data: + surveys_schema = SurveySchema(many=True, only=("id", "name")) + else: + surveys_schema = SurveySchema(many=True) return { 'items': surveys_schema.dump(items), diff --git a/met-web/src/components/survey/create/OptionsForm.tsx b/met-web/src/components/survey/create/OptionsForm.tsx index a81317896..b39175d98 100644 --- a/met-web/src/components/survey/create/OptionsForm.tsx +++ b/met-web/src/components/survey/create/OptionsForm.tsx @@ -26,17 +26,20 @@ const OptionsForm = () => { const handleFetchSurveys = async () => { try { - const fetchedLinkableSurveys = await fetchSurveys({ - is_unlinked: true, - exclude_hidden: true, - exclude_template: true, - }); - setAvailableLinkSurveys(fetchedLinkableSurveys); - - const fetchedClonableSurveys = await fetchSurveys({ - exclude_hidden: true, - }); + const [fetchedLinkableSurveys, fetchedClonableSurveys] = await Promise.all([ + fetchSurveys({ + is_unlinked: true, + exclude_hidden: true, + exclude_template: true, + reduce_data: true, + }), + fetchSurveys({ + exclude_hidden: true, + reduce_data: true, + }), + ]); + setAvailableLinkSurveys(fetchedLinkableSurveys); setAvailableCloneSurveys(fetchedClonableSurveys); setLoadingSurveys(false); } catch (error) { diff --git a/met-web/src/services/surveyService/index.ts b/met-web/src/services/surveyService/index.ts index 08b6c390f..c9e64b12e 100644 --- a/met-web/src/services/surveyService/index.ts +++ b/met-web/src/services/surveyService/index.ts @@ -8,6 +8,7 @@ interface FetchSurveyParams { is_unlinked?: boolean; exclude_hidden?: boolean; exclude_template?: boolean; + reduce_data?: boolean; } export const fetchSurveys = async (params: FetchSurveyParams = {}): Promise => { const responseData = await http.GetRequest>(Endpoints.Survey.GET_LIST, { ...params });