-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QuickEdit: Add password field data to the pages quick edit #66567
Changes from 14 commits
fc76d1b
5dad068
83bf28a
e132f95
a4c0d85
b21e81d
34dcc07
1a5147a
5d1234e
c969697
67fa0b8
0f1b2dd
770c200
02b8eb0
6abc19e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
CheckboxControl, | ||
__experimentalVStack as VStack, | ||
TextControl, | ||
} from '@wordpress/components'; | ||
import type { DataFormControlProps } from '@wordpress/dataviews'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
|
||
function PasswordEdit( { | ||
data, | ||
onChange, | ||
field, | ||
}: DataFormControlProps< BasePost > ) { | ||
const [ showPassword, setShowPassword ] = useState( | ||
!! field.getValue( { item: data } ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice detail, thanks. |
||
); | ||
|
||
const handleTogglePassword = ( value: boolean ) => { | ||
setShowPassword( value ); | ||
if ( ! value ) { | ||
onChange( { password: '' } ); | ||
} | ||
}; | ||
|
||
return ( | ||
<VStack | ||
as="fieldset" | ||
spacing={ 4 } | ||
className="fields-controls__password" | ||
> | ||
<CheckboxControl | ||
__nextHasNoMarginBottom | ||
label={ __( 'Password protected' ) } | ||
help={ __( 'Only visible to those who know the password' ) } | ||
checked={ showPassword } | ||
onChange={ handleTogglePassword } | ||
/> | ||
{ showPassword && ( | ||
<div className="fields-controls__password-input"> | ||
<TextControl | ||
label={ __( 'Password' ) } | ||
onChange={ ( value ) => | ||
onChange( { | ||
password: value, | ||
} ) | ||
} | ||
value={ field.getValue( { item: data } ) || '' } | ||
placeholder={ __( 'Use a secure password' ) } | ||
type="text" | ||
__next40pxDefaultSize | ||
__nextHasNoMarginBottom | ||
maxLength={ 255 } | ||
/> | ||
</div> | ||
) } | ||
</VStack> | ||
); | ||
} | ||
export default PasswordEdit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import type { Field } from '@wordpress/dataviews'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
import PasswordEdit from './edit'; | ||
|
||
const passwordField: Field< BasePost > = { | ||
id: 'password', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this field type? I presume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although given this is a password, I wonder if we should add support for a new type to manage hidden texts? Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a sensible thought. I think |
||
type: 'text', | ||
getValue: ( { item } ) => item.password, | ||
Edit: PasswordEdit, | ||
enableSorting: false, | ||
enableHiding: false, | ||
isVisible: ( item ) => item.status !== 'private', | ||
}; | ||
|
||
export default passwordField; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a bit of JSDoc for this export, so it shows up in the docs (README) instead of "undocumented declaration"? (see parentField example) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup will do, one minute :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: 6abc19e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these styles be part of the dataviews/fields package instead? There's probably more places where we're doing this wrong, but DataViews specific classes shouldn't be used by consumers. They are not public API and can change without notice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not opposed to moving it to the password field specifically, there was two main reasons I end up doing it here:
Having said that, I can add the same CSS to the password field specifically, so it is still panel specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm, I see your point. We need the combination of panel + field. These styles could live in
edit-site
(current),dataviews
(but then would have wordpress field specific styles), orfields
(but then would have dataviews-specific styles). None of the three options is ideal. Let's leave it as it is and keep an eye for similar things.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@louwie17 had a thought I wanted to share: what is this border for? is it for separating fields that are combined, like status & password are? If so, what if we refactor this to add the border automatically in that situation?