Skip to content

Commit 3929a2b

Browse files
authored
Hosting Dashboard: Fix glue records validation (#106050)
* Fix glue records validation message by switching to `ValidatedInputControl` * Fix suffix looking bad for long domain names * Fix type issues * Update and use the `SuffixInputControl` component for the input * Fix type
1 parent d50d494 commit 3929a2b

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
import {
2-
__experimentalInputControl as InputControl,
32
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
3+
privateApis,
44
} from '@wordpress/components';
5+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
6+
import { Text } from '../../components/text';
57
import type React from 'react';
68

9+
const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
10+
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
11+
'@wordpress/components'
12+
);
13+
const { ValidatedInputControl } = unlock( privateApis );
14+
715
export default function SuffixInputControl( {
816
suffix,
917
...props
10-
}: React.ComponentProps< typeof InputControl > ) {
18+
}: React.ComponentProps< typeof ValidatedInputControl > ) {
1119
return (
12-
<InputControl
20+
<ValidatedInputControl
1321
{ ...props }
14-
suffix={ <InputControlSuffixWrapper variant="control">{ suffix }</InputControlSuffixWrapper> }
22+
suffix={
23+
<InputControlSuffixWrapper>
24+
<Text variant="muted" style={ { whiteSpace: 'nowrap' } }>
25+
{ suffix }
26+
</Text>
27+
</InputControlSuffixWrapper>
28+
}
1529
/>
1630
);
1731
}

client/dashboard/domains/domain-glue-records/form.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import {
2-
Card,
3-
CardBody,
4-
__experimentalVStack as VStack,
5-
__experimentalInputControl as InputControl,
6-
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
7-
Button,
8-
} from '@wordpress/components';
1+
import { Card, CardBody, __experimentalVStack as VStack, Button } from '@wordpress/components';
92
import { DataForm, isItemValid } from '@wordpress/dataviews';
103
import { useState, useMemo } from '@wordpress/element';
114
import { __ } from '@wordpress/i18n';
125
import { ButtonStack } from '../../components/button-stack';
13-
import { Text } from '../../components/text';
6+
import SuffixInputControl from '../../components/input-control/suffix-input-control';
147
import { isValidIpAddress, isValidNameServerSubdomain } from '../../utils/domain';
158
import type { DomainGlueRecord } from '@automattic/api-core';
169
import type { Field } from '@wordpress/dataviews';
@@ -61,22 +54,21 @@ export default function DomainGlueRecordsForm( {
6154
const { id, getValue } = field;
6255
const suffix = `.${ domainName }`;
6356
const value = getValue( { item: data } ).replace( suffix, '' );
57+
const validationMessage = field.isValid?.custom?.( data, field );
6458

6559
return (
66-
// TODO: Show the error via Data Form when the ValidatedInputControl component is ready.
67-
<InputControl
68-
__next40pxDefaultSize
60+
<SuffixInputControl
61+
required={ !! field.isValid?.required }
6962
label={ field.label }
7063
placeholder={ field.placeholder }
7164
value={ value }
72-
onChange={ ( value ) => {
65+
onChange={ ( value: string ) => {
7366
return onChange( { [ id ]: value + suffix } );
7467
} }
75-
suffix={
76-
<InputControlSuffixWrapper>
77-
<Text variant="muted">{ suffix }</Text>
78-
</InputControlSuffixWrapper>
68+
customValidity={
69+
validationMessage ? { type: 'invalid', message: validationMessage } : undefined
7970
}
71+
suffix={ suffix }
8072
/>
8173
);
8274
},

client/dashboard/sites/site-change-address-modal/content.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ const SubdomainInputControlEdit = < Item, >( {
4545
<SuffixInputControl
4646
label={ field.label }
4747
value={ getValue( { item: data } ) }
48-
__next40pxDefaultSize
49-
suffix={ <Text variant="muted">{ DOMAIN_SUFFIX }</Text> }
50-
onChange={ ( newValue ) => {
48+
suffix={ DOMAIN_SUFFIX }
49+
onChange={ ( newValue: string ) => {
5150
onChange( { [ id ]: newValue } as Partial< Item > );
5251
} }
5352
/>

0 commit comments

Comments
 (0)