Skip to content

Commit

Permalink
t: Add getOBSSystemsSubsystemsComponentsIds utility function to parse…
Browse files Browse the repository at this point in the history
… systems ids from components_json parameter.
  • Loading branch information
sebastian-aranda committed Jan 9, 2025
1 parent 5e776b7 commit bc776de
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
82 changes: 81 additions & 1 deletion love/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ export function arrangeNarrativelogOBSSystemsSubsystemsComponents(systemsIds, su
});

// We assume that the hierarchy will always have a single root (system)
return JSON.stringify(hierarchy[0]);
return JSON.stringify(hierarchy[0] ?? {});
}

/**
Expand Down Expand Up @@ -2323,3 +2323,83 @@ export function validateOBSSystemsSubsystemsComponentsIds(systemsIds, subsystems
componentsIds: validComponentsIds,
};
}

/**
* Function to get OBS systems, subsystems and components ids.
* @param {object} systemsHierarchy JSON object with the components in the form of:
* * {
* name: "System-A",
* children: [
* {
* name: "Subsystem-A",
* children: [
* {
* name: "Component-A",
* },
* ],
* },
* {
* name: "Subsystem-B",
* children: [
* {
* name: "Component-B",
* },
* ],
* },
* ],
* }
* @returns {object} Object with valid ids for systems, subsystems and components.
*/
export function getOBSSystemsSubsystemsComponentsIds(systemsHierarchy) {
const systemsIds = [];
const subsystemsIds = [];
const componentsIds = [];

const systemName = systemsHierarchy?.name;
const system = OLE_OBS_SYSTEMS[systemName];
if (system) {
systemsIds.push(system.id);
}

if (systemsHierarchy?.children) {
const availableSubsystemsIds = OLE_OBS_SYSTEMS[systemName]?.children;
const availableSubsystems = Object.entries(OLE_OBS_SUBSYSTEMS)
.filter(([ssn, ss]) => {
return availableSubsystemsIds.includes(ss.id);
})
.map(([ssn, ss]) => ({ name: ssn, ...ss }));

const subsystemsHierarchy = systemsHierarchy.children.map((ssh) => {
const subsystem = availableSubsystems.find((ssa) => ssa.name.includes(ssh.name));
return { ...subsystem, children: ssh.children };
});

subsystemsHierarchy.forEach((subsystemHierarchy) => {
const subsystemName = subsystemHierarchy.name;
subsystemsIds.push(subsystemHierarchy.id);
if (subsystemHierarchy?.children) {
const availableComponentsIds = OLE_OBS_SUBSYSTEMS[subsystemName]?.children;
const availableComponents = Object.entries(OLE_OBS_SUBSYSTEMS_COMPONENTS)
.filter(([cn, c]) => {
return availableComponentsIds.includes(c.id);
})
.map(([cn, c]) => ({ name: cn, ...c }));

const componentsHierarchy = subsystemHierarchy.children.map((ch) => {
const component = availableComponents.find((ca) => ca.name.includes(ch.name));
return { ...component };
});

componentsHierarchy.forEach((componentHierarchy) => {
componentsIds.push(componentHierarchy.id);
});
}
});
}

return {
systemsIds,
subsystemsIds,
componentsIds,
};
}
10 changes: 10 additions & 0 deletions love/src/components/OLE/NonExposure/NonExposureEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import ManagerInterface, {
arrangeJiraOBSSystemsSubsystemsComponentsSelection,
arrangeNarrativelogOBSSystemsSubsystemsComponents,
validateOBSSystemsSubsystemsComponentsIds,
getOBSSystemsSubsystemsComponentsIds,
} from 'Utils';
import { getIconLevel, closeCalendar } from '../OLE';
import styles from './NonExposure.module.css';
Expand Down Expand Up @@ -103,6 +104,15 @@ class NonExposureEdit extends Component {
logEdit['date_begin'] = logEdit['date_begin'] ? Moment(logEdit['date_begin'] + 'Z') : '';
logEdit['date_end'] = logEdit['date_end'] ? Moment(logEdit['date_end'] + 'Z') : '';

if (logEdit['components_json']) {
const { systemsIds, subsystemsIds, componentsIds } = getOBSSystemsSubsystemsComponentsIds(
logEdit['components_json'],
);
logEdit['systems_ids'] = systemsIds;
logEdit['subsystems_ids'] = subsystemsIds;
logEdit['components_ids'] = componentsIds;
}

this.state = {
logEdit: { ...NonExposureEdit.defaultProps.logEdit, ...logEdit },
savingLog: false,
Expand Down

0 comments on commit bc776de

Please sign in to comment.