Skip to content

Fix: Kit name input & validation - Export flow [ED-19345]#31376

Merged
ManorHazaz merged 14 commits intoelementor:mainfrom
ManorHazaz:tweak/ED-19345
Jun 3, 2025
Merged

Fix: Kit name input & validation - Export flow [ED-19345]#31376
ManorHazaz merged 14 commits intoelementor:mainfrom
ManorHazaz:tweak/ED-19345

Conversation

@ManorHazaz
Copy link
Copy Markdown
Contributor

No description provided.

.replace( /[<>:"/\\|?*]/g, '' )
.trim();

const fileName = sanitizedKitName || 'elementor-kit';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the fallback twice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second default would only be needed in the edge case where someone enters a kit name consisting only of special characters (like "///???") that get completely removed during sanitization.
But added a variable to hold them both


const kitName = exportContext.data.kitInfo?.title || 'elementor-kit';
const sanitizedKitName = kitName
.replace( /[<>:"/\\|?*]/g, '' )
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe give the regex a readable variable name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


const validateKitName = ( value ) => {
if ( ! value || 0 === value.trim().length ) {
return __( 'Must add a kit name', 'elementor' );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return __( 'Must add a kit name', 'elementor' );
return __( 'Kit name is required', 'elementor' );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No based on Shiri design

return { ...state, kitInfo: { ...state.kitInfo, title: payload } };
case 'SET_KIT_DESCRIPTION':
return { ...state, kitInfo: { ...state.kitInfo, description: payload } };
case 'SET_KIT_NAME_VALIDATOR':
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand why the validator is part of the context? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, I was sure I needed it for some reason

export default function KitName() {
const exportContext = useContext( ExportContext );
const [ error, setError ] = useState( null );
const [ touched, setTouched ] = useState( false );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touched did not make sense immediately. Maybe inputModified or something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed completely, and simplified the code.

@ManorHazaz ManorHazaz merged commit 52b2929 into elementor:main Jun 3, 2025
21 checks passed
@ManorHazaz ManorHazaz deleted the tweak/ED-19345 branch June 3, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants