mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15: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;
|
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) {
|
export function getPageFromMatch(match: any) {
|
||||||
let page = parseInt(match.params.page, 10);
|
let page = parseInt(match.params.page, 10);
|
||||||
if (isNaN(page) || !page) {
|
if (isNaN(page) || !page) {
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
// @flow
|
// @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", () => {
|
describe("tests for getPageFromMatch", () => {
|
||||||
function createMatch(page: string) {
|
function createMatch(page: string) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
PENDING_SUFFIX,
|
PENDING_SUFFIX,
|
||||||
SUCCESS_SUFFIX
|
SUCCESS_SUFFIX
|
||||||
} from "../../modules/types";
|
} from "../../modules/types";
|
||||||
import { apiClient } from "@scm-manager/ui-components";
|
import { apiClient, urls } from "@scm-manager/ui-components";
|
||||||
import { isPending } from "../../modules/pending";
|
import { isPending } from "../../modules/pending";
|
||||||
import { getFailure } from "../../modules/failure";
|
import { getFailure } from "../../modules/failure";
|
||||||
import type {
|
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_SUCCESS = `${FETCH_CHANGESETS}_${SUCCESS_SUFFIX}`;
|
||||||
export const FETCH_CHANGESETS_FAILURE = `${FETCH_CHANGESETS}_${FAILURE_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 = "scm/repos/FETCH_CHANGESET";
|
||||||
export const FETCH_CHANGESET_PENDING = `${FETCH_CHANGESET}_${PENDING_SUFFIX}`;
|
export const FETCH_CHANGESET_PENDING = `${FETCH_CHANGESET}_${PENDING_SUFFIX}`;
|
||||||
export const FETCH_CHANGESET_SUCCESS = `${FETCH_CHANGESET}_${SUCCESS_SUFFIX}`;
|
export const FETCH_CHANGESET_SUCCESS = `${FETCH_CHANGESET}_${SUCCESS_SUFFIX}`;
|
||||||
export const FETCH_CHANGESET_FAILURE = `${FETCH_CHANGESET}_${FAILURE_SUFFIX}`;
|
export const FETCH_CHANGESET_FAILURE = `${FETCH_CHANGESET}_${FAILURE_SUFFIX}`;
|
||||||
|
|
||||||
//********end of detailed view add
|
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
//TODO: Content type
|
//TODO: Content type
|
||||||
|
|
||||||
//********added for detailed view of changesets
|
|
||||||
|
|
||||||
export function fetchChangesetIfNeeded(repository: Repository, id: string) {
|
export function fetchChangesetIfNeeded(repository: Repository, id: string) {
|
||||||
return (dispatch: any, getState: any) => {
|
return (dispatch: any, getState: any) => {
|
||||||
if (shouldFetchChangeset(getState(), repository, id)) {
|
if (shouldFetchChangeset(getState(), repository, id)) {
|
||||||
@@ -46,7 +40,7 @@ export function fetchChangeset(repository: Repository, id: string) {
|
|||||||
return function(dispatch: any) {
|
return function(dispatch: any) {
|
||||||
dispatch(fetchChangesetPending(repository, id));
|
dispatch(fetchChangesetPending(repository, id));
|
||||||
return apiClient
|
return apiClient
|
||||||
.get(repository._links.changesets.href + id)
|
.get(createChangesetUrl(repository, id))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => dispatch(fetchChangesetSuccess(data, repository, id)))
|
.then(data => dispatch(fetchChangesetSuccess(data, repository, id)))
|
||||||
.catch(err => {
|
.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(
|
export function fetchChangesetPending(
|
||||||
repository: Repository,
|
repository: Repository,
|
||||||
id: string
|
id: string
|
||||||
@@ -93,8 +91,6 @@ function fetchChangesetFailure(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//********end of detailed view add
|
|
||||||
|
|
||||||
export function fetchChangesets(
|
export function fetchChangesets(
|
||||||
repository: Repository,
|
repository: Repository,
|
||||||
branch?: Branch,
|
branch?: Branch,
|
||||||
@@ -266,21 +262,6 @@ function extractChangesetsByIds(changesets: any) {
|
|||||||
|
|
||||||
return changesetsByIds;
|
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
|
//selectors
|
||||||
export function getChangesets(
|
export function getChangesets(
|
||||||
@@ -291,15 +272,15 @@ export function getChangesets(
|
|||||||
const key = createItemId(repository, branch);
|
const key = createItemId(repository, branch);
|
||||||
|
|
||||||
const changesets = state.changesets[key];
|
const changesets = state.changesets[key];
|
||||||
if (!changesets) {
|
if (!changesets || !changesets.list) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return changesets.list.entries.map((id: string) => {
|
return changesets.list.entries.map((id: string) => {
|
||||||
return changesets.byId[id];
|
return changesets.byId[id];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//********added for detailed view of changesets
|
|
||||||
export function getChangeset(
|
export function getChangeset(
|
||||||
state: Object,
|
state: Object,
|
||||||
repository: Repository,
|
repository: Repository,
|
||||||
@@ -350,7 +331,6 @@ export function getFetchChangesetFailure(
|
|||||||
createChangesetItemId(repository, id)
|
createChangesetItemId(repository, id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//********end of added for detailed view of changesets
|
|
||||||
|
|
||||||
export function isFetchChangesetsPending(
|
export function isFetchChangesetsPending(
|
||||||
state: Object,
|
state: Object,
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ describe("changesets", () => {
|
|||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
changesets: {
|
changesets: {
|
||||||
byKey: {
|
|
||||||
"foo/bar": {
|
"foo/bar": {
|
||||||
byId: {
|
byId: {
|
||||||
id1: { id: "id1" },
|
id1: { id: "id1" },
|
||||||
@@ -160,7 +159,6 @@ describe("changesets", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const store = mockStore(state);
|
const store = mockStore(state);
|
||||||
@@ -427,7 +425,6 @@ describe("changesets", () => {
|
|||||||
it("should return changeset", () => {
|
it("should return changeset", () => {
|
||||||
const state = {
|
const state = {
|
||||||
changesets: {
|
changesets: {
|
||||||
byKey: {
|
|
||||||
"foo/bar": {
|
"foo/bar": {
|
||||||
byId: {
|
byId: {
|
||||||
id1: { id: "id1" },
|
id1: { id: "id1" },
|
||||||
@@ -435,7 +432,6 @@ describe("changesets", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const result = getChangeset(state, repository, "id1");
|
const result = getChangeset(state, repository, "id1");
|
||||||
expect(result).toEqual({ id: "id1" });
|
expect(result).toEqual({ id: "id1" });
|
||||||
@@ -478,7 +474,6 @@ describe("changesets", () => {
|
|||||||
it("should return false if changeset exists", () => {
|
it("should return false if changeset exists", () => {
|
||||||
const state = {
|
const state = {
|
||||||
changesets: {
|
changesets: {
|
||||||
byKey: {
|
|
||||||
"foo/bar": {
|
"foo/bar": {
|
||||||
byId: {
|
byId: {
|
||||||
id1: { id: "id1" },
|
id1: { id: "id1" },
|
||||||
@@ -486,7 +481,6 @@ describe("changesets", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const result = shouldFetchChangeset(state, repository, "id2");
|
const result = shouldFetchChangeset(state, repository, "id2");
|
||||||
expect(result).toEqual(false);
|
expect(result).toEqual(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user