-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/PXWEB2-319-Add-metainfo-to-cells
- Loading branch information
Showing
13 changed files
with
442 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
libs/pxweb2-api-client/src/models/VariablePlacementType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.