@contentful/field-editor-slug 2.2.1 → 2.2.2-canary.2

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.
@@ -274,6 +274,35 @@ describe('SlugEditor', ()=>{
274
274
  expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
275
275
  });
276
276
  });
277
+ it('shows warning instead of error when unique validation is disabled on content model', async ()=>{
278
+ const { field, sdk } = createMocks({
279
+ titleField: 'Slug value',
280
+ field: 'slug-value'
281
+ });
282
+ field.validations = [];
283
+ sdk.entry.getSys.mockReturnValue({
284
+ id: 'entry-id',
285
+ publishedVersion: undefined,
286
+ contentType: {
287
+ sys: {
288
+ id: 'content-type-id'
289
+ }
290
+ }
291
+ });
292
+ sdk.cma.entry.getMany.mockResolvedValue({
293
+ total: 2
294
+ });
295
+ const { queryByText, getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_SlugEditor.SlugEditor, {
296
+ field: field,
297
+ baseSdk: sdk,
298
+ isInitiallyDisabled: false
299
+ }));
300
+ await (0, _react1.waitFor)(()=>{
301
+ expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
302
+ expect(queryByText('This slug has already been published in another entry.')).toBeInTheDocument();
303
+ expect(getByTestId('cf-ui-text-input')).not.toHaveAttribute('aria-invalid');
304
+ });
305
+ });
277
306
  });
278
307
  describe('should react to title changes', ()=>{
279
308
  it('when field is disabled', async ()=>{
@@ -19,6 +19,7 @@ _export(exports, {
19
19
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
20
20
  const _f36components = require("@contentful/f36-components");
21
21
  const _f36icons = require("@contentful/f36-icons");
22
+ const _f36note = require("@contentful/f36-note");
22
23
  const _core = require("@lingui/core");
23
24
  const _usedebounce = require("use-debounce");
24
25
  const _makeSlug = require("./services/makeSlug");
@@ -145,6 +146,13 @@ function SlugEditorFieldStatic(props) {
145
146
  }, _core.i18n._({
146
147
  id: "FieldEditors.Slug.SlugEditorField.DuplicateSlugError",
147
148
  message: "This slug has already been published in another entry"
149
+ })), hasDuplicate && !isUniqueValidationEnabled && /*#__PURE__*/ _react.createElement(_f36note.Note, {
150
+ variant: "warning",
151
+ testId: "slug-editor-duplicate-warning",
152
+ className: _styles.uniqueValidationError
153
+ }, _core.i18n._({
154
+ id: "FieldEditors.Slug.SlugEditorField.DuplicateSlugWarning",
155
+ message: "This slug has already been published in another entry."
148
156
  })));
149
157
  }
150
158
  function SlugEditorField(props) {
@@ -229,6 +229,35 @@ describe('SlugEditor', ()=>{
229
229
  expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
230
230
  });
231
231
  });
232
+ it('shows warning instead of error when unique validation is disabled on content model', async ()=>{
233
+ const { field, sdk } = createMocks({
234
+ titleField: 'Slug value',
235
+ field: 'slug-value'
236
+ });
237
+ field.validations = [];
238
+ sdk.entry.getSys.mockReturnValue({
239
+ id: 'entry-id',
240
+ publishedVersion: undefined,
241
+ contentType: {
242
+ sys: {
243
+ id: 'content-type-id'
244
+ }
245
+ }
246
+ });
247
+ sdk.cma.entry.getMany.mockResolvedValue({
248
+ total: 2
249
+ });
250
+ const { queryByText, getByTestId } = render(/*#__PURE__*/ React.createElement(SlugEditor, {
251
+ field: field,
252
+ baseSdk: sdk,
253
+ isInitiallyDisabled: false
254
+ }));
255
+ await waitFor(()=>{
256
+ expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
257
+ expect(queryByText('This slug has already been published in another entry.')).toBeInTheDocument();
258
+ expect(getByTestId('cf-ui-text-input')).not.toHaveAttribute('aria-invalid');
259
+ });
260
+ });
232
261
  });
233
262
  describe('should react to title changes', ()=>{
234
263
  it('when field is disabled', async ()=>{
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { Spinner, TextInput, ValidationMessage } from '@contentful/f36-components';
3
3
  import { LinkSimpleIcon } from '@contentful/f36-icons';
4
+ import { Note } from '@contentful/f36-note';
4
5
  import { i18n as $_i18n } from "@lingui/core";
5
6
  import { useDebounce } from 'use-debounce';
6
7
  import { makeSlug } from './services/makeSlug';
@@ -86,6 +87,13 @@ export function SlugEditorFieldStatic(props) {
86
87
  }, $_i18n._({
87
88
  id: "FieldEditors.Slug.SlugEditorField.DuplicateSlugError",
88
89
  message: "This slug has already been published in another entry"
90
+ })), hasDuplicate && !isUniqueValidationEnabled && /*#__PURE__*/ React.createElement(Note, {
91
+ variant: "warning",
92
+ testId: "slug-editor-duplicate-warning",
93
+ className: styles.uniqueValidationError
94
+ }, $_i18n._({
95
+ id: "FieldEditors.Slug.SlugEditorField.DuplicateSlugWarning",
96
+ message: "This slug has already been published in another entry."
89
97
  })));
90
98
  }
91
99
  export function SlugEditorField(props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-slug",
3
- "version": "2.2.1",
3
+ "version": "2.2.2-canary.2+4797c8d5",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "registry": "https://npm.pkg.github.com/"
61
61
  },
62
- "gitHead": "6a566b8c6a30e4d96641e580a644c0be49115e07"
62
+ "gitHead": "4797c8d502ae3dc55e22bf12f5aef2762f010a09"
63
63
  }