Skip to content

Commit

Permalink
Kamu UI 468 readme does not refresh when navigating between datasets (#…
Browse files Browse the repository at this point in the history
…469)

* replaced onInit with onChanges lifecycle

* changed CHANGELOG.md

* reset edit mode

---------

Co-authored-by: Dmitriy Borzenko <[email protected]>
  • Loading branch information
dmitriy-borzenko and Dmitriy Borzenko authored Nov 1, 2024
1 parent b2bd928 commit 394ba4f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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
### Fixed
- Readme section refresh when navigating between datasets

## [0.28.3] - 2024-10-30
### Fixed
- Query explainer successfully validates commitment and shows data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Apollo, ApolloModule } from "apollo-angular";
import { ApolloTestingModule } from "apollo-angular/testing";
import { SharedTestModule } from "src/app/common/shared-test.module";
import { DatasetCommitService } from "../../services/dataset-commit.service";
import { SecurityContext } from "@angular/core";
import { SecurityContext, SimpleChanges } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { FormsModule } from "@angular/forms";
Expand Down Expand Up @@ -100,4 +100,18 @@ describe("ReadmeSectionComponent", () => {
expect(updateReadmeSpy).toHaveBeenCalledTimes(1);
flush();
}));

it("should check readme updated in the onChanges hook", () => {
const modifiedReadmeContent = mockReadmeContent + "modified";
const readmeSimpleChanges: SimpleChanges = {
currentReadme: {
previousValue: mockReadmeContent,
currentValue: modifiedReadmeContent,
firstChange: false,
isFirstChange: () => false,
},
};
component.ngOnChanges(readmeSimpleChanges);
expect(component.readmeState).toEqual(modifiedReadmeContent);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { ChangeDetectionStrategy, Component, EventEmitter, inject, Input, OnInit, Output } from "@angular/core";
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
inject,
Input,
OnChanges,
Output,
SimpleChanges,
} from "@angular/core";
import { DatasetBasicsFragment } from "src/app/api/kamu.graphql.interface";
import { MaybeNull } from "src/app/common/app.types";
import { BaseComponent } from "src/app/common/base.component";
Expand All @@ -13,7 +22,7 @@ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
styleUrls: ["./readme-section.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ReadmeSectionComponent extends BaseComponent implements OnInit {
export class ReadmeSectionComponent extends BaseComponent implements OnChanges {
@Input({ required: true }) public datasetBasics: DatasetBasicsFragment;
@Input({ required: true }) public currentReadme?: MaybeNull<string>;
@Input({ required: true }) public editingInProgress = false;
Expand All @@ -31,9 +40,10 @@ export class ReadmeSectionComponent extends BaseComponent implements OnInit {
private datasetCommitService = inject(DatasetCommitService);
private loggedUserService = inject(LoggedUserService);

public ngOnInit(): void {
if (this.currentReadme) {
this.readmeState = this.currentReadme;
ngOnChanges(changes: SimpleChanges): void {
if (changes.currentReadme && changes.currentReadme.currentValue !== changes.currentReadme.previousValue) {
this.readmeState = changes.currentReadme.currentValue as string;
this.editingInProgress = false;
}
}

Expand Down

0 comments on commit 394ba4f

Please sign in to comment.