File tree Expand file tree Collapse file tree
components/stix/subtype-property/subtype-view
services/connectors/rest-api Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 => {
You can’t perform that action at this time.
0 commit comments