1- import { Icon , notify } from "design-react-kit" ;
1+ import { notify } from "design-react-kit" ;
22import { set } from "lodash" ;
33import { useCallback , useEffect , useState } from "react" ;
44import {
@@ -11,7 +11,6 @@ import {
1111import useFormPersist from "react-hook-form-persist" ;
1212import { useTranslation } from "react-i18next" ;
1313import { RequiredDeep } from "type-fest" ;
14-
1514import licenses from "../../generated/licenses.json" ;
1615import { allLangs } from "../../i18n" ;
1716import categories from "../contents/categories" ;
@@ -31,7 +30,6 @@ import softwareTypes from "../contents/softwareTypes";
3130import fileImporter from "../importers/file.importer" ;
3231import importFromGitlab from "../importers/gitlab.importer" ;
3332import importStandard from "../importers/standard.importer" ;
34- import linter from "../linter" ;
3533import publicCodeAdapter from "../publiccode-adapter" ;
3634import { isMinorThanLatest , toSemVerObject } from "../semver" ;
3735import { useAppDispatch , useAppSelector } from "../store" ;
@@ -54,23 +52,28 @@ import EditorScreenshots from "./EditorScreenshots";
5452import EditorSelect from "./EditorSelect" ;
5553import EditorUsedBy from "./EditorUsedBy" ;
5654import EditorVideos from "./EditorVideos" ;
57- import { Footer } from "./Foot" ;
58-
59- import InfoBox from "./InfoBox" ;
55+ import EditorToolbar from "./EditorToolbar" ;
6056import PubliccodeYmlLanguages from "./PubliccodeYmlLanguages" ;
61- import { WarningModal } from "./WarningModal" ;
62- import { YamlModal } from "./YamlModal" ;
57+ import { Warning } from "./WarningBox" ;
6358
64- const PUBLIC_CODE_EDITOR_WARNINGS = "PUBLIC_CODE_EDITOR_WARNINGS" ;
59+ const validatorFn = async ( values : PublicCode ) => {
60+ try {
61+ const results = await validator ( {
62+ publiccode : JSON . stringify ( values ) ,
63+ baseURL : values . url ,
64+ } ) ;
6565
66- const validatorFn = async ( values : PublicCode ) =>
67- await validator ( { publiccode : JSON . stringify ( values ) , baseURL : values . url } ) ;
66+ return results ;
67+ } catch ( error ) {
68+ console . log ( "error validating" ) ;
69+ }
70+ } ;
6871
6972const checkWarnings = async ( values : PublicCode ) => {
7073 const res = await validatorFn ( values ) ;
7174 const warnings = new Map < string , { type : string ; message : string } > ( ) ;
7275
73- for ( const { key, description } of res . warnings ) {
76+ for ( const { key, description } of res ? .warnings || [ ] ) {
7477 warnings . set ( key , {
7578 type : "warning" ,
7679 message : description ,
@@ -84,17 +87,20 @@ const resolver: Resolver<PublicCode | PublicCodeWithDeprecatedFields> = async (
8487 values
8588) => {
8689 console . log ( values ) ;
90+
91+ // return { values, errors: {} }; //@TODO REMOVE: USED TO IGNORE VALIDATIONS
92+
8793 const res = await validatorFn ( values as PublicCode ) ;
8894
89- if ( res . errors . length === 0 )
95+ if ( res ? .errors . length === 0 )
9096 return {
9197 values,
9298 errors : { } ,
9399 } ;
94100
95101 const errors : Record < string , { type : string ; message : string } > = { } ;
96102
97- for ( const { key, description } of res . errors ) {
103+ for ( const { key, description } of res ? .errors || [ ] ) {
98104 set ( errors , key , {
99105 type : "error" ,
100106 message : description ,
@@ -115,7 +121,19 @@ const defaultValues = {
115121 it : defaultItaly ,
116122} ;
117123
118- export default function Editor ( ) {
124+ type EditorProps = {
125+ setData : ( data : PublicCode ) => void ;
126+ setWarnings : ( items : Warning [ ] ) => void ;
127+ isPublicCodeImported : boolean ;
128+ setPublicCodeImported : ( value : boolean ) => void ;
129+ } ;
130+
131+ export default function Editor ( {
132+ setData,
133+ setWarnings,
134+ isPublicCodeImported,
135+ setPublicCodeImported,
136+ } : EditorProps ) {
119137 //#region Common
120138 const dispatch = useAppDispatch ( ) ;
121139 //#endregion
@@ -126,24 +144,6 @@ export default function Editor() {
126144 const configCountrySections = countrySection . parse ( DEFAULT_COUNTRY_SECTIONS ) ;
127145 const [ currentPublicodeYmlVersion , setCurrentPubliccodeYmlVersion ] =
128146 useState ( "" ) ;
129- const [ isYamlModalVisible , setYamlModalVisibility ] = useState ( false ) ;
130- const [ isPublicCodeImported , setPublicCodeImported ] = useState ( false ) ;
131- const [ isWarningModalVisible , setWarningModalVisibility ] = useState ( false ) ;
132- const [ warnings , setWarnings ] = useState < { key : string ; message : string } [ ] > (
133- [ ]
134- ) ;
135-
136- useEffect ( ( ) => {
137- const warnings = localStorage . getItem ( PUBLIC_CODE_EDITOR_WARNINGS ) ;
138-
139- if ( warnings ) {
140- setWarnings ( JSON . parse ( warnings ) ) ;
141- }
142- } , [ ] ) ;
143-
144- useEffect ( ( ) => {
145- localStorage . setItem ( PUBLIC_CODE_EDITOR_WARNINGS , JSON . stringify ( warnings ) ) ;
146- } , [ warnings ] ) ;
147147
148148 const getNestedValue = (
149149 obj : PublicCodeWithDeprecatedFields ,
@@ -159,17 +159,13 @@ export default function Editor() {
159159
160160 const isDeprecatedFieldVisible = ( fieldName : PublicCodeDeprecatedField ) => {
161161 const values = getValues ( ) as PublicCodeWithDeprecatedFields ;
162-
163162 if ( ! values ) {
164163 return false ;
165164 }
166-
167165 const fieldValue = getNestedValue ( values , fieldName ) ; //values[fieldName]
168-
169166 if ( fieldValue === null || fieldValue === undefined ) {
170167 return false ;
171168 }
172-
173169 return true ;
174170 } ;
175171 const isContractorsVisible = ( ) => {
@@ -258,8 +254,12 @@ export default function Editor() {
258254
259255 //#region form action handlers
260256 const submitHandler = handleSubmit (
261- async ( ) => {
262- setYamlModalVisibility ( true ) ;
257+ async ( data ) => {
258+ console . log ( "handleSubmit" , data ) ;
259+ //todo change to values
260+ if ( data ) {
261+ setData ( data as PublicCode ) ;
262+ }
263263 } ,
264264 ( e : FieldErrors < PublicCode > ) => {
265265 notify (
@@ -352,7 +352,7 @@ export default function Editor() {
352352
353353 return (
354354 < div className = 'container' >
355- { ! ! warnings . length && (
355+ { /* { !!warnings.length && (
356356 <div className='p-2 bd-highlight'>
357357 <Icon
358358 icon='it-warning-circle'
@@ -362,7 +362,7 @@ export default function Editor() {
362362 />
363363
364364 </div>
365- ) }
365+ )} */ }
366366
367367 < FormProvider { ...methods } >
368368 < form >
@@ -594,7 +594,9 @@ export default function Editor() {
594594 < hr />
595595 { countrySection . isVisible ( configCountrySections , "italy" ) && (
596596 < div >
597- < h2 > { t ( "countrySpecificSection.italy" ) } </ h2 >
597+ < div >
598+ < h4 > { t ( "countrySpecificSection.italy" ) } </ h4 >
599+ </ div >
598600 < span >
599601 < EditorInput < "name" > fieldName = 'name' required />
600602 </ span >
@@ -605,9 +607,8 @@ export default function Editor() {
605607 ) }
606608 </ form >
607609 </ FormProvider >
608- < Footer
610+ < EditorToolbar
609611 reset = { ( ) => resetFormHandler ( ) }
610- submit = { ( ) => undefined }
611612 loadRemoteYaml = { ( url ) => loadRemoteYamlHandler ( url ) }
612613 loadFileYaml = { ( file ) => loadFileYamlHandler ( file ) }
613614 trigger = { ( ) => submitHandler ( ) }
0 commit comments