Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
feat(vm-logs): replace keywords with search (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Shakhov committed Nov 2, 2018
1 parent ff0f5aa commit d9096e5
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 201 deletions.
29 changes: 11 additions & 18 deletions src/app/vm-logs/containers/vm-logs-filter.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as fromVmLogsVm from '../redux/vm-logs-vm.reducers';
import * as fromVmLogs from '../redux/vm-logs.reducers';
import * as fromVmLogFiles from '../redux/vm-log-files.reducers';
import * as fromAccounts from '../../reducers/accounts/redux/accounts.reducers';
import { Keyword } from '../models/keyword.model';
import { Time } from '../../shared/components/time-picker/time-picker.component';
import { UserTagsSelectors } from '../../root-store';
import * as accountActions from '../../reducers/accounts/redux/accounts.actions';
Expand All @@ -35,7 +34,7 @@ const FILTER_KEY = 'logsFilters';
[selectedAccountIds]="selectedAccountIds$ | async"
[selectedVmId]="selectedVmId$ | async"
[selectedLogFile]="selectedLogFile$ | async"
[keywords]="keywords$ | async"
[search]="search$ | async"
[startDate]="startDate$ | async | csDateObjectToDate"
[startTime]="startTime$ | async"
[endDate]="endDate$ | async | csDateObjectToDate"
Expand All @@ -47,8 +46,7 @@ const FILTER_KEY = 'logsFilters';
(vmChanged)="onVmChange($event)"
(logFileChanged)="onLogFileChange($event)"
(refreshed)="onRefresh()"
(keywordAdded)="onKeywordAdd($event)"
(keywordRemoved)="onKeywordRemove($event)"
(searchChanged)="onSearchChange($event)"
(startDateChanged)="onStartDateChange($event)"
(startTimeChanged)="onStartTimeChange($event)"
(endDateChanged)="onEndDateChange($event)"
Expand All @@ -63,7 +61,7 @@ export class VmLogsFilterContainerComponent extends WithUnsubscribe()
readonly selectedAccountIds$ = this.store.pipe(select(fromVmLogsVm.filterSelectedAccountIds));
readonly vms$ = this.store.pipe(select(selectFilteredVMs));
readonly selectedVmId$ = this.store.pipe(select(fromVmLogsVm.filterSelectedVmId));
readonly keywords$ = this.store.pipe(select(fromVmLogs.filterKeywords));
readonly search$ = this.store.pipe(select(fromVmLogs.filterSearch));
readonly startDate$ = this.store.pipe(select(fromVmLogs.filterStartDate));
readonly startTime$ = this.store.pipe(select(fromVmLogs.filterStartTime));
readonly endDate$ = this.store.pipe(select(fromVmLogs.filterEndDate));
Expand All @@ -80,7 +78,7 @@ export class VmLogsFilterContainerComponent extends WithUnsubscribe()
{
vm: { type: 'string' },
accounts: { type: 'array', defaultOption: [] },
keywords: { type: 'array', defaultOption: [] },
search: { type: 'string' },
startDate: { type: 'string' },
endDate: { type: 'string' },
logFile: { type: 'string' },
Expand Down Expand Up @@ -114,12 +112,8 @@ export class VmLogsFilterContainerComponent extends WithUnsubscribe()
this.store.dispatch(new vmLogActions.LoadVmLogsRequest());
}

public onKeywordAdd(keyword: Keyword) {
this.store.dispatch(new vmLogActions.VmLogsAddKeyword(keyword));
}

public onKeywordRemove(keyword: Keyword) {
this.store.dispatch(new vmLogActions.VmLogsRemoveKeyword(keyword));
public onSearchChange(search: string) {
this.store.dispatch(new vmLogActions.VmLogsUpdateSearch(search));
}

public onStartDateChange(date: Date) {
Expand Down Expand Up @@ -152,7 +146,7 @@ export class VmLogsFilterContainerComponent extends WithUnsubscribe()
this.initFilters();

combineLatest(
this.keywords$,
this.search$,
this.startDate$,
this.endDate$,
this.selectedVmId$,
Expand All @@ -164,13 +158,13 @@ export class VmLogsFilterContainerComponent extends WithUnsubscribe()
takeUntil(this.unsubscribe$),
debounceTime(100),
)
.subscribe(([keywords, startDate, endDate, vm, accounts, logFile, newestFirst]) => {
.subscribe(([search, startDate, endDate, vm, accounts, logFile, newestFirst]) => {
this.filterService.update({
vm,
accounts,
logFile,
newestFirst,
keywords: keywords.map(keyword => keyword.text),
search,
startDate: moment(startDate).toISOString(),
endDate: moment(endDate).toISOString(),
});
Expand All @@ -184,7 +178,7 @@ export class VmLogsFilterContainerComponent extends WithUnsubscribe()
private initFilters(): void {
const {
vm,
keywords,
search,
accounts,
startDate,
endDate,
Expand All @@ -196,8 +190,7 @@ export class VmLogsFilterContainerComponent extends WithUnsubscribe()
this.store.dispatch(new vmLogActions.VmLogsUpdateVmId(vm));
}

const wrappedKeywords = (keywords || []).map(text => ({ text }));
this.store.dispatch(new vmLogActions.VmLogsUpdateKeywords(wrappedKeywords));
this.store.dispatch(new vmLogActions.VmLogsUpdateSearch(search));
this.store.dispatch(new vmLogActions.VmLogsUpdateAccountIds(accounts || []));
this.store.dispatch(new vmLogActions.VmLogsUpdateNewestFirst(newestFirst));

Expand Down
3 changes: 0 additions & 3 deletions src/app/vm-logs/models/keyword.model.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ describe('loadVmLogsRequestParams selector', () => {
jasmine.clock().mockDate(date.toDate());
});

it('should select load logs request params without keywords', () => {
it('should select load logs request params without search', () => {
const id = 'test-id';
const keywords = [];
const search = null;

const params = loadVmLogsRequestParams.projector(id, keywords);
const params = loadVmLogsRequestParams.projector(id, search);

expect(params).toEqual({
id,
Expand All @@ -22,15 +22,15 @@ describe('loadVmLogsRequestParams selector', () => {
});
});

it('should select load logs request params with keywords', () => {
it('should select load logs request params with search', () => {
const id = 'test-id';
const keywords = [{ text: 'test-keyword1' }, { text: 'test-keyword2' }];
const search = 'test-search';

const params = loadVmLogsRequestParams.projector(id, keywords);
const params = loadVmLogsRequestParams.projector(id, search);

expect(params).toEqual({
id,
keywords: 'test-keyword1,test-keyword2',
keywords: search,
startDate: '1970-01-01T00:00:00.000',
endDate: '1970-01-01T00:00:00.000',
sort: 'timestamp',
Expand All @@ -50,7 +50,7 @@ describe('loadVmLogsRequestParams selector', () => {
it('should set sort: -timestamp if newest first = true', () => {
const id = 'test-id';

const params = loadVmLogsRequestParams.projector(id, [], date, date, '', true);
const params = loadVmLogsRequestParams.projector(id, null, date, date, '', true);

expect(params).toEqual({
...defaultRequestParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { filterSelectedVmId } from '../vm-logs-vm.reducers';
import { LoadVmLogsRequestParams } from '../../models/load-vm-logs-request-params';
import {
filterEndDate,
filterKeywords,
filterSearch,
filterNewestFirst,
filterSelectedLogFile,
filterStartDate,
Expand All @@ -13,16 +13,16 @@ import * as pickBy from 'lodash/pickBy';

export const loadVmLogsRequestParams = createSelector(
filterSelectedVmId,
filterKeywords,
filterSearch,
filterStartDate,
filterEndDate,
filterSelectedLogFile,
filterNewestFirst,
(id, keywords, startDate, endDate, logFile, newestFirst): LoadVmLogsRequestParams => {
(id, search, startDate, endDate, logFile, newestFirst): LoadVmLogsRequestParams => {
const fields = {
id,
logFile,
keywords: keywords.map(keyword => keyword.text).join(','),
keywords: search,
startDate: moment(startDate)
.toISOString()
.slice(0, -1),
Expand Down
25 changes: 7 additions & 18 deletions src/app/vm-logs/redux/vm-logs-auto-update.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { createFeatureSelector, createSelector } from '@ngrx/store';
import * as vmLogsActions from './vm-logs.actions';
import { DateObject } from '../models/date-object.model';


export interface State {
isAutoUpdateEnabled: boolean,
startDate: DateObject,
endDate: DateObject,
isAutoUpdateEnabled: boolean;
startDate: DateObject;
endDate: DateObject;
}

export const initialState: State = {
Expand All @@ -15,10 +14,7 @@ export const initialState: State = {
endDate: null,
};

export function reducer(
state = initialState,
action: vmLogsActions.Actions
): State {
export function reducer(state = initialState, action: vmLogsActions.Actions): State {
switch (action.type) {
case vmLogsActions.VmLogsActionTypes.ENABLE_AUTO_UPDATE: {
return {
Expand Down Expand Up @@ -54,20 +50,13 @@ export function reducer(
}
}


export const getVmLogsAutoUpdateState = createFeatureSelector<State>('vmLogsAutoUpdate');

export const selectIsAutoUpdateEnabled = createSelector(
getVmLogsAutoUpdateState,
state => state.isAutoUpdateEnabled
state => state.isAutoUpdateEnabled,
);

export const selectStartDate = createSelector(
getVmLogsAutoUpdateState,
state => state.startDate
);
export const selectStartDate = createSelector(getVmLogsAutoUpdateState, state => state.startDate);

export const selectEndDate = createSelector(
getVmLogsAutoUpdateState,
state => state.endDate
);
export const selectEndDate = createSelector(getVmLogsAutoUpdateState, state => state.endDate);
27 changes: 5 additions & 22 deletions src/app/vm-logs/redux/vm-logs.actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Action } from '@ngrx/store';
import { VmLog } from '../models/vm-log.model';
import { Keyword } from '../models/keyword.model';
import { Time } from '../../shared/components/time-picker/time-picker.component';
import { DateObject } from '../models/date-object.model';
import { VmLogFile } from '../models/vm-log-file.model';
Expand All @@ -13,9 +12,7 @@ export enum VmLogsActionTypes {
LOAD_AUTO_UPDATE_VM_LOGS_ERROR = '[VM Logs] LOAD_AUTO_UPDATE_VM_LOGS_ERROR',
LOAD_VM_LOG_FILES_REQUEST = '[VM Logs] LOAD_VM_LOG_FILES_REQUEST',
LOAD_VM_LOG_FILES_RESPONSE = '[VM Logs] LOAD_VM_LOG_FILES_RESPONSE',
VM_LOGS_UPDATE_KEYWORDS = '[VM Logs] VM_LOGS_UPDATE_KEYWORDS',
VM_LOGS_ADD_KEYWORD = '[VM Logs] VM_LOGS_ADD_KEYWORD',
VM_LOGS_REMOVE_KEYWORD = '[VM Logs] VM_LOGS_REMOVE_KEYWORD',
VM_LOGS_UPDATE_SEARCH = '[VM Logs] VM_LOGS_UPDATE_SEARCH',
VM_LOGS_UPDATE_START_DATE_TIME = '[VM Logs] VM_LOGS_UPDATE_START_DATE_TIME',
VM_LOGS_UPDATE_START_DATE = '[VM Logs] VM_LOGS_UPDATE_START_DATE',
VM_LOGS_UPDATE_START_TIME = '[VM Logs] VM_LOGS_UPDATE_START_TIME',
Expand Down Expand Up @@ -69,22 +66,10 @@ export class LoadVmLogFilesResponse implements Action {
constructor(public payload: VmLogFile[]) {}
}

export class VmLogsUpdateKeywords implements Action {
readonly type = VmLogsActionTypes.VM_LOGS_UPDATE_KEYWORDS;
export class VmLogsUpdateSearch implements Action {
readonly type = VmLogsActionTypes.VM_LOGS_UPDATE_SEARCH;

constructor(public payload: Keyword[]) {}
}

export class VmLogsAddKeyword implements Action {
readonly type = VmLogsActionTypes.VM_LOGS_ADD_KEYWORD;

constructor(readonly payload: Keyword) {}
}

export class VmLogsRemoveKeyword implements Action {
readonly type = VmLogsActionTypes.VM_LOGS_REMOVE_KEYWORD;

constructor(readonly payload: Keyword) {}
constructor(public payload: string) {}
}

export class VmLogsUpdateStartDateTime implements Action {
Expand Down Expand Up @@ -179,9 +164,7 @@ export type Actions =
| LoadAutoUpdateVmLogsError
| LoadVmLogFilesRequest
| LoadVmLogFilesResponse
| VmLogsUpdateKeywords
| VmLogsAddKeyword
| VmLogsRemoveKeyword
| VmLogsUpdateSearch
| VmLogsUpdateVmId
| VmLogsUpdateAccountIds
| VmLogsUpdateStartDateTime
Expand Down
34 changes: 5 additions & 29 deletions src/app/vm-logs/redux/vm-logs.reducers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,23 @@ describe('VM logs reducer', () => {
});
});

it('should add keywords', () => {
const keyword = {
text: 'test-keyword',
};
it('should update search', () => {
const search = 'test-search';

const state = reducer(undefined, {
type: VmLogsActionTypes.VM_LOGS_ADD_KEYWORD,
payload: keyword,
type: VmLogsActionTypes.VM_LOGS_UPDATE_SEARCH,
payload: search,
});

expect(state).toEqual({
...initialState,
filters: {
...initialState.filters,
keywords: [keyword],
search,
},
});
});

it('should remove keywords', () => {
const keyword = {
text: 'test-keyword',
};

const state = reducer(
{
...initialState,
filters: {
...initialState.filters,
keywords: [keyword],
},
},
{
type: VmLogsActionTypes.VM_LOGS_REMOVE_KEYWORD,
payload: keyword,
},
);

expect(state).toEqual(initialState);
});

it('should toggle newest first', () => {
const toggledState = reducer(undefined, {
type: VmLogsActionTypes.VM_LOGS_TOGGLE_NEWEST_FIRST,
Expand Down
Loading

0 comments on commit d9096e5

Please sign in to comment.