Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added unsaved changes indication #2503

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,31 @@ exports[`UrlBoxComponent should render correctly 1`] = `
<div
class="url-box__input-actions"
>

<button
class="url-box__button"
nz-dropdown=""
nztrigger="click"
nz-tooltip=""
nztooltipplacement="bottom"
track-id="save_to_collection"
type="button"
>
<app-icon
name="save"
name="plus-circle"
/>
</button>

<button
class="url-box__button"
nz-tooltip=""
nztooltipplacement="bottom"
track-id="export_window"
type="button"
>
<app-icon
name="file-down"
/>
</button>

<nz-dropdown-menu>
<ul
nz-menu=""
>

<li
nz-menu-item=""
>

</li>

<li
nz-menu-item=""
>

</li>

</ul>

</nz-dropdown-menu>
<button
class="url-box__button"
nz-tooltip=""
Expand Down Expand Up @@ -225,37 +219,31 @@ exports[`UrlBoxComponent should render correctly with queryOperations > 1 1`] =
<div
class="url-box__input-actions"
>

<button
class="url-box__button"
nz-dropdown=""
nztrigger="click"
nz-tooltip=""
nztooltipplacement="bottom"
track-id="save_to_collection"
type="button"
>
<app-icon
name="save"
name="plus-circle"
/>
</button>

<button
class="url-box__button"
nz-tooltip=""
nztooltipplacement="bottom"
track-id="export_window"
type="button"
>
<app-icon
name="file-down"
/>
</button>

<nz-dropdown-menu>
<ul
nz-menu=""
>

<li
nz-menu-item=""
>

</li>

<li
nz-menu-item=""
>

</li>

</ul>

</nz-dropdown-menu>
<button
class="url-box__button"
nz-tooltip=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,42 @@
></app-x-input>
</div>
<div class="url-box__input-actions">
@if (currentCollection) {
<button
type="button"
class="url-box__button"
[ngClass]="{ 'url-box__button--disabled': !hasUnsavedChanges }"
(click)="updateQueryInCollectionChange.emit()"
track-id="update_in_collection"
nz-tooltip
[nzTooltipTitle]="'COLLECTION_UPDATE_WINDOW_IN_COLLECTION' | translate"
nzTooltipPlacement="bottom"
>
<app-icon name="save"></app-icon>
</button>
}
<button
type="button"
nz-dropdown
nzTrigger="click"
[nzDropdownMenu]="urlBoxActionMenu"
class="url-box__button"
(click)="addToCollectionChange.emit()"
track-id="save_to_collection"
nz-tooltip
[nzTooltipTitle]="'SAVE_TO_COLLECTION_BUTTON' | translate"
nzTooltipPlacement="bottom"
>
<app-icon name="save"></app-icon>
<app-icon name="plus-circle"></app-icon>
</button>
<button
type="button"
class="url-box__button"
(click)="exportWindowChange.emit()"
track-id="export_window"
nz-tooltip
[nzTooltipTitle]="'EXPORT_WINDOW_TEXT' | translate"
nzTooltipPlacement="bottom"
>
<app-icon name="file-down"></app-icon>
</button>
<nz-dropdown-menu #urlBoxActionMenu="nzDropdownMenu">
<ul nz-menu>
@if (currentCollection) {
<li nz-menu-item (click)="updateQueryInCollectionChange.emit()">
{{ 'COLLECTION_UPDATE_WINDOW_IN_COLLECTION' | translate }} ({{
currentCollection.title
}})
</li>
}
<li nz-menu-item (click)="addToCollectionChange.emit()">
{{ 'SAVE_TO_COLLECTION_BUTTON' | translate }}
</li>
<li nz-menu-item (click)="exportWindowChange.emit()">
{{ 'EXPORT_WINDOW_TEXT' | translate }}
</li>
</ul>
</nz-dropdown-menu>
<button
type="button"
class="url-box__button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class UrlBoxComponent {
@Input() queryOperations: OperationDefinitionNode[] = [];
@Input() streamState = '';
@Input() currentCollection?: IQueryCollection;
@Input() hasUnsavedChanges = false;

@Output() toggleDocsChange = new EventEmitter();
@Output() reloadDocsChange = new EventEmitter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[queryOperations]="queryOperations$ | async"
[streamState]="streamState$ | async"
[currentCollection]="currentCollection$ | async"
[hasUnsavedChanges]="hasUnsavedChanges$ | async"
(urlChange)="setApiUrl($event)"
(httpVerbChange)="setApiMethod($event)"
(sendRequest)="sendRequest()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export class WindowComponent implements OnInit {
editorShortcutMapping$: Observable<IDictionary>;
variableToType$: Observable<IDictionary>;

hasUnsavedChanges$: Observable<boolean>;

// Using getter/setter for the windowId to update the windowId$ subject.
// We need the windowId$ subject to update the getWindowState observable
// whenever the windowId changes, in order to get the right window state.
Expand Down Expand Up @@ -169,17 +171,13 @@ export class WindowComponent implements OnInit {
this.disableLineNumbers$ = this.store.pipe(
select((state) => state.settings.disableLineNumbers)
);
this.collections$ = this.store.pipe(
select((state) => state.collection.list)
);
this.collections$ = this.store.pipe(select((state) => state.collection.list));
this.activeWindowId$ = this.store.pipe(
select((state) => state.windowsMeta.activeWindowId)
);

this.query$ = this.getWindowState().pipe(select(fromRoot.getQueryState));
this.queryResult$ = this.getWindowState().pipe(
select(fromRoot.getQueryResult)
);
this.queryResult$ = this.getWindowState().pipe(select(fromRoot.getQueryResult));
this.showDocs$ = this.getWindowState().pipe(select(fromRoot.getShowDocs));
this.docView$ = this.getWindowState().pipe(select(fromRoot.getDocView));
this.docsIsLoading$ = this.getWindowState().pipe(
Expand Down Expand Up @@ -208,9 +206,7 @@ export class WindowComponent implements OnInit {
this.responseHeaders$ = this.getWindowState().pipe(
select(fromRoot.getResponseHeaders)
);
this.isSubscribed$ = this.getWindowState().pipe(
select(fromRoot.isSubscribed)
);
this.isSubscribed$ = this.getWindowState().pipe(select(fromRoot.isSubscribed));
this.subscriptionResponses$ = this.getWindowState().pipe(
select(fromRoot.getSubscriptionResponses)
);
Expand All @@ -235,8 +231,7 @@ export class WindowComponent implements OnInit {
return this.collections$.pipe(
map((collections) => {
return collections.find(
(collection) =>
str(collection.id) === str(data.layout.collectionId)
(collection) => str(collection.id) === str(data.layout.collectionId)
);
})
);
Expand All @@ -245,17 +240,11 @@ export class WindowComponent implements OnInit {
return EMPTY;
})
);
this.preRequest$ = this.getWindowState().pipe(
select(fromRoot.getPreRequest)
);
this.postRequest$ = this.getWindowState().pipe(
select(fromRoot.getPostRequest)
);
this.preRequest$ = this.getWindowState().pipe(select(fromRoot.getPreRequest));
this.postRequest$ = this.getWindowState().pipe(select(fromRoot.getPostRequest));
this.layout$ = this.getWindowState().pipe(select(fromRoot.getLayout));

this.resultPaneUiActions$ = this.store.select(
fromRoot.getResultPaneUiActions
);
this.resultPaneUiActions$ = this.store.select(fromRoot.getResultPaneUiActions);
this.resultPaneBottomPanels$ = this.store.select(
fromRoot.getResultPaneBottomPanels
);
Expand All @@ -277,6 +266,13 @@ export class WindowComponent implements OnInit {
}),
catchError(() => EMPTY)
);

this.hasUnsavedChanges$ = this.store.pipe(
withLatestFrom(this.windowId$),
switchMap(([state, windowId]) => {
return select(fromRoot.selectHasUnsavedChanges(windowId))(of(state));
})
);
}

ngOnInit() {
Expand Down Expand Up @@ -312,9 +308,7 @@ export class WindowComponent implements OnInit {
if (this.gql.isSchema(data.schema.schema)) {
this.gqlSchema = data.schema.schema;
} else {
const schema = this.gql.getIntrospectionSchema(
data.schema.introspection
);
const schema = this.gql.getIntrospectionSchema(data.schema.introspection);
if (schema) {
this.store.dispatch(
new schemaActions.SetSchemaAction(this.windowId, schema)
Expand All @@ -328,9 +322,7 @@ export class WindowComponent implements OnInit {

setApiUrl(url: string) {
if (url !== this.apiUrl) {
this.store.dispatch(
new queryActions.SetUrlAction({ url }, this.windowId)
);
this.store.dispatch(new queryActions.SetUrlAction({ url }, this.windowId));
this.store.dispatch(
new queryActions.SendIntrospectionQueryRequestAction(this.windowId)
);
Expand All @@ -355,9 +347,7 @@ export class WindowComponent implements OnInit {
}

cancelRequest() {
this.store.dispatch(
new queryActions.CancelQueryRequestAction(this.windowId)
);
this.store.dispatch(new queryActions.CancelQueryRequestAction(this.windowId));
}

selectOperation(selectedOperation: string) {
Expand All @@ -371,17 +361,12 @@ export class WindowComponent implements OnInit {

setQueryEditorState(queryEditorState: QueryEditorState) {
this.store.dispatch(
new queryActions.SetQueryEditorStateAction(
this.windowId,
queryEditorState
)
new queryActions.SetQueryEditorStateAction(this.windowId, queryEditorState)
);
}

startSubscription() {
this.store.dispatch(
new queryActions.StartSubscriptionAction(this.windowId)
);
this.store.dispatch(new queryActions.StartSubscriptionAction(this.windowId));
}

stopSubscription() {
Expand Down
Loading
Loading