Skip to content

Commit c75e653

Browse files
authored
Merge pull request #695 from center-for-threat-informed-defense/fix/fetching-parent-data-sources
Fix fetching parent data source & subtype table sorting
2 parents c05b92a + 380940d commit c75e653

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎src/app/components/stix/subtype-property/subtype-view/subtype-view.component.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ export class SubtypeViewComponent implements OnInit {
2020
public get fieldLabels(): string[] {
2121
return this.config.subtypeFields.map(f => (f.label ? f.label : f.name));
2222
}
23-
2423
public get valueCopy() {
2524
return JSON.parse(JSON.stringify(this.config.object[this.config.field])); //deep copy
2625
}
26+
public get keyField(): string {
27+
return this.config.subtypeFields.find(subtype => subtype.key)?.name;
28+
}
2729

2830
ngOnInit(): void {
2931
this.detailTable = this.valueCopy;
32+
if (this.keyField) {
33+
this.sortTableByKey();
34+
}
3035
this.buildTable();
3136
}
3237

@@ -65,6 +70,17 @@ export class SubtypeViewComponent implements OnInit {
6570
return '';
6671
}
6772

73+
private sortTableByKey(): void {
74+
const key = this.keyField;
75+
this.detailTable.sort((a, b) => {
76+
const aValue = a[key] ?? '';
77+
const bValue = b[key] ?? '';
78+
return String(aValue).localeCompare(String(bValue), undefined, {
79+
sensitivity: 'base',
80+
});
81+
});
82+
}
83+
6884
// Build table of values including any inline citations
6985
public buildTable(): void {
7086
// get subtype field that supports references

‎src/app/services/connectors/rest-api/rest-api-connector.service.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,12 @@ export class RestApiConnectorService extends ApiConnector {
903903
switchMap(result => {
904904
// fetch parent data source of data component
905905
const x = result as any[];
906-
if (x[0].attackType != 'data-component') return of(result);
906+
if (!x[0] || x[0].attackType != 'data-component') return of(result);
907+
907908
const d = x[0] as DataComponent;
909+
// if no data source ref, just return the data component
910+
if (!d.dataSourceRef) return of([d]);
911+
// otherwise, fetch the parent data source
908912
return this.getDataSource(d.dataSourceRef).pipe(
909913
// fetch data source from REST API
910914
map(data_source => {

0 commit comments

Comments
 (0)