Skip to content

Commit

Permalink
Boolean felttyper vises feil og filtreres ikke korrekt #1579
Browse files Browse the repository at this point in the history
  • Loading branch information
olemp committed Jan 16, 2025
1 parent 7c90852 commit 9c68ef9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ export function useFilter(props: IFilterProps) {
* Render filter items
*/
const renderItems = () => {
return state.items.map((props, idx) => (
return state.items.map((item, idx) => (
<FilterItem
key={idx}
{...props}
onChange={(_event, { checked }) => onChange(props, checked as boolean)}
{...item}
column={props.column}
onChange={(_event, { checked }) => onChange(item, checked as boolean)}
/>
))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Checkbox } from '@fluentui/react-components'
import React, { FC } from 'react'
import styles from './FilterItem.module.scss'
import { IFilterItemProps } from './types'
import { Checkbox } from '@fluentui/react-components'
import { useFilterItem } from './useFilterItem'

export const FilterItem: FC<IFilterItemProps> = (props) => {
const { label } = useFilterItem(props)
return (
<Checkbox
className={styles.filterItem}
label={props.name}
label={label}
checked={props.selected}
onChange={props.onChange}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { IColumn } from '@fluentui/react'
import { CheckboxProps } from '@fluentui/react-components'

export interface IFilterItemProps extends Pick<CheckboxProps, 'onChange'> {
name: string
value: string
selected?: boolean
column?: IColumn
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import strings from 'SharedLibraryStrings'
import _ from 'lodash'
import { IFilterItemProps } from './types'

export function useFilterItem(props: IFilterItemProps) {
switch (props.column.data.renderAs) {
case 'boolean': {
const valueIfTrue = _.get(props, 'column.data.dataTypeProperties.valueIfTrue', strings.BooleanYes)
const valueIfFalse = _.get(props, 'column.data.dataTypeProperties.valueIfFalse', strings.BooleanNo)
return { label: parseInt(props.value) === 1 ? valueIfTrue : valueIfFalse }
}
default: {
return { label: props.name }
}
}
}
3 changes: 2 additions & 1 deletion SharePointFramework/shared-library/src/loc/mystrings.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
declare interface ISharedLibraryStrings {
BooleanYes: string
BooleanNo: string
GtModerationStatus_Choice_Draft: string
GtModerationStatus_Choice_Published: string
SaveText: string
Expand Down
2 changes: 2 additions & 0 deletions SharePointFramework/shared-library/src/loc/nb-no.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ define([], function () {
TriangleLabel: 'Trekant',
TypeLabel: 'Type',
SyncListAddingField: 'Legger til felt {0} i prosjektegenskaper...',
BooleanYes: 'Ja',
BooleanNo: 'Nei',
}
})

0 comments on commit 9c68ef9

Please sign in to comment.