@contentful/field-editor-rich-text 4.9.2 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,7 +163,10 @@ function HyperlinkModal(props) {
163
163
  async function selectEntry() {
164
164
  const options = {
165
165
  locale: props.sdk.field.locale,
166
- contentTypes: (0, _getLinkedContentTypeIdsForNodeType.default)(props.sdk.field, _richtexttypes.INLINES.ENTRY_HYPERLINK)
166
+ contentTypes: (0, _getLinkedContentTypeIdsForNodeType.default)(props.sdk.field, _richtexttypes.INLINES.ENTRY_HYPERLINK),
167
+ recommendations: {
168
+ searchQuery: props.linkText
169
+ }
167
170
  };
168
171
  const entry = await props.sdk.dialogs.selectSingleEntry(options);
169
172
  if (entry) {
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ describe('HyperlinkModal recommendations.searchQuery feature', ()=>{
3
+ it('should pass linkText as searchQuery to selectSingleEntry', ()=>{
4
+ const mockSelectSingleEntry = jest.fn();
5
+ const linkText = 'example search text';
6
+ const expectedOptions = {
7
+ locale: 'en-US',
8
+ contentTypes: [
9
+ 'exampleCT'
10
+ ],
11
+ recommendations: {
12
+ searchQuery: linkText
13
+ }
14
+ };
15
+ mockSelectSingleEntry(expectedOptions);
16
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expectedOptions);
17
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
18
+ recommendations: {
19
+ searchQuery: linkText
20
+ }
21
+ }));
22
+ });
23
+ it('should update searchQuery when linkText changes', ()=>{
24
+ const mockSelectSingleEntry = jest.fn();
25
+ const modifiedText = 'modified text';
26
+ const expectedOptions = {
27
+ locale: 'en-US',
28
+ contentTypes: [
29
+ 'exampleCT'
30
+ ],
31
+ recommendations: {
32
+ searchQuery: modifiedText
33
+ }
34
+ };
35
+ mockSelectSingleEntry(expectedOptions);
36
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
37
+ recommendations: {
38
+ searchQuery: modifiedText
39
+ }
40
+ }));
41
+ });
42
+ it('should handle empty linkText', ()=>{
43
+ const mockSelectSingleEntry = jest.fn();
44
+ const expectedOptions = {
45
+ locale: 'en-US',
46
+ contentTypes: [
47
+ 'exampleCT'
48
+ ],
49
+ recommendations: {
50
+ searchQuery: ''
51
+ }
52
+ };
53
+ mockSelectSingleEntry(expectedOptions);
54
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
55
+ recommendations: {
56
+ searchQuery: ''
57
+ }
58
+ }));
59
+ });
60
+ });
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
- import { TextLink, Button, FormControl, FormLabel, Select, TextInput, Form, ModalContent, ModalControls } from '@contentful/f36-components';
2
+ import { Button, Form, FormControl, FormLabel, ModalContent, ModalControls, Select, TextInput, TextLink } from '@contentful/f36-components';
3
3
  import tokens from '@contentful/f36-tokens';
4
4
  import { EntityProvider } from '@contentful/field-editor-reference';
5
5
  import { ModalDialogLauncher } from '@contentful/field-editor-shared';
6
6
  import { INLINES } from '@contentful/rich-text-types';
7
7
  import { css } from 'emotion';
8
- import { getNodeEntryFromSelection, insertLink, LINK_TYPES, focus } from '../../helpers/editor';
8
+ import { focus, getNodeEntryFromSelection, insertLink, LINK_TYPES } from '../../helpers/editor';
9
9
  import getAllowedResourcesForNodeType from '../../helpers/getAllowedResourcesForNodeType';
10
10
  import getLinkedContentTypeIdsForNodeType from '../../helpers/getLinkedContentTypeIdsForNodeType';
11
11
  import { isNodeTypeEnabled } from '../../helpers/validations';
@@ -99,7 +99,10 @@ export function HyperlinkModal(props) {
99
99
  async function selectEntry() {
100
100
  const options = {
101
101
  locale: props.sdk.field.locale,
102
- contentTypes: getLinkedContentTypeIdsForNodeType(props.sdk.field, INLINES.ENTRY_HYPERLINK)
102
+ contentTypes: getLinkedContentTypeIdsForNodeType(props.sdk.field, INLINES.ENTRY_HYPERLINK),
103
+ recommendations: {
104
+ searchQuery: props.linkText
105
+ }
103
106
  };
104
107
  const entry = await props.sdk.dialogs.selectSingleEntry(options);
105
108
  if (entry) {
@@ -0,0 +1,59 @@
1
+ describe('HyperlinkModal recommendations.searchQuery feature', ()=>{
2
+ it('should pass linkText as searchQuery to selectSingleEntry', ()=>{
3
+ const mockSelectSingleEntry = jest.fn();
4
+ const linkText = 'example search text';
5
+ const expectedOptions = {
6
+ locale: 'en-US',
7
+ contentTypes: [
8
+ 'exampleCT'
9
+ ],
10
+ recommendations: {
11
+ searchQuery: linkText
12
+ }
13
+ };
14
+ mockSelectSingleEntry(expectedOptions);
15
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expectedOptions);
16
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
17
+ recommendations: {
18
+ searchQuery: linkText
19
+ }
20
+ }));
21
+ });
22
+ it('should update searchQuery when linkText changes', ()=>{
23
+ const mockSelectSingleEntry = jest.fn();
24
+ const modifiedText = 'modified text';
25
+ const expectedOptions = {
26
+ locale: 'en-US',
27
+ contentTypes: [
28
+ 'exampleCT'
29
+ ],
30
+ recommendations: {
31
+ searchQuery: modifiedText
32
+ }
33
+ };
34
+ mockSelectSingleEntry(expectedOptions);
35
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
36
+ recommendations: {
37
+ searchQuery: modifiedText
38
+ }
39
+ }));
40
+ });
41
+ it('should handle empty linkText', ()=>{
42
+ const mockSelectSingleEntry = jest.fn();
43
+ const expectedOptions = {
44
+ locale: 'en-US',
45
+ contentTypes: [
46
+ 'exampleCT'
47
+ ],
48
+ recommendations: {
49
+ searchQuery: ''
50
+ }
51
+ };
52
+ mockSelectSingleEntry(expectedOptions);
53
+ expect(mockSelectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
54
+ recommendations: {
55
+ searchQuery: ''
56
+ }
57
+ }));
58
+ });
59
+ });
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { Link } from '@contentful/field-editor-reference';
3
3
  import { FieldAppSDK } from '@contentful/field-editor-shared';
4
4
  import { ResourceLink } from '@contentful/rich-text-types';
5
- import { PlateEditor, Path } from '../../internal/types';
5
+ import { Path, PlateEditor } from '../../internal/types';
6
6
  import { TrackingPluginActions } from '../../plugins/Tracking';
7
7
  interface HyperlinkModalProps {
8
8
  linkText?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "4.9.2",
3
+ "version": "4.10.0",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -88,5 +88,5 @@
88
88
  "publishConfig": {
89
89
  "registry": "https://npm.pkg.github.com/"
90
90
  },
91
- "gitHead": "c43c17b9bb1036b1d5aec267ad45adc8c136d528"
91
+ "gitHead": "299f71af5a480a95605b33898bead31cc239c918"
92
92
  }