Skip to content

Commit

Permalink
Merge branch 'main' into feature/PXWEB2-319-Add-metainfo-to-cells
Browse files Browse the repository at this point in the history
  • Loading branch information
PerIngeVaaje committed Nov 14, 2024
2 parents 53dd2da + 06158a3 commit b9fbb92
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 307 deletions.
4 changes: 3 additions & 1 deletion apps/pxweb2/src/app/components/Presentation/Presentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export function Presentation({ selectedTabId }: propsType) {
.filter((variable) => variable.mandatory)
.every((variable) =>
selectedVBValues.some(
(selectedVariable) => selectedVariable.id === variable.id
(selectedVariable) =>
selectedVariable.id === variable.id &&
selectedVariable.values.length > 0
)
);

Expand Down
8 changes: 6 additions & 2 deletions apps/pxweb2/src/app/components/Selection/Selection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from 'react-i18next';
import { useState, useEffect } from 'react';

import { TableService } from '@pxweb2/pxweb2-api-client';
import { metadataOutputFormat, MetadataOutputFormatType, TableService } from '@pxweb2/pxweb2-api-client';
import { mapTableMetadataResponse } from '../../../mappers/TableMetadataResponseMapper';
import { mapTableSelectionResponse } from '../../../mappers/TableSelectionResponseMapper';
import {
Expand Down Expand Up @@ -211,11 +211,15 @@ export function Selection({
variables.setIsLoadingMetadata(true);
}

TableService.getMetadataById(selectedTabId, i18n.resolvedLanguage)
const outputFormat: metadataOutputFormat = MetadataOutputFormatType.JSON_PX;
const metaDataDefaultSelection = true;

TableService.getMetadataById(selectedTabId, i18n.resolvedLanguage, outputFormat, metaDataDefaultSelection)
.then((tableMetadataResponse) => {
const pxTabMetadata: PxTableMetadata = mapTableMetadataResponse(
tableMetadataResponse
);

setPxTableMetadata(pxTabMetadata);
if (pxTableMetaToRender !== null) {
setPxTableMetaToRender(null);
Expand Down
115 changes: 67 additions & 48 deletions apps/pxweb2/src/mappers/TableMetadataResponseMapper.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,78 @@
import { AbstractCodeListVariable, TableMetadataResponse, VariableTypeEnum } from "@pxweb2/pxweb2-api-client";
import { PxTableMetadata, VartypeEnum } from "@pxweb2/pxweb2-ui";

export function mapTableMetadataResponse(response: TableMetadataResponse): PxTableMetadata {
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) => {
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 {
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
};
})
text: note.text,
mandatory: note.mandatory != null ? note.mandatory : false,
};
}),
language: ""
}),
};
}),
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;
}
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}`
);
}
}
7 changes: 3 additions & 4 deletions docs/project/plans.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Plans

The project has different goals, and one of them is to launch a test-version of PxWeb in mid 2024.
Another goal is to deliver a beta-version of PxWeb based on PxWebAPI 2.0 during 2024.
The project has different goals, one of which is to launch a test-version of PxWeb 2.0 in mid 2024. Another goal is to deliver a version of PxWeb 2.0 based on PxWebAPI 2.0 during spring 2025.


## PxWeb 2.0 delivery testversion June 2024
- New PxWeb page with variablebox and table, getting data from API 2.0
- Language management
- Algorithm for choosing the best result for displaying a table
- Chose different values in variable and see changes in the table
- Choose different values in variable and see changes in the table


![Picture of detail-page of variabel and the table in PxWeb 2.0](https://github.com/PxTools/PxWeb2/assets/81364833/39acd512-a589-4734-af96-4e76983f644d)


## Maintasks autumn 2024
## Maintasks spring 2025

- Main-page for PxWeb 2.0
- Graph
Expand Down
1 change: 1 addition & 0 deletions libs/pxweb2-api-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export { TimeVariable } from './models/TimeVariable';
export type { updated } from './models/updated';
export type { Value } from './models/Value';
export type { ValueMap } from './models/ValueMap';
export type { VariablePlacementType } from './models/VariablePlacementType';
export type { VariableSelection } from './models/VariableSelection';
export type { VariablesSelection } from './models/VariablesSelection';
export { VariableTypeEnum } from './models/VariableTypeEnum';
Expand Down
6 changes: 5 additions & 1 deletion libs/pxweb2-api-client/src/models/ConfigResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import type { SourceReference } from './SourceReference';
*/
export type ConfigResponse = {
/**
* The version of then API
* The version of the API spesification
*/
apiVersion: string;
/**
* The version of the API implementation
*/
appVersion: string;
/**
* A list of language that exists for the data.
*/
Expand Down
15 changes: 15 additions & 0 deletions libs/pxweb2-api-client/src/models/VariablePlacementType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type VariablePlacementType = {
/**
* List of variables that should be placed in the heading in the resulting data
*/
heading?: Array<string>;
/**
* List of variables that should be placed in the stub in the resulting data
*/
stub?: Array<string>;
};

2 changes: 2 additions & 0 deletions libs/pxweb2-api-client/src/models/VariablesSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { VariablePlacementType } from './VariablePlacementType';
import type { VariableSelection } from './VariableSelection';
export type VariablesSelection = {
selection: Array<VariableSelection>;
palcement?: VariablePlacementType;
};

Loading

0 comments on commit b9fbb92

Please sign in to comment.