Skip to content

Commit 1f7e460

Browse files
committed
Refactor: use ID instead of name
Remove or deprecate name
1 parent f912d5c commit 1f7e460

13 files changed

+85
-47
lines changed

packages/js/src/introductions/components/introduction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const Introduction = () => {
1010
const introduction = useSelect( select => select( STORE_NAME_INTRODUCTIONS ).selectCurrentIntroduction(), [] );
1111
const components = useIntroductionsContext();
1212

13-
const Component = useMemo( () => components?.[ introduction?.name ], [ introduction, components ] );
13+
const Component = useMemo( () => components?.[ introduction?.id ], [ introduction, components ] );
1414

1515
if ( ! Component ) {
1616
return null;

packages/js/src/introductions/components/provider.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export const IntroductionProvider = ( { children, initialComponents } ) => {
2323
const [ components, setComponents ] = useState( initialComponents );
2424
const introductions = useSelect( select => select( STORE_NAME_INTRODUCTIONS ).selectIntroductions(), [] );
2525

26-
const registerComponent = useCallback( ( name, Component ) => {
27-
const introduction = find( introductions, { name } );
26+
const registerComponent = useCallback( ( id, Component ) => {
27+
const introduction = find( introductions, { id } );
2828
if ( ! introduction ) {
2929
// Bail when unknown.
30-
console.error( "Warning: Introductions received a registration for an unknown key:", name );
30+
console.error( "Warning: Introductions received a registration for an unknown key:", id );
3131
return;
3232
}
33-
setComponents( currentComponents => ( { ...currentComponents, [ name ]: Component } ) );
33+
setComponents( currentComponents => ( { ...currentComponents, [ id ]: Component } ) );
3434
}, [ introductions, setComponents ] );
3535

3636
useEffect( () => {

packages/js/src/introductions/store/introductions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { get, map } from "lodash";
44
export const INTRODUCTIONS_NAME = "introductions";
55

66
const adapter = createEntityAdapter( {
7-
selectId: introduction => introduction.name,
7+
selectId: introduction => introduction.id,
88
sortComparer: ( a, b ) => {
99
if ( a.priority === b.priority ) {
1010
return 0;
@@ -15,10 +15,10 @@ const adapter = createEntityAdapter( {
1515

1616
/**
1717
* @param {Object} introduction The introduction.
18-
* @returns {{name: string, priority: number}} The prepared introduction.
18+
* @returns {{id: string, priority: number}} The prepared introduction.
1919
*/
2020
const prepareIntroduction = introduction => ( {
21-
name: introduction.name || nanoid(),
21+
id: introduction.id || nanoid(),
2222
priority: introduction.priority || 0,
2323
} );
2424

src/introductions/application/ai-generate-titles-and-descriptions-introduction-upsell.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,27 @@ public function __construct(
4747
$this->options_helper = $options_helper;
4848
}
4949

50+
/**
51+
* Returns the ID.
52+
*
53+
* @return string
54+
*/
55+
public function get_id() {
56+
return 'ai-generate-titles-and-descriptions-upsell';
57+
}
58+
5059
/**
5160
* Returns the unique name.
5261
*
62+
* @deprecated 21.6
63+
* @codeCoverageIgnore
64+
*
5365
* @return string
5466
*/
5567
public function get_name() {
56-
return 'ai-generate-titles-and-descriptions-upsell';
68+
_deprecated_function( __METHOD__, 'Yoast SEO 21.6', 'Please use get_id() instead' );
69+
70+
return $this->get_id();
5771
}
5872

5973
/**

src/introductions/application/introductions-collector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public function get_for( $user_id ) {
4545
if ( ! $introduction->should_show() ) {
4646
continue;
4747
}
48-
if ( $this->is_seen( $introduction->get_name(), $metadata ) ) {
48+
if ( $this->is_seen( $introduction->get_id(), $metadata ) ) {
4949
continue;
5050
}
5151
$bucket->add_introduction(
52-
new Introduction_Item( $introduction->get_name(), $introduction->get_priority() )
52+
new Introduction_Item( $introduction->get_id(), $introduction->get_priority() )
5353
);
5454
}
5555

src/introductions/domain/introduction-interface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@
77
*/
88
interface Introduction_Interface {
99

10+
/**
11+
* Returns the ID.
12+
*
13+
* @return string
14+
*/
15+
public function get_id();
16+
1017
/**
1118
* Returns the unique name.
1219
*
20+
* @deprecated 21.6
21+
* @codeCoverageIgnore
22+
*
1323
* @return string
1424
*/
1525
public function get_name();

src/introductions/domain/introduction-item.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
class Introduction_Item {
99

1010
/**
11-
* The unique name.
11+
* The ID.
1212
*
1313
* @var string
1414
*/
15-
private $name;
15+
private $id;
1616

1717
/**
1818
* The priority.
@@ -24,11 +24,11 @@ class Introduction_Item {
2424
/**
2525
* Constructs the instance.
2626
*
27-
* @param string $name The unique name.
27+
* @param string $id The ID.
2828
* @param int $priority The priority.
2929
*/
30-
public function __construct( $name, $priority ) {
31-
$this->name = $name;
30+
public function __construct( $id, $priority ) {
31+
$this->id = $id;
3232
$this->priority = $priority;
3333
}
3434

@@ -39,18 +39,18 @@ public function __construct( $name, $priority ) {
3939
*/
4040
public function to_array() {
4141
return [
42-
'name' => $this->get_name(),
42+
'id' => $this->get_id(),
4343
'priority' => $this->get_priority(),
4444
];
4545
}
4646

4747
/**
48-
* Returns the unique name.
48+
* Returns the ID.
4949
*
5050
* @return string
5151
*/
52-
public function get_name() {
53-
return $this->name;
52+
public function get_id() {
53+
return $this->id;
5454
}
5555

5656
/**

src/introductions/user-interface/introductions-integration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private function update_user_introductions( $user_id, $introductions ) {
153153
$metadata = [];
154154
}
155155
foreach ( $introductions as $introduction ) {
156-
$metadata[ $introduction['name'] ] = true;
156+
$metadata[ $introduction['id'] ] = true;
157157
}
158158
$this->user_helper->update_meta( $user_id, '_yoast_wpseo_introductions', $metadata );
159159
}

tests/unit/doubles/introductions/introduction-mock.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
class Introduction_Mock implements Introduction_Interface {
1111

1212
/**
13-
* Holds the name.
13+
* Holds the ID.
1414
*
1515
* @var string
1616
*/
17-
private $name;
17+
private $id;
1818

1919
/**
2020
* Holds the priority.
@@ -33,19 +33,33 @@ class Introduction_Mock implements Introduction_Interface {
3333
/**
3434
* Constructs the introduction mock.
3535
*/
36-
public function __construct( $name, $priority, $should_show ) {
37-
$this->name = $name;
36+
public function __construct( $id, $priority, $should_show ) {
37+
$this->id = $id;
3838
$this->priority = $priority;
3939
$this->should_show = $should_show;
4040
}
4141

42+
/**
43+
* Returns the ID.
44+
*
45+
* @return string
46+
*/
47+
public function get_id() {
48+
return $this->id;
49+
}
50+
4251
/**
4352
* Returns the unique name.
4453
*
54+
* @deprecated 21.6
55+
* @codeCoverageIgnore
56+
*
4557
* @return string
4658
*/
4759
public function get_name() {
48-
return $this->name;
60+
_deprecated_function( __METHOD__, 'Yoast SEO 21.6', 'Please use get_id() instead' );
61+
62+
return $this->id;
4963
}
5064

5165
/**

tests/unit/introductions/application/ai-generate-titles-and-descriptions-introduction-upsell-test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public function test_constructor() {
7070
}
7171

7272
/**
73-
* Tests getting the name.
73+
* Tests getting the ID.
7474
*
75-
* @covers ::get_name
75+
* @covers ::get_id
7676
*/
7777
public function test_get_name() {
78-
$this->assertSame( 'ai-generate-titles-and-descriptions-upsell', $this->instance->get_name() );
78+
$this->assertSame( 'ai-generate-titles-and-descriptions-upsell', $this->instance->get_id() );
7979
}
8080

8181
/**

tests/unit/introductions/application/introductions-collector-test.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function collector_get_data() {
8282
'user_introductions_metadata' => [],
8383
'expected_result' => [
8484
[
85-
'name' => 'test1',
85+
'id' => 'test1',
8686
'priority' => 1,
8787
],
8888
],
@@ -98,11 +98,11 @@ public function collector_get_data() {
9898
'user_introductions_metadata' => [],
9999
'expected_result' => [
100100
[
101-
'name' => 'test1',
101+
'id' => 'test1',
102102
'priority' => 1,
103103
],
104104
[
105-
'name' => 'test2',
105+
'id' => 'test2',
106106
'priority' => 2,
107107
],
108108
],
@@ -117,7 +117,7 @@ public function collector_get_data() {
117117
'user_introductions_metadata' => [],
118118
'expected_result' => [
119119
[
120-
'name' => 'test2',
120+
'id' => 'test2',
121121
'priority' => 2,
122122
],
123123
],
@@ -133,7 +133,7 @@ public function collector_get_data() {
133133
'user_introductions_metadata' => [],
134134
'expected_result' => [
135135
[
136-
'name' => 'test2',
136+
'id' => 'test2',
137137
'priority' => 2,
138138
],
139139
],
@@ -150,7 +150,7 @@ public function collector_get_data() {
150150
'user_introductions_metadata' => [],
151151
'expected_result' => [
152152
[
153-
'name' => 'test1',
153+
'id' => 'test1',
154154
'priority' => 1,
155155
],
156156
],
@@ -171,7 +171,7 @@ public function collector_get_data() {
171171
],
172172
'expected_result' => [
173173
[
174-
'name' => 'test2',
174+
'id' => 'test2',
175175
'priority' => 2,
176176
],
177177
],
@@ -190,11 +190,11 @@ public function collector_get_data() {
190190
'user_introductions_metadata' => false,
191191
'expected_result' => [
192192
[
193-
'name' => 'test1',
193+
'id' => 'test1',
194194
'priority' => 1,
195195
],
196196
[
197-
'name' => 'test2',
197+
'id' => 'test2',
198198
'priority' => 2,
199199
],
200200
],
@@ -215,7 +215,7 @@ public function collector_get_data() {
215215
'user_introductions_metadata' => [],
216216
'expected_result' => [
217217
[
218-
'name' => 'test1',
218+
'id' => 'test1',
219219
'priority' => 1,
220220
],
221221
],

tests/unit/introductions/domain/introduction-item-test.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function set_up() {
3737
* @covers ::__construct
3838
*/
3939
public function test_construct() {
40-
$this->assertEquals( 'test', $this->getPropertyValue( $this->instance, 'name' ) );
40+
$this->assertEquals( 'test', $this->getPropertyValue( $this->instance, 'id' ) );
4141
$this->assertEquals( 5, $this->getPropertyValue( $this->instance, 'priority' ) );
4242
}
4343

@@ -49,20 +49,20 @@ public function test_construct() {
4949
public function test_to_array() {
5050
$this->assertEquals(
5151
[
52-
'name' => 'test',
52+
'id' => 'test',
5353
'priority' => 5,
5454
],
5555
$this->instance->to_array()
5656
);
5757
}
5858

5959
/**
60-
* Tests getting the name.
60+
* Tests getting the ID.
6161
*
62-
* @covers ::get_name
62+
* @covers ::get_id
6363
*/
64-
public function test_get_name() {
65-
$this->assertEquals( 'test', $this->instance->get_name() );
64+
public function test_get_id() {
65+
$this->assertEquals( 'test', $this->instance->get_id() );
6666
}
6767

6868
/**

tests/unit/introductions/domain/introductions-bucket-test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public function test_to_array() {
5353
$this->assertEquals(
5454
[
5555
[
56-
'name' => 'test1',
56+
'id' => 'test1',
5757
'priority' => 1,
5858
],
5959
[
60-
'name' => 'test2',
60+
'id' => 'test2',
6161
'priority' => 2,
6262
],
6363
],

0 commit comments

Comments
 (0)