Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] apply the correct timestamp to admin page #32379

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions x-pack/plugins/code/public/actions/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { createAction } from 'redux-actions';
import { RepoStatus } from '../reducers';

export const loadStatus = createAction<string>('LOAD STATUS');
export const loadStatusSuccess = createAction<any>('LOAD STATUS SUCCESS');
Expand All @@ -18,12 +19,6 @@ export const loadRepo = createAction<string>('LOAD REPO');
export const loadRepoSuccess = createAction<any>('LOAD REPO SUCCESS');
export const loadRepoFailed = createAction<any>('LOAD REPO FAILED');

export interface RepoProgress {
repoUri: string;
progress: number;
cloneProgress?: any;
}

export const updateCloneProgress = createAction<RepoProgress>('UPDATE CLONE PROGRESS');
export const updateIndexProgress = createAction<RepoProgress>('UPDATE INDEX PROGRESS');
export const updateDeleteProgress = createAction<RepoProgress>('UPDATE DELETE PROGRESS');
export const updateCloneProgress = createAction<RepoStatus>('UPDATE CLONE PROGRESS');
export const updateIndexProgress = createAction<RepoStatus>('UPDATE INDEX PROGRESS');
export const updateDeleteProgress = createAction<RepoStatus>('UPDATE DELETE PROGRESS');
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CodeProjectItem extends React.PureComponent<{
}> {
public render() {
const { project, status, enableManagement } = this.props;
const { name, org, nextUpdateTimestamp, uri, url } = project;
const { name, org, uri, url } = project;
const onClickDelete = () => this.props.deleteRepo && this.props.deleteRepo(uri);
const onClickIndex = () => this.props.indexRepo && this.props.indexRepo(uri);
const onClickSettings = () => this.props.openSettings && this.props.openSettings(uri, url);
Expand All @@ -65,7 +65,7 @@ class CodeProjectItem extends React.PureComponent<{
} else if (status.state === RepoState.READY) {
footer = (
<Footer data-test-subj="repositoryIndexDone">
LAST UPDATED: {moment(nextUpdateTimestamp).fromNow()}
LAST UPDATED: {moment(status.timestamp).fromNow()}
</Footer>
);
} else if (status.state === RepoState.DELETING) {
Expand Down
32 changes: 20 additions & 12 deletions x-pack/plugins/code/public/components/admin_page/project_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import {
EuiText,
EuiTitle,
} from '@elastic/eui';
import moment from 'moment';
import React, { ChangeEvent } from 'react';
import { connect } from 'react-redux';
import styled from 'styled-components';
import { Repository } from '../../../model';
import { importRepo } from '../../actions';
import { RootState } from '../../reducers';
import { RepoStatus, RootState } from '../../reducers';
import { CallOutType } from '../../reducers/repository';
import { ProjectItem } from './project_item';
import { ProjectSettings } from './project_settings';
Expand All @@ -47,27 +48,34 @@ enum SortOptionsValue {
recently_added = 'recently_added',
}

const sortFunctions: { [k: string]: (a: Repository, b: Repository) => number } = {
[SortOptionsValue.alphabetical_asc]: (a: Repository, b: Repository) =>
a.name!.localeCompare(b.name!),
[SortOptionsValue.alphabetical_desc]: (a: Repository, b: Repository) =>
b.name!.localeCompare(a.name!),
[SortOptionsValue.updated_asc]: () => -1,
[SortOptionsValue.updated_desc]: () => -1,
[SortOptionsValue.recently_added]: () => -1,
const sortFunctionsFactory = (status: { [key: string]: RepoStatus }) => {
const sortFunctions: { [k: string]: (a: Repository, b: Repository) => number } = {
[SortOptionsValue.alphabetical_asc]: (a: Repository, b: Repository) =>
a.name!.localeCompare(b.name!),
[SortOptionsValue.alphabetical_desc]: (a: Repository, b: Repository) =>
b.name!.localeCompare(a.name!),
[SortOptionsValue.updated_asc]: (a: Repository, b: Repository) =>
moment(status[b.uri].timestamp).diff(moment(status[a.uri].timestamp)),
[SortOptionsValue.updated_desc]: (a: Repository, b: Repository) =>
moment(status[a.uri].timestamp).diff(moment(status[b.uri].timestamp)),
[SortOptionsValue.recently_added]: () => {
return -1;
},
};
return sortFunctions;
};

const sortOptions = [
{ value: SortOptionsValue.alphabetical_asc, inputDisplay: 'A to Z' },
{ value: SortOptionsValue.alphabetical_desc, inputDisplay: 'Z to A' },
{ value: SortOptionsValue.updated_asc, inputDisplay: 'Last Updated ASC' },
{ value: SortOptionsValue.updated_desc, inputDisplay: 'Last Updated DESC' },
{ value: SortOptionsValue.recently_added, inputDisplay: 'Recently Added' },
// { value: SortOptionsValue.recently_added, inputDisplay: 'Recently Added' },
];

interface Props {
projects: Repository[];
status: any;
status: { [key: string]: RepoStatus };
isAdmin: boolean;
importRepo: (repoUrl: string) => void;
importLoading: boolean;
Expand Down Expand Up @@ -173,7 +181,7 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
const projectsCount = projects.length;
const modal = this.state.showImportProjectModal && this.renderImportModal();

const sortedProjects = projects.sort(sortFunctions[this.state.sortOption]);
const sortedProjects = projects.sort(sortFunctionsFactory(status)[this.state.sortOption]);

const repoList = sortedProjects.map((repo: Repository) => (
<ProjectItem
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/code/public/reducers/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export enum RepoState {
}

export interface RepoStatus {
state: RepoState;
progress?: number;
repoUri: string;
progress: number;
cloneProgress?: any;
timestamp?: Date;
state?: RepoState;
}

export interface StatusState {
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/code/public/sagas/project_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import moment from 'moment';
import { Action } from 'redux-actions';
import { delay } from 'redux-saga';
import { all, call, put, takeEvery, takeLatest } from 'redux-saga/effects';
Expand Down Expand Up @@ -156,10 +157,11 @@ const handleRepoCloneStatusPolling = createRepoStatusPollingHandler(
}

if (status.gitStatus) {
const { progress, cloneProgress } = status.gitStatus;
const { progress, cloneProgress, timestamp } = status.gitStatus;
yield put(
updateCloneProgress({
progress,
timestamp: moment(timestamp).toDate(),
repoUri,
cloneProgress,
})
Expand Down Expand Up @@ -204,6 +206,7 @@ const handleRepoIndexStatusPolling = createRepoStatusPollingHandler(
yield put(
updateIndexProgress({
progress: status.indexStatus.progress,
timestamp: moment(status.indexStatus.timestamp).toDate(),
repoUri,
})
);
Expand Down Expand Up @@ -249,6 +252,7 @@ const handleRepoDeleteStatusPolling = createRepoStatusPollingHandler(
yield put(
updateDeleteProgress({
progress: status.deleteStatus.progress,
timestamp: moment(status.deleteStatus.timestamp).toDate(),
repoUri,
})
);
Expand Down