Skip to content

Commit

Permalink
Don't use an object as an id so app doesn't crash (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
jafeltra authored Oct 9, 2024
1 parent 78eb699 commit e172742
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/JSONEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ const checkFshType = (def) => {

const checkIdToDisplay = (def) => {
if (def.id) {
return def.id;
if (typeof def.id === 'object') {
// NOTE: This case shouldn't really happen -- it only comes up when id was assigned using an inline instance
if (def.id.value) {
return def.id.value;
}
} else {
// Typical case
return def.id;
}
}
if (def.resourceType) {
// Logical Model instances don't always have an id, so fall back to last part of the resourceType
Expand Down
37 changes: 37 additions & 0 deletions tests/components/JSONEditor.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,43 @@ describe('file tree display', () => {
expect(untitledDef).toBeInTheDocument();
});

// NOTE: This is not a typical case -- but just check that it works so that FSH Online doesn't crash if an inline instance is assigned to id
it('displays the id.value if definition id is an object', () => {
const profileWithObjectId = {
profiles: [
{
resourceType: 'StructureDefinition',
id: { value: 'example-object-id' } // object id with a value to use as id
},
{
resourceType: 'StructureDefinition',
id: { extension: [{ valueString: 'do not display this as an id' }] } // object without a value to use as id
}
],
extensions: [],
logicals: [],
resources: [],
instances: [],
valueSets: [],
codeSystems: []
};
const { getByText } = render(
<JSONEditor
showNewText={true}
setShowNewText={() => {}}
isWaiting={false}
updateTextValue={() => {}}
text={JSON.stringify(profileWithObjectId, null, 2)}
/>,
container
);

const structureDef = getByText('example-object-id');
expect(structureDef).toBeInTheDocument();
const exampleLM = getByText('Instance of StructureDefinition');
expect(exampleLM).toBeInTheDocument();
});

it('sorts a definition to Unknown Type if a definition does not have a resourceType', () => {
const profileWithoutId = {
profiles: [
Expand Down

0 comments on commit e172742

Please sign in to comment.