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

Tree item abort #6757

Merged
merged 18 commits into from
Jul 14, 2023
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
8 changes: 6 additions & 2 deletions e2e/tests/functional/forms.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ test.describe('Persistence operations @couchdb', () => {
]);

//Slow down the test a bit
await expect(page.getByRole('treeitem', { name: `  ${myItemsFolderName}` })).toBeVisible();
await expect(page2.getByRole('treeitem', { name: `  ${myItemsFolderName}` })).toBeVisible();
await expect(
page.getByRole('button', { name: `Expand ${myItemsFolderName} folder` })
).toBeVisible();
await expect(
page2.getByRole('button', { name: `Expand ${myItemsFolderName} folder` })
).toBeVisible();

// Both pages: Click the Create button
await Promise.all([
Expand Down
36 changes: 36 additions & 0 deletions e2e/tests/functional/tree.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,42 @@ test.describe('Main Tree', () => {
]);
});
});
test('Opening and closing an item before the request has been fulfilled will abort the request @couchdb', async ({
page,
openmctConfig
}) => {
const { myItemsFolderName } = openmctConfig;
let requestWasAborted = false;

page.on('requestfailed', (request) => {
// check if the request was aborted
if (request.failure().errorText === 'net::ERR_ABORTED') {
requestWasAborted = true;
}
});

await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: 'Foo'
});

// Intercept and delay request
const delayInMs = 500;

await page.route('**', async (route, request) => {
await new Promise((resolve) => setTimeout(resolve, delayInMs));
route.continue();
});

// Quickly Expand/close the root folder
await page
.getByRole('button', {
name: `Expand ${myItemsFolderName} folder`
})
.dblclick({ delay: 400 });

expect(requestWasAborted).toBe(true);
});
});

/**
Expand Down
11 changes: 8 additions & 3 deletions src/api/objects/ObjectAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,16 @@ export default class ObjectAPI {
return domainObject;
})
.catch((error) => {
console.warn(`Failed to retrieve ${keystring}:`, error);
delete this.cache[keystring];
const result = this.applyGetInterceptors(identifier);

return result;
// suppress abort errors
if (error.name === 'AbortError') {
return;
}

console.warn(`Failed to retrieve ${keystring}:`, error);

return this.applyGetInterceptors(identifier);
});

this.cache[keystring] = objectPromise;
Expand Down
11 changes: 9 additions & 2 deletions src/api/objects/ObjectAPISpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,17 @@ describe('The Object API', () => {
});

it('displays a notification in the event of an error', () => {
mockProvider.get.and.returnValue(Promise.reject());
openmct.notifications.warn = jasmine.createSpy('warn');
mockProvider.get.and.returnValue(
Promise.reject({
name: 'Error',
status: 404,
statusText: 'Not Found'
})
);

return objectAPI.get(mockDomainObject.identifier).catch(() => {
expect(openmct.notifications.error).toHaveBeenCalledWith(
expect(openmct.notifications.warn).toHaveBeenCalledWith(
`Failed to retrieve object ${TEST_NAMESPACE}:${TEST_KEY}`
);
});
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/persistence/couch/CouchObjectProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,16 @@ class CouchObjectProvider {

return json;
} catch (error) {
// abort errors are expected
if (error.name === 'AbortError') {
return;
}

// Network error, CouchDB unreachable.
if (response === null) {
this.indicator.setIndicatorToState(DISCONNECTED);
console.error(error.message);

throw new Error(`CouchDB Error - No response"`);
} else {
if (body?.model && isNotebookOrAnnotationType(body.model)) {
Expand Down
17 changes: 17 additions & 0 deletions src/ui/components/viewControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
<template>
<span
:class="[controlClass, { 'c-disclosure-triangle--expanded': value }, { 'is-enabled': enabled }]"
tabindex="0"
role="button"
:aria-label="ariaLabelValue"
:aria-expanded="value ? 'true' : 'false'"
@click="handleClick"
@keydown.enter="handleClick"
></span>
</template>

Expand All @@ -42,6 +47,18 @@ export default {
controlClass: {
type: String,
default: 'c-disclosure-triangle'
},
domainObject: {
type: Object,
default: () => {}
}
},
computed: {
ariaLabelValue() {
const name = this.domainObject.name ? ` ${this.domainObject.name}` : '';
const type = this.domainObject.type ? ` ${this.domainObject.type}` : '';

return `${this.value ? 'Collapse' : 'Expand'}${name}${type}`;
}
},
methods: {
Expand Down
5 changes: 3 additions & 2 deletions src/ui/layout/mct-tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,13 @@ export default {
},
async openTreeItem(parentItem) {
const parentPath = parentItem.navigationPath;
const abortSignal = this.startItemLoad(parentPath);

this.startItemLoad(parentPath);
// pass in abort signal when functional
const childrenItems = await this.loadAndBuildTreeItemsFor(
parentItem.object.identifier,
parentItem.objectPath
parentItem.objectPath,
abortSignal
);
const parentIndex = this.treeItems.indexOf(parentItem);

Expand Down
1 change: 1 addition & 0 deletions src/ui/layout/tree-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<view-control
ref="action"
class="c-tree__item__view-control"
:domain-object="node.object"
:value="isOpen || isLoading"
:enabled="!activeSearch && hasComposition"
@input="itemAction()"
Expand Down