Skip to content

Commit

Permalink
Kamu UI 533 return to the previously opened page after login (#538)
Browse files Browse the repository at this point in the history
* set redirect url when dataset not found

* changed CHANGELOG.md

* minor changes

---------

Co-authored-by: Dmitriy Borzenko <[email protected]>
  • Loading branch information
dmitriy-borzenko and Dmitriy Borzenko authored Feb 3, 2025
1 parent 28805f2 commit 3b512d7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added a feature for changing account email
- Added `redirectUrl` parameter in the URL for login page
### Fixed
- Private datasets: return to the previously opened page after login

## [0.38.0] - 2025-01-27
### Changed
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ export class AppComponent extends BaseComponent implements OnInit {
}

public onLogin(): void {
this.localStorageService.setRedirectAfterLoginUrl(this.router.url);
if (!this.localStorageService.redirectAfterLoginUrl) {
this.localStorageService.setRedirectAfterLoginUrl(this.router.url);
}
this.navigationService.navigateToLogin();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class DatasetSettingsGeneralTabComponent extends BaseComponent implements
]
: [
"You will decide who else has access",
"It will appear in search results on for people with access",
"It will appear in search results only for people with access",
"You can control the level of access others have",
],
warningText: !this.isPrivate
Expand Down
23 changes: 19 additions & 4 deletions src/app/dataset-view/dataset.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {
mockDatasetLineageResponse,
} from "../search/mock.data";
import { TestBed } from "@angular/core/testing";
import { Apollo, ApolloModule } from "apollo-angular";
import { Apollo, APOLLO_OPTIONS } from "apollo-angular";
import { DatasetApi } from "../api/dataset.api";
import { ModalService } from "../components/modal/modal.service";
import { DatasetService } from "./dataset.service";
import { DatasetSubscriptionsService } from "./dataset.subscriptions.service";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { ApolloTestingModule } from "apollo-angular/testing";
import {
DataQueryResultErrorKind,
DatasetBasicsFragment,
Expand Down Expand Up @@ -45,8 +44,24 @@ describe("AppDatasetService", () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ApolloModule, ApolloTestingModule, HttpClientTestingModule],
providers: [DatasetApi, ModalService, DatasetService, DatasetSubscriptionsService, Apollo],
imports: [HttpClientTestingModule],
providers: [
DatasetApi,
ModalService,
DatasetService,
DatasetSubscriptionsService,
Apollo,
{
provide: APOLLO_OPTIONS,
useFactory: () => {
return {
cache: {
evict: () => null,
},
};
},
},
],
});
service = TestBed.inject(DatasetService);
datasetApi = TestBed.inject(DatasetApi);
Expand Down
10 changes: 10 additions & 0 deletions src/app/dataset-view/dataset.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LocalStorageService } from "src/app/services/local-storage.service";
import { SqlExecutionError } from "../common/errors";
import {
BlockRef,
Expand Down Expand Up @@ -39,12 +40,15 @@ import { parseCurrentSchema } from "../common/app.helpers";
import { APOLLO_OPTIONS } from "apollo-angular";
import { resetCacheHelper } from "../apollo-cache.helper";
import { parseDataRows } from "../common/data.helpers";
import { Router } from "@angular/router";

@Injectable({ providedIn: "root" })
export class DatasetService {
private datasetApi = inject(DatasetApi);
private datasetSubsService = inject(DatasetSubscriptionsService);
private injector = inject(Injector);
private router = inject(Router);
private localStorageService = inject(LocalStorageService);
private currentHeadBlockHash: string;
private dataset$: Subject<DatasetBasicsFragment> = new Subject<DatasetBasicsFragment>();

Expand Down Expand Up @@ -81,6 +85,12 @@ export class DatasetService {
throw new SqlExecutionError(dataTail.errorMessage);
}
} else {
this.localStorageService.setRedirectAfterLoginUrl(this.router.url);
const cache = this.injector.get(APOLLO_OPTIONS).cache;
cache.evict({
id: "ROOT_QUERY",
fieldName: "datasets",
});
throw new DatasetNotFoundError();
}
}),
Expand Down

0 comments on commit 3b512d7

Please sign in to comment.