Skip to content

Commit

Permalink
Kamu 165 set watermark add event from UI (#105)
Browse files Browse the repository at this point in the history
* Added modal window.
* Add @danielmoncada/angular-datetime-picker package.
* Added datetime-picker component.
* Add description in the template.
* Add unit tests.
* Fix min value for dateTime picker.
* Add timezone dropdown.
* Add timezone difference.
  • Loading branch information
dmitriy-borzenko authored Jun 13, 2023
1 parent 896bf6f commit bdc45ff
Show file tree
Hide file tree
Showing 16 changed files with 381 additions and 37 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2023-05-31
## [Unreleased] - 2023-06-13

### Added

Expand All @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Read step
- Merge step
- The ability to edit SetPollingSource event
- Editing SetWaterMark event

## [0.6.0] - 2023-02-27

Expand Down
24 changes: 20 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"@angular/router": "^14.2.0",
"@angular/service-worker": "14.2.0",
"@apollo/client": "^3.0.0",
"@danielmoncada/angular-datetime-picker": "^16.0.1",
"@danielmoncada/angular-datetime-picker-moment-adapter": "^3.0.1",
"@ng-bootstrap/ng-bootstrap": "13.0.0",
"@popperjs/core": "^2.10.2",
"@rxweb/reactive-form-validators": "^13.0.0",
Expand All @@ -50,7 +52,7 @@
"d3-scale": "^3.2.1",
"graphql": "^16.0.0",
"lodash": "^4.17.21",
"moment-timezone": "^0.5.31",
"moment-timezone": "^0.5.43",
"monaco-editor": "^0.34.0",
"ng-multiselect-dropdown": "^0.3.9",
"ngx-highlightjs": "^7.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/data.helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ it("should check description for SetWatermark block", () => {
},
};
expect(DataHelpers.descriptionForMetadataBlock(setWatermarkBlock)).toEqual(
`Watermark updated to ${watermarkTime}`,
`Watermark updated`,
);
});

Expand Down
15 changes: 12 additions & 3 deletions src/app/common/data.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class DataHelpers {
"Basic information updated";
public static readonly BLOCK_DESCRIBE_SET_ATTACHMENTS =
"Attachments updated";
public static readonly BLOCK_DESCRIBE_SET_WATERMARK = "Watermark updated";
private static readonly SHIFT_ATTACHMENTS_VIEW = "\u00A0".repeat(12);

public static capitalizeFirstLetter(
Expand Down Expand Up @@ -149,9 +150,7 @@ export class DataHelpers {
case "SetVocab":
return DataHelpers.BLOCK_DESCRIBE_SET_VOCAB;
case "SetWatermark":
return `Watermark updated to ${
event.outputWatermark as string
}`;
return DataHelpers.BLOCK_DESCRIBE_SET_WATERMARK;
case "SetPollingSource":
return DataHelpers.BLOCK_DESCRIBE_SET_POLLING_SOURCE;
case "SetInfo":
Expand Down Expand Up @@ -208,3 +207,13 @@ export const getValidators = (
});
return validatorsToAdd;
};

export const MY_MOMENT_FORMATS = {
parseInput: "DD/MM/YY HH:mm:ss",
fullPickerInput: "DD/MM/YYYY HH:mm:ss A z",
datePickerInput: "DD/MM/YYYY",
timePickerInput: "HH:mm:ss",
monthYearLabel: "MMM YYYY",
dateA11yLabel: "LL",
monthYearA11yLabel: "MMMM YYYY",
};
7 changes: 4 additions & 3 deletions src/app/components/timeline-component/timeline.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
'SetLicense',
'SetVocab',
'SetTransform',
'SetPollingSource'
'SetPollingSource',
'SetWatermark'
].includes(block.event.__typename)
"
>more_horiz</mat-icon
Expand All @@ -57,8 +58,8 @@
)
"
data-test-id="navigate-to-block"
>{{ descriptionForMetadataBlock(block) }}</a
>
>{{ descriptionForMetadataBlock(block) }}
</a>
</div>

<div class="d-flex align-items-center mt-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,14 @@
"
[label]="'Watermark:'"
>
<app-display-time
[data]="
currentState.metadata.metadata
.currentWatermark
"
></app-display-time>
<a class="page-link">
<app-display-time
[data]="
currentState.metadata.metadata
.currentWatermark
"
></app-display-time>
</a>
</app-block-row-data>
</div>
</div>
Expand Down Expand Up @@ -491,7 +493,7 @@
currentState?.metadata?.kind === 'ROOT'
"
>
<h3 class="box-title text-center">There is no metadata.</h3>
<h3 class="box-title text-center mt-4">There is no metadata.</h3>
</ng-container>
<ng-container
*ngIf="
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<div class="d-flex p-4">
<div class="flex-grow-1 ms-2 text-center">
<span class="fs-5 fw-bold"> Set Watermark</span>
</div>
<div>
<button
type="button"
class="btn-close"
aria-label="Close"
(click)="activeModal.close()"
></button>
</div>
</div>
<div class="px-4">
<mat-divider></mat-divider>
</div>
<div class="p-4">
<div class="d-flex align-middle">
<span>
<mat-icon class="fs-4">help_outline</mat-icon>
</span>
<p class="ps-2">
A watermark defines a point in event time for which with a high
probability all preceding events have been already observed. Telling
the system
<em
>"You most likely will not get any events with time less than T
any more"</em
>
allows it to advance the downstream computations, like windowed
aggregations and streaming joins, and ensure consistent results.
Watermarks are typically advanced automatically based on observed
data or information from the data source, but you can also set them
manually here.
</p>
</div>
</div>

<div class="body text-center">
<div class="d-flex align-items-center pb-4 ms-4 ps-4">
<span class="me-4">Time zone:</span>
<select class="form-select w-75" [(ngModel)]="timeZone">
<option [ngValue]="timeZone">
(UTC{{ createOffset(this.date) }}) {{ timeZone }}
</option>
</select>
</div>
<div class="d-flex align-items-center ms-4 ps-4">
<span>Watermark:</span>
<input
[(ngModel)]="date"
[owlDateTime]="fromdatepicker"
placeholder="Date Time"
class="form-control w-65 ms-4"
name="fromDate"
[min]="minLocalWatermark"
/>
<owl-date-time #fromdatepicker></owl-date-time>
<span [owlDateTimeTrigger]="fromdatepicker" class="trigger ms-2"
><mat-icon>calendar_month</mat-icon>
</span>
</div>
</div>
<div class="p-4 d-flex justify-content-end">
<button
type="button"
class="btn btn-success"
(click)="commitSetWatermarkEvent(); activeModal.close()"
data-test-id="commit-setWatermark-event"
[disabled]="isDateValid"
>
Save
</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.custom-picker
z-index: 9999!important

.w-65
width: 67% !important
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { EditWatermarkModalComponent } from "./edit-watermark-modal.component";
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
import { Apollo } from "apollo-angular";
import { MatDividerModule } from "@angular/material/divider";
import { MatIconModule } from "@angular/material/icon";
import {
OwlDateTimeModule,
OwlNativeDateTimeModule,
} from "@danielmoncada/angular-datetime-picker";
import { OwlMomentDateTimeModule } from "@danielmoncada/angular-datetime-picker-moment-adapter";
import { FormsModule } from "@angular/forms";
import timekeeper from "timekeeper";
import { mockDatasetBasicsFragment } from "src/app/search/mock.data";
import { emitClickOnElementByDataTestId } from "src/app/common/base-test.helpers.spec";
import { AppDatasetCreateService } from "src/app/dataset-create/dataset-create.service";
import { of } from "rxjs";

describe("EditWatermarkModalComponent", () => {
let component: EditWatermarkModalComponent;
let fixture: ComponentFixture<EditWatermarkModalComponent>;
let appDatasetCreateService: AppDatasetCreateService;
const FROZEN_TIME = new Date("2022-10-01 12:00:00");

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [EditWatermarkModalComponent],
providers: [Apollo, NgbActiveModal],
imports: [
MatDividerModule,
MatIconModule,
OwlDateTimeModule,
OwlNativeDateTimeModule,
OwlMomentDateTimeModule,
FormsModule,
],
}).compileComponents();

fixture = TestBed.createComponent(EditWatermarkModalComponent);
component = fixture.componentInstance;
appDatasetCreateService = TestBed.inject(AppDatasetCreateService);
component.datasetBasics = mockDatasetBasicsFragment;
});

it("should create", () => {
expect(component).toBeTruthy();
});

beforeAll(() => {
timekeeper.freeze(FROZEN_TIME);
});

it("should check init date when currentWatermark is null", () => {
const result = new Date();
fixture.detectChanges();
expect(component.date).toEqual(result);
});

it("should check init minLocalWatermark when currentWatermark is not null", () => {
(component.currentWatermark = "2023-03-12T00:00:00+00:00"),
fixture.detectChanges();
const result = "2023-03-12T00:00:00.000Z";
expect(component.minLocalWatermark).toEqual(result);
});

it("should check commit SetWatermark event", () => {
fixture.detectChanges();
const commitSetWatermarkEventSpy = spyOn(
component,
"commitSetWatermarkEvent",
).and.callThrough();
spyOn(appDatasetCreateService, "commitEventToDataset").and.returnValue(
of(),
);
emitClickOnElementByDataTestId(fixture, "commit-setWatermark-event");
expect(commitSetWatermarkEventSpy).toHaveBeenCalledTimes(1);
});

afterAll(() => {
timekeeper.reset();
});
});
Loading

0 comments on commit bdc45ff

Please sign in to comment.