-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
217 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
judo-ui-react/src/main/resources/actor/src/components/widgets/CardsFilter.tsx.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{{> fragment.header.hbs }} | ||
|
||
import { type FC, useState, useCallback } from 'react'; | ||
import Grid from '@mui/material/Grid'; | ||
import Typography from '@mui/material/Typography'; | ||
import Button from '@mui/material/Button'; | ||
import FormGroup from '@mui/material/FormGroup'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Checkbox from '@mui/material/Checkbox'; | ||
import { useL10N } from '~/l10n/l10n-context'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export interface CardsFilterDefinition { | ||
type: 'boolean' | 'string'; | ||
field: string; | ||
label: string; | ||
values: { value: any, label: string }[]; | ||
} | ||
|
||
export const CardsFilter: FC<{ filterDefinitions: CardsFilterDefinition[], onFiltersChanged?: (values: Record<string, any>) => void }> = ({ filterDefinitions, onFiltersChanged }) => { | ||
const { locale: l10nLocale } = useL10N(); | ||
const { t } = useTranslation(); | ||
|
||
const [values, setValues] = useState<Record<string, any>>({}); | ||
|
||
const updateValue = useCallback((field: string, value: any) => { | ||
const newValues = { | ||
...values, | ||
[field]: values[field] === value ? null : value, | ||
}; | ||
setValues(newValues); | ||
onFiltersChanged?.(newValues); | ||
}, [values]); | ||
|
||
const clearFilters = useCallback(() => { | ||
setValues({}); | ||
onFiltersChanged?.({}); | ||
}, [values]); | ||
|
||
return ( | ||
<Grid container direction="row" spacing={2}> | ||
<Grid item xs={12}> | ||
<Typography variant="h4"> | ||
Filters | ||
</Typography> | ||
<Button variant={'text'} onClick={clearFilters} >Clear all</Button> | ||
</Grid> | ||
{filterDefinitions.map(d => ( | ||
<Grid item xs={12} key={d.field}> | ||
<Typography variant="subtitle1"> | ||
{d.label}: | ||
</Typography> | ||
<FormGroup> | ||
{d.values.map(v => ( | ||
<FormControlLabel | ||
key={`${d.label}-${v.value}`} | ||
control={<Checkbox | ||
size="small" | ||
checked={values[d.field as any] === v.value} | ||
onClick={() => updateValue(d.field, v.value)} | ||
/>} | ||
label={v.label} | ||
/> | ||
))} | ||
</FormGroup> | ||
</Grid> | ||
))} | ||
</Grid> | ||
); | ||
}; |
64 changes: 64 additions & 0 deletions
64
judo-ui-react/src/main/resources/actor/src/components/widgets/DefaultCard.tsx.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{{> fragment.header.hbs }} | ||
|
||
import { type FC, useCallback } from 'react'; | ||
import Grid from '@mui/material/Grid'; | ||
import Card from '@mui/material/Card'; | ||
import CardContent from '@mui/material/CardContent'; | ||
import Typography from '@mui/material/Typography'; | ||
import CardActions from '@mui/material/CardActions'; | ||
import Button from '@mui/material/Button'; | ||
import type { | ||
GridColDef, | ||
GridEventListener, | ||
GridValidRowModel, | ||
} from '@mui/x-data-grid{{ getMUIDataGridPlanSuffix }}'; | ||
import { useL10N } from '~/l10n/l10n-context'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export interface CardProps<T extends GridValidRowModel> { | ||
row: T; | ||
columns: GridColDef<T>[]; | ||
onRowClick?: (row: T) => void; | ||
} | ||
|
||
export const DefaultCard: FC<CardProps<any>> = ({ onRowClick, row, columns }) => { | ||
const { locale: l10nLocale } = useL10N(); | ||
const { t } = useTranslation(); | ||
|
||
const formatValue = useCallback((value: any) => { | ||
if (value instanceof Date) { | ||
return new Intl.DateTimeFormat(l10nLocale, { | ||
year: 'numeric', | ||
month: '2-digit', | ||
day: '2-digit', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit', | ||
hour12: false | ||
}).format(value); | ||
} | ||
if (value === undefined || value === null) { | ||
return ''; | ||
} | ||
return value.toString(); | ||
}, []); | ||
|
||
return ( | ||
<Grid item sm={12} md={6} lg={6} xl={4}> | ||
<Card variant="outlined"> | ||
<CardContent> | ||
{columns.map((k, idx) => ( | ||
<Typography key={`${row.__identifier}-${k.field}`} variant={idx === 0 ? 'h5' : 'body2'}> | ||
{formatValue(row[k.field])} | ||
</Typography> | ||
))} | ||
</CardContent> | ||
<CardActions> | ||
<Button size="small" onClick={() => onRowClick?.(row)}> | ||
Learn More | ||
</Button> | ||
</CardActions> | ||
</Card> | ||
</Grid> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters