@@ -3,13 +3,16 @@ import {
3
3
__experimentalHStack as HStack ,
4
4
__experimentalVStack as VStack ,
5
5
Button ,
6
+ CheckboxControl ,
7
+ ExternalLink ,
6
8
} from '@wordpress/components' ;
7
9
import { useDispatch } from '@wordpress/data' ;
10
+ import { createInterpolateElement } from '@wordpress/element' ;
8
11
import { __ } from '@wordpress/i18n' ;
9
12
import { store as noticesStore } from '@wordpress/notices' ;
10
13
import { useState } from 'react' ;
11
14
import type { SiteSettings } from '../../data/types' ;
12
- import type { Field , SimpleFormField } from '@automattic/dataviews' ;
15
+ import type { Field , Form } from '@automattic/dataviews' ;
13
16
import type { UseMutationResult } from '@tanstack/react-query' ;
14
17
15
18
const fields : Field < SiteSettings > [ ] = [
@@ -38,12 +41,56 @@ const fields: Field< SiteSettings >[] = [
38
41
} ,
39
42
] ,
40
43
} ,
44
+ {
45
+ id : 'wpcom_discourage_search_engines' ,
46
+ Edit : 'checkbox' ,
47
+ label : __ ( 'Discourage search engines from indexing this site' ) ,
48
+ description : __ (
49
+ 'This does not block access to your site — it is up to search engines to honor your request.'
50
+ ) ,
51
+ isVisible : ( { wpcom_site_visibility } : SiteSettings ) => wpcom_site_visibility === 'public' ,
52
+ } ,
53
+ {
54
+ id : 'wpcom_prevent_third_party_sharing' ,
55
+ Edit : ( { field, onChange, data, hideLabelFromVision } ) => (
56
+ < CheckboxControl
57
+ __nextHasNoMarginBottom
58
+ label = { hideLabelFromVision ? '' : field . label }
59
+ checked = { field . getValue ( { item : data } ) }
60
+ disabled = { data . wpcom_discourage_search_engines }
61
+ onChange = { ( ) => {
62
+ onChange ( { [ field . id ] : ! field . getValue ( { item : data } ) } ) ;
63
+ } }
64
+ help = { createInterpolateElement (
65
+ __ (
66
+ 'This will present this site’s content from being shared with our licensed network of content and research partners, including those that train AI models. <a>Learn more</a>'
67
+ ) ,
68
+ {
69
+ a : (
70
+ // TODO investigate whether localizeUrl() is safe to import into dashboard
71
+ < ExternalLink
72
+ /* eslint-disable-next-line wpcalypso/i18n-unlocalized-url */
73
+ href = "https://wordpress.com/support/privacy-settings/make-your-website-public/#prevent-third-party-sharing"
74
+ children = { null } // ExternalLink's children prop is marked as required
75
+ />
76
+ ) ,
77
+ }
78
+ ) }
79
+ />
80
+ ) ,
81
+ label : __ ( 'Prevent third-party sharing for this site' ) ,
82
+ isVisible : ( { wpcom_site_visibility } : SiteSettings ) => wpcom_site_visibility === 'public' ,
83
+ } ,
41
84
] ;
42
85
43
86
const form = {
44
- type : 'regular' as const ,
45
- fields : [ { id : 'wpcom_site_visibility' , labelPosition : 'none' } as SimpleFormField ] ,
46
- } ;
87
+ type : 'regular' ,
88
+ fields : [
89
+ { id : 'wpcom_site_visibility' , labelPosition : 'none' } ,
90
+ 'wpcom_discourage_search_engines' ,
91
+ 'wpcom_prevent_third_party_sharing' ,
92
+ ] ,
93
+ } satisfies Form ;
47
94
48
95
export function PrivacyForm ( {
49
96
settings,
@@ -55,6 +102,9 @@ export function PrivacyForm( {
55
102
const { createSuccessNotice, createErrorNotice } = useDispatch ( noticesStore ) ;
56
103
const [ formData , setFormData ] = useState ( {
57
104
wpcom_site_visibility : settings . wpcom_site_visibility ,
105
+ wpcom_discourage_search_engines : settings . wpcom_discourage_search_engines ,
106
+ wpcom_prevent_third_party_sharing :
107
+ settings . wpcom_discourage_search_engines || settings . wpcom_prevent_third_party_sharing ,
58
108
} ) ;
59
109
60
110
const isDirty = Object . entries ( formData ) . some (
@@ -78,19 +128,38 @@ export function PrivacyForm( {
78
128
} ;
79
129
80
130
return (
81
- < form onSubmit = { handleSubmit } >
131
+ < form onSubmit = { handleSubmit } className = "dashboard-site-settings-privacy-form" >
82
132
< VStack spacing = { 4 } >
83
133
< DataForm < SiteSettings >
84
134
data = { formData }
85
135
fields = { fields }
86
136
form = { form }
87
137
onChange = { ( edits : Partial < SiteSettings > ) => {
88
- setFormData ( ( data ) => ( { ...data , ...edits } ) ) ;
138
+ setFormData ( ( data ) => {
139
+ const newFormData = { ...data , ...edits } ;
140
+
141
+ if ( edits . wpcom_site_visibility !== undefined ) {
142
+ // Forget any previous edits to the discoverability controls when the visibility changes.
143
+ newFormData . wpcom_discourage_search_engines =
144
+ settings . wpcom_discourage_search_engines ;
145
+ newFormData . wpcom_prevent_third_party_sharing =
146
+ settings . wpcom_discourage_search_engines ||
147
+ settings . wpcom_prevent_third_party_sharing ;
148
+ }
149
+
150
+ if ( edits . wpcom_discourage_search_engines === true ) {
151
+ // Checking the search engine box forces the third party checkbox too.
152
+ newFormData . wpcom_prevent_third_party_sharing = true ;
153
+ }
154
+
155
+ return newFormData ;
156
+ } ) ;
89
157
} }
90
158
/>
91
159
< HStack justify = "flex-start" >
92
160
< Button
93
161
variant = "primary"
162
+ __next40pxDefaultSize
94
163
type = "submit"
95
164
isBusy = { isPending }
96
165
disabled = { isPending || ! isDirty }
0 commit comments