mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
fixed changeset urls without slash at the end
This commit is contained in:
@@ -5,6 +5,21 @@ export function withContextPath(path: string) {
|
||||
return contextPath + path;
|
||||
}
|
||||
|
||||
export function withEndingSlash(url: string) {
|
||||
if (url.endsWith("/")) {
|
||||
return url;
|
||||
}
|
||||
return url + "/";
|
||||
}
|
||||
|
||||
export function concat(base: string, ...parts: string) {
|
||||
let url = base;
|
||||
for ( let p of parts) {
|
||||
url = withEndingSlash(url) + p;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export function getPageFromMatch(match: any) {
|
||||
let page = parseInt(match.params.page, 10);
|
||||
if (isNaN(page) || !page) {
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
// @flow
|
||||
import { getPageFromMatch } from "./urls";
|
||||
import { concat, getPageFromMatch, withEndingSlash } from "./urls";
|
||||
|
||||
describe("tests for withEndingSlash", () => {
|
||||
|
||||
it("should append missing slash", () => {
|
||||
expect(withEndingSlash("abc")).toBe("abc/");
|
||||
});
|
||||
|
||||
it("should not append a second slash", () => {
|
||||
expect(withEndingSlash("abc/")).toBe("abc/");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("concat tests", () => {
|
||||
|
||||
it("should concat the parts to a single url", () => {
|
||||
expect(concat("a")).toBe("a");
|
||||
expect(concat("a", "b")).toBe("a/b");
|
||||
expect(concat("a", "b", "c")).toBe("a/b/c");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("tests for getPageFromMatch", () => {
|
||||
function createMatch(page: string) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
PENDING_SUFFIX,
|
||||
SUCCESS_SUFFIX
|
||||
} from "../../modules/types";
|
||||
import { apiClient } from "@scm-manager/ui-components";
|
||||
import { apiClient, urls } from "@scm-manager/ui-components";
|
||||
import { isPending } from "../../modules/pending";
|
||||
import { getFailure } from "../../modules/failure";
|
||||
import type {
|
||||
@@ -20,20 +20,14 @@ export const FETCH_CHANGESETS_PENDING = `${FETCH_CHANGESETS}_${PENDING_SUFFIX}`;
|
||||
export const FETCH_CHANGESETS_SUCCESS = `${FETCH_CHANGESETS}_${SUCCESS_SUFFIX}`;
|
||||
export const FETCH_CHANGESETS_FAILURE = `${FETCH_CHANGESETS}_${FAILURE_SUFFIX}`;
|
||||
|
||||
//********added for detailed view of changesets
|
||||
|
||||
export const FETCH_CHANGESET = "scm/repos/FETCH_CHANGESET";
|
||||
export const FETCH_CHANGESET_PENDING = `${FETCH_CHANGESET}_${PENDING_SUFFIX}`;
|
||||
export const FETCH_CHANGESET_SUCCESS = `${FETCH_CHANGESET}_${SUCCESS_SUFFIX}`;
|
||||
export const FETCH_CHANGESET_FAILURE = `${FETCH_CHANGESET}_${FAILURE_SUFFIX}`;
|
||||
|
||||
//********end of detailed view add
|
||||
|
||||
// actions
|
||||
//TODO: Content type
|
||||
|
||||
//********added for detailed view of changesets
|
||||
|
||||
export function fetchChangesetIfNeeded(repository: Repository, id: string) {
|
||||
return (dispatch: any, getState: any) => {
|
||||
if (shouldFetchChangeset(getState(), repository, id)) {
|
||||
@@ -46,7 +40,7 @@ export function fetchChangeset(repository: Repository, id: string) {
|
||||
return function(dispatch: any) {
|
||||
dispatch(fetchChangesetPending(repository, id));
|
||||
return apiClient
|
||||
.get(repository._links.changesets.href + id)
|
||||
.get(createChangesetUrl(repository, id))
|
||||
.then(response => response.json())
|
||||
.then(data => dispatch(fetchChangesetSuccess(data, repository, id)))
|
||||
.catch(err => {
|
||||
@@ -55,6 +49,10 @@ export function fetchChangeset(repository: Repository, id: string) {
|
||||
};
|
||||
}
|
||||
|
||||
function createChangesetUrl(repository: Repository, id: string) {
|
||||
return urls.concat(repository._links.changesets.href, id);
|
||||
}
|
||||
|
||||
export function fetchChangesetPending(
|
||||
repository: Repository,
|
||||
id: string
|
||||
@@ -93,8 +91,6 @@ function fetchChangesetFailure(
|
||||
};
|
||||
}
|
||||
|
||||
//********end of detailed view add
|
||||
|
||||
export function fetchChangesets(
|
||||
repository: Repository,
|
||||
branch?: Branch,
|
||||
@@ -266,21 +262,6 @@ function extractChangesetsByIds(changesets: any) {
|
||||
|
||||
return changesetsByIds;
|
||||
}
|
||||
//********added for detailed view of changesets
|
||||
|
||||
function addChangesetToChangesets(data: any, oldChangesetsByIds: any) {
|
||||
const changeset = data;
|
||||
const changesetsByIds = {};
|
||||
|
||||
changesetsByIds[changeset.id] = changeset;
|
||||
|
||||
for (let id in oldChangesetsByIds) {
|
||||
changesetsByIds[id] = oldChangesetsByIds[id];
|
||||
}
|
||||
|
||||
return changesetsByIds;
|
||||
}
|
||||
//********end of added for detailed view of changesets
|
||||
|
||||
//selectors
|
||||
export function getChangesets(
|
||||
@@ -291,15 +272,15 @@ export function getChangesets(
|
||||
const key = createItemId(repository, branch);
|
||||
|
||||
const changesets = state.changesets[key];
|
||||
if (!changesets) {
|
||||
if (!changesets || !changesets.list) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return changesets.list.entries.map((id: string) => {
|
||||
return changesets.byId[id];
|
||||
});
|
||||
}
|
||||
|
||||
//********added for detailed view of changesets
|
||||
export function getChangeset(
|
||||
state: Object,
|
||||
repository: Repository,
|
||||
@@ -350,7 +331,6 @@ export function getFetchChangesetFailure(
|
||||
createChangesetItemId(repository, id)
|
||||
);
|
||||
}
|
||||
//********end of added for detailed view of changesets
|
||||
|
||||
export function isFetchChangesetsPending(
|
||||
state: Object,
|
||||
|
||||
@@ -152,7 +152,6 @@ describe("changesets", () => {
|
||||
|
||||
const state = {
|
||||
changesets: {
|
||||
byKey: {
|
||||
"foo/bar": {
|
||||
byId: {
|
||||
id1: { id: "id1" },
|
||||
@@ -160,7 +159,6 @@ describe("changesets", () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const store = mockStore(state);
|
||||
@@ -427,7 +425,6 @@ describe("changesets", () => {
|
||||
it("should return changeset", () => {
|
||||
const state = {
|
||||
changesets: {
|
||||
byKey: {
|
||||
"foo/bar": {
|
||||
byId: {
|
||||
id1: { id: "id1" },
|
||||
@@ -435,7 +432,6 @@ describe("changesets", () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = getChangeset(state, repository, "id1");
|
||||
expect(result).toEqual({ id: "id1" });
|
||||
@@ -478,7 +474,6 @@ describe("changesets", () => {
|
||||
it("should return false if changeset exists", () => {
|
||||
const state = {
|
||||
changesets: {
|
||||
byKey: {
|
||||
"foo/bar": {
|
||||
byId: {
|
||||
id1: { id: "id1" },
|
||||
@@ -486,7 +481,6 @@ describe("changesets", () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = shouldFetchChangeset(state, repository, "id2");
|
||||
expect(result).toEqual(false);
|
||||
|
||||
Reference in New Issue
Block a user