1
- import { SortState } from '@navikt/ds-react' ;
1
+ import { SortState , Switch } from '@navikt/ds-react' ;
2
2
import { listSort } from '@navikt/skjemadigitalisering-shared-components' ;
3
3
import { FormsApiGlobalTranslation } from '@navikt/skjemadigitalisering-shared-domain' ;
4
4
import { useMemo , useState } from 'react' ;
@@ -14,6 +14,7 @@ interface Props {
14
14
}
15
15
16
16
const GlobalTranslationsTable = ( { translations, addNewRow, loading = false } : Props ) => {
17
+ const [ isFilterChecked , setIsFilterChecked ] = useState ( false ) ;
17
18
const [ sortState , setSortState ] = useState < SortState > ( ) ;
18
19
const { updateTranslation, errors, editState } = useEditGlobalTranslations ( ) ;
19
20
@@ -27,25 +28,34 @@ const GlobalTranslationsTable = ({ translations, addNewRow, loading = false }: P
27
28
} ) ;
28
29
} ;
29
30
31
+ const filteredRows = useMemo < FormsApiGlobalTranslation [ ] | undefined > ( ( ) => {
32
+ return isFilterChecked ? translations ?. filter ( ( row ) => ! row . nn || ! row . en ) : translations ;
33
+ } , [ isFilterChecked , translations ] ) ;
34
+
30
35
const sortedRows = useMemo < FormsApiGlobalTranslation [ ] | undefined > ( ( ) => {
31
- return translations
36
+ return filteredRows
32
37
?. slice ( )
33
38
. sort ( listSort . getLocaleComparator ( sortState ?. orderBy , sortState ?. direction , addNewRow ) ) ;
34
- } , [ translations , sortState ?. orderBy , sortState ?. direction , addNewRow ] ) ;
39
+ } , [ filteredRows , sortState ?. orderBy , sortState ?. direction , addNewRow ] ) ;
35
40
36
41
return (
37
- < TranslationTable loading = { loading || ! sortedRows } sort = { sortState } onSortChange = { handleSort } >
38
- { addNewRow && < NewTranslationRow /> }
39
- { sortedRows ?. map ( ( row ) => (
40
- < TranslationRow
41
- key = { row . key }
42
- translation = { row }
43
- updateTranslation = { updateTranslation }
44
- errors = { errors }
45
- editState = { editState }
46
- />
47
- ) ) }
48
- </ TranslationTable >
42
+ < >
43
+ < Switch checked = { isFilterChecked } onChange = { ( event ) => setIsFilterChecked ( event . target . checked ) } >
44
+ Vis kun manglende oversettelser
45
+ </ Switch >
46
+ < TranslationTable loading = { loading || ! sortedRows } sort = { sortState } onSortChange = { handleSort } >
47
+ { addNewRow && < NewTranslationRow /> }
48
+ { sortedRows ?. map ( ( row ) => (
49
+ < TranslationRow
50
+ key = { row . key }
51
+ translation = { row }
52
+ updateTranslation = { updateTranslation }
53
+ errors = { errors }
54
+ editState = { editState }
55
+ />
56
+ ) ) }
57
+ </ TranslationTable >
58
+ </ >
49
59
) ;
50
60
} ;
51
61
0 commit comments