diff --git a/packages/pxweb2-api-client/src/index.ts b/packages/pxweb2-api-client/src/index.ts index 47dfbf5c6..edfa273d1 100644 --- a/packages/pxweb2-api-client/src/index.ts +++ b/packages/pxweb2-api-client/src/index.ts @@ -11,13 +11,13 @@ export { Adjustment } from './models/Adjustment'; export type { ApiFeature } from './models/ApiFeature'; export type { BasePeriod } from './models/BasePeriod'; export { ClassType } from './models/ClassType'; -export type { codeListId } from './models/codeListId'; -export type { CodeListInformation } from './models/CodeListInformation'; -export type { CodeListMetadata } from './models/CodeListMetadata'; -export type { CodeListResponse } from './models/CodeListResponse'; -export type { CodeLists } from './models/CodeLists'; -export type { CodeListsResponse } from './models/CodeListsResponse'; -export { CodeListType } from './models/CodeListType'; +export type { codelistId } from './models/codelistId'; +export type { CodelistInformation } from './models/CodelistInformation'; +export type { CodelistMetadata } from './models/CodelistMetadata'; +export type { CodelistResponse } from './models/CodelistResponse'; +export type { Codelists } from './models/Codelists'; +export type { CodelistsResponse } from './models/CodelistsResponse'; +export { CodelistType } from './models/CodelistType'; export type { ConfigResponse } from './models/ConfigResponse'; export type { Contact } from './models/Contact'; export { Dataset } from './models/Dataset'; @@ -26,14 +26,9 @@ export type { Discontinued } from './models/Discontinued'; export type { extension } from './models/extension'; export type { extension_dimension } from './models/extension_dimension'; export type { extension_root } from './models/extension_root'; -export type { FolderContentItem } from './models/FolderContentItem'; -export { FolderContentItemTypeEnum } from './models/FolderContentItemTypeEnum'; -export type { FolderInformation } from './models/FolderInformation'; -export type { FolderResponse } from './models/FolderResponse'; -export type { Heading } from './models/Heading'; export type { href } from './models/href'; export type { id } from './models/id'; -export type { include_discontinued } from './models/include_discontinued'; +export type { includeDiscontinued } from './models/includeDiscontinued'; export type { jsonstat_category } from './models/jsonstat_category'; export type { jsonstat_extension_link } from './models/jsonstat_extension_link'; export type { jsonstat_link } from './models/jsonstat_link'; @@ -60,12 +55,14 @@ export type { Problem } from './models/Problem'; export type { query } from './models/query'; export type { Role } from './models/Role'; export type { SavedQuery } from './models/SavedQuery'; +export type { SavedQueryResponse } from './models/SavedQueryResponse'; export type { SelectionResponse } from './models/SelectionResponse'; export type { source } from './models/source'; export type { SourceReference } from './models/SourceReference'; export type { strarray } from './models/strarray'; export type { strarray_by_str_dict } from './models/strarray_by_str_dict'; -export { Table } from './models/Table'; +export type { Table } from './models/Table'; +export { TableCategory } from './models/TableCategory'; export type { TableResponse } from './models/TableResponse'; export type { TablesResponse } from './models/TablesResponse'; export { TimeUnit } from './models/TimeUnit'; @@ -75,7 +72,7 @@ export type { VariablePlacementType } from './models/VariablePlacementType'; export type { VariableSelection } from './models/VariableSelection'; export type { VariablesSelection } from './models/VariablesSelection'; +export { CodelistsService } from './services/CodelistsService'; export { ConfigurationService } from './services/ConfigurationService'; -export { NavigationService } from './services/NavigationService'; export { SavedQueriesService } from './services/SavedQueriesService'; -export { TableService } from './services/TableService'; +export { TablesService } from './services/TablesService'; diff --git a/packages/pxweb2-api-client/src/models/CodeListInformation.ts b/packages/pxweb2-api-client/src/models/CodelistInformation.ts similarity index 64% rename from packages/pxweb2-api-client/src/models/CodeListInformation.ts rename to packages/pxweb2-api-client/src/models/CodelistInformation.ts index 3e4060330..842afa787 100644 --- a/packages/pxweb2-api-client/src/models/CodeListInformation.ts +++ b/packages/pxweb2-api-client/src/models/CodelistInformation.ts @@ -2,18 +2,18 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { CodeListType } from './CodeListType'; +import type { CodelistType } from './CodelistType'; import type { Link } from './Link'; -export type CodeListInformation = { +export type CodelistInformation = { /** - * The identity of the CodeList + * The identity of the codelist */ id: string; /** - * A textual name for the CodeList + * A textual name for the codelist */ label: string; - type: CodeListType; + type: CodelistType; /** * Links to associated information about the code list */ diff --git a/packages/pxweb2-api-client/src/models/CodeListMetadata.ts b/packages/pxweb2-api-client/src/models/CodelistMetadata.ts similarity index 75% rename from packages/pxweb2-api-client/src/models/CodeListMetadata.ts rename to packages/pxweb2-api-client/src/models/CodelistMetadata.ts index 163663f67..f1df6d283 100644 --- a/packages/pxweb2-api-client/src/models/CodeListMetadata.ts +++ b/packages/pxweb2-api-client/src/models/CodelistMetadata.ts @@ -2,9 +2,9 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { CodeListType } from './CodeListType'; +import type { CodelistType } from './CodelistType'; import type { Link } from './Link'; -export type CodeListMetadata = { +export type CodelistMetadata = { /** * The identiyer for the codelist */ @@ -13,7 +13,7 @@ export type CodeListMetadata = { * The textual name for the codelist. */ label: string; - type: CodeListType; + type: CodelistType; links: Array; }; diff --git a/packages/pxweb2-api-client/src/models/CodeListResponse.ts b/packages/pxweb2-api-client/src/models/CodelistResponse.ts similarity index 89% rename from packages/pxweb2-api-client/src/models/CodeListResponse.ts rename to packages/pxweb2-api-client/src/models/CodelistResponse.ts index 5aa7e08d4..047f323a3 100644 --- a/packages/pxweb2-api-client/src/models/CodeListResponse.ts +++ b/packages/pxweb2-api-client/src/models/CodelistResponse.ts @@ -2,10 +2,10 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { CodeListType } from './CodeListType'; +import type { CodelistType } from './CodelistType'; import type { Link } from './Link'; import type { ValueMap } from './ValueMap'; -export type CodeListResponse = { +export type CodelistResponse = { /** * The identiyer for the codelist */ @@ -30,7 +30,7 @@ export type CodeListResponse = { * The value code that should be used for elimination. If not set the variable will be eliminated by summing up all values. */ eliminationValueCode?: string; - type: CodeListType; + type: CodelistType; values: Array; links: Array; }; diff --git a/packages/pxweb2-api-client/src/models/CodeListType.ts b/packages/pxweb2-api-client/src/models/CodelistType.ts similarity index 89% rename from packages/pxweb2-api-client/src/models/CodeListType.ts rename to packages/pxweb2-api-client/src/models/CodelistType.ts index a4e1c77be..d69f50332 100644 --- a/packages/pxweb2-api-client/src/models/CodeListType.ts +++ b/packages/pxweb2-api-client/src/models/CodelistType.ts @@ -5,7 +5,7 @@ /** * Type of codelist */ -export enum CodeListType { +export enum CodelistType { AGGREGATION = 'Aggregation', VALUESET = 'Valueset', } diff --git a/packages/pxweb2-api-client/src/models/CodeLists.ts b/packages/pxweb2-api-client/src/models/Codelists.ts similarity index 61% rename from packages/pxweb2-api-client/src/models/CodeLists.ts rename to packages/pxweb2-api-client/src/models/Codelists.ts index 08d820f14..6793ea243 100644 --- a/packages/pxweb2-api-client/src/models/CodeLists.ts +++ b/packages/pxweb2-api-client/src/models/Codelists.ts @@ -2,8 +2,8 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { CodeListInformation } from './CodeListInformation'; +import type { CodelistInformation } from './CodelistInformation'; /** * Available codelists for this dimension */ -export type CodeLists = Array; +export type Codelists = Array; diff --git a/packages/pxweb2-api-client/src/models/CodeListsResponse.ts b/packages/pxweb2-api-client/src/models/CodelistsResponse.ts similarity index 68% rename from packages/pxweb2-api-client/src/models/CodeListsResponse.ts rename to packages/pxweb2-api-client/src/models/CodelistsResponse.ts index ed148e0b9..dd6c5dff3 100644 --- a/packages/pxweb2-api-client/src/models/CodeListsResponse.ts +++ b/packages/pxweb2-api-client/src/models/CodelistsResponse.ts @@ -2,14 +2,14 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { CodeListMetadata } from './CodeListMetadata'; +import type { CodelistMetadata } from './CodelistMetadata'; import type { Link } from './Link'; -export type CodeListsResponse = { +export type CodelistsResponse = { /** * The language code for the language used in this response */ language: string; - codeLists?: Array; + codelists?: Array; links?: Array; }; diff --git a/packages/pxweb2-api-client/src/models/FolderContentItem.ts b/packages/pxweb2-api-client/src/models/FolderContentItem.ts deleted file mode 100644 index de564284f..000000000 --- a/packages/pxweb2-api-client/src/models/FolderContentItem.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* generated using openapi-typescript-codegen -- do not edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { FolderContentItemTypeEnum } from './FolderContentItemTypeEnum'; -/** - * Navigation item. - */ -export type FolderContentItem = { - /** - * One of Heading, Table or FolderInformation - */ - type: FolderContentItemTypeEnum; - id: string; - /** - * Display text - */ - label: string | null; - /** - * Longer text describing node. - */ - description?: string | null; - /** - * String for sorting the contents in folder - */ - sortCode?: string; -}; - diff --git a/packages/pxweb2-api-client/src/models/FolderContentItemTypeEnum.ts b/packages/pxweb2-api-client/src/models/FolderContentItemTypeEnum.ts deleted file mode 100644 index a4ebc67dc..000000000 --- a/packages/pxweb2-api-client/src/models/FolderContentItemTypeEnum.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* generated using openapi-typescript-codegen -- do not edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export enum FolderContentItemTypeEnum { - HEADING = 'Heading', - FOLDER_INFORMATION = 'FolderInformation', - TABLE = 'Table', -} diff --git a/packages/pxweb2-api-client/src/models/FolderInformation.ts b/packages/pxweb2-api-client/src/models/FolderInformation.ts deleted file mode 100644 index c3e63fae9..000000000 --- a/packages/pxweb2-api-client/src/models/FolderInformation.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* generated using openapi-typescript-codegen -- do not edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { FolderContentItem } from './FolderContentItem'; -import type { Link } from './Link'; -/** - * Folder information item - */ -export type FolderInformation = (FolderContentItem & { - tags?: Array; - /** - * Links to ... - */ - links: Array | null; -}); - diff --git a/packages/pxweb2-api-client/src/models/FolderResponse.ts b/packages/pxweb2-api-client/src/models/FolderResponse.ts deleted file mode 100644 index e3a575a5d..000000000 --- a/packages/pxweb2-api-client/src/models/FolderResponse.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* generated using openapi-typescript-codegen -- do not edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { FolderContentItem } from './FolderContentItem'; -import type { Link } from './Link'; -/** - * Folder item - */ -export type FolderResponse = { - /** - * The language code (ISO 639) for this response - */ - language: string; - id: string | null; - /** - * Display text - */ - label: string | null; - /** - * Longer text describing node. - */ - description?: string | null; - tags?: Array; - folderContents: Array | null; - /** - * Links to ... - */ - links: Array | null; -}; - diff --git a/packages/pxweb2-api-client/src/models/Heading.ts b/packages/pxweb2-api-client/src/models/Heading.ts deleted file mode 100644 index 4b0dec82b..000000000 --- a/packages/pxweb2-api-client/src/models/Heading.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* generated using openapi-typescript-codegen -- do not edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { FolderContentItem } from './FolderContentItem'; -/** - * Heading item - */ -export type Heading = FolderContentItem; - diff --git a/packages/pxweb2-api-client/src/models/SavedQueryResponse.ts b/packages/pxweb2-api-client/src/models/SavedQueryResponse.ts new file mode 100644 index 000000000..37d9bc878 --- /dev/null +++ b/packages/pxweb2-api-client/src/models/SavedQueryResponse.ts @@ -0,0 +1,19 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Link } from './Link'; +import type { SavedQuery } from './SavedQuery'; +export type SavedQueryResponse = { + /** + * The language code for the language requested + */ + language: string; + /** + * The id of the saved query + */ + id: string; + savedQuery: SavedQuery; + links: Array; +}; + diff --git a/packages/pxweb2-api-client/src/models/Table.ts b/packages/pxweb2-api-client/src/models/Table.ts index 9acb1c80e..40321bdc7 100644 --- a/packages/pxweb2-api-client/src/models/Table.ts +++ b/packages/pxweb2-api-client/src/models/Table.ts @@ -3,14 +3,27 @@ /* tslint:disable */ /* eslint-disable */ import type { Discontinued } from './Discontinued'; -import type { FolderContentItem } from './FolderContentItem'; import type { Link } from './Link'; import type { PathElement } from './PathElement'; +import type { TableCategory } from './TableCategory'; import type { TimeUnit } from './TimeUnit'; /** * Table item */ -export type Table = (FolderContentItem & { +export type Table = { + id: string; + /** + * Display text + */ + label: string | null; + /** + * Longer text describing node. + */ + description?: string | null; + /** + * String for sorting the contents in folder + */ + sortCode?: string; tags?: Array; /** * Date and time when the figures in the table was last updated, in UTC time. @@ -24,10 +37,7 @@ export type Table = (FolderContentItem & { * Last period */ lastPeriod: string | null; - /** - * Mostly for internal use. Which category table belongs to. internal, public, private or section. - */ - category?: Table.category; + category?: TableCategory; /** * List of varibles name */ @@ -53,16 +63,5 @@ export type Table = (FolderContentItem & { * Links to ... */ links: Array | null; -}); -export namespace Table { - /** - * Mostly for internal use. Which category table belongs to. internal, public, private or section. - */ - export enum category { - INTERNAL = 'internal', - PUBLIC = 'public', - PRIVATE = 'private', - SECTION = 'section', - } -} +}; diff --git a/packages/pxweb2-api-client/src/models/TableCategory.ts b/packages/pxweb2-api-client/src/models/TableCategory.ts new file mode 100644 index 000000000..5e23d897c --- /dev/null +++ b/packages/pxweb2-api-client/src/models/TableCategory.ts @@ -0,0 +1,13 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +/** + * Mostly for internal use. Which category table belongs to. internal, public, private or section. + */ +export enum TableCategory { + INTERNAL = 'internal', + PUBLIC = 'public', + PRIVATE = 'private', + SECTION = 'section', +} diff --git a/packages/pxweb2-api-client/src/models/VariableSelection.ts b/packages/pxweb2-api-client/src/models/VariableSelection.ts index 7d9f56af2..98132ede2 100644 --- a/packages/pxweb2-api-client/src/models/VariableSelection.ts +++ b/packages/pxweb2-api-client/src/models/VariableSelection.ts @@ -10,7 +10,7 @@ export type VariableSelection = { /** * The identifier of the codelist that should be applied */ - codeList?: string | null; + codelist?: string | null; /** * An array of string that specifies wich values sould be selected. Either as value codes or value expressions */ diff --git a/packages/pxweb2-api-client/src/models/codeListId.ts b/packages/pxweb2-api-client/src/models/codelistId.ts similarity index 69% rename from packages/pxweb2-api-client/src/models/codeListId.ts rename to packages/pxweb2-api-client/src/models/codelistId.ts index 538b2c09f..f0377d11b 100644 --- a/packages/pxweb2-api-client/src/models/codeListId.ts +++ b/packages/pxweb2-api-client/src/models/codelistId.ts @@ -3,6 +3,6 @@ /* tslint:disable */ /* eslint-disable */ /** - * Identifier for a code list + * Identifier for a codelist */ -export type codeListId = string; +export type codelistId = string; diff --git a/packages/pxweb2-api-client/src/models/extension_dimension.ts b/packages/pxweb2-api-client/src/models/extension_dimension.ts index ece1d763f..aca9c7d2f 100644 --- a/packages/pxweb2-api-client/src/models/extension_dimension.ts +++ b/packages/pxweb2-api-client/src/models/extension_dimension.ts @@ -4,7 +4,7 @@ /* eslint-disable */ import type { Adjustment } from './Adjustment'; import type { BasePeriod } from './BasePeriod'; -import type { CodeLists } from './CodeLists'; +import type { Codelists } from './Codelists'; import type { jsonstat_noteMandatory } from './jsonstat_noteMandatory'; import type { MeasuringType } from './MeasuringType'; import type { PriceType } from './PriceType'; @@ -33,7 +33,7 @@ export type extension_dimension = { * Information about how variables are presented */ show?: string; - codeLists?: CodeLists; + codelists?: Codelists; /** * Indicates if data is stock, flow or average. */ diff --git a/packages/pxweb2-api-client/src/models/include_discontinued.ts b/packages/pxweb2-api-client/src/models/includeDiscontinued.ts similarity index 82% rename from packages/pxweb2-api-client/src/models/include_discontinued.ts rename to packages/pxweb2-api-client/src/models/includeDiscontinued.ts index 0874a8a1c..16f5aa41d 100644 --- a/packages/pxweb2-api-client/src/models/include_discontinued.ts +++ b/packages/pxweb2-api-client/src/models/includeDiscontinued.ts @@ -5,4 +5,4 @@ /** * Decides if discontinued tables are included in response. */ -export type include_discontinued = boolean; +export type includeDiscontinued = boolean; diff --git a/packages/pxweb2-api-client/src/models/pastDays.ts b/packages/pxweb2-api-client/src/models/pastDays.ts index 241694eba..55f8e9dc6 100644 --- a/packages/pxweb2-api-client/src/models/pastDays.ts +++ b/packages/pxweb2-api-client/src/models/pastDays.ts @@ -3,6 +3,6 @@ /* tslint:disable */ /* eslint-disable */ /** - * Selects only tables that was updated from the time of execution going back number of days stated by the parameter pastDays. Valid values for past days are integers between 1 and ? + * Selects only tables that was updated from the time of execution going back number of days stated by the parameter pastDays. Valid values for past days are positive integers. */ export type pastDays = number; diff --git a/packages/pxweb2-api-client/src/services/CodelistsService.ts b/packages/pxweb2-api-client/src/services/CodelistsService.ts new file mode 100644 index 000000000..29290535c --- /dev/null +++ b/packages/pxweb2-api-client/src/services/CodelistsService.ts @@ -0,0 +1,37 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { CodelistResponse } from '../models/CodelistResponse'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; +export class CodelistsService { + /** + * Get codelist by {id}. + * @param id Id + * @param lang The language if the default is not what you want. + * @returns CodelistResponse Success + * @throws ApiError + */ + public static getCodelistById( + id: string, + lang?: string | null, + ): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/codelists/{id}', + path: { + 'id': id, + }, + query: { + 'lang': lang, + }, + errors: { + 400: `Error response for 400`, + 404: `Error response for 404`, + 429: `Error response for 429`, + }, + }); + } +} diff --git a/packages/pxweb2-api-client/src/services/ConfigurationService.ts b/packages/pxweb2-api-client/src/services/ConfigurationService.ts index 9e9159bb8..2dffd3b3d 100644 --- a/packages/pxweb2-api-client/src/services/ConfigurationService.ts +++ b/packages/pxweb2-api-client/src/services/ConfigurationService.ts @@ -8,7 +8,7 @@ import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; export class ConfigurationService { /** - * Get API configuration settings. + * Get API configuration. * @returns ConfigResponse Success * @throws ApiError */ diff --git a/packages/pxweb2-api-client/src/services/NavigationService.ts b/packages/pxweb2-api-client/src/services/NavigationService.ts deleted file mode 100644 index 0b26bd65c..000000000 --- a/packages/pxweb2-api-client/src/services/NavigationService.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* generated using openapi-typescript-codegen -- do not edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -import type { FolderResponse } from '../models/FolderResponse'; -import type { CancelablePromise } from '../core/CancelablePromise'; -import { OpenAPI } from '../core/OpenAPI'; -import { request as __request } from '../core/request'; -export class NavigationService { - /** - * Get root Folder. - * @param lang The language if the default is not what you want. - * @returns FolderResponse Success - * @throws ApiError - */ - public static getNavigationRoot( - lang?: string | null, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/navigation', - query: { - 'lang': lang, - }, - errors: { - 400: `Error response for 400`, - 404: `Error response for 404`, - 429: `Error response for 429`, - }, - }); - } - /** - * Gets Folder by {id}. - * @param id Id - * @param lang The language if the default is not what you want. - * @returns FolderResponse Success - * @throws ApiError - */ - public static getNavigationById( - id: string, - lang?: string | null, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/navigation/{id}', - path: { - 'id': id, - }, - query: { - 'lang': lang, - }, - errors: { - 400: `Error response for 400`, - 404: `Error response for 404`, - 429: `Error response for 429`, - }, - }); - } -} diff --git a/packages/pxweb2-api-client/src/services/SavedQueriesService.ts b/packages/pxweb2-api-client/src/services/SavedQueriesService.ts index c71484dd6..143c1c3f1 100644 --- a/packages/pxweb2-api-client/src/services/SavedQueriesService.ts +++ b/packages/pxweb2-api-client/src/services/SavedQueriesService.ts @@ -5,6 +5,7 @@ import type { OutputFormatParamType } from '../models/OutputFormatParamType'; import type { OutputFormatType } from '../models/OutputFormatType'; import type { SavedQuery } from '../models/SavedQuery'; +import type { SavedQueryResponse } from '../models/SavedQueryResponse'; import type { SelectionResponse } from '../models/SelectionResponse'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; @@ -12,8 +13,8 @@ import { request as __request } from '../core/request'; export class SavedQueriesService { /** * Save a query for later use. - * @param requestBody A saved query - * @returns SavedQuery Saved query created + * @param requestBody A saved query in JSON format without an Id. + * @returns SavedQuery Saved query created and returned with the id specified. * @throws ApiError */ public static createSaveQuery( @@ -32,13 +33,17 @@ export class SavedQueriesService { } /** * Retrieves the content of a saved query. + * **Used for retrieving a saved query** + * * Get the saved query by id. + * * The saved query contains the selection and other parameters that were used when the query was created. + * * @param id Id - * @returns SavedQuery Success + * @returns SavedQueryResponse Success * @throws ApiError */ public static getSaveQuery( id: string, - ): CancelablePromise { + ): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/savedqueries/{id}', @@ -54,6 +59,10 @@ export class SavedQueriesService { } /** * Retrieves the data by running the saved query. + * **Used for retrieving data by running a saved query** + * * Get the data by running the saved query. + * * The saved query contains the selection and other parameters that were used when the query was created. + * * @param id Id * @param lang The language if the default is not what you want. * @param outputFormat @@ -87,7 +96,7 @@ export class SavedQueriesService { }); } /** - * Retrieves the selection that the saved query will result in. + * Retrieves the selection that the saved query will result in. Selection expressions will be transformed into actual value codes. * @param id Id * @param lang The language if the default is not what you want. * @returns SelectionResponse Success diff --git a/packages/pxweb2-api-client/src/services/TableService.ts b/packages/pxweb2-api-client/src/services/TablesService.ts similarity index 79% rename from packages/pxweb2-api-client/src/services/TableService.ts rename to packages/pxweb2-api-client/src/services/TablesService.ts index 4db7179ff..13d1f9d73 100644 --- a/packages/pxweb2-api-client/src/services/TableService.ts +++ b/packages/pxweb2-api-client/src/services/TablesService.ts @@ -2,7 +2,6 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { CodeListResponse } from '../models/CodeListResponse'; import type { Dataset } from '../models/Dataset'; import type { OutputFormatParamType } from '../models/OutputFormatParamType'; import type { OutputFormatType } from '../models/OutputFormatType'; @@ -13,12 +12,12 @@ import type { VariablesSelection } from '../models/VariablesSelection'; import type { CancelablePromise } from '../core/CancelablePromise'; import { OpenAPI } from '../core/OpenAPI'; import { request as __request } from '../core/request'; -export class TableService { +export class TablesService { /** * Get all Tables. * @param lang The language if the default is not what you want. * @param query Selects only tables that that matches a criteria which is specified by the search parameter. - * @param pastDays Selects only tables that was updated from the time of execution going back number of days stated by the parameter pastDays. Valid values for past days are integers between 1 and ? + * @param pastDays Selects only tables that was updated from the time of execution going back number of days stated by the parameter pastDays. Valid values for past days are positive integers. * @param includeDiscontinued Decides if discontinued tables are included in response. * @param pageNumber Pagination: Decides which page number to return * @param pageSize Pagination: Decides how many tables per page @@ -74,26 +73,22 @@ export class TableService { }); } /** - * Get Metadata about Table by {id}. + * Get metadata about table by {id}. * **Used for listing detailed information about a specific table** * * List all variables and values and all other metadata needed to be able to fetch data * - * * Also links to where to: - * + Fetch - * - Where to get information about codelists - * - * * 2 output formats - * + Custom json - * - JSON-stat2 - * * @param id Id * @param lang The language if the default is not what you want. - * @param defaultSelection If metadata should be included as if default selection would have been applied. - * This is a technical parameter that is used by PxWeb for initial loading of tables. + * @param defaultSelection This is a technical parameter that is used by PxWeb for initial loading of tables. + * If metadata should be included as if default selection would have been applied see /tables{id}/defaultselection endpoint. * - * @param savedQuery Id for a saved query that should be be applied before metadata is returned. + * @param savedQuery This is a technical parameter that is used by PxWeb for initial loading of tables. + * Id for a saved query that should be be applied before metadata is returned see /savedqueries. + * + * @param codelist This is a technical parameter that is used by PxWeb. + * The identifier of the codelist that should be applied to the metadata. + * If not specified no codelist will be applied. * - * @param codelist * @returns Dataset Success * @throws ApiError */ @@ -124,8 +119,10 @@ export class TableService { }); } /** - * Get the default selection for Table by {id}. - * Get information about what is selected for the table by default when no selection is made i the /data endpoint. + * Get the default selection for table by {id}. + * This is a technical parameter that is used by PxWeb for initial loading of tables. + * Get information about the default selection for the /tables/{id}/data endpoint. + * * @param id Id * @param lang The language if the default is not what you want. * @returns SelectionResponse Success @@ -152,42 +149,22 @@ export class TableService { }); } /** - * Get Codelist by {id}. - * @param id Id - * @param lang The language if the default is not what you want. - * @returns CodeListResponse Success - * @throws ApiError - */ - public static getTableCodeListById( - id: string, - lang?: string | null, - ): CancelablePromise { - return __request(OpenAPI, { - method: 'GET', - url: '/codelists/{id}', - path: { - 'id': id, - }, - query: { - 'lang': lang, - }, - errors: { - 400: `Error response for 400`, - 404: `Error response for 404`, - 429: `Error response for 429`, - }, - }); - } - /** - * Get data from table by {id}. + * Get data for table by {id}. + * **Used for fetching data from a table** + * * Get data from a table by id. + * * The data can be filtered by variable codes and values. + * * The response can be formatted in different formats. + * * The placement of the variables can be customized with heading and stub variables. + * * If no selection is specified for filtering the data the default selection will be applied. + * * @param id Id * @param lang The language if the default is not what you want. * @param valuecodes * @param codelist * @param outputFormat * @param outputFormatParams - * @param heading Commaseparated list of variable codes that should be placed in the heading in the resulting data - * @param stub Commaseparated list of variable codes that should be placed in the stub in the resulting data + * @param heading Comma separated list of variable codes that should be placed in the heading in the resulting data + * @param stub Comma separated list of variable codes that should be placed in the stub in the resulting data * @returns string Success * @throws ApiError */ @@ -225,12 +202,12 @@ export class TableService { }); } /** - * Get data from table by {id}. + * Get data for table by {id}. * @param id Id * @param lang The language if the default is not what you want. * @param outputFormat * @param outputFormatParams - * @param requestBody A selection + * @param requestBody A selection in JSON format for filtering the data. If no selection is specified the default selection will be applied. * @returns string Success * @throws ApiError */ diff --git a/packages/pxweb2-ui/src/lib/components/Select/Select.tsx b/packages/pxweb2-ui/src/lib/components/Select/Select.tsx index d16ea30ec..6cd35876f 100644 --- a/packages/pxweb2-ui/src/lib/components/Select/Select.tsx +++ b/packages/pxweb2-ui/src/lib/components/Select/Select.tsx @@ -26,7 +26,7 @@ export type SelectProps = { className?: string; addModal: (name: string, closeFunction: () => void) => void; removeModal: (name: string) => void; - codeListLabelId?: string; + codelistLabelId?: string; }; // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -51,7 +51,7 @@ export function Select({ className = '', addModal, removeModal, - codeListLabelId, + codelistLabelId, }: Readonly) { const cssClasses = className.length > 0 ? ' ' + className : ''; @@ -84,7 +84,7 @@ export function Select({ className={cssClasses} addModal={addModal} removeModal={removeModal} - codeListLabelId={codeListLabelId} + codelistLabelId={codelistLabelId} /> )} @@ -164,7 +164,7 @@ type VariableBoxSelectProps = Pick< | 'onChange' | 'tabIndex' | 'className' - | 'codeListLabelId' + | 'codelistLabelId' > & { languageDirection: 'ltr' | 'rtl'; addModal: (id: string, onClose: () => void) => void; @@ -185,7 +185,7 @@ function VariableBoxSelect({ className = '', addModal, removeModal, - codeListLabelId, + codelistLabelId, }: VariableBoxSelectProps) { const cssClasses = className.length > 0 ? ' ' + className : ''; @@ -301,7 +301,7 @@ function VariableBoxSelect({ { mandatory={false} languageDirection="ltr" values={[{ code: 'test-1', label: 'test-1' }]} - codeLists={[]} + codelists={[]} onChangeCodeList={() => { return; }} diff --git a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.stories.tsx b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.stories.tsx index c5492e9b9..880e5f9f1 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.stories.tsx +++ b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.stories.tsx @@ -4,7 +4,7 @@ import { VariableBox, VariableBoxProps, SelectedVBValues } from './VariableBox'; import { SelectOption } from '../Select/SelectOptionType'; import { Value } from '../../shared-types/value'; import { VartypeEnum } from '../../shared-types/vartypeEnum'; -import { CodeList } from '../../shared-types/codelist'; +import { Codelist } from '../../shared-types/codelist'; const meta = { title: 'Components/VariableBox', @@ -41,7 +41,7 @@ const mockValues = [ { code: '05', label: 'Oppland' }, ]; -const mockCodeLists: CodeList[] = [ +const mockCodeLists: Codelist[] = [ { id: 'list1', label: 'Main regions', values: mockValues }, { id: 'list2', label: 'Counties', values: [] }, ]; @@ -49,7 +49,7 @@ const mockCodeLists: CodeList[] = [ const mockSelectedValues: SelectedVBValues[] = [ { id: 'region', - selectedCodeList: 'list1', + selectedCodelist: 'list1', values: ['01', '03'], }, ]; @@ -63,9 +63,9 @@ const commonProps = { languageDirection: 'ltr' as const, type: VartypeEnum.CONTENTS_VARIABLE, values: mockValues, - codeLists: mockCodeLists, + codelists: mockCodeLists, onChangeCodeList: (selectedItem: SelectOption | undefined, varId: string) => { - console.log('CodeList changed:', selectedItem, 'for variable:', varId); + console.log('Codelist changed:', selectedItem, 'for variable:', varId); }, onChangeCheckbox: (varId: string, value: string) => { console.log('Checkbox changed for variable:', varId, 'value:', value); @@ -120,7 +120,7 @@ export const MandatoryWithError: Story = { selectedValues: [ { id: 'region', - selectedCodeList: undefined, + selectedCodelist: undefined, values: [], }, ], @@ -133,7 +133,7 @@ export const AllValuesSelected: Story = { selectedValues: [ { id: 'region', - selectedCodeList: 'list1', + selectedCodelist: 'list1', values: mockValues.map((v) => v.code), }, ], @@ -146,7 +146,7 @@ export const NoValuesSelected: Story = { selectedValues: [ { id: 'region', - selectedCodeList: 'list1', + selectedCodelist: 'list1', values: [], }, ], @@ -173,7 +173,7 @@ export const ManyValues: Story = { selectedValues: [ { id: 'region', - selectedCodeList: 'list1', + selectedCodelist: 'list1', values: ['0001', '0010', '0025'], }, ], diff --git a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.tsx b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.tsx index 0995f754d..61c4f58e7 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.tsx +++ b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBox.tsx @@ -10,7 +10,7 @@ import { Value } from '../../shared-types/value'; export type SelectedVBValues = { id: string; - selectedCodeList: string | undefined; + selectedCodelist: string | undefined; values: Value['code'][]; }; @@ -41,7 +41,7 @@ export function VariableBox({ mandatory = false, type, values, - codeLists, + codelists, selectedValues, onChangeCodeList, onChangeCheckbox, @@ -99,7 +99,7 @@ export function VariableBox({ label={capitalizedVariableName} languageDirection={languageDirection} values={values} - codeLists={codeLists} + codelists={codelists} selectedValues={selectedValues} totalValues={totalValues} totalChosenValues={totalChosenValues} diff --git a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.spec.tsx b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.spec.tsx index 3ab1c320c..00740eb7d 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.spec.tsx +++ b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.spec.tsx @@ -155,7 +155,7 @@ describe('With Virtuoso mock', () => { vi.resetModules(); }); - it('should set aria-labelledby to include codeListLabelId when codeLists are present', () => { + it('should set aria-labelledby to include codelistLabelId when codelists are present', () => { render( { { code: 'test-7', label: 'test-7' }, { code: 'test-8', label: 'test-8' }, ]} - codeLists={[ + codelists={[ { id: 'cl-1', - label: 'CodeList 1', + label: 'Codelist 1', values: [{ code: 'test-1', label: 'test-1' }], }, ]} @@ -209,7 +209,7 @@ describe('With Virtuoso mock', () => { expect(ariaLabelledBy).toMatch(/^title-test-1 codelist-label-/); }); - it('should set aria-labelledby to only title-varId when codeLists are not present', () => { + it('should set aria-labelledby to only title-varId when codelists are not present', () => { render( { { code: 'test-6', label: 'test-6' }, { code: 'test-7', label: 'test-7' }, ]} - codeLists={[]} + codelists={[]} onChangeCodeList={() => { return; }} diff --git a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.tsx b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.tsx index 9576ddb0d..0740c8be2 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.tsx +++ b/packages/pxweb2-ui/src/lib/components/VariableBox/VariableBoxContent/VariableBoxContent.tsx @@ -60,7 +60,7 @@ export function VariableBoxContent({ languageDirection, type, values, - codeLists, + codelists, selectedValues, totalValues, totalChosenValues, @@ -80,13 +80,13 @@ export function VariableBoxContent({ const [items, setItems] = useState([]); const [uniqueId] = useState(() => uuidv4()); const valuesOnlyList = useRef(null); - const hasCodeLists = codeLists && codeLists.length > 0; + const hasCodeLists = codelists && codelists.length > 0; const hasSevenOrMoreValues = values && values.length > 6; const [initiallyHadSevenOrMoreValues] = useState(hasSevenOrMoreValues); const hasTwoOrMoreValues = values && values.length > 1; const hasSelectAndSearch = hasCodeLists && hasSevenOrMoreValues; const valuesToRender = structuredClone(values); - const codeListLabelId = 'codelist-label-' + uniqueId; + const codelistLabelId = 'codelist-label-' + uniqueId; const searchedValues: Value[] = values.filter( (value) => @@ -198,16 +198,16 @@ export function VariableBoxContent({ }, [totalChosenValues, totalValues, searchedValues, selectedValuesForVar]); const mappedAndSortedCodeLists: SelectOption[] = - mapAndSortCodeLists(codeLists); + mapAndSortCodeLists(codelists); // needs the selected, mapped code list for the current variable const currentVarSelectedCodeListId = selectedValues.find( (variable) => variable.id === varId, - )?.selectedCodeList; - const selectedCodeListMapped = mappedAndSortedCodeLists.find( - (codeList) => codeList.value === currentVarSelectedCodeListId, + )?.selectedCodelist; + const selectedCodelistMapped = mappedAndSortedCodeLists.find( + (codelist) => codelist.value === currentVarSelectedCodeListId, ); - const selectedCodeListOrUndefined = selectedCodeListMapped ?? undefined; + const selectedCodelistOrUndefined = selectedCodelistMapped ?? undefined; const handleChangingCodeListInVariableBox = ( selectedItem: SelectOption, @@ -271,7 +271,7 @@ export function VariableBoxContent({ }} aria-labelledby={ hasCodeLists - ? `title-${varId} ${codeListLabelId}` + ? `title-${varId} ${codelistLabelId}` : `title-${varId}` } variant="inVariableBox" @@ -480,8 +480,8 @@ export function VariableBoxContent({ addModal={addModal} removeModal={removeModal} options={mappedAndSortedCodeLists} - selectedOption={selectedCodeListOrUndefined} - codeListLabelId={codeListLabelId} + selectedOption={selectedCodelistOrUndefined} + codelistLabelId={codelistLabelId} onChange={(selectedItem) => selectedItem && handleChangingCodeListInVariableBox( diff --git a/packages/pxweb2-ui/src/lib/components/VariableBox/utils.spec.ts b/packages/pxweb2-ui/src/lib/components/VariableBox/utils.spec.ts index abea5a762..a76a9f52a 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableBox/utils.spec.ts +++ b/packages/pxweb2-ui/src/lib/components/VariableBox/utils.spec.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; -import { CodeList } from '../../shared-types/codelist'; +import { Codelist } from '../../shared-types/codelist'; import { SelectOption } from '../Select/SelectOptionType'; import { sortSelectOptionsGroupingsLast, mapAndSortCodeLists } from './utils'; @@ -64,20 +64,20 @@ describe('sortSelectOptionsGroupingsFirst', () => { }); describe('mapAndSortCodeLists', () => { - it('should return an empty array if codeLists is undefined', () => { + it('should return an empty array if codelists is undefined', () => { const result = mapAndSortCodeLists(undefined); expect(result).toEqual([]); }); - it('should return an empty array if codeLists is empty', () => { + it('should return an empty array if codelists is empty', () => { const result = mapAndSortCodeLists([]); expect(result).toEqual([]); }); - it('should map codeLists to select options without sorting if no sorting is needed', () => { - const codeLists: CodeList[] = [ + it('should map codelists to select options without sorting if no sorting is needed', () => { + const codelists: Codelist[] = [ { id: 'test_1', label: 'Test 1' }, { id: 'test_2', label: 'Test 2' }, ]; @@ -85,13 +85,13 @@ describe('mapAndSortCodeLists', () => { { value: 'test_1', label: 'Test 1' }, { value: 'test_2', label: 'Test 2' }, ]; - const result = mapAndSortCodeLists(codeLists); + const result = mapAndSortCodeLists(codelists); expect(result).toEqual(expected); }); - it('should map and sort codeLists if sorting is needed', () => { - const codeLists: CodeList[] = [ + it('should map and sort codelists if sorting is needed', () => { + const codelists: Codelist[] = [ { id: 'agg_test', label: 'AGG Test' }, { id: 'vs_test', label: 'VS Test' }, ]; @@ -99,7 +99,7 @@ describe('mapAndSortCodeLists', () => { { value: 'vs_test', label: 'VS Test' }, { value: 'agg_test', label: 'AGG Test' }, ]; - const result = mapAndSortCodeLists(codeLists); + const result = mapAndSortCodeLists(codelists); expect(result).toEqual(expected); }); diff --git a/packages/pxweb2-ui/src/lib/components/VariableBox/utils.ts b/packages/pxweb2-ui/src/lib/components/VariableBox/utils.ts index f4916ce3b..2fb39507e 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableBox/utils.ts +++ b/packages/pxweb2-ui/src/lib/components/VariableBox/utils.ts @@ -1,5 +1,5 @@ import { SelectOption } from '../Select/SelectOptionType'; -import { CodeList } from '../../shared-types/codelist'; +import { Codelist } from '../../shared-types/codelist'; import { mapCodeListsToSelectOptions } from '../../util/util'; export const sortSelectOptionsGroupingsLast = ( @@ -19,16 +19,16 @@ export const sortSelectOptionsGroupingsLast = ( }; export const mapAndSortCodeLists = ( - codeLists: CodeList[] | undefined, + codelists: Codelist[] | undefined, ): SelectOption[] => { - if (!codeLists || codeLists.length === 0) { + if (!codelists || codelists.length === 0) { return []; } const needsSorting = - codeLists.some((codeList) => codeList.id.toLowerCase().startsWith('vs_')) && - codeLists.some((codeList) => codeList.id.toLowerCase().startsWith('agg_')); - const mappedCodeLists = mapCodeListsToSelectOptions(codeLists); + codelists.some((codelist) => codelist.id.toLowerCase().startsWith('vs_')) && + codelists.some((codelist) => codelist.id.toLowerCase().startsWith('agg_')); + const mappedCodeLists = mapCodeListsToSelectOptions(codelists); if (needsSorting) { return sortSelectOptionsGroupingsLast(mappedCodeLists); diff --git a/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.spec.tsx b/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.spec.tsx index e5a6cef43..af0710e9a 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.spec.tsx +++ b/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.spec.tsx @@ -23,7 +23,7 @@ const mockPxTableMetadataSingle: PxTableMetadata = { label: 'Test Variable 1 Value 2', }, ], - codeLists: [], + codelists: [], type: VartypeEnum.CONTENTS_VARIABLE, }, ], @@ -45,7 +45,7 @@ const mockPxTableMetadataMultiple: PxTableMetadata = { label: 'Test Value', }, ], - codeLists: [], + codelists: [], type: VartypeEnum.CONTENTS_VARIABLE, }, { @@ -62,7 +62,7 @@ const mockPxTableMetadataMultiple: PxTableMetadata = { label: 'Test Variable 2 Value 2', }, ], - codeLists: [], + codelists: [], type: VartypeEnum.CONTENTS_VARIABLE, }, ], diff --git a/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.tsx b/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.tsx index 78f8f27bf..a95da1bbb 100644 --- a/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.tsx +++ b/packages/pxweb2-ui/src/lib/components/VariableList/VariableList.tsx @@ -64,7 +64,7 @@ export function VariableList({ mandatory={variable.mandatory} type={variable.type} values={variable.values} - codeLists={variable.codeLists} + codelists={variable.codelists} selectedValues={selectedVBValues} onChangeCodeList={handleCodeListChange} onChangeMixedCheckbox={handleMixedCheckboxChange} diff --git a/packages/pxweb2-ui/src/lib/shared-types/codelist.ts b/packages/pxweb2-ui/src/lib/shared-types/codelist.ts index f69a67bc2..9b7168aed 100644 --- a/packages/pxweb2-ui/src/lib/shared-types/codelist.ts +++ b/packages/pxweb2-ui/src/lib/shared-types/codelist.ts @@ -1,6 +1,6 @@ import { Value } from './value'; -export type CodeList = { +export type Codelist = { /** * The identiyer for the codelist */ diff --git a/packages/pxweb2-ui/src/lib/shared-types/variable.ts b/packages/pxweb2-ui/src/lib/shared-types/variable.ts index 573c22ab2..219c0b09a 100644 --- a/packages/pxweb2-ui/src/lib/shared-types/variable.ts +++ b/packages/pxweb2-ui/src/lib/shared-types/variable.ts @@ -1,4 +1,4 @@ -import { CodeList } from './codelist'; +import { Codelist } from './codelist'; import { Note } from './note'; import { Value } from './value'; import { VartypeEnum } from './vartypeEnum'; @@ -9,6 +9,6 @@ export type Variable = { type: VartypeEnum; mandatory: boolean; values: Value[]; - codeLists?: CodeList[]; + codelists?: Codelist[]; notes?: Note[]; }; diff --git a/packages/pxweb2-ui/src/lib/util/util.spec.ts b/packages/pxweb2-ui/src/lib/util/util.spec.ts index 24035a4ef..62d267650 100644 --- a/packages/pxweb2-ui/src/lib/util/util.spec.ts +++ b/packages/pxweb2-ui/src/lib/util/util.spec.ts @@ -5,7 +5,7 @@ import { mapCodeListToSelectOption, mapCodeListsToSelectOptions, } from './util'; -import { CodeList } from '../shared-types/codelist'; +import { Codelist } from '../shared-types/codelist'; import { SelectOption } from '../components/Select/SelectOptionType'; describe('getCSSVariable', () => { @@ -24,9 +24,9 @@ describe('getCSSVariable', () => { }); describe('mapCodeListToSelectOption', () => { - it('should map a CodeList to a SelectOption', () => { - const codeList: CodeList = { id: '1', label: 'Option 1' }; - const result: SelectOption = mapCodeListToSelectOption(codeList); + it('should map a Codelist to a SelectOption', () => { + const codelist: Codelist = { id: '1', label: 'Option 1' }; + const result: SelectOption = mapCodeListToSelectOption(codelist); expect(result).toEqual({ label: 'Option 1', value: '1' }); }); @@ -34,11 +34,11 @@ describe('mapCodeListToSelectOption', () => { describe('mapCodeListsToSelectOptions', () => { it('should map an array of CodeLists to an array of SelectOptions', () => { - const codeLists: CodeList[] = [ + const codelists: Codelist[] = [ { id: '1', label: 'Option 1' }, { id: '2', label: 'Option 2' }, ]; - const result: SelectOption[] = mapCodeListsToSelectOptions(codeLists); + const result: SelectOption[] = mapCodeListsToSelectOptions(codelists); expect(result).toEqual([ { label: 'Option 1', value: '1' }, diff --git a/packages/pxweb2-ui/src/lib/util/util.ts b/packages/pxweb2-ui/src/lib/util/util.ts index f9b88208b..22944a21b 100644 --- a/packages/pxweb2-ui/src/lib/util/util.ts +++ b/packages/pxweb2-ui/src/lib/util/util.ts @@ -1,4 +1,4 @@ -import { CodeList } from '../shared-types/codelist'; +import { Codelist } from '../shared-types/codelist'; import { SelectOption } from '../components/Select/SelectOptionType'; import { IconProps } from '../components/Icon/Icon'; @@ -8,18 +8,18 @@ export const getCSSVariable = (variable: string): string => { return cssVar; }; -export const mapCodeListToSelectOption = (codeList: CodeList): SelectOption => { +export const mapCodeListToSelectOption = (codelist: Codelist): SelectOption => { return { - label: codeList.label, - value: codeList.id, + label: codelist.label, + value: codelist.id, }; }; // return array of SelectOption objects export const mapCodeListsToSelectOptions = ( - codeList: CodeList[], + codelist: Codelist[], ): SelectOption[] => { - return codeList.map((code) => ({ + return codelist.map((code) => ({ label: code.label, value: code.id, })); diff --git a/packages/pxweb2/src/app/components/ContentTop/ContentTop.spec.tsx b/packages/pxweb2/src/app/components/ContentTop/ContentTop.spec.tsx index 2f26088fe..3df9245bc 100644 --- a/packages/pxweb2/src/app/components/ContentTop/ContentTop.spec.tsx +++ b/packages/pxweb2/src/app/components/ContentTop/ContentTop.spec.tsx @@ -134,12 +134,12 @@ const selectedVBValues: SelectedVBValues[] = [ { id: 'Region', values: ['R_1', 'R_2'], - selectedCodeList: '', + selectedCodelist: '', }, - { id: 'Alder', values: ['1', '2'], selectedCodeList: '' }, - { id: 'Civilstatus', values: ['CS_1', 'CS_2'], selectedCodeList: '' }, - { id: 'Kon', values: ['G_1'], selectedCodeList: '' }, - { id: 'TIME', values: ['1968', '1969'], selectedCodeList: '' }, + { id: 'Alder', values: ['1', '2'], selectedCodelist: '' }, + { id: 'Civilstatus', values: ['CS_1', 'CS_2'], selectedCodelist: '' }, + { id: 'Kon', values: ['G_1'], selectedCodelist: '' }, + { id: 'TIME', values: ['1968', '1969'], selectedCodelist: '' }, ]; const noteInfo = diff --git a/packages/pxweb2/src/app/components/FilterSidebar/FilterSidebar.spec.tsx b/packages/pxweb2/src/app/components/FilterSidebar/FilterSidebar.spec.tsx index da7bd8466..a2c1ca4a8 100644 --- a/packages/pxweb2/src/app/components/FilterSidebar/FilterSidebar.spec.tsx +++ b/packages/pxweb2/src/app/components/FilterSidebar/FilterSidebar.spec.tsx @@ -4,11 +4,7 @@ import '@testing-library/jest-dom/vitest'; import { vi } from 'vitest'; import userEvent from '@testing-library/user-event'; -import { - Table, - TimeUnit, - FolderContentItemTypeEnum, -} from '@pxweb2/pxweb2-api-client'; +import { Table, TimeUnit } from '@pxweb2/pxweb2-api-client'; import { FilterSidebar } from './FilterSidebar'; import { FilterContext } from '../../context/FilterContext'; import { @@ -64,7 +60,6 @@ vi.mock('@pxweb2/pxweb2-ui', () => ({ // Helper function to create mock tables const createMockTable = (id: string, overrides?: Partial): Table => ({ - type: FolderContentItemTypeEnum.TABLE, id, label: `Table ${id}`, updated: null, diff --git a/packages/pxweb2/src/app/components/FilterSidebar/YearRangeFilter.spec.tsx b/packages/pxweb2/src/app/components/FilterSidebar/YearRangeFilter.spec.tsx index afcafee78..c347c48a6 100644 --- a/packages/pxweb2/src/app/components/FilterSidebar/YearRangeFilter.spec.tsx +++ b/packages/pxweb2/src/app/components/FilterSidebar/YearRangeFilter.spec.tsx @@ -5,10 +5,7 @@ import { render, screen, fireEvent, within } from '@testing-library/react'; import { YearRangeFilter } from './YearRangeFilter'; import { FilterContext } from '../../context/FilterContext'; import type { StartPageState } from '../../pages/StartPage/StartPageTypes'; -import { - type Table, - FolderContentItemTypeEnum, -} from '@pxweb2/pxweb2-api-client'; +import { type Table } from '@pxweb2/pxweb2-api-client'; vi.mock('react-i18next', async () => { const actual = @@ -45,7 +42,6 @@ describe('YearRangeFilter', () => { const sampleTables: Table[] = [ { - type: FolderContentItemTypeEnum.TABLE, id: 'table1', label: 'Test Table 1', firstPeriod: '2000', @@ -55,7 +51,6 @@ describe('YearRangeFilter', () => { links: null, }, { - type: FolderContentItemTypeEnum.TABLE, id: 'table2', label: 'Test Table 2', firstPeriod: '2001', diff --git a/packages/pxweb2/src/app/components/NavigationDrawer/Drawers/DrawerSave.tsx b/packages/pxweb2/src/app/components/NavigationDrawer/Drawers/DrawerSave.tsx index 1f88a5e1d..2321f7858 100644 --- a/packages/pxweb2/src/app/components/NavigationDrawer/Drawers/DrawerSave.tsx +++ b/packages/pxweb2/src/app/components/NavigationDrawer/Drawers/DrawerSave.tsx @@ -302,11 +302,11 @@ export function DrawerSave({ tableId }: DrawerSaveProps) { variableCode: id, valueCodes: valCodes, }; - const selectedCodeList = variables.getSelectedCodelistById(id); + const selectedCodelist = variables.getSelectedCodelistById(id); // Add selected codelist to selection if it exists - if (selectedCodeList) { - selection.codeList = selectedCodeList; + if (selectedCodelist) { + selection.codelist = selectedCodelist; } selections.push(selection); diff --git a/packages/pxweb2/src/app/components/Selection/Selection.tsx b/packages/pxweb2/src/app/components/Selection/Selection.tsx index 29c188958..90ad946cd 100644 --- a/packages/pxweb2/src/app/components/Selection/Selection.tsx +++ b/packages/pxweb2/src/app/components/Selection/Selection.tsx @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react'; import { ApiError, - TableService, + TablesService, SavedQueriesService, SelectionResponse, PathElement, @@ -65,7 +65,7 @@ function addValueToNewVariable( ) { const newSelectedValues = [ ...selectedValuesArr, - { id: varId, selectedCodeList: undefined, values: [value] }, + { id: varId, selectedCodelist: undefined, values: [value] }, ]; return newSelectedValues; @@ -84,13 +84,13 @@ function removeValueOfVariable( if ( hasMultipleValuesSelected || (!hasMultipleValuesSelected && - variable.selectedCodeList !== undefined) + variable.selectedCodelist !== undefined) ) { variable.values = variable.values.filter((val) => val !== value); } if ( !hasMultipleValuesSelected && - variable.selectedCodeList === undefined + variable.selectedCodelist === undefined ) { return null; } @@ -133,7 +133,7 @@ function addMultipleValuesToVariable( ...selectedValuesArr, { id: varId, - selectedCodeList: undefined, + selectedCodelist: undefined, values: valuesToAdd .filter((v) => searchedValues.includes(v)) .map((value) => value.code), @@ -172,7 +172,7 @@ function removeMultipleValuesToVariable( ...selectedValuesArr, { id: varId, - selectedCodeList: undefined, + selectedCodelist: undefined, values: valuesToAdd .filter((v) => searchedValues.includes(v)) .map((value) => value.code), @@ -190,14 +190,14 @@ function removeAllValuesOfVariable( const newValues: SelectedVBValues[] = selectedValuesArr .map((variable) => { if (variable.id === varId) { - if (variable.selectedCodeList !== undefined) { + if (variable.selectedCodelist !== undefined) { return { id: varId, - selectedCodeList: variable.selectedCodeList, + selectedCodelist: variable.selectedCodelist, values: [], }; } - if (variable.selectedCodeList === undefined) { + if (variable.selectedCodelist === undefined) { return null; } } @@ -292,13 +292,13 @@ export function Selection({ // Make parallel calls to getMetadataById and getTableById Promise.all([ - TableService.getMetadataById( + TablesService.getMetadataById( selectedTabId, i18n.resolvedLanguage, metaDataDefaultSelection, savedQueryId, ), - TableService.getTableById(selectedTabId, i18n.resolvedLanguage), + TablesService.getTableById(selectedTabId, i18n.resolvedLanguage), ]) .then(([Dataset, TableData]) => { const pxTable: PxTable = mapJsonStat2Response(Dataset, false); @@ -343,7 +343,7 @@ export function Selection({ ).filter( (variable) => variable.values.length > 0 || - variable.selectedCodeList !== undefined, + variable.selectedCodelist !== undefined, ); setSelectedVBValues(initialSelection); variables.syncVariablesAndValues(initialSelection); @@ -382,7 +382,7 @@ export function Selection({ i18n.resolvedLanguage, ); } else { - response = await TableService.getDefaultSelection( + response = await TablesService.getDefaultSelection( selectedTabId, i18n.resolvedLanguage, ); @@ -395,7 +395,7 @@ export function Selection({ return response; } - async function handleCodeListChange( + async function handleCodelistChange( selectedItem: SelectOption, varId: string, ) { @@ -418,14 +418,14 @@ export function Selection({ const isNewCodelist = prevSelectedValues?.find((variable) => variable.id === varId) - ?.selectedCodeList !== selectedItem?.value; + ?.selectedCodelist !== selectedItem?.value; if (!isNewCodelist) { return; // No change in codelist selection } // Collect selected codelists for all variables, including the newly selected one - const selectedCodeLists = getSelectedCodelists( + const selectedCodelists = getSelectedCodelists( prevSelectedValues, selectedItem, varId, @@ -434,12 +434,12 @@ export function Selection({ setIsFadingVariableList(true); // Get table metadata in the new codelist context - TableService.getMetadataById( + TablesService.getMetadataById( selectedTabId, i18n.resolvedLanguage, false, '', - selectedCodeLists, + selectedCodelists, ) .then((Dataset) => { const pxTable: PxTable = mapJsonStat2Response(Dataset, false); @@ -571,7 +571,7 @@ export function Selection({ hasLoadedDefaultSelection={hasLoadedInitialSelection} isChangingCodeList={isFadingVariableList} isTablet={isTablet} - handleCodeListChange={handleCodeListChange} + handleCodeListChange={handleCodelistChange} handleCheckboxChange={handleCheckboxChange} handleMixedCheckboxChange={handleMixedCheckboxChange} addModal={addModal} diff --git a/packages/pxweb2/src/app/components/Selection/selectionUtils.spec.ts b/packages/pxweb2/src/app/components/Selection/selectionUtils.spec.ts index f51fd4803..fb8e51ce6 100644 --- a/packages/pxweb2/src/app/components/Selection/selectionUtils.spec.ts +++ b/packages/pxweb2/src/app/components/Selection/selectionUtils.spec.ts @@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from 'vitest'; import { updateSelectedCodelistForVariable, - addSelectedCodeListToVariable, + addSelectedCodelistToVariable, getSelectedCodelists, } from './selectionUtils'; import { @@ -15,15 +15,15 @@ import { describe('selectionUtils', () => { const varId = 'var1'; - const codeListA = { id: 'A', label: 'List A', values: [] }; - const codeListB = { id: 'B', label: 'List B', values: [] }; + const codelistA = { id: 'A', label: 'List A', values: [] }; + const codelistB = { id: 'B', label: 'List B', values: [] }; const selectOptionA: SelectOption = { label: 'List A', value: 'A' }; const selectOptionB: SelectOption = { label: 'List B', value: 'B' }; const variableMeta: Variable = { id: varId, - codeLists: [codeListA, codeListB], + codelists: [codelistA, codelistB], label: '', type: VartypeEnum.CONTENTS_VARIABLE, mandatory: false, @@ -34,13 +34,13 @@ describe('selectionUtils', () => { beforeEach(() => { prevSelectedValues = [ - { id: varId, selectedCodeList: 'A', values: ['x'] }, - { id: 'var2', selectedCodeList: 'C', values: ['y'] }, + { id: varId, selectedCodelist: 'A', values: ['x'] }, + { id: 'var2', selectedCodelist: 'C', values: ['y'] }, ]; }); describe('setSelectedCodelist', () => { - it('returns undefined if newSelectedCodeList is not found', () => { + it('returns undefined if newSelectedCodelist is not found', () => { const invalidOption: SelectOption = { label: 'Invalid', value: 'Z' }; const mockMetadata: PxTableMetadata = { variables: [variableMeta], @@ -103,7 +103,7 @@ describe('selectionUtils', () => { ); expect(result).toBeDefined(); - expect(result?.find((v) => v.id === varId)?.selectedCodeList).toBe('B'); + expect(result?.find((v) => v.id === varId)?.selectedCodelist).toBe('B'); expect(result?.find((v) => v.id === varId)?.values).toEqual([]); }); @@ -111,7 +111,7 @@ describe('selectionUtils', () => { const newVarId = 'var3'; const newMeta: Variable = { id: newVarId, - codeLists: [codeListA], + codelists: [codelistA], label: '', type: VartypeEnum.CONTENTS_VARIABLE, mandatory: false, @@ -145,7 +145,7 @@ describe('selectionUtils', () => { mockMetadata, ); - expect(result?.find((v) => v.id === newVarId)?.selectedCodeList).toBe( + expect(result?.find((v) => v.id === newVarId)?.selectedCodelist).toBe( 'A', ); }); @@ -153,7 +153,7 @@ describe('selectionUtils', () => { it('applies mandatory defaults', () => { const mandatoryVariable: Variable = { id: varId, - codeLists: [codeListB], + codelists: [codelistB], label: '', type: VartypeEnum.CONTENTS_VARIABLE, mandatory: true, @@ -196,7 +196,7 @@ describe('selectionUtils', () => { it('does not apply mandatory defaults when variable is not mandatory', () => { const nonMandatoryVariable: Variable = { id: varId, - codeLists: [codeListB], + codelists: [codelistB], label: '', type: VartypeEnum.CONTENTS_VARIABLE, mandatory: false, @@ -237,7 +237,7 @@ describe('selectionUtils', () => { const varId2 = 'var2'; const mandatoryVariable: Variable = { id: varId, - codeLists: [codeListB], + codelists: [codelistB], label: '', type: VartypeEnum.CONTENTS_VARIABLE, mandatory: true, @@ -245,7 +245,7 @@ describe('selectionUtils', () => { }; const mandatoryVariable2: Variable = { id: varId2, - codeLists: [codeListA], + codelists: [codelistA], label: '', type: VartypeEnum.CONTENTS_VARIABLE, mandatory: true, @@ -272,10 +272,10 @@ describe('selectionUtils', () => { notes: [], }; const prevValuesWithData = [ - { id: varId, selectedCodeList: 'A', values: ['existing'] }, + { id: varId, selectedCodelist: 'A', values: ['existing'] }, { id: varId2, - selectedCodeList: 'C', + selectedCodelist: 'C', values: ['existing-value-1', 'existing-value-2'], }, ]; @@ -297,27 +297,27 @@ describe('selectionUtils', () => { }); }); - describe('addSelectedCodeListToVariable', () => { - it('updates existing variable with new selectedCodeList and resets values', () => { + describe('addSelectedCodelistToVariable', () => { + it('updates existing variable with new selectedCodelist and resets values', () => { const currentVariable = prevSelectedValues[0]; - const result = addSelectedCodeListToVariable( + const result = addSelectedCodelistToVariable( currentVariable, prevSelectedValues, varId, selectOptionB, ); - expect(result.find((v) => v.id === varId)?.selectedCodeList).toBe('B'); + expect(result.find((v) => v.id === varId)?.selectedCodelist).toBe('B'); expect(result.find((v) => v.id === varId)?.values).toEqual([]); }); it('adds a new variable if currentVariable is undefined', () => { - const result = addSelectedCodeListToVariable( + const result = addSelectedCodelistToVariable( undefined, prevSelectedValues, 'var3', selectOptionA, ); - expect(result.find((v) => v.id === 'var3')?.selectedCodeList).toBe('A'); + expect(result.find((v) => v.id === 'var3')?.selectedCodelist).toBe('A'); expect(result.find((v) => v.id === 'var3')?.values).toEqual([]); }); }); diff --git a/packages/pxweb2/src/app/components/Selection/selectionUtils.ts b/packages/pxweb2/src/app/components/Selection/selectionUtils.ts index 77fe98324..88afa1989 100644 --- a/packages/pxweb2/src/app/components/Selection/selectionUtils.ts +++ b/packages/pxweb2/src/app/components/Selection/selectionUtils.ts @@ -17,22 +17,22 @@ export function updateSelectedCodelistForVariable( (variable) => variable.id === varId, ); - const newSelectedCodeList = currentVariableMetadata?.codeLists?.find( + const newSelectedCodelist = currentVariableMetadata?.codelists?.find( (codelist) => codelist.id === selectedItem.value, ); - if (!newSelectedCodeList) { + if (!newSelectedCodelist) { return; } - const newMappedSelectedCodeList = - mapCodeListToSelectOption(newSelectedCodeList); + const newMappedSelectedCodelist = + mapCodeListToSelectOption(newSelectedCodelist); - const newSelectedValues = addSelectedCodeListToVariable( + const newSelectedValues = addSelectedCodelistToVariable( currentSelectedVariable, prevSelectedValues, varId, - newMappedSelectedCodeList, + newMappedSelectedCodelist, ); return applyMandatoryDefaultsForVariable( @@ -68,7 +68,7 @@ function applyMandatoryDefaultsForVariable( }); } -export function addSelectedCodeListToVariable( +export function addSelectedCodelistToVariable( currentVariable: SelectedVBValues | undefined, selectedValuesArr: SelectedVBValues[], varId: string, @@ -81,7 +81,7 @@ export function addSelectedCodeListToVariable( if (variable.id === varId) { return { ...variable, - selectedCodeList: selectedItem.value, + selectedCodelist: selectedItem.value, values: [], // Always reset values when changing codelist }; } @@ -94,7 +94,7 @@ export function addSelectedCodeListToVariable( ...selectedValuesArr, { id: varId, - selectedCodeList: selectedItem.value, + selectedCodelist: selectedItem.value, values: [], }, ]; @@ -110,20 +110,20 @@ export function getSelectedCodelists( ): Record { // Get table metadata in the new codelist context // Collect selected codelists for all variables, including the newly selected one - const selectedCodeLists: Record = {}; + const selectedCodelists: Record = {}; // Add existing selected codelists prevSelectedValues.forEach((variable) => { - if (variable.selectedCodeList) { - selectedCodeLists[variable.id] = variable.selectedCodeList; + if (variable.selectedCodelist) { + selectedCodelists[variable.id] = variable.selectedCodelist; } }); // Add/overwrite with the newly selected codelist for this variable - // selectedCodeLists[varId] = newMappedSelectedCodeList.value; + // selectedCodelists[varId] = newMappedSelectedCodelist.value; if (selectedItem) { - selectedCodeLists[varId] = selectedItem.value; + selectedCodelists[varId] = selectedItem.value; } - return selectedCodeLists; + return selectedCodelists; } diff --git a/packages/pxweb2/src/app/context/TableDataProvider.tsx b/packages/pxweb2/src/app/context/TableDataProvider.tsx index a969bf1dd..3b0b16fe4 100644 --- a/packages/pxweb2/src/app/context/TableDataProvider.tsx +++ b/packages/pxweb2/src/app/context/TableDataProvider.tsx @@ -7,7 +7,7 @@ import { Dataset, OutputFormatType, SavedQueriesService, - TableService, + TablesService, VariableSelection, VariablesSelection, } from '@pxweb2/pxweb2-api-client'; @@ -786,23 +786,24 @@ const TableDataProvider: React.FC = ({ children }) => { // Get the right codelists for the variables variablesSelection.selection.forEach((varSel) => { - if (varSel.codeList) { + if (varSel.codelist) { const diffSelection = notLoadedVarSelection.selection.find( (sel) => sel.variableCode === varSel.variableCode, ); if (diffSelection) { - diffSelection.codeList = varSel.codeList; + diffSelection.codelist = varSel.codelist; } else { // All variables that have codelists must be present in the API-call. // If not present, we need to add them to the notLoadedVarSelection. notLoadedVarSelection.selection.push({ variableCode: varSel.variableCode, valueCodes: [], - codeList: varSel.codeList, + codelist: varSel.codelist, }); } } }); + // Get the not already loaded data from the API let pxTable = await fetchFromApi(tableId, i18n, notLoadedVarSelection); @@ -907,8 +908,8 @@ const TableDataProvider: React.FC = ({ children }) => { } // We need to check that the variable codelist has not been changed // else { - // if (selection.codeList) { - // if (variable.codeList !== selection.codeList) { + // if (selection.codelist) { + // if (variable.codelist !== selection.codelist) { // return false; // } // } @@ -940,11 +941,11 @@ const TableDataProvider: React.FC = ({ children }) => { variablesSelection.selection.forEach((selection) => { const currentCodelist = variableCodelists[selection.variableCode]; - if (currentCodelist !== selection.codeList) { + if (currentCodelist !== selection.codelist) { codelistChanged = true; setVariableCodelists((prevCodelists) => ({ ...prevCodelists, - [selection.variableCode]: selection.codeList ?? '', + [selection.variableCode]: selection.codelist ?? '', })); } }); @@ -967,15 +968,15 @@ const TableDataProvider: React.FC = ({ children }) => { // Get selection from Selection provider const ids = variables.getUniqueIds(); ids.forEach((id) => { - const selectedCodeList = variables.getSelectedCodelistById(id); + const selectedCodelist = variables.getSelectedCodelistById(id); const selection: VariableSelection = { variableCode: id, valueCodes: variables.getSelectedValuesByIdSorted(id), }; // Add selected codelist to selection if it exists - if (selectedCodeList) { - selection.codeList = selectedCodeList; + if (selectedCodelist) { + selection.codelist = selectedCodelist; } selections.push(selection); @@ -1050,7 +1051,7 @@ const TableDataProvider: React.FC = ({ children }) => { variablesSelection: VariablesSelection, ): Promise => { let result: PxTable | null = null; - const res = await TableService.getTableDataByPost( + const res = await TablesService.getTableDataByPost( tableId, i18n.language, OutputFormatType.JSON_STAT2, diff --git a/packages/pxweb2/src/app/context/VariablesProvider.tsx b/packages/pxweb2/src/app/context/VariablesProvider.tsx index 6a3fb222c..dff333bff 100644 --- a/packages/pxweb2/src/app/context/VariablesProvider.tsx +++ b/packages/pxweb2/src/app/context/VariablesProvider.tsx @@ -138,7 +138,7 @@ export const VariablesProvider: React.FC<{ children: React.ReactNode }> = ({ const getSelectedCodelistById = (variableId: string) => { const selectedCodelist = selectedVBValues?.find( (item) => item.id === variableId, - )?.selectedCodeList; + )?.selectedCodelist; return selectedCodelist; }; diff --git a/packages/pxweb2/src/app/util/export/exportUtil.spec.ts b/packages/pxweb2/src/app/util/export/exportUtil.spec.ts index 52ab8b427..4e2eb86c3 100644 --- a/packages/pxweb2/src/app/util/export/exportUtil.spec.ts +++ b/packages/pxweb2/src/app/util/export/exportUtil.spec.ts @@ -9,7 +9,7 @@ import { import { OutputFormatType, OutputFormatParamType, - TableService, + TablesService, VariablesSelection, } from '@pxweb2/pxweb2-api-client'; @@ -26,7 +26,7 @@ vi.mock('@pxweb2/pxweb2-api-client', () => ({ INCLUDE_TITLE: 'INCLUDE_TITLE', SEPARATOR_SEMICOLON: 'SEPARATOR_SEMICOLON', }, - TableService: { + TablesService: { getTableDataByPost: vi.fn(), }, })); @@ -90,11 +90,11 @@ describe('exportToFile', () => { }); it('should export as excel', async () => { - vi.mocked(TableService.getTableDataByPost).mockResolvedValueOnce( + vi.mocked(TablesService.getTableDataByPost).mockResolvedValueOnce( 'excel-data', ); await exportToFile(tabId, lang, variablesSelection, OutputFormatType.XLSX); - expect(TableService.getTableDataByPost).toHaveBeenCalledWith( + expect(TablesService.getTableDataByPost).toHaveBeenCalledWith( tabId, lang, OutputFormatType.XLSX, @@ -105,11 +105,11 @@ describe('exportToFile', () => { }, 7000); it('should export as csv', async () => { - vi.mocked(TableService.getTableDataByPost).mockResolvedValueOnce( + vi.mocked(TablesService.getTableDataByPost).mockResolvedValueOnce( 'csv-data', ); await exportToFile(tabId, lang, variablesSelection, OutputFormatType.CSV); - expect(TableService.getTableDataByPost).toHaveBeenCalledWith( + expect(TablesService.getTableDataByPost).toHaveBeenCalledWith( tabId, lang, OutputFormatType.CSV, @@ -124,9 +124,11 @@ describe('exportToFile', () => { }, 7000); it('should export as px', async () => { - vi.mocked(TableService.getTableDataByPost).mockResolvedValueOnce('px-data'); + vi.mocked(TablesService.getTableDataByPost).mockResolvedValueOnce( + 'px-data', + ); await exportToFile(tabId, lang, variablesSelection, OutputFormatType.PX); - expect(TableService.getTableDataByPost).toHaveBeenCalledWith( + expect(TablesService.getTableDataByPost).toHaveBeenCalledWith( tabId, lang, OutputFormatType.PX, @@ -138,7 +140,7 @@ describe('exportToFile', () => { it('should export as jsonstat2', async () => { const jsonData = { foo: 'bar' }; - vi.mocked(TableService.getTableDataByPost).mockResolvedValueOnce( + vi.mocked(TablesService.getTableDataByPost).mockResolvedValueOnce( JSON.stringify(jsonData), ); await exportToFile( @@ -147,7 +149,7 @@ describe('exportToFile', () => { variablesSelection, OutputFormatType.JSON_STAT2, ); - expect(TableService.getTableDataByPost).toHaveBeenCalledWith( + expect(TablesService.getTableDataByPost).toHaveBeenCalledWith( tabId, lang, OutputFormatType.JSON_STAT2, @@ -158,11 +160,11 @@ describe('exportToFile', () => { }, 7000); it('should export as html', async () => { - vi.mocked(TableService.getTableDataByPost).mockResolvedValueOnce( + vi.mocked(TablesService.getTableDataByPost).mockResolvedValueOnce( 'html-data', ); await exportToFile(tabId, lang, variablesSelection, OutputFormatType.HTML); - expect(TableService.getTableDataByPost).toHaveBeenCalledWith( + expect(TablesService.getTableDataByPost).toHaveBeenCalledWith( tabId, lang, OutputFormatType.HTML, @@ -173,7 +175,7 @@ describe('exportToFile', () => { }, 7000); it('should export as parquet', async () => { - vi.mocked(TableService.getTableDataByPost).mockResolvedValueOnce( + vi.mocked(TablesService.getTableDataByPost).mockResolvedValueOnce( 'parquet-data', ); await exportToFile( @@ -182,7 +184,7 @@ describe('exportToFile', () => { variablesSelection, OutputFormatType.PARQUET, ); - expect(TableService.getTableDataByPost).toHaveBeenCalledWith( + expect(TablesService.getTableDataByPost).toHaveBeenCalledWith( tabId, lang, OutputFormatType.PARQUET, diff --git a/packages/pxweb2/src/app/util/export/exportUtil.ts b/packages/pxweb2/src/app/util/export/exportUtil.ts index a9c764381..d21348c48 100644 --- a/packages/pxweb2/src/app/util/export/exportUtil.ts +++ b/packages/pxweb2/src/app/util/export/exportUtil.ts @@ -3,7 +3,7 @@ import { OutputFormatType, SavedQueriesService, SavedQuery, - TableService, + TablesService, VariablesSelection, } from '@pxweb2/pxweb2-api-client'; @@ -12,7 +12,7 @@ export type TimeFilter = 'from' | 'top' | 'selected'; /** * Exports data to a file in the specified format. * The function determines the output format and parameters based on the provided fileFormat. - * It then retrieves the table data using TableService and triggers a download of the file. + * It then retrieves the table data using TablesService and triggers a download of the file. * * @param {string} tabId - The ID of the tab containing the data to export. * @param {string} lang - The language code for the export. @@ -30,7 +30,7 @@ export async function exportToFile( getOutputFormatParams(outputFormat); const fileExtension: string = getFileExtension(outputFormat); - await TableService.getTableDataByPost( + await TablesService.getTableDataByPost( tabId, lang, outputFormat, diff --git a/packages/pxweb2/src/app/util/tableHandler.spec.ts b/packages/pxweb2/src/app/util/tableHandler.spec.ts index e0c7460ac..afe35f51c 100644 --- a/packages/pxweb2/src/app/util/tableHandler.spec.ts +++ b/packages/pxweb2/src/app/util/tableHandler.spec.ts @@ -5,15 +5,15 @@ import { Table, TablesResponse, TimeUnit, - FolderContentItemTypeEnum, + TableCategory, } from '@pxweb2/pxweb2-api-client'; -// Mock TableService.listAllTables +// Mock TablesService.listAllTables vi.mock(import('@pxweb2/pxweb2-api-client'), async (importOriginal) => { const actual = await importOriginal(); return { ...actual, - TableService: { + TablesService: { listAllTables: vi.fn(), }, OpenAPI: vi.fn(), @@ -27,7 +27,6 @@ describe('getAllTables', () => { language: 'en', tables: [ { - type: FolderContentItemTypeEnum.TABLE, id: 'TAB4707', label: 'Test table', description: '', @@ -38,7 +37,7 @@ describe('getAllTables', () => { source: 'Test', paths: [[{ id: 'TEST', label: 'Test' }]], links: [], - category: Table.category.PUBLIC, + category: TableCategory.PUBLIC, timeUnit: TimeUnit.ANNUAL, } as Table, ], @@ -56,9 +55,9 @@ describe('getAllTables', () => { vi.resetAllMocks(); }); - it('should fetch and return tables from TableService', async () => { - const { TableService } = await import('@pxweb2/pxweb2-api-client'); - vi.mocked(TableService.listAllTables).mockResolvedValueOnce( + it('should fetch and return tables from TablesService', async () => { + const { TablesService } = await import('@pxweb2/pxweb2-api-client'); + vi.mocked(TablesService.listAllTables).mockResolvedValueOnce( mockSuccessResponse, ); @@ -69,8 +68,8 @@ describe('getAllTables', () => { }); it('should retry with fallback language when receiving unsupported language error', async () => { - const { TableService } = await import('@pxweb2/pxweb2-api-client'); - const listAllTablesSpy = vi.mocked(TableService.listAllTables); + const { TablesService } = await import('@pxweb2/pxweb2-api-client'); + const listAllTablesSpy = vi.mocked(TablesService.listAllTables); // First call throws unsupported language error listAllTablesSpy.mockRejectedValueOnce({ @@ -112,8 +111,8 @@ describe('getAllTables', () => { }); it('should throw error when both original and fallback language calls fail', async () => { - const { TableService } = await import('@pxweb2/pxweb2-api-client'); - const listAllTablesSpy = vi.mocked(TableService.listAllTables); + const { TablesService } = await import('@pxweb2/pxweb2-api-client'); + const listAllTablesSpy = vi.mocked(TablesService.listAllTables); // First call throws unsupported language error listAllTablesSpy.mockRejectedValueOnce({ @@ -157,7 +156,6 @@ const testFilterSubjectTimeDisallow: Filter[] = [ ]; const tableYear: Table = { - type: FolderContentItemTypeEnum.TABLE, id: '13618', label: '13618: Personer, etter arbeidsstyrkestatus, kjønn og alder. Bruddjusterte tall 2009-2022', @@ -165,7 +163,7 @@ const tableYear: Table = { updated: '2023-04-11T06:00:00Z', firstPeriod: '2009', lastPeriod: '2022', - category: Table.category.PUBLIC, + category: TableCategory.PUBLIC, variableNames: [ 'arbeidsstyrkestatus', 'kjønn', diff --git a/packages/pxweb2/src/app/util/tableHandler.ts b/packages/pxweb2/src/app/util/tableHandler.ts index f0b30d369..8fae9767e 100644 --- a/packages/pxweb2/src/app/util/tableHandler.ts +++ b/packages/pxweb2/src/app/util/tableHandler.ts @@ -1,6 +1,6 @@ import { type Table, - TableService, + TablesService, OpenAPI, ApiError, } from '@pxweb2/pxweb2-api-client'; @@ -14,7 +14,7 @@ export async function getAllTables(language?: string) { OpenAPI.BASE = baseUrl; try { - const response = await TableService.listAllTables( + const response = await TablesService.listAllTables( language || config.language.defaultLanguage, undefined, undefined, @@ -32,7 +32,7 @@ export async function getAllTables(language?: string) { // This ensures it is only retried once before failing completely. If fallback works, user should not be inconvenienced. if (error?.body?.title && error?.body?.title == 'Unsupported language') { try { - const response = await TableService.listAllTables( + const response = await TablesService.listAllTables( config.language.fallbackLanguage, undefined, undefined, diff --git a/packages/pxweb2/src/app/util/testing-utils.tsx b/packages/pxweb2/src/app/util/testing-utils.tsx index 78169dc7d..d973d2a26 100644 --- a/packages/pxweb2/src/app/util/testing-utils.tsx +++ b/packages/pxweb2/src/app/util/testing-utils.tsx @@ -28,7 +28,7 @@ function mockTableService() { HTML: 'HTML', PARQUET: 'PARQUET', }, - TableService: { + TablesService: { getTableById: vi.fn().mockResolvedValue({ id: 'TAB638', label: @@ -50,7 +50,7 @@ function mockTableService() { }, ], }), - getTableCodeListById: vi.fn().mockResolvedValue({ + getTableCodelistById: vi.fn().mockResolvedValue({ id: 'vs_RegionLän07', label: 'County', language: 'en', @@ -168,12 +168,12 @@ function mockTableService() { { rel: 'self', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/vs_RegionLän07?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/vs_RegionLän07?lang=en', }, { rel: 'alternate', hreflang: 'sv', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/vs_RegionLän07?lang=sv', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/vs_RegionLän07?lang=sv', }, ], }), @@ -926,7 +926,7 @@ function mockTableService() { }, }, show: 'code_value', - codeLists: [ + codelists: [ { id: 'agg_RegionA-region_2', label: 'A-regions', @@ -935,7 +935,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionA-region_2?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionA-region_2?lang=en', }, ], }, @@ -947,7 +947,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionKommungrupp2005-_1?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionKommungrupp2005-_1?lang=en', }, ], }, @@ -959,7 +959,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionKommungrupp2011-?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionKommungrupp2011-?lang=en', }, ], }, @@ -971,7 +971,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionKommungrupp2017-?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionKommungrupp2017-?lang=en', }, ], }, @@ -983,7 +983,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionKommungrupp2023-?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionKommungrupp2023-?lang=en', }, ], }, @@ -995,7 +995,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionLA1998?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionLA1998?lang=en', }, ], }, @@ -1007,7 +1007,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionLA2003_1?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionLA2003_1?lang=en', }, ], }, @@ -1019,7 +1019,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionLA2008?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionLA2008?lang=en', }, ], }, @@ -1031,7 +1031,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionLA2013?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionLA2013?lang=en', }, ], }, @@ -1043,7 +1043,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionLA2018?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionLA2018?lang=en', }, ], }, @@ -1055,7 +1055,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionStoromr-04_2?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionStoromr-04_2?lang=en', }, ], }, @@ -1067,7 +1067,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionStoromr05-_1?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionStoromr05-_1?lang=en', }, ], }, @@ -1079,7 +1079,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionNUTS1_2008?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionNUTS1_2008?lang=en', }, ], }, @@ -1091,7 +1091,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionNUTS2_2008?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionNUTS2_2008?lang=en', }, ], }, @@ -1103,7 +1103,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_RegionNUTS3_2008?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_RegionNUTS3_2008?lang=en', }, ], }, @@ -1115,7 +1115,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/vs_RegionKommun07?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/vs_RegionKommun07?lang=en', }, ], }, @@ -1127,7 +1127,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/vs_RegionLän07?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/vs_RegionLän07?lang=en', }, ], }, @@ -1139,7 +1139,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/vs_RegionRiket99?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/vs_RegionRiket99?lang=en', }, ], }, @@ -1165,7 +1165,7 @@ function mockTableService() { extension: { elimination: true, show: 'value', - codeLists: [], + codelists: [], }, }, Alder: { @@ -1383,7 +1383,7 @@ function mockTableService() { extension: { elimination: true, show: 'value', - codeLists: [ + codelists: [ { id: 'agg_Ålder10årJ', label: '´10-year intervals', @@ -1392,7 +1392,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_Ålder10årJ?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_Ålder10årJ?lang=en', }, ], }, @@ -1404,7 +1404,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/agg_Ålder5år?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/agg_Ålder5år?lang=en', }, ], }, @@ -1416,7 +1416,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/vs_Ålder1årA?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/vs_Ålder1årA?lang=en', }, ], }, @@ -1428,7 +1428,7 @@ function mockTableService() { { rel: 'metadata', hreflang: 'en', - href: 'https://api.scb.se/OV0104/v2beta/api/v2/codeLists/vs_ÅlderTotA?lang=en', + href: 'https://api.scb.se/OV0104/v2beta/api/v2/codelists/vs_ÅlderTotA?lang=en', }, ], }, @@ -1459,7 +1459,7 @@ function mockTableService() { extension: { elimination: true, show: 'value', - codeLists: [], + codelists: [], }, link: { describedby: [ @@ -1505,7 +1505,7 @@ function mockTableService() { BE0101N2: '', }, show: 'value', - codeLists: [], + codelists: [], measuringType: { BE0101N1: 'Stock', BE0101N2: 'Flow', @@ -1645,7 +1645,7 @@ function mockTableService() { extension: { elimination: false, show: 'code', - codeLists: [], + codelists: [], }, }, }, @@ -1701,7 +1701,7 @@ function mockTableService() { }, { variableCode: 'Region', - codeList: 'vs_RegionKommun07', + codelist: 'vs_RegionKommun07', valueCodes: [ '0114', '0115', @@ -2005,7 +2005,7 @@ function mockTableService() { }, { variableCode: 'Alder', - codeList: 'vs_Ålder1årA', + codelist: 'vs_Ålder1årA', valueCodes: [], }, ], diff --git a/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.spec.ts b/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.spec.ts index 800dfa7ae..d92d6d69b 100644 --- a/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.spec.ts +++ b/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.spec.ts @@ -1,4 +1,4 @@ -import { ClassType, CodeListType, Dataset } from '@pxweb2/pxweb2-api-client'; +import { ClassType, CodelistType, Dataset } from '@pxweb2/pxweb2-api-client'; import { mapJsonStat2Response, createDataAndStatus, @@ -71,17 +71,17 @@ describe('JsonStat2ResponseMapper', () => { }, }, - codeLists: [ + codelists: [ { id: 'cd1', label: 'Codelist 1', - type: CodeListType.AGGREGATION, + type: CodelistType.AGGREGATION, links: [], }, { id: 'cd2', label: 'Codelist 2', - type: CodeListType.VALUESET, + type: CodelistType.VALUESET, links: [], }, ], @@ -116,7 +116,7 @@ describe('JsonStat2ResponseMapper', () => { CONTENT2: '1 January each year', }, show: 'value', - codeLists: [], + codelists: [], }, }, }, @@ -190,9 +190,9 @@ describe('JsonStat2ResponseMapper', () => { expect(pxTable.metadata.variables.length).equals(3); expect(pxTable.metadata.variables[0].values.length).equals(2); expect(pxTable.metadata.variables[0].mandatory).equals(true); - expect(pxTable.metadata.variables[0].codeLists?.length).equals(0); + expect(pxTable.metadata.variables[0].codelists?.length).equals(0); expect(pxTable.metadata.variables[1].mandatory).equals(false); - expect(pxTable.metadata.variables[1].codeLists?.length).equals(2); + expect(pxTable.metadata.variables[1].codelists?.length).equals(2); expect(pxTable.metadata.contacts?.length).equals(2); expect(pxTable.metadata.notes?.length).equals(3); expect(pxTable.metadata.notes[0].mandatory).equals(true); @@ -345,7 +345,7 @@ describe('JsonStat2ResponseMapper', () => { { code: '2021', label: '2021' }, { code: '2022', label: '2022' }, ], - codeLists: [], + codelists: [], notes: [], }, { @@ -357,7 +357,7 @@ describe('JsonStat2ResponseMapper', () => { { code: 'US', label: 'United States' }, { code: 'UK', label: 'United Kingdom' }, ], - codeLists: [], + codelists: [], notes: [], }, ], @@ -424,7 +424,7 @@ describe('JsonStat2ResponseMapper', () => { { code: '2021', label: '2021' }, { code: '2022', label: '2022' }, ], - codeLists: [], + codelists: [], notes: [], }, { @@ -436,7 +436,7 @@ describe('JsonStat2ResponseMapper', () => { { code: 'US', label: 'United States' }, { code: 'UK', label: 'United Kingdom' }, ], - codeLists: [], + codelists: [], notes: [], }, ], @@ -502,7 +502,7 @@ describe('JsonStat2ResponseMapper', () => { type: VartypeEnum.REGULAR_VARIABLE, mandatory: true, values: [{ code: '2021', label: '2021' }], - codeLists: [], + codelists: [], notes: [], }, ], diff --git a/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.ts b/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.ts index fe9c37348..9090bf6ec 100644 --- a/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.ts +++ b/packages/pxweb2/src/mappers/JsonStat2ResponseMapper.ts @@ -5,7 +5,7 @@ import { jsonstat_note, jsonstat_noteMandatory, extension_dimension, - CodeListInformation, + CodelistInformation, } from '@pxweb2/pxweb2-api-client'; import { Dimensions, @@ -17,7 +17,7 @@ import { VartypeEnum, PxTableData, PxTableMetadata, - CodeList, + Codelist, Contact, ContentInfo, Note, @@ -277,7 +277,7 @@ function mapDimension(id: string, dimension: any, role: any): Variable | null { type: variableType, mandatory: getMandatoryVariable(dimension.extension), values: mapVariableValues(dimension, isContentVariable), - codeLists: getCodelists(dimension.extension), + codelists: getCodelists(dimension.extension), notes: mapNotes(dimension.note, dimension.extension?.noteMandatory), valueDisplayType: getValueDisplayType(dimension.extension), }; @@ -457,17 +457,17 @@ function getMandatoryVariable( } /** - * Maps the code lists of a dimension from a JSON-stat 2.0 response to an array of CodeList objects. + * Maps the code lists of a dimension from a JSON-stat 2.0 response to an array of Codelist objects. * * @param dimensionExtension - The dimension extension object from the JSON-stat 2.0 response. - * @returns An array of CodeList objects. + * @returns An array of Codelist objects. */ -function getCodelists(dimensionExtension: extension_dimension): CodeList[] { - if (dimensionExtension?.codeLists) { - return dimensionExtension.codeLists.map((codeList: CodeListInformation) => { +function getCodelists(dimensionExtension: extension_dimension): Codelist[] { + if (dimensionExtension?.codelists) { + return dimensionExtension.codelists.map((codelist: CodelistInformation) => { return { - id: codeList.id, - label: codeList.label, + id: codelist.id, + label: codelist.label, }; }); } diff --git a/packages/pxweb2/src/mappers/TableMetadataResponseMapper.ts b/packages/pxweb2/src/mappers/TableMetadataResponseMapper.ts deleted file mode 100644 index 815fa5311..000000000 --- a/packages/pxweb2/src/mappers/TableMetadataResponseMapper.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - AbstractCodeListVariable, - TableMetadataResponse, - VariableTypeEnum, -} from '@pxweb2/pxweb2-api-client'; -import { PxTableMetadata, VartypeEnum } from '@pxweb2/pxweb2-ui'; - -export function mapTableMetadataResponse( - response: TableMetadataResponse, -): PxTableMetadata { - try { - const pxTableMetadata: PxTableMetadata = { - id: response.id, - label: response.label, - updated: response.updated ? new Date(response.updated) : new Date(), - variables: response.variables.map((variable) => { - return { - id: variable.id, - label: variable.label, - type: mapVariableTypeEnum(variable.type), - mandatory: - (variable as AbstractCodeListVariable).elimination != null - ? !(variable as AbstractCodeListVariable).elimination - : true, - values: (variable as AbstractCodeListVariable).values.map((value) => { - return { - label: value.label, - code: value.code, - notes: value.notes?.map((note) => { - return { - text: note.text, - mandatory: note.mandatory != null ? note.mandatory : false, - }; - }), - }; - }), - codeLists: (variable as AbstractCodeListVariable).codeLists?.map( - (codeList) => { - return { - id: codeList.id, - label: codeList.label, - }; - }, - ), - notes: variable.notes?.map((note) => { - return { - text: note.text, - mandatory: note.mandatory != null ? note.mandatory : false, - }; - }), - }; - }), - language: '', - }; - - return pxTableMetadata; - } catch (error) { - console.error('Error mapping table metadata response', error); - throw new Error('Error mapping table metadata response'); - } -} - -function mapVariableTypeEnum(type: VariableTypeEnum): VartypeEnum { - switch (type) { - case VariableTypeEnum.CONTENTS_VARIABLE: - return VartypeEnum.CONTENTS_VARIABLE; - case VariableTypeEnum.TIME_VARIABLE: - return VartypeEnum.TIME_VARIABLE; - case VariableTypeEnum.GEOGRAPHICAL_VARIABLE: - return VartypeEnum.GEOGRAPHICAL_VARIABLE; - case VariableTypeEnum.REGULAR_VARIABLE: - return VartypeEnum.REGULAR_VARIABLE; - default: - throw new Error( - `Unknown variable type in mapTableMetadataResponse: ${type}`, - ); - } -} diff --git a/packages/pxweb2/src/mappers/TableSelectionResponseMapper.spec.ts b/packages/pxweb2/src/mappers/TableSelectionResponseMapper.spec.ts index 39be68c82..a5e79e31e 100644 --- a/packages/pxweb2/src/mappers/TableSelectionResponseMapper.spec.ts +++ b/packages/pxweb2/src/mappers/TableSelectionResponseMapper.spec.ts @@ -14,7 +14,7 @@ describe('TableSelectionResponseMapper', () => { }, { variableCode: 'testVarCode2', - codeList: 'testCodeList', + codelist: 'testCodelist', valueCodes: ['testValueCode2'], }, ], @@ -26,12 +26,12 @@ describe('TableSelectionResponseMapper', () => { expect(result).toEqual([ { id: 'testVarCode', - selectedCodeList: undefined, + selectedCodelist: undefined, values: ['testValueCode'], }, { id: 'testVarCode2', - selectedCodeList: 'testCodeList', + selectedCodelist: 'testCodelist', values: ['testValueCode2'], }, ]); diff --git a/packages/pxweb2/src/mappers/TableSelectionResponseMapper.ts b/packages/pxweb2/src/mappers/TableSelectionResponseMapper.ts index cabfe60d2..194b55be2 100644 --- a/packages/pxweb2/src/mappers/TableSelectionResponseMapper.ts +++ b/packages/pxweb2/src/mappers/TableSelectionResponseMapper.ts @@ -8,7 +8,7 @@ export function mapTableSelectionResponse( (variable) => { return { id: variable.variableCode, - selectedCodeList: variable.codeList ? variable.codeList : undefined, + selectedCodelist: variable.codelist ? variable.codelist : undefined, values: variable.valueCodes ? variable.valueCodes : [], }; },