mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-19 21:16:18 +00:00
Enhanced edit tags action so that it calls PATCH endpoint
This commit is contained in:
@@ -63,6 +63,7 @@ export default class ShlinkApiClient {
|
||||
this.performRequest(`/short-urls/${shortCode}`, 'DELETE', { domain })
|
||||
.then(() => {});
|
||||
|
||||
/* @deprecated. If using Shlink 2.6.0 or greater, use updateShortUrlMeta instead */
|
||||
public readonly updateShortUrlTags = async (
|
||||
shortCode: string,
|
||||
domain: OptionalString,
|
||||
@@ -75,9 +76,9 @@ export default class ShlinkApiClient {
|
||||
shortCode: string,
|
||||
domain: OptionalString,
|
||||
meta: ShlinkShortUrlMeta,
|
||||
): Promise<ShlinkShortUrlMeta> =>
|
||||
this.performRequest(`/short-urls/${shortCode}`, 'PATCH', { domain }, meta)
|
||||
.then(() => meta);
|
||||
): Promise<ShortUrl> =>
|
||||
this.performRequest<ShortUrl>(`/short-urls/${shortCode}`, 'PATCH', { domain }, meta)
|
||||
.then(({ data }) => data);
|
||||
|
||||
public readonly listTags = async (): Promise<ShlinkTags> =>
|
||||
this.performRequest<{ tags: ShlinkTagsResponse }>('/tags', 'GET', { withStats: 'true' })
|
||||
|
||||
@@ -59,6 +59,7 @@ export interface ShlinkVisitsParams {
|
||||
|
||||
export interface ShlinkShortUrlMeta extends ShortUrlMeta {
|
||||
longUrl?: string;
|
||||
tags?: string[];
|
||||
}
|
||||
|
||||
export interface ShlinkDomain {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Action, Dispatch } from 'redux';
|
||||
import { prop } from 'ramda';
|
||||
import { buildActionCreator, buildReducer } from '../../utils/helpers/redux';
|
||||
import { GetState } from '../../container/types';
|
||||
import { OptionalString } from '../../utils/utils';
|
||||
@@ -6,6 +7,8 @@ import { ShortUrlIdentifier } from '../data';
|
||||
import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
|
||||
import { ProblemDetailsError } from '../../api/types';
|
||||
import { parseApiError } from '../../api/utils';
|
||||
import { isReachableServer } from '../../servers/data';
|
||||
import { versionMatch } from '../../utils/helpers/version';
|
||||
|
||||
/* eslint-disable padding-line-between-statements */
|
||||
export const EDIT_SHORT_URL_TAGS_START = 'shlink/shortUrlTags/EDIT_SHORT_URL_TAGS_START';
|
||||
@@ -50,10 +53,19 @@ export const editShortUrlTags = (buildShlinkApiClient: ShlinkApiClientBuilder) =
|
||||
tags: string[],
|
||||
) => async (dispatch: Dispatch, getState: GetState) => {
|
||||
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
|
||||
const { updateShortUrlTags } = buildShlinkApiClient(getState);
|
||||
const { selectedServer } = getState();
|
||||
const supportsTagsInPatch = isReachableServer(selectedServer) && versionMatch(
|
||||
selectedServer.version,
|
||||
{ minVersion: '2.6.0' },
|
||||
);
|
||||
const { updateShortUrlTags, updateShortUrlMeta } = buildShlinkApiClient(getState);
|
||||
|
||||
try {
|
||||
const normalizedTags = await updateShortUrlTags(shortCode, domain, tags);
|
||||
const normalizedTags = await (
|
||||
supportsTagsInPatch
|
||||
? updateShortUrlMeta(shortCode, domain, { tags }).then(prop('tags'))
|
||||
: updateShortUrlTags(shortCode, domain, tags)
|
||||
);
|
||||
|
||||
dispatch<EditShortUrlTagsAction>({ tags: normalizedTags, shortCode, domain, type: SHORT_URL_TAGS_EDITED });
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user