File tree Expand file tree Collapse file tree
pages/CreateChangeRequestPage Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import NERFailButton from '../../components/NERFailButton';
3636import NERSuccessButton from '../../components/NERSuccessButton' ;
3737import { wbsNamePipe } from '../../utils/pipes' ;
3838import PageLayout from '../../components/PageLayout' ;
39+ import { wbsNumComparator } from 'shared/src/validate-wbs' ;
3940
4041interface CreateChangeRequestViewProps {
4142 wbsNum : string ;
@@ -103,6 +104,7 @@ const CreateChangeRequestsView: React.FC<CreateChangeRequestViewProps> = ({
103104 if ( isError ) return < ErrorPage message = { error ?. message } /> ;
104105
105106 const projectOptions : { label : string ; id : string } [ ] = [ ] ;
107+
106108 const wbsDropdownOptions : { label : string ; id : string } [ ] = [ ] ;
107109
108110 projects . forEach ( ( project : Project ) => {
@@ -122,6 +124,8 @@ const CreateChangeRequestsView: React.FC<CreateChangeRequestViewProps> = ({
122124 } ) ;
123125 } ) ;
124126
127+ wbsDropdownOptions . sort ( ( wbsNum1 , wbsNum2 ) => wbsNumComparator ( wbsNum1 . id , wbsNum2 . id ) ) ;
128+
125129 const wbsAutocompleteOnChange = (
126130 _event : React . SyntheticEvent < Element , Event > ,
127131 value : { label : string ; id : string } | null
Original file line number Diff line number Diff line change 1+ import { wbsNumComparator } from 'shared' ;
2+ import '@testing-library/jest-dom/extend-expect' ;
3+
4+ describe ( 'wbsNumComparator' , ( ) => {
5+ it ( 'should correctly compare two WBS Numbers' , ( ) => {
6+ expect ( wbsNumComparator ( '1.1.3' , '1.3.4' ) ) . toBe ( - 1 ) ;
7+ expect ( wbsNumComparator ( '1.2.1' , '1.2.1' ) ) . toBe ( 0 ) ;
8+ expect ( wbsNumComparator ( '1.3.4' , '1.1.3' ) ) . toBe ( 1 ) ;
9+ expect ( wbsNumComparator ( '2.3.4' , '1.1.3' ) ) . toBe ( 1 ) ;
10+ expect ( wbsNumComparator ( '1.3.4' , '2.1.3' ) ) . toBe ( - 1 ) ;
11+ } ) ;
12+ } ) ;
Original file line number Diff line number Diff line change 55
66import { WbsNumber } from './types/project-types' ;
77
8+ /**
9+ * Compares two wbs numbers in ascending order
10+ *
11+ * @param wbsNum1 WBS number to compare
12+ * @param wbsNum2 WBS number to compare
13+ */
14+ export const wbsNumComparator = ( wbsNum1 : string , wbsNum2 : string ) => {
15+ const wbsParts1 = wbsNum1 . split ( '.' ) . map ( Number ) ;
16+ const wbsParts2 = wbsNum2 . split ( '.' ) . map ( Number ) ;
17+
18+ for ( let i = 0 ; i < wbsParts1 . length ; i ++ ) {
19+ if ( wbsParts1 [ i ] < wbsParts2 [ i ] ) {
20+ return - 1 ;
21+ } else if ( wbsParts1 [ i ] > wbsParts2 [ i ] ) {
22+ return 1 ;
23+ }
24+ }
25+
26+ return 0 ;
27+ } ;
28+
829/**
930 * Ensure the provided wbsNum is a valid Work Breakdown Structure Number
1031 *
You can’t perform that action at this time.
0 commit comments