-
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.
* Added DataTable for passwords. * Added Password Page. --------- Co-authored-by: Pavel <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,752 additions
and
1,017 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
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
29 changes: 29 additions & 0 deletions
29
code/frontend/src/Common/components/CheckboxGroup/CheckboxGroup.tsx
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,29 @@ | ||
import { Checkbox, Stack } from '@chakra-ui/react'; | ||
import { FC } from 'react'; | ||
|
||
import { useLocale } from '~/locale'; | ||
|
||
import { CheckboxGroupProps } from './CheckboxGroup.types'; | ||
|
||
export const CheckboxGroup: FC<CheckboxGroupProps> = props => { | ||
const { options, selectedKeys, onChange, onToggleAll } = props; | ||
const locale = useLocale(); | ||
|
||
return ( | ||
<Stack spacing={[1, 5]}> | ||
<Checkbox | ||
isChecked={selectedKeys.length === options.length} | ||
isIndeterminate={selectedKeys.length > 0 && selectedKeys.length !== options.length} | ||
onChange={onToggleAll} | ||
> | ||
{locale.checkboxes.selectAll} | ||
</Checkbox> | ||
|
||
{options.map(({ key, label }) => ( | ||
<Checkbox key={key} isChecked={selectedKeys.indexOf(key) > -1} onChange={() => onChange(key)}> | ||
{label} | ||
</Checkbox> | ||
))} | ||
</Stack> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
code/frontend/src/Common/components/CheckboxGroup/CheckboxGroup.types.ts
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,8 @@ | ||
import { Option } from '~/Common/types'; | ||
|
||
export interface CheckboxGroupProps { | ||
options: Option[]; | ||
selectedKeys: string[]; | ||
onChange: (key: string) => void; | ||
onToggleAll: () => void; | ||
} |
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,2 @@ | ||
export * from './CheckboxGroup'; | ||
export * from './CheckboxGroup.types'; |
47 changes: 47 additions & 0 deletions
47
code/frontend/src/Common/components/DataTable/DataTable.tsx
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,47 @@ | ||
import { Table, Thead, Tbody, Tr } from '@chakra-ui/react'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { HeaderCell, TableCell } from './components'; | ||
import { DataTableProps, FilterSettings } from './DataTable.types'; | ||
|
||
export function DataTable<Data extends object>(props: DataTableProps<Data>) { | ||
const { data, columns, getRowKey, onFilterChange } = props; | ||
|
||
const [filterSettings, setFilterSettings] = useState<FilterSettings>({}); | ||
|
||
useEffect(() => { | ||
if (onFilterChange) onFilterChange(filterSettings); | ||
}, [filterSettings]); | ||
|
||
return ( | ||
<Table> | ||
<Thead> | ||
<Tr> | ||
{columns.map(column => ( | ||
<HeaderCell | ||
key={column.name} | ||
column={column} | ||
onFilterChange={selectedKeys => | ||
setFilterSettings(prevState => ({ ...prevState, [column.name]: selectedKeys })) | ||
} | ||
/> | ||
))} | ||
</Tr> | ||
</Thead> | ||
|
||
<Tbody> | ||
{data.map(row => { | ||
const rowKey = getRowKey(row); | ||
|
||
return ( | ||
<Tr key={rowKey}> | ||
{columns.map(({ name, getRowValue }) => ( | ||
<TableCell key={`${rowKey}-${name}`} value={getRowValue(row)} /> | ||
))} | ||
</Tr> | ||
); | ||
})} | ||
</Tbody> | ||
</Table> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
code/frontend/src/Common/components/DataTable/DataTable.types.ts
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,19 @@ | ||
import { Option } from '~/Common/types'; | ||
|
||
export type Column<DataType extends object> = { | ||
name: string; | ||
title: string; | ||
filterOptions?: Option[]; | ||
getRowValue: (row: DataType) => string; | ||
}; | ||
|
||
export type FilterSettings = { | ||
[name: string]: string[]; | ||
}; | ||
|
||
export type DataTableProps<DataType extends object> = { | ||
data: DataType[]; | ||
columns: Column<DataType>[]; | ||
getRowKey: (row: DataType) => string; | ||
onFilterChange?: (filterSettings: FilterSettings) => void; | ||
}; |
51 changes: 51 additions & 0 deletions
51
code/frontend/src/Common/components/DataTable/components/HeaderCell.tsx
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,51 @@ | ||
import { Popover, Th, Flex, PopoverTrigger, IconButton, Portal, PopoverContent, PopoverBody } from '@chakra-ui/react'; | ||
import { FilterList } from '@mui/icons-material'; | ||
import { useEffect } from 'react'; | ||
|
||
import { CheckboxGroup } from '../../CheckboxGroup'; | ||
import { Column } from '../DataTable.types'; | ||
|
||
import { useCheckboxGroupKeys } from '~/Common/hooks'; | ||
|
||
interface HeaderCellProps<Data extends object> { | ||
column: Column<Data>; | ||
onFilterChange: (selectedKeys: string[]) => void; | ||
} | ||
|
||
export function HeaderCell<Data extends object>({ column, onFilterChange }: HeaderCellProps<Data>) { | ||
const { title, filterOptions = [] } = column; | ||
const { selectedKeys, onChange, onToggleAll } = useCheckboxGroupKeys(filterOptions); | ||
|
||
useEffect(() => { | ||
if (filterOptions.length > 0) onFilterChange(selectedKeys); | ||
}, [filterOptions, selectedKeys]); | ||
|
||
return ( | ||
<Popover> | ||
<Th> | ||
<Flex justifyContent={'space-between'} alignItems={'center'}> | ||
{title} | ||
|
||
{filterOptions.length > 0 && ( | ||
<PopoverTrigger> | ||
<IconButton colorScheme="blue" aria-label="Search database" icon={<FilterList />} /> | ||
</PopoverTrigger> | ||
)} | ||
</Flex> | ||
|
||
<Portal> | ||
<PopoverContent minWidth={'3xs'} width={'auto'}> | ||
<PopoverBody padding={'12px 16px'}> | ||
<CheckboxGroup | ||
options={filterOptions} | ||
selectedKeys={selectedKeys} | ||
onChange={onChange} | ||
onToggleAll={onToggleAll} | ||
/> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Portal> | ||
</Th> | ||
</Popover> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
code/frontend/src/Common/components/DataTable/components/TableCell.tsx
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,9 @@ | ||
import { Td } from '@chakra-ui/react'; | ||
|
||
interface TableCellProps { | ||
value: string; | ||
} | ||
|
||
export function TableCell({ value }: TableCellProps) { | ||
return <Td>{value}</Td>; | ||
} |
2 changes: 2 additions & 0 deletions
2
code/frontend/src/Common/components/DataTable/components/index.ts
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,2 @@ | ||
export * from './HeaderCell'; | ||
export * from './TableCell'; |
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,2 @@ | ||
export * from './DataTable'; | ||
export * from './DataTable.types'; |
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,2 @@ | ||
export * from './CheckboxGroup'; | ||
export * from './DataTable'; |
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 @@ | ||
export * from './useCheckboxGroupKeys'; |
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,18 @@ | ||
import { useState } from 'react'; | ||
|
||
import { Option } from '../types'; | ||
|
||
export const useCheckboxGroupKeys = (options: Option[]) => { | ||
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); | ||
|
||
const onChange = (key: string) => { | ||
setSelectedKeys(prevState => (prevState.includes(key) ? prevState.filter(k => k !== key) : [...prevState, key])); | ||
}; | ||
const onToggleAll = () => { | ||
setSelectedKeys(prevState => { | ||
return prevState.length === 0 ? options.map(({ key }) => key) : []; | ||
}); | ||
}; | ||
|
||
return { selectedKeys, onChange, onToggleAll }; | ||
}; |
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,3 @@ | ||
export * from './components'; | ||
export * from './hooks'; | ||
export * from './types'; |
26 changes: 26 additions & 0 deletions
26
code/frontend/src/Common/stories/CheckboxGroup.stories.tsx
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,26 @@ | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
|
||
import { CheckboxGroup } from '../components'; | ||
import { useCheckboxGroupKeys } from '../hooks'; | ||
|
||
import { patternFilterOptions } from '~/Passwords/data'; | ||
|
||
export default { | ||
title: 'Common/components/CheckboxGroup' | ||
} as Meta; | ||
|
||
export const Default: StoryFn = () => { | ||
const { selectedKeys, onChange, onToggleAll } = useCheckboxGroupKeys(patternFilterOptions); | ||
|
||
return ( | ||
<CheckboxGroup | ||
options={patternFilterOptions} | ||
selectedKeys={selectedKeys} | ||
onChange={onChange} | ||
onToggleAll={onToggleAll} | ||
/> | ||
); | ||
}; | ||
|
||
Default.args = {}; | ||
Default.storyName = 'CheckboxGroup'; |
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,54 @@ | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
|
||
import { Column, DataTable } from '../components/DataTable'; | ||
|
||
import { patternFilterOptions } from '~/Passwords/data'; | ||
|
||
export default { | ||
title: 'Common/components/DataTable' | ||
} as Meta; | ||
|
||
type UnitConversion = { | ||
key: string; | ||
fromUnit: string; | ||
toUnit: string; | ||
factor: number; | ||
}; | ||
|
||
const data: UnitConversion[] = [ | ||
{ | ||
key: 'inches', | ||
fromUnit: 'inches', | ||
toUnit: 'millimetres (mm)', | ||
factor: 25.4 | ||
}, | ||
{ | ||
key: 'feet', | ||
fromUnit: 'feet', | ||
toUnit: 'centimetres (cm)', | ||
factor: 30.48 | ||
}, | ||
{ | ||
key: 'yards', | ||
fromUnit: 'yards', | ||
toUnit: 'metres (m)', | ||
factor: 0.91444 | ||
} | ||
]; | ||
|
||
const columns: Column<UnitConversion>[] = [ | ||
{ name: 'fromUnit', title: 'To convert', getRowValue: row => row.fromUnit }, | ||
{ | ||
name: 'toUnit', | ||
title: 'Into', | ||
filterOptions: patternFilterOptions, | ||
getRowValue: row => row.toUnit | ||
}, | ||
{ name: 'factor', title: 'Multiply by', getRowValue: row => row.factor.toString() } | ||
]; | ||
|
||
export const Default: StoryFn = () => { | ||
return <DataTable columns={columns} data={data} getRowKey={row => row.key} />; | ||
}; | ||
|
||
Default.storyName = 'DataTable'; |
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,4 @@ | ||
export interface Option { | ||
key: string; | ||
label: string; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
code/frontend/src/Info/components/ServerlessPassTitle/ServerlessPassTitle.tsx
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,19 @@ | ||
import { Flex, Text } from '@chakra-ui/react'; | ||
|
||
import { useLocale } from '~/locale'; | ||
|
||
export const ServerlessPassTitle: React.FC = () => { | ||
const { root } = useLocale(); | ||
|
||
return ( | ||
<Flex alignItems={'flex-start'}> | ||
<Text fontSize={56} fontWeight={'bold'}> | ||
{root.header.title} | ||
</Text> | ||
|
||
<Text fontSize={'sm'} fontWeight={'bold'}> | ||
{root.header.tm} | ||
</Text> | ||
</Flex> | ||
); | ||
}; |
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 @@ | ||
export * from './ServerlessPassTitle'; |
Oops, something went wrong.