Skip to content

Commit 9d2284b

Browse files
authored
remove human-readable automatic slug generation (#132593) (#133089)
* remove human-readable automatic slug generation * make change non-breaking * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * remove test Co-authored-by: streamich <[email protected]> Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit e857b30) # Conflicts: # src/plugins/share/server/url_service/short_urls/short_url_client.ts
1 parent 183db65 commit 9d2284b

File tree

8 files changed

+11
-58
lines changed

8 files changed

+11
-58
lines changed

src/plugins/share/README.mdx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,6 @@ const url = await shortUrls.create({
215215
});
216216
```
217217

218-
You can make the short URL slug human-readable by specifying the
219-
`humanReadableSlug` flag:
220-
221-
```ts
222-
const url = await shortUrls.create({
223-
locator,
224-
params: {
225-
dashboardId: '123',
226-
},
227-
humanReadableSlug: true,
228-
});
229-
```
230-
231218
Or you can manually specify the slug for the short URL using the `slug` option:
232219

233220
```ts

src/plugins/share/common/url_service/short_urls/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ export interface ShortUrlCreateParams<P extends SerializableRecord> {
7979
* URL. This part will be visible to the user, it can have user-friendly text.
8080
*/
8181
slug?: string;
82-
83-
/**
84-
* Whether to generate a slug automatically. If `true`, the slug will be
85-
* a human-readable text consisting of three worlds: "<adjective>-<adjective>-<noun>".
86-
*/
87-
humanReadableSlug?: boolean;
8882
}
8983

9084
/**

src/plugins/share/public/url_service/short_urls/short_url_client.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ describe('create()', () => {
8888
body: expect.any(String),
8989
});
9090
expect(JSON.parse(fetchSpy.mock.calls[0][1].body)).toStrictEqual({
91-
humanReadableSlug: false,
9291
locatorId: LEGACY_SHORT_URL_LOCATOR_ID,
9392
params: {
9493
url: 'https://example.com/foo/bar',
@@ -173,7 +172,6 @@ describe('createFromLongUrl()', () => {
173172
body: expect.any(String),
174173
});
175174
expect(JSON.parse(fetchSpy.mock.calls[0][1].body)).toStrictEqual({
176-
humanReadableSlug: true,
177175
locatorId: LEGACY_SHORT_URL_LOCATOR_ID,
178176
params: {
179177
url: '/a/b/c',

src/plugins/share/public/url_service/short_urls/short_url_client.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@ export class BrowserShortUrlClient implements IShortUrlClient {
5959
locator,
6060
params,
6161
slug = undefined,
62-
humanReadableSlug = false,
6362
}: ShortUrlCreateParams<P>): Promise<ShortUrl<P>> {
6463
const { http } = this.dependencies;
6564
const data = await http.fetch<ShortUrlData<P>>('/api/short_url', {
6665
method: 'POST',
6766
body: JSON.stringify({
6867
locatorId: locator.id,
6968
slug,
70-
humanReadableSlug,
7169
params,
7270
}),
7371
});
@@ -113,7 +111,6 @@ export class BrowserShortUrlClient implements IShortUrlClient {
113111

114112
const result = await this.createWithLocator({
115113
locator,
116-
humanReadableSlug: true,
117114
params: {
118115
url: relativeUrl,
119116
},

src/plugins/share/server/url_service/http/short_urls/register_create_route.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export const registerCreateRoute = (router: IRouter, url: ServerUrlService) => {
2626
minLength: 3,
2727
maxLength: 255,
2828
}),
29+
/**
30+
* @deprecated
31+
*
32+
* This field is deprecated as the API does not support automatic
33+
* human-readable slug generation.
34+
*
35+
* @todo This field will be removed in a future version. It is left
36+
* here for backwards compatibility.
37+
*/
2938
humanReadableSlug: schema.boolean({
3039
defaultValue: false,
3140
}),
@@ -36,7 +45,7 @@ export const registerCreateRoute = (router: IRouter, url: ServerUrlService) => {
3645
router.handleLegacyErrors(async (ctx, req, res) => {
3746
const savedObjects = ctx.core.savedObjects.client;
3847
const shortUrls = url.shortUrls.get({ savedObjects });
39-
const { locatorId, params, slug, humanReadableSlug } = req.body;
48+
const { locatorId, params, slug } = req.body;
4049
const locator = url.locators.get(locatorId);
4150

4251
if (!locator) {
@@ -51,7 +60,6 @@ export const registerCreateRoute = (router: IRouter, url: ServerUrlService) => {
5160
locator,
5261
params,
5362
slug,
54-
humanReadableSlug,
5563
});
5664

5765
return res.ok({

src/plugins/share/server/url_service/short_urls/short_url_client.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ describe('ServerShortUrlClient', () => {
128128
})
129129
).rejects.toThrowError(new UrlServiceError(`Slug "lala" already exists.`, 'SLUG_EXISTS'));
130130
});
131-
132-
test('can automatically generate human-readable slug', async () => {
133-
const { client, locator } = setup();
134-
const shortUrl = await client.create({
135-
locator,
136-
humanReadableSlug: true,
137-
params: {
138-
url: '/app/test#foo/bar/baz',
139-
},
140-
});
141-
142-
expect(shortUrl.data.slug.split('-').length).toBe(3);
143-
});
144131
});
145132

146133
describe('.get()', () => {

src/plugins/share/server/url_service/short_urls/short_url_client.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import type { SerializableRecord } from '@kbn/utility-types';
1010
import { SavedObjectReference } from 'kibana/server';
11-
import { generateSlug } from 'random-word-slugs';
1211
import { ShortUrlRecord } from '.';
1312
import type {
1413
IShortUrlClient,
@@ -60,14 +59,13 @@ export class ServerShortUrlClient implements IShortUrlClient {
6059
locator,
6160
params,
6261
slug = '',
63-
humanReadableSlug = false,
6462
}: ShortUrlCreateParams<P>): Promise<ShortUrl<P>> {
6563
if (slug) {
6664
validateSlug(slug);
6765
}
6866

6967
if (!slug) {
70-
slug = humanReadableSlug ? generateSlug() : randomStr(4);
68+
slug = randomStr(5);
7169
}
7270

7371
const { storage, currentVersion } = this.dependencies;

test/api_integration/apis/short_url/create_short_url/main.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,6 @@ export default function ({ getService }: FtrProviderContext) {
7070
expect(response.body.url).to.be('');
7171
});
7272

73-
it('can generate a human-readable slug, composed of three words', async () => {
74-
const response = await supertest.post('/api/short_url').send({
75-
locatorId: 'LEGACY_SHORT_URL_LOCATOR',
76-
params: {},
77-
humanReadableSlug: true,
78-
});
79-
80-
expect(response.status).to.be(200);
81-
expect(typeof response.body.slug).to.be('string');
82-
const words = response.body.slug.split('-');
83-
expect(words.length).to.be(3);
84-
for (const word of words) {
85-
expect(word.length > 0).to.be(true);
86-
}
87-
});
88-
8973
it('can create a short URL with custom slug', async () => {
9074
const rnd = Math.round(Math.random() * 1e6) + 1;
9175
const slug = 'test-slug-' + Date.now() + '-' + rnd;

0 commit comments

Comments
 (0)