-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: prototype for abstracted backend call with proper error handling
- Loading branch information
1 parent
1e39980
commit ee28e15
Showing
30 changed files
with
892 additions
and
302 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import DangerousTwoToneIcon from '@mui/icons-material/DangerousTwoTone'; | ||
import WarningAmberIcon from '@mui/icons-material/WarningAmber'; | ||
import { sentenceCase, snakeCase } from 'change-case'; | ||
import { type FC } from 'react'; | ||
|
||
import { InputField, type KeyValuePair, type Row } from './InputField.tsx'; | ||
|
||
type NonEditableRowProps = { | ||
row: Row; | ||
editable: false; | ||
customKey?: string; | ||
}; | ||
|
||
type EditableRowProps = { | ||
row: Row; | ||
editable: (editedRow: Row) => void; | ||
customKey?: string; | ||
}; | ||
|
||
type RowProps = NonEditableRowProps | EditableRowProps; | ||
export const DataRow: FC<RowProps> = ({ row, editable, customKey }) => { | ||
const colorClassName = row.errors.length > 0 ? 'text-red-600' : row.warnings.length > 0 ? 'text-yellow-600' : ''; | ||
|
||
return ( | ||
<tr key={snakeCase(customKey ?? row.key)}> | ||
<td className={`w-1/4 ${colorClassName}`}>{sentenceCase(row.key)}:</td> | ||
<td className='pr-3 text-right '> | ||
<ErrorAndWarningIcons row={row} /> | ||
</td> | ||
<td className='w-full'> | ||
{editable === false ? ( | ||
<div className='px-3'>{row.value}</div> | ||
) : ( | ||
<InputField row={row} onChange={editable} colorClassName={colorClassName} /> | ||
)} | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
type ErrorAndWarningIconsProps = { | ||
row: Row; | ||
}; | ||
const ErrorAndWarningIcons: FC<ErrorAndWarningIconsProps> = ({ row }) => { | ||
return ( | ||
<> | ||
{row.warnings.length > 0 ? ( | ||
<div className='tooltip tooltip-warning whitespace-pre-line' data-tip={row.warnings.join('\n')}> | ||
<WarningAmberIcon color='warning' /> | ||
</div> | ||
) : null} | ||
{row.errors.length > 0 ? ( | ||
<div className='tooltip tooltip-error whitespace-pre-line' data-tip={row.errors.join('\n')}> | ||
<DangerousTwoToneIcon color='error' /> | ||
</div> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
type ProcessedDataRowProps = { | ||
row: KeyValuePair; | ||
customKey?: string; | ||
}; | ||
|
||
export const ProcessedDataRow: FC<ProcessedDataRowProps> = ({ row, customKey }) => { | ||
return ( | ||
<tr key={snakeCase(customKey ?? row.key)}> | ||
<td className={`w-1/4 `}>{sentenceCase(row.key)}:</td> | ||
<td /> | ||
<td className='w-full'> | ||
<div className='px-3'>{row.value}</div>{' '} | ||
</td> | ||
</tr> | ||
); | ||
}; |
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 @@ | ||
import UndoTwoToneIcon from '@mui/icons-material/UndoTwoTone'; | ||
import { type FC, useState } from 'react'; | ||
|
||
export type KeyValuePair = { | ||
value: string; | ||
key: string; | ||
}; | ||
|
||
export type Row = { | ||
warnings: string[]; | ||
errors: string[]; | ||
initialValue: string; | ||
} & KeyValuePair; | ||
|
||
type InputFieldProps = { | ||
row: Row; | ||
onChange: (editedRow: Row) => void; | ||
colorClassName: string; | ||
}; | ||
|
||
export const InputField: FC<InputFieldProps> = ({ row, onChange, colorClassName }) => { | ||
const [isFocused, setIsFocused] = useState(false); | ||
return ( | ||
<> | ||
<input | ||
name={row.key} | ||
className={`border border-gray-200 rounded-md w-full ${ | ||
row.value !== row.initialValue ? 'pl-3 pr-12' : 'px-3' | ||
} ${colorClassName}`} | ||
value={row.value} | ||
onChange={(e) => onChange({ ...row, value: e.target.value })} | ||
onFocus={() => setIsFocused(() => true)} | ||
onBlur={() => setIsFocused(() => false)} | ||
/> | ||
<button | ||
className='bg-white bg-opacity-50 rounded-lg -m-12 px-3' | ||
onClick={() => onChange({ ...row, value: row.initialValue })} | ||
> | ||
{row.value !== row.initialValue && ( | ||
<div | ||
className='tooltip tooltip-info whitespace-pre-line' | ||
data-tip={'Revert to: ' + row.initialValue} | ||
> | ||
<UndoTwoToneIcon color='action' /> | ||
</div> | ||
)} | ||
</button> | ||
{isFocused && row.warnings.length + row.errors.length > 0 ? ( | ||
<div className='absolute bg-white border border-gray-400 rounded-md p-2 mt-1 align-top'> | ||
{row.errors.map((error) => ( | ||
<div key={error} className='text-red-600'> | ||
{error} | ||
</div> | ||
))} | ||
{row.warnings.map((warning) => ( | ||
<div key={warning} className='text-yellow-600'> | ||
{warning} | ||
</div> | ||
))} | ||
</div> | ||
) : null} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.