mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-21 06:52:11 +01:00
Implemented paging
WIP
This commit is contained in:
@@ -10,10 +10,11 @@ import {
|
||||
import {
|
||||
fetchChangesets,
|
||||
fetchChangesetsByNamespaceNameAndBranch,
|
||||
getChangesets,
|
||||
getFetchChangesetsFailure,
|
||||
isFetchChangesetsPending,
|
||||
selectListAsCollection
|
||||
selectListAsCollection,
|
||||
fetchChangesetsByLink,
|
||||
getChangesetsFromState
|
||||
} from "../modules/changesets";
|
||||
import type { History } from "history";
|
||||
import {
|
||||
@@ -34,7 +35,9 @@ type Props = {
|
||||
name: string,
|
||||
branch: string
|
||||
) => void,
|
||||
list: PagedCollection
|
||||
list: PagedCollection,
|
||||
fetchChangesetsByLink: string => void,
|
||||
page: number
|
||||
};
|
||||
|
||||
class Changesets extends React.Component<State, Props> {
|
||||
@@ -44,7 +47,11 @@ class Changesets extends React.Component<State, Props> {
|
||||
}
|
||||
|
||||
onPageChange = (link: string) => {
|
||||
const { namespace, name } = this.props.repository;
|
||||
const branch = this.props.match.params.branch;
|
||||
this.props.fetchChangesetsByLink(namespace, name, link, branch);
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
const { namespace, name } = this.props.repository;
|
||||
const branchName = this.props.match.params.branch;
|
||||
@@ -112,28 +119,27 @@ class Changesets extends React.Component<State, Props> {
|
||||
};
|
||||
}
|
||||
|
||||
const createKey = (
|
||||
namespace: string,
|
||||
name: string,
|
||||
branch?: string
|
||||
): string => {
|
||||
let key = `${namespace}/${name}`;
|
||||
if (branch) {
|
||||
key = key + `/${branch}`;
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
const mapStateToProps = (state, ownProps: Props) => {
|
||||
const { namespace, name } = ownProps.repository;
|
||||
const loading = isFetchChangesetsPending(
|
||||
state,
|
||||
namespace,
|
||||
name,
|
||||
ownProps.match.params.branch
|
||||
);
|
||||
const changesets = getChangesets(
|
||||
state,
|
||||
namespace,
|
||||
name,
|
||||
ownProps.match.params.branch
|
||||
);
|
||||
const { branch } = ownProps.match.params;
|
||||
const key = createKey(namespace, name, branch);
|
||||
const loading = isFetchChangesetsPending(state, namespace, name, branch);
|
||||
const changesets = getChangesetsFromState(state, key);
|
||||
const branchNames = getBranchNames(namespace, name, state);
|
||||
const error = getFetchChangesetsFailure(
|
||||
state,
|
||||
namespace,
|
||||
name,
|
||||
ownProps.match.params.branch
|
||||
);
|
||||
const list = selectListAsCollection(state);
|
||||
const error = getFetchChangesetsFailure(state, namespace, name, branch);
|
||||
const list = selectListAsCollection(state, key);
|
||||
|
||||
return {
|
||||
loading,
|
||||
@@ -160,6 +166,14 @@ const mapDispatchToProps = dispatch => {
|
||||
},
|
||||
fetchBranchesByNamespaceAndName: (namespace: string, name: string) => {
|
||||
dispatch(fetchBranchesByNamespaceAndName(namespace, name));
|
||||
},
|
||||
fetchChangesetsByLink: (
|
||||
namespace: string,
|
||||
name: string,
|
||||
link: string,
|
||||
branch?: string
|
||||
) => {
|
||||
dispatch(fetchChangesetsByLink(namespace, name, link, branch));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,7 +9,8 @@ import { apiClient } from "@scm-manager/ui-components";
|
||||
import { isPending } from "../../modules/pending";
|
||||
import { getFailure } from "../../modules/failure";
|
||||
import { combineReducers } from "redux";
|
||||
import type { Action, PagedCollection } from "@scm-manager/ui-types";
|
||||
import type { Action, Changeset, PagedCollection } from "@scm-manager/ui-types";
|
||||
import ChangesetAvatar from "../components/ChangesetAvatar";
|
||||
|
||||
export const FETCH_CHANGESETS = "scm/repos/FETCH_CHANGESETS";
|
||||
export const FETCH_CHANGESETS_PENDING = `${FETCH_CHANGESETS}_${PENDING_SUFFIX}`;
|
||||
@@ -20,6 +21,26 @@ const REPO_URL = "repositories";
|
||||
//TODO: Content type
|
||||
// actions
|
||||
|
||||
export function fetchChangesetsByLink(
|
||||
namespace: string,
|
||||
name: string,
|
||||
link: string,
|
||||
branch?: string
|
||||
) {
|
||||
return function(dispatch: any) {
|
||||
// dispatch(fetchChangesetsPending(namespace, name, branch));
|
||||
return apiClient
|
||||
.get(link)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
dispatch(fetchChangesetsSuccess(data, namespace, name, branch));
|
||||
})
|
||||
.catch(cause => {
|
||||
dispatch(fetchChangesetsFailure(namespace, name, cause, branch));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchChangesetsWithOptions(
|
||||
namespace: string,
|
||||
name: string,
|
||||
@@ -140,36 +161,25 @@ function byKeyReducer(
|
||||
): Object {
|
||||
switch (action.type) {
|
||||
case FETCH_CHANGESETS_SUCCESS:
|
||||
const changesets = action.payload._embedded.changesets;
|
||||
const changesetIds = changesets.map(c => c.id);
|
||||
const key = action.itemId;
|
||||
let oldChangesets = { [key]: {} };
|
||||
if (state[key] !== undefined) {
|
||||
oldChangesets[key] = state[key];
|
||||
}
|
||||
const byIds = extractChangesetsByIds(changesets, oldChangesets[key].byId);
|
||||
return {
|
||||
...state,
|
||||
[key]: {
|
||||
byId: extractChangesetsByIds(action.payload, oldChangesets[key].byId)
|
||||
}
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
function listReducer(
|
||||
state: any = {},
|
||||
action: Action = { type: "UNKNOWN" }
|
||||
): Object {
|
||||
switch (action.type) {
|
||||
case FETCH_CHANGESETS_SUCCESS:
|
||||
const changesets = action.payload._embedded.changesets;
|
||||
const changesetIds = changesets.map(c => c.id);
|
||||
return {
|
||||
entries: changesetIds,
|
||||
entry: {
|
||||
page: action.payload.page,
|
||||
pageTotal: action.payload.pageTotal,
|
||||
_links: action.payload._links
|
||||
byId: { ...byIds },
|
||||
list: {
|
||||
entries: changesetIds,
|
||||
entry: {
|
||||
page: action.payload.page,
|
||||
pageTotal: action.payload.pageTotal,
|
||||
_links: action.payload._links
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
default:
|
||||
@@ -178,12 +188,10 @@ function listReducer(
|
||||
}
|
||||
|
||||
export default combineReducers({
|
||||
list: listReducer,
|
||||
byKey: byKeyReducer
|
||||
});
|
||||
|
||||
function extractChangesetsByIds(data: any, oldChangesetsByIds: any) {
|
||||
const changesets = data._embedded.changesets;
|
||||
function extractChangesetsByIds(changesets: any, oldChangesetsByIds: any) {
|
||||
const changesetsByIds = {};
|
||||
|
||||
for (let changeset of changesets) {
|
||||
@@ -237,21 +245,38 @@ export function getFetchChangesetsFailure(
|
||||
);
|
||||
}
|
||||
|
||||
const selectList = (state: Object) => {
|
||||
if (state.changesets && state.changesets.list) {
|
||||
return state.changesets.list;
|
||||
const selectList = (state: Object, key: string) => {
|
||||
if (state.changesets.byKey[key] && state.changesets.byKey[key].list) {
|
||||
return state.changesets.byKey[key].list;
|
||||
}
|
||||
return {};
|
||||
};
|
||||
|
||||
const selectListEntry = (state: Object): Object => {
|
||||
const list = selectList(state);
|
||||
const selectListEntry = (state: Object, key: string): Object => {
|
||||
const list = selectList(state, key);
|
||||
if (list.entry) {
|
||||
return list.entry;
|
||||
}
|
||||
return {};
|
||||
};
|
||||
|
||||
export const selectListAsCollection = (state: Object): PagedCollection => {
|
||||
return selectListEntry(state);
|
||||
export const selectListAsCollection = (
|
||||
state: Object,
|
||||
key: string
|
||||
): PagedCollection => {
|
||||
return selectListEntry(state, key);
|
||||
};
|
||||
|
||||
export function getChangesetsFromState(state: Object, key: string) {
|
||||
const changesetIds = selectList(state, key).entries;
|
||||
if (!changesetIds) {
|
||||
return null;
|
||||
}
|
||||
const changesetEntries: Changeset[] = [];
|
||||
|
||||
for (let id of changesetIds) {
|
||||
changesetEntries.push(state.changesets.byKey[key].byId[id]);
|
||||
}
|
||||
|
||||
return changesetEntries;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ describe("changesets", () => {
|
||||
expect(newState.byKey["foo/bar"].byId["changeset3"].description).toEqual(
|
||||
"bar"
|
||||
);
|
||||
expect(newState.list).toEqual({
|
||||
expect(newState.byKey["foo/bar"].list).toEqual({
|
||||
entry: {
|
||||
page: 1,
|
||||
pageTotal: 10,
|
||||
|
||||
@@ -22,7 +22,6 @@ public class GroupDto extends HalRepresentation {
|
||||
private Instant lastModified;
|
||||
@Pattern(regexp = "^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$")
|
||||
private String name;
|
||||
@NotEmpty
|
||||
private String type;
|
||||
private Map<String, String> properties;
|
||||
private List<String> members;
|
||||
|
||||
Reference in New Issue
Block a user