-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improved validation feedback (#365)
- Loading branch information
1 parent
197bb19
commit b8d0f27
Showing
10 changed files
with
200 additions
and
35 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
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,43 @@ | ||
import { Icon, Modal, ModalBody } from "design-react-kit"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
interface Props { | ||
display: boolean; | ||
toggle: () => void; | ||
warnings: { key: string, message: string }[] | ||
} | ||
|
||
export const WarningModal = ({ display, toggle, warnings = [] }: Props): JSX.Element => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Modal | ||
isOpen={display} | ||
toggle={toggle}> | ||
<ModalBody> | ||
<h3><Icon icon="it-warning-circle" color="warning" title={t("editor.warnings")} /> {t("editor.warnings")}</h3> | ||
<div className="it-list-wrapper"> | ||
{warnings.length | ||
? | ||
<ul className="it-list"> | ||
<li> | ||
{warnings.map(({ key, message }) => | ||
<li key={key}> | ||
<div className="list-item"> | ||
<div className="it-right-zone"> | ||
<div> | ||
<h4 className="text m-0">{key}</h4> | ||
<p className="small m-0">{message}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</li> | ||
)} | ||
</li> | ||
</ul> | ||
: <p>Non ci sono warning</p>} | ||
|
||
</div> | ||
</ModalBody> | ||
</Modal>) | ||
} |
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,27 @@ | ||
import flattenObjectToRecord from "./flatten-object-to-record"; | ||
|
||
describe('Flatten object to record', () => { | ||
it('should return a record given a object with a object-ish property', () => { | ||
//arrage | ||
const mockData = { en: { type: "error", message: "this is an error message" } }; | ||
//act | ||
const actual = flattenObjectToRecord(mockData); | ||
//assert | ||
expect(actual).toBeDefined(); | ||
expect(actual.en).toBeDefined() | ||
expect(actual.en.type).toBe(mockData.en.type) | ||
expect(actual.en.message).toBe(mockData.en.message) | ||
}) | ||
|
||
it('should return a record given a object with a object-ish property - deep', () => { | ||
//arrage | ||
const mockData = { description: { en: { type: "error", message: "this is an error message" } } }; | ||
//act | ||
const actual = flattenObjectToRecord(mockData); | ||
//assert | ||
expect(actual).toBeDefined(); | ||
expect(actual['description.en']).toBeDefined(); | ||
expect(actual['description.en'].type).toBe("error") | ||
expect(actual['description.en'].message).toBe("this is an error message") | ||
}) | ||
}) |
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,28 @@ | ||
function flattenObject( | ||
obj: object, | ||
parentKey = '', | ||
separator = '.' | ||
): Record<string, { type: string; message: string }> { | ||
return Object.entries(obj).reduce((acc, [key, value]) => { | ||
const newKey = parentKey ? `${parentKey}${separator}${key}` : key; | ||
|
||
// Controlla se il valore è un oggetto e ha proprietà | ||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) { | ||
const isLeaf = Object.keys(value).every( | ||
(k) => typeof value[k] !== 'object' || value[k] === null | ||
); | ||
|
||
if (isLeaf) { | ||
// Se è una foglia, aggiungilo direttamente | ||
acc[newKey] = value as { type: string; message: string }; | ||
} else { | ||
// Altrimenti continua la ricorsione | ||
Object.assign(acc, flattenObject(value, newKey, separator)); | ||
} | ||
} | ||
|
||
return acc; | ||
}, {} as Record<string, { type: string; message: string }>); | ||
} | ||
|
||
export default flattenObject |
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
Oops, something went wrong.