Skip to content

Commit

Permalink
Add ability to rename daataset.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Borzenko committed Aug 16, 2023
1 parent 0bc3b0b commit a9dd115
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/app/api/dataset.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
DeleteDatasetMutation,
GetDatasetSchemaGQL,
GetDatasetSchemaQuery,
RenameDatasetGQL,
RenameDatasetMutation,
UpdateReadmeGQL,
UpdateReadmeMutation,
} from "src/app/api/kamu.graphql.interface";
Expand Down Expand Up @@ -54,6 +56,7 @@ export class DatasetApi {
private datasetSchemaGQL: GetDatasetSchemaGQL,
private updateReadmeGQL: UpdateReadmeGQL,
private deleteDatasetGQL: DeleteDatasetGQL,
private renameDatasetGQL: RenameDatasetGQL,
) {}

public getDatasetMainData(params: {
Expand Down Expand Up @@ -254,4 +257,18 @@ export class DatasetApi {
}),
);
}

public renameDataset(datasetId: string, newName: string): Observable<RenameDatasetMutation | null | undefined> {
return this.renameDatasetGQL
.mutate({
datasetId,
newName,
})
.pipe(
first(),
map((result: MutationResult<RenameDatasetMutation>) => {
return result.data;
}),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { NavigationService } from "src/app/services/navigation.service";
import { Injectable } from "@angular/core";
import { DatasetApi } from "src/app/api/dataset.api";
import { map } from "rxjs/operators";
import { DeleteDatasetMutation } from "src/app/api/kamu.graphql.interface";
import { DeleteDatasetMutation, RenameDatasetMutation } from "src/app/api/kamu.graphql.interface";
import { DatasetViewTypeEnum } from "src/app/dataset-view/dataset-view.interface";
import { promiseWithCatch } from "src/app/common/app.helpers";
import { ModalService } from "src/app/components/modal/modal.service";
import { DatasetService } from "src/app/dataset-view/dataset.service";

@Injectable({
providedIn: "root",
Expand All @@ -16,6 +17,7 @@ export class DatasetSettingsService {
private datasetApi: DatasetApi,
private navigationService: NavigationService,
private modalService: ModalService,
private datasetService: DatasetService,
) {}

public deleteDataset(datasetId: string): Observable<void> {
Expand All @@ -37,4 +39,35 @@ export class DatasetSettingsService {
}),
);
}

public renameDataset(accountName: string, datasetId: string, newName: string): Observable<void> {
return this.datasetApi.renameDataset(datasetId, newName).pipe(
map((data: RenameDatasetMutation | undefined | null) => {
console.log("data", data);
if (data?.datasets.byId?.rename.__typename === "RenameResultSuccess") {
this.datasetService
.requestDatasetMainData({
accountName,
datasetName: newName,
})
.subscribe();
this.navigationService.navigateToDatasetView({
accountName,
datasetName: newName,
tab: DatasetViewTypeEnum.Overview,
});
} else {
if (data) {
promiseWithCatch(
this.modalService.error({
title: "Can't rename dataset",
message: data.datasets.byId?.rename.message,
yesButtonText: "Ok",
}),
);
}
}
}),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@ <h2>General</h2>
/>
</dd>
</dl>
<button class="ms-4 rename-btn" type="button">Rename</button>
<button
class="ms-4 rename-btn"
type="button"
(click)="renameDataset()"
[disabled]="!renameDatasetForm.valid"
>
Rename
</button>
<div *ngIf="datasetName?.invalid && (datasetName?.touched || datasetName?.dirty)">
<span *ngIf="datasetName?.errors?.['required']" class="text-danger fs-12">Name is required</span>
<span *ngIf="datasetName?.errors?.['pattern']" class="text-danger fs-12">Invalid dataset name</span>
</div>
</form>
<div class="mt-4">
<h2>Danger Zone</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ p
h2
font-weight: 400
margin: 0
dl
margin: 0

.p-responsive
padding-left: 16px
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { DatasetSettingsService } from "./services/dataset-settings.service";
import { ChangeDetectionStrategy, Component, Input, OnInit } from "@angular/core";
import { ChangeDetectionStrategy, Component, Input } from "@angular/core";
import { DatasetBasicsFragment } from "src/app/api/kamu.graphql.interface";
import { promiseWithCatch } from "src/app/common/app.helpers";
import { BaseComponent } from "src/app/common/base.component";
Expand All @@ -12,7 +12,7 @@ import { ModalService } from "src/app/components/modal/modal.service";
styleUrls: ["./settings.component.sass"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SettingsTabComponent extends BaseComponent implements OnInit {
export class SettingsTabComponent extends BaseComponent {
@Input() public datasetBasics?: DatasetBasicsFragment;
public renameDatasetForm: FormGroup;

Expand All @@ -31,15 +31,25 @@ export class SettingsTabComponent extends BaseComponent implements OnInit {
});
}

ngOnInit(): void {
console.log("yes");
public get datasetName() {
return this.renameDatasetForm.get("datasetName");
}

public renameDataset(): void {
const datasetId = this.datasetBasics?.id as string;
const accountName = this.getDatasetInfoFromUrl().accountName;
this.trackSubscription(
this.datasetSettingsService
.renameDataset(accountName, datasetId, this.datasetName?.value as string)
.subscribe(),
);
}

public deleteDataset(): void {
promiseWithCatch(
this.modalService.error({
title: "Delete",
message: "Do you want to delete dataset?",
message: "Do you want to delete a dataset?",
yesButtonText: "Ok",
noButtonText: "Cancel",
handler: (ok) => {
Expand Down

0 comments on commit a9dd115

Please sign in to comment.