Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsdoc files once loaded do not show descriptions #1605

Closed
danyill opened this issue Nov 28, 2024 · 0 comments · Fixed by #1606
Closed

nsdoc files once loaded do not show descriptions #1605

danyill opened this issue Nov 28, 2024 · 0 comments · Fixed by #1606
Assignees
Labels
Kind: Bug Something isn't working

Comments

@danyill
Copy link
Collaborator

danyill commented Nov 28, 2024

Describe the bug

When nsdoc files are loaded the user should see nice descriptions in, for instance the IED editor

Image

To Reproduce
Steps to reproduce the behavior:

  1. Open SCD file, here's an example: test_file.scd.zip
  2. Load nsdocs under Settings
  3. Open IED editor
  4. See no descriptions

Expected behavior

Want descriptions!

Screenshots

When I open the sample file, I see no descriptions with the nsdocs loaded:

Image

Additional context

It seems like the functions called in getDataDescription are referring to null objects:

export interface Nsdoc {
nsdoc72?: XMLDocument;
nsdoc73?: XMLDocument;
nsdoc74?: XMLDocument;
nsdoc81?: XMLDocument;
getDataDescription: (element: Element, ancestors?: Element[]) => { label: string; }
}
const [nsd72, nsd73, nsd74, nsd81] = await Promise.all([iec6185072, iec6185073, iec6185074, iec6185081]);
/**
* Initialize the full Nsdoc object.
* @returns A fully initialized Nsdoc object for wizards/editors to use.
*/
export function initializeNsdoc(): Nsdoc {
const [nsdoc72, nsdoc73, nsdoc74, nsdoc81] = [
localStorage.getItem('IEC 61850-7-2') ? new DOMParser().parseFromString(localStorage.getItem('IEC 61850-7-2')!, 'application/xml') : undefined,
localStorage.getItem('IEC 61850-7-3') ? new DOMParser().parseFromString(localStorage.getItem('IEC 61850-7-3')!, 'application/xml') : undefined,
localStorage.getItem('IEC 61850-7-4') ? new DOMParser().parseFromString(localStorage.getItem('IEC 61850-7-4')!, 'application/xml') : undefined,
localStorage.getItem('IEC 61850-8-1') ? new DOMParser().parseFromString(localStorage.getItem('IEC 61850-8-1')!, 'application/xml') : undefined
]
const iedElementTagNames = ['LN', 'LN0', 'DO', 'SDO', 'DOI', 'DA', 'BDA', 'DAI'] as const;
type IEDElementTagNames = typeof iedElementTagNames[number];
type GetDataDescription = (element: Element, ancestors?: Element[]) => { label: string; };
const getDataDescriptions: Record<
IEDElementTagNames,
{
getDataDescription: GetDataDescription;
}
> = {
LN: {
getDataDescription: getLNDataDescription
},
LN0: {
getDataDescription: getLNDataDescription
},
DO: {
getDataDescription: getDODataDescription
},
SDO: {
getDataDescription: getSDODataDescription
},
DOI: {
getDataDescription: getDODataDescription
},
DA: {
getDataDescription: getDADataDescription
},
BDA: {
getDataDescription: getBDADataDescription
},
DAI: {
getDataDescription: getDADataDescription
}
};
/**
* Getting data descriptions for LN(0) elements out of the IEC 61850-7-4 .nsdoc file.
* @param element - The element to use for searching the LN description.
* @returns Documentation from the .nsdoc file for this LN(0) file, or the lnClass attribute in case no description can be found.
*/
function getLNDataDescription(element: Element): { label: string; } {
const lnClassAttribute = element.getAttribute('lnClass')!;
const lnClass = nsd74.querySelector(`NS > LNClasses > LNClass[name="${lnClassAttribute}"]`);
const lnClassDescription = getNsdocDocumentation(nsdoc74!, lnClass?.getAttribute('titleID'));
return {
label: lnClassDescription ? lnClassDescription + ' (' + lnClassAttribute + ')' : lnClassAttribute
};
}

e.g.

function getLNDataDescription(element: Element): { label: string; } { 
     const lnClassAttribute = element.getAttribute('lnClass')!; 
     const lnClass = nsd74.querySelector(`NS > LNClasses > LNClass[name="${lnClassAttribute}"]`); 
     const lnClassDescription = getNsdocDocumentation(nsdoc74!, lnClass?.getAttribute('titleID')); 
  
     return { 
       label: lnClassDescription ? lnClassDescription + ' (' + lnClassAttribute + ')' : lnClassAttribute 
     }; 
   } 

On my machine, very often, for instance nsdoc74 is null.
In this file it's hard for me to see how it can be anything other than null as it is defined in initializeNsdoc within the function scope and it is not available in the getXXDataDescription functions.

PR with a possible fix coming shortly.

@danyill danyill added the Kind: Bug Something isn't working label Nov 28, 2024
@danyill danyill self-assigned this Nov 28, 2024
@danyill danyill linked a pull request Nov 28, 2024 that will close this issue
@trusz trusz closed this as completed in ddcd5fc Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kind: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant