Skip to content

Commit

Permalink
Show warning draft
Browse files Browse the repository at this point in the history
  • Loading branch information
demusdev committed Nov 27, 2024
1 parent 22f77f6 commit 4db6d91
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 18 deletions.
36 changes: 36 additions & 0 deletions resources/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,27 @@ type CompactionMetadataOnly {
recursive: Boolean!
}

union CompareChainsResult = CompareChainsResultStatus | CompareChainsResultError

type CompareChainsResultError {
reason: CompareChainsResultReason!
}

type CompareChainsResultReason {
message: String!
}

type CompareChainsResultStatus {
message: CompareChainsStatus!
}

enum CompareChainsStatus {
EQUAL
BEHIND
AHEAD
DIVERGED
}

enum CompressionFormat {
GZIP
ZIP
Expand Down Expand Up @@ -635,6 +656,10 @@ type DatasetMetadata {
"""
currentPushSources: [AddPushSource!]!
"""
Sync statuses of push remotes
"""
pushSyncStatuses: DatasetPushStatuses!
"""
Current transformation used by the derivative dataset
"""
currentTransform: SetTransform
Expand Down Expand Up @@ -705,8 +730,19 @@ type DatasetPermissions {
canSchedule: Boolean!
}

type DatasetPushStatus {
remote: DatasetRefRemote!
result: CompareChainsResult!
}

type DatasetPushStatuses {
statuses: [DatasetPushStatus!]!
}

scalar DatasetRef

scalar DatasetRefRemote

type DatasetState {
"""
Globally unique identity of the dataset
Expand Down
23 changes: 23 additions & 0 deletions src/app/api/dataset.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
UpdateWatermarkMutation,
DatasetHeadBlockHashGQL,
DatasetHeadBlockHashQuery,
DatasetPushSyncStatusesGQL,
DatasetPushSyncStatusesQuery,
} from "src/app/api/kamu.graphql.interface";
import AppValues from "src/app/common/app.values";
import { ApolloQueryResult } from "@apollo/client/core";
Expand Down Expand Up @@ -74,6 +76,7 @@ export class DatasetApi {
private updateWatermarkGQL = inject(UpdateWatermarkGQL);
private datasetHeadBlockHashGQL = inject(DatasetHeadBlockHashGQL);
private datasetSystemTimeBlockByHashGQL = inject(DatasetSystemTimeBlockByHashGQL);
private datasetPushSyncStatusesGQL = inject(DatasetPushSyncStatusesGQL);

public getDatasetMainData(params: {
accountName: string;
Expand Down Expand Up @@ -439,6 +442,26 @@ export class DatasetApi {
);
}

public datasetPushSyncStatuses(datasetId: string): Observable<DatasetPushSyncStatusesQuery> {
return this.datasetPushSyncStatusesGQL
.watch(
{ datasetId },

{
...noCacheFetchPolicy,
context: {
skipLoading: true,
},
},
)
.valueChanges.pipe(
first(),
map((result: ApolloQueryResult<DatasetPushSyncStatusesQuery>) => {
return result.data;
}),
);
}

public static generateDatasetKeyFragment(ownerRef: string | undefined, datasetId: string): StoreObject {
return {
__typename: "Dataset",
Expand Down
17 changes: 17 additions & 0 deletions src/app/api/gql/dataset-push-sync-statuses.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
query datasetPushSyncStatuses($datasetId: DatasetID!) {
datasets {
byId(datasetId: $datasetId) {
metadata {
pushSyncStatuses {
statuses {
remote,
result {
... on CompareChainsResultStatus { message }
... on CompareChainsResultError { reason { message } }
}
}
}
}
}
}
}
107 changes: 107 additions & 0 deletions src/app/api/kamu.graphql.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type Scalars = {
DatasetID: string;
DatasetName: string;
DatasetRef: string;
DatasetRefRemote: string;
/**
* Implement the DateTime<Utc> scalar
*
Expand Down Expand Up @@ -318,6 +319,30 @@ export type CompactionMetadataOnly = {
recursive: Scalars["Boolean"];
};

export type CompareChainsResult = CompareChainsResultError | CompareChainsResultStatus;

export type CompareChainsResultError = {
__typename?: "CompareChainsResultError";
reason: CompareChainsResultReason;
};

export type CompareChainsResultReason = {
__typename?: "CompareChainsResultReason";
message: Scalars["String"];
};

export type CompareChainsResultStatus = {
__typename?: "CompareChainsResultStatus";
message: CompareChainsStatus;
};

export enum CompareChainsStatus {
Ahead = "AHEAD",
Behind = "BEHIND",
Diverged = "DIVERGED",
Equal = "EQUAL",
}

export enum CompressionFormat {
Gzip = "GZIP",
Zip = "ZIP",
Expand Down Expand Up @@ -746,6 +771,8 @@ export type DatasetMetadata = {
currentVocab?: Maybe<SetVocab>;
/** Last recorded watermark */
currentWatermark?: Maybe<Scalars["DateTime"]>;
/** Sync statuses of push remotes */
pushSyncStatuses: DatasetPushStatuses;
};

export type DatasetMetadataCurrentSchemaArgs = {
Expand Down Expand Up @@ -797,6 +824,17 @@ export type DatasetPermissions = {
canView: Scalars["Boolean"];
};

export type DatasetPushStatus = {
__typename?: "DatasetPushStatus";
remote: Scalars["DatasetRefRemote"];
result: CompareChainsResult;
};

export type DatasetPushStatuses = {
__typename?: "DatasetPushStatuses";
statuses: Array<DatasetPushStatus>;
};

export type DatasetState = {
__typename?: "DatasetState";
/** Alias to be used in the query */
Expand Down Expand Up @@ -2692,6 +2730,36 @@ export type DatasetProtocolsQuery = {
};
};

export type DatasetPushSyncStatusesQueryVariables = Exact<{
datasetId: Scalars["DatasetID"];
}>;

export type DatasetPushSyncStatusesQuery = {
__typename?: "Query";
datasets: {
__typename?: "Datasets";
byId?: {
__typename?: "Dataset";
metadata: {
__typename?: "DatasetMetadata";
pushSyncStatuses: {
__typename?: "DatasetPushStatuses";
statuses: Array<{
__typename?: "DatasetPushStatus";
remote: string;
result:
| {
__typename?: "CompareChainsResultError";
reason: { __typename?: "CompareChainsResultReason"; message: string };
}
| { __typename?: "CompareChainsResultStatus"; message: CompareChainsStatus };
}>;
};
};
} | null;
};
};

export type GetDatasetSchemaQueryVariables = Exact<{
datasetId: Scalars["DatasetID"];
}>;
Expand Down Expand Up @@ -6177,6 +6245,45 @@ export class DatasetProtocolsGQL extends Apollo.Query<DatasetProtocolsQuery, Dat
super(apollo);
}
}
export const DatasetPushSyncStatusesDocument = gql`
query datasetPushSyncStatuses($datasetId: DatasetID!) {
datasets {
byId(datasetId: $datasetId) {
metadata {
pushSyncStatuses {
statuses {
remote
result {
... on CompareChainsResultStatus {
message
}
... on CompareChainsResultError {
reason {
message
}
}
}
}
}
}
}
}
}
`;

@Injectable({
providedIn: "root",
})
export class DatasetPushSyncStatusesGQL extends Apollo.Query<
DatasetPushSyncStatusesQuery,
DatasetPushSyncStatusesQueryVariables
> {
document = DatasetPushSyncStatusesDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const GetDatasetSchemaDocument = gql`
query getDatasetSchema($datasetId: DatasetID!) {
datasets {
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/modal/modal-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import { DynamicComponent } from "./dynamic.component";
<p *ngIf="context && context.message" class="modal__msg mt-4" data-test-id="modalMessage">
{{ context.message }}
</p>
<p *ngIf="context && context.htmlMessage"
class="modal__msg mt-4"
data-test-id="modalHtmlMessage"
[innerHTML]="context.htmlMessage">
</p>
</div>
<div
class="modal__dialog__footer-block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { BaseComponent } from "../../../../../common/base.component";
import { promiseWithCatch } from "../../../../../common/app.helpers";
import { ModalService } from "../../../../../components/modal/modal.service";
import {
CompareChainsResultError,
CompareChainsResultStatus, CompareChainsStatus,
DatasetBasicsFragment,
DatasetFlowType,
DatasetKind,
DatasetPermissionsFragment,
DatasetPermissionsFragment, DatasetPushSyncStatusesQuery,
} from "../../../../../api/kamu.graphql.interface";
import { DatasetSettingsService } from "../../services/dataset-settings.service";
import { Observable, shareReplay } from "rxjs";
Expand All @@ -19,6 +21,7 @@ import { NavigationService } from "src/app/services/navigation.service";
import AppValues from "src/app/common/app.values";
import { DatasetViewTypeEnum } from "src/app/dataset-view/dataset-view.interface";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { DatasetApi } from "../../../../../api/dataset.api";

@Component({
selector: "app-dataset-settings-general-tab",
Expand All @@ -45,6 +48,7 @@ export class DatasetSettingsGeneralTabComponent extends BaseComponent implements
private datasetCompactionService = inject(DatasetCompactionService);
private flowsService = inject(DatasetFlowsService);
private navigationService = inject(NavigationService);
private datasetApi = inject(DatasetApi);

public ngOnInit(): void {
this.renameError$ = this.datasetSettingsService.renameDatasetErrorOccurrences.pipe(shareReplay());
Expand Down Expand Up @@ -103,22 +107,59 @@ export class DatasetSettingsGeneralTabComponent extends BaseComponent implements
public deleteDataset(): void {
const datasetId = this.datasetBasics.id;
const accountId = this.datasetBasics.owner.id;
promiseWithCatch(
this.modalService.error({
title: "Delete",
message: "Do you want to delete a dataset?",
yesButtonText: "Ok",
noButtonText: "Cancel",
handler: (ok) => {
if (ok) {
this.datasetSettingsService
.deleteDataset(accountId, datasetId)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe();

this.datasetApi.datasetPushSyncStatuses(datasetId).subscribe((data: DatasetPushSyncStatusesQuery) => {
const statuses = data.datasets.byId?.metadata.pushSyncStatuses.statuses ?? [];
const lines: string[] = [];
const error_lines: string[] = [];
statuses.forEach((status) => {
console.log(status);
if (status.result.__typename === "CompareChainsResultStatus") {
const result: CompareChainsResultStatus = status.result;
if (result.message === CompareChainsStatus.Ahead) {
lines.push(`behind "${status.remote}"`);
} else if (result.message === CompareChainsStatus.Behind) {
lines.push(`ahead of "${status.remote}"`);
} else if (result.message === CompareChainsStatus.Diverged) {
lines.push(`diverged from "${status.remote}"`);
}
},
}),
);
} else if (status.result.__typename === "CompareChainsResultError") {
const result: CompareChainsResultError = status.result;
error_lines.push(` - could not check state of '${status.remote}'. Error: ${result.reason.message}`);
}
});

let message = "";
if (lines.length > 0 || error_lines.length > 0) {
message = `Dataset is out of sync with remote(s):<br><br>`;
lines.forEach((line) => {
message += `${line}<br>`;
});
error_lines.forEach((line) => {
message += `${line}<br>`;
});
message += "<br><br>";
}
message += "Do you want to delete a dataset?";

promiseWithCatch(
this.modalService.error({
title: "Delete",
bigTextBlock: true,
htmlMessage: message,
yesButtonText: "Ok",
noButtonText: "Cancel",
handler: (ok) => {
if (ok) {
this.datasetSettingsService
.deleteDataset(accountId, datasetId)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe();
}
},
}),
);
});
}

public resetDataset(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/app/dataset-view/dataset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DatasetLineageBasicsFragment,
DatasetLineageFragment,
DatasetPageInfoFragment,
DatasetPermissionsFragment,
DatasetPermissionsFragment, DatasetPushSyncStatusesQuery,
GetDatasetBasicsWithPermissionsQuery,
GetDatasetLineageQuery,
GetDatasetSchemaQuery,
Expand Down
Loading

0 comments on commit 4db6d91

Please sign in to comment.