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

issue 1651: progress bar error state #1673

Merged
merged 15 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
57 changes: 28 additions & 29 deletions src/features/locators/reducers/identifyElements.thunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getLocalStorage, LocalStorageKey } from '../../../common/utils/localSto
import { selectAutoGeneratingLocatorTypes, selectPageObjById } from '../../pageObjects/selectors/pageObjects.selectors';
import { RootState } from '../../../app/store/store';
import { runLocatorsGeneration } from './runLocatorsGeneration.thunk';
import { finishProgressBar } from '../../pageObjects/progressBar.slice';
import { finishProgressBar, setProgressError } from '../../pageObjects/progressBar.slice';
import { delay } from '../utils/delay';
import { fetchPageDocument } from '../../../services/pageDocument/fetchPageDocument.thunk';
import { createDocumentForRobula } from '../../../services/pageDocument/pageDocument.slice';
Expand Down Expand Up @@ -45,38 +45,37 @@ export const identifyElements = createAsyncThunk('locators/identifyElements', as
throw new Error(error);
}

if (data) {
const locators = data
.filter((el: PredictedEntity) => el.is_shown)
.map((el: PredictedEntity) => {
return {
...el,
element_id: `${el.element_id}_${pageObj}`,
jdnHash: el.element_id,
pageObj: pageObj,
};
});

await thunkAPI.dispatch(fetchPageDocument()).unwrap();
thunkAPI.dispatch(createDocumentForRobula(data));

thunkAPI.dispatch(finishProgressBar());
/* progress-bar finish animation delay: */
await delay(2000);

if (pageData) {
thunkAPI.dispatch(setPageData({ id: pageObj, pageData }));
}

await thunkAPI.dispatch(createLocators({ predictedElements: locators, library }));
if (!data) {
throw new Error('No data received from server');
}

return thunkAPI.fulfillWithValue(locators);
const locators = data
.filter((el: PredictedEntity) => el.is_shown)
.map((el: PredictedEntity) => {
return {
...el,
element_id: `${el.element_id}_${pageObj}`,
jdnHash: el.element_id,
pageObj: pageObj,
};
});

await thunkAPI.dispatch(fetchPageDocument()).unwrap();
thunkAPI.dispatch(createDocumentForRobula(data));

thunkAPI.dispatch(finishProgressBar());
/* progress-bar finish animation delay: */
await delay(2000);

if (pageData) {
thunkAPI.dispatch(setPageData({ id: pageObj, pageData }));
}

throw new Error('Something went wrong');
thunkAPI.dispatch(createLocators({ predictedElements: locators, library }));

return thunkAPI.fulfillWithValue(locators);
} catch (error) {
// can use params in the function so that when the progress bar is finished there will be information about errors
thunkAPI.dispatch(finishProgressBar(error.message));
thunkAPI.dispatch(setProgressError(error.message));
return thunkAPI.rejectWithValue(null);
}
});
Expand Down
8 changes: 6 additions & 2 deletions src/features/pageObjects/progressBar.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ const progressBarSlice = createSlice({
state.startTime = 0;
state.error = '';
},
finishProgressBar(state, action: PayloadAction<string | undefined>) {
finishProgressBar(state) {
state.stage = 3;
state.progress = 100;
state.error = action.payload || '';
},
setProgressError(state, action: PayloadAction<string>) {
state.error = action.payload;
state.progress = 100;
},
setStartTime(state, action: PayloadAction<number>) {
state.startTime = action.payload;
Expand All @@ -59,6 +62,7 @@ export const {
increaseStage,
finishProgressBar,
setStartTime,
setProgressError,
} = progressBarSlice.actions;

export default progressBarSlice.reducer;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const updateProgress = createAsyncThunk('progressBar/updateProgress', asy

while (true) {
const state = (getState() as RootState).progressBar;
if (state.stage === totalStages && state.progress === 100) {
if (state.stage === totalStages || state.progress === 100) {
break;
}

Expand Down
5 changes: 2 additions & 3 deletions src/features/pageObjects/styles/progressBar.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
margin: 8px 16px 0;

.progress-bar {
width: calc(100% - 8px);
transition: width linear 100ms;
Iogsotot marked this conversation as resolved.
Show resolved Hide resolved
width: calc(100% - 36px);

&.finished {
width: calc(100% + 5px);
width: 100%;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/pageServices/pageDataHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import connector, { sendMessage } from './connector';
import { HttpEndpoint, request } from '../services/backend';
import { createOverlay } from './contentScripts/createOverlay';
import { getFullDocumentWithStyles } from '../common/utils/getFullDocumentWithStyles';
import { PredictedEntity } from '../features/locators/types/locator.types';
import { ILocator, PredictedEntity } from '../features/locators/types/locator.types';
import { getLibrarySelectors } from '../services/rules/createSelector';
import { VueRules } from '../services/rules/Vue.rules';
// /* global chrome */
Expand All @@ -21,7 +21,7 @@ export const removeOverlay = () => {
chrome.storage.sync.set({ overlayID });

connector.attachContentScript(() => {
chrome.storage.sync.get(['overlayID'], ({ id }) => {
chrome.storage.sync.get(['overlayID'], ({ overlayID: id }) => {
const overlay = document.getElementById(id);
if (overlay) overlay.remove();
});
Expand Down Expand Up @@ -60,7 +60,7 @@ export const predictElements = (endpoint: HttpEndpoint): PredictElementsType =>
);
};

export const setParents = async (elements: any) => {
export const setParents = async (elements: ILocator[]) => {
return sendMessage.assignParents(elements).then((response) => response);
};

Expand Down
Loading