-
Notifications
You must be signed in to change notification settings - Fork 61
feat(studio): Set default site directory location #2710
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
Open
mikaoelitiana
wants to merge
14
commits into
Automattic:trunk
Choose a base branch
from
mikaoelitiana:587-default-location
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+259
−161
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dd31477
Add storage support for custom site directory
mikaoelitiana 6c627cf
Add IPC helpers for default site directory
mikaoelitiana c509411
Use default site preference in dialog helpers
mikaoelitiana 14f4de8
wip: create new component
mikaoelitiana 31d2d4d
fix: refactor default site directory functions
mikaoelitiana c2de6a1
fix: resolve default site directory dynamically
mikaoelitiana c9c034b
fix: resolve default directory for site names
mikaoelitiana 7106f76
refactor: create independant form path input component
mikaoelitiana 47676d5
Replace DefaultDirectoryPicker with FormPathInputComponent in Prefere…
mikaoelitiana 6e633a4
Remove unused DefaultDirectoryPicker component
mikaoelitiana 4a6bbfe
fix: merge conflicts
mikaoelitiana e8eface
Merge branch 'trunk' into 587-default-location
wojtekn 7d1facc
fix: address PR review comments
mikaoelitiana b51b71d
Merge trunk and fix conflicts
mikaoelitiana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,66 @@ | ||
| import { useI18n } from '@wordpress/react-i18n'; | ||
| import FolderIcon from 'src/components/folder-icon'; | ||
| import { cx } from 'src/lib/cx'; | ||
| import { SiteFormError } from './site-form-error'; | ||
|
|
||
| export interface FormPathInputComponentProps { | ||
| value: string; | ||
| onClick: () => void; | ||
| error?: string; | ||
| doesPathContainWordPress: boolean; | ||
| id?: string; | ||
| } | ||
|
|
||
| export function FormPathInputComponent( { | ||
| value, | ||
| onClick, | ||
| error, | ||
| doesPathContainWordPress, | ||
| id, | ||
| }: FormPathInputComponentProps ) { | ||
| const { __ } = useI18n(); | ||
| return ( | ||
| <div className="flex flex-col gap-2"> | ||
| <button | ||
| aria-invalid={ !! error } | ||
| /** | ||
| * The below `aria-describedby` presumes the error message always | ||
| * relates to the local path input, which is true currently as it is the | ||
| * only data validation in place. If we ever introduce additional data | ||
| * validation we need to expand the robustness of this | ||
| * `aria-describedby` attribute so that it only targets relevant error | ||
| * messages. | ||
| */ | ||
| aria-describedby={ error ? 'site-path-error' : undefined } | ||
| type="button" | ||
| aria-label={ `${ value }, ${ __( 'Select different local path' ) }` } | ||
| className={ cx( | ||
| 'flex flex-row items-stretch rounded-sm border border-frame-border focus:border-frame-theme focus:shadow-[0_0_0_0.5px] focus:shadow-a8c-blue-50 outline-none transition-shadow transition-linear duration-100 [&_.local-path-icon]:focus:border-l-frame-theme [&:disabled]:cursor-not-allowed', | ||
| error && 'border-red-500 [&_.local-path-icon]:border-l-red-500' | ||
| ) } | ||
| data-testid="select-path-button" | ||
| onClick={ onClick } | ||
| id={ id } | ||
| > | ||
| <div aria-hidden="true" tabIndex={ -1 } className="w-full text-left pl-3 py-3 min-h-10"> | ||
| { value } | ||
| </div> | ||
| <div | ||
| aria-hidden="true" | ||
| className="local-path-icon flex items-center py-[9px] px-2.5 self-center" | ||
| > | ||
| <FolderIcon className="text-frame-text-secondary" /> | ||
| </div> | ||
| </button> | ||
| <SiteFormError | ||
| error={ error } | ||
| tipMessage={ | ||
| doesPathContainWordPress | ||
| ? __( 'The existing WordPress site at this path will be added.' ) | ||
| : '' | ||
| } | ||
| /> | ||
| <input type="hidden" data-testid="local-path-input" value={ value } /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,37 @@ | ||
| import { Icon } from '@wordpress/components'; | ||
| import { cautionFilled, tip } from '@wordpress/icons'; | ||
| import { cx } from 'src/lib/cx'; | ||
|
|
||
| export interface SiteFormErrorProps { | ||
| error?: string; | ||
| tipMessage?: string; | ||
| className?: string; | ||
| } | ||
|
|
||
| export const SiteFormError = ( { error, tipMessage = '', className = '' }: SiteFormErrorProps ) => { | ||
| return ( | ||
| ( error || tipMessage ) && ( | ||
| <div | ||
| id="site-path-error" | ||
| role="alert" | ||
| aria-atomic="true" | ||
| className={ cx( | ||
| 'flex items-start gap-1 text-xs', | ||
| error ? 'text-red-500' : 'text-frame-text-secondary', | ||
| className | ||
| ) } | ||
| > | ||
| <Icon | ||
| className={ cx( | ||
| 'shrink-0 basis-4', | ||
| error ? 'fill-red-500' : 'fill-frame-text-secondary' | ||
| ) } | ||
| icon={ error ? cautionFilled : tip } | ||
| width={ 16 } | ||
| height={ 16 } | ||
| /> | ||
| <p>{ error ? error : tipMessage }</p> | ||
| </div> | ||
| ) | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
SiteFormErrorcalls__( tipMessage )even though callers (e.g.,FormPathInputComponent) already pass a translated string via__(...). This results in translating an already-translated string (and using translated text as a key), which can break localization. Consider either (a) requiring callers to pass an untranslated key and translating inside, or (b) treatingtipMessageas already-localized and rendering it directly without calling__again.