File tree Expand file tree Collapse file tree
routes/(console)/project-[region]-[project]/auth Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11export type PrefRow = { key : string ; value : string } ;
22
3- export function normalizePrefs ( entries : [ string , string ] [ ] | PrefRow [ ] ) : [ string , string ] [ ] {
3+ function stringTrim ( s : unknown ) : string {
4+ return String ( s ?? '' ) . trim ( ) ;
5+ }
6+
7+ export function normalizePrefs (
8+ entries : [ string , unknown ] [ ] | PrefRow [ ] | { key : unknown ; value : unknown } [ ]
9+ ) : [ string , string ] [ ] {
410 return entries
511 . map ( ( item ) : [ string , string ] =>
6- Array . isArray ( item ) ? [ item [ 0 ] , item [ 1 ] ] : [ item . key , item . value ]
12+ Array . isArray ( item )
13+ ? [ String ( item [ 0 ] ?? '' ) , String ( item [ 1 ] ?? '' ) ]
14+ : [ String ( item . key ?? '' ) , String ( item . value ?? '' ) ]
715 )
8-
9- . filter ( ( [ k , v ] ) => k . trim ( ) && v . trim ( ) )
16+ . filter ( ( [ k , v ] ) => stringTrim ( k ) . length > 0 && stringTrim ( v ) . length > 0 )
1017 . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) ) ;
1118}
1219
@@ -23,5 +30,5 @@ export function isAddDisabled(prefs: PrefRow[] | null): boolean {
2330}
2431
2532export function sanitizePrefs ( prefs : PrefRow [ ] ) {
26- return prefs . filter ( ( p ) => p . key . trim ( ) && p . value . trim ( ) ) ;
33+ return prefs . filter ( ( p ) => stringTrim ( p . key ) . length > 0 && stringTrim ( p . value ) . length > 0 ) ;
2734}
Original file line number Diff line number Diff line change 2222
2323 $ : if (prefs ) {
2424 const currentNormalized = normalizePrefs (prefs );
25- const originalNormalized = normalizePrefs (
26- Object .entries (($team ?.prefs ?? {}) as Record <string , string >)
27- );
25+ const originalNormalized = normalizePrefs (Object .entries ($team ?.prefs ?? {}));
2826
2927 arePrefsDisabled = deepEqual (currentNormalized , originalNormalized );
3028 }
3331 let arePrefsDisabled = true ;
3432
3533 onMount (async () => {
36- const entries = Object .entries (( $team ?.prefs ?? {}) as Record < string , string > );
34+ const entries = Object .entries ($team ?.prefs ?? {});
3735 prefs =
3836 entries .length > 0
39- ? entries .map (([key , value ]) => createPrefRow (key , value ))
37+ ? entries .map (([key , value ]) =>
38+ createPrefRow (String (key ?? ' ' ), String (value ?? ' ' ))
39+ )
4040 : [createPrefRow ()];
4141 });
4242
Original file line number Diff line number Diff line change 3434 const entries = Object .entries ($user ?.prefs ?? {});
3535 prefs =
3636 entries .length > 0
37- ? entries .map (([key , value ]) => createPrefRow (key , value ))
37+ ? entries .map (([key , value ]) =>
38+ createPrefRow (String (key ?? ' ' ), String (value ?? ' ' ))
39+ )
3840 : [createPrefRow ()];
3941 });
4042
You can’t perform that action at this time.
0 commit comments