Skip to content

Commit

Permalink
OD-17487 Removed dirty form check on navigation link follow. Removed …
Browse files Browse the repository at this point in the history
…redundant props drilling code
  • Loading branch information
Yury Yasuchenya authored and yuryyas committed Sep 5, 2022
1 parent 79a8a66 commit a54c099
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 13,264 deletions.
1 change: 1 addition & 0 deletions .idea/jsLinters/eslint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
*/

import * as React from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { Dispatch } from "redux";
import { connect } from "react-redux";
import clsx from "clsx";
import { createStyles, withStyles } from "@mui/styles";
import { darken } from "@mui/material/styles";
import SwipeableDrawer from "@mui/material/SwipeableDrawer";
import Divider from "@mui/material/Divider";
import { useEffect, useMemo, useState } from "react";
import { Backdrop } from "@mui/material";
import Collapse from "@mui/material/Collapse";
import Typography from "@mui/material/Typography";
Expand All @@ -24,9 +24,7 @@ import { State } from "../../../../reducers/state";
import { getDashboardSearch } from "../../../../containers/dashboard/actions";
import { openInternalLink } from "../../../utils/links";
import { getEntityDisplayName } from "../../../utils/getEntityDisplayName";
import {
checkPermissions, getOnDemandScripts, getUserPreferences, showConfirm
} from "../../../actions";
import { checkPermissions, getOnDemandScripts, getUserPreferences, showConfirm } from "../../../actions";
import { setSwipeableDrawerSelection, toggleSwipeableDrawer } from "./actions";
import UserSearch from "./components/UserSearch";
import SearchResults from "./components/searchResults/SearchResults";
Expand Down Expand Up @@ -122,7 +120,6 @@ const styles = (theme: AppTheme) =>

interface Props {
form: string;
isFormDirty: boolean;
resetEditView: any;
showConfirm: ShowConfirmCaller;
classes: any;
Expand Down Expand Up @@ -158,7 +155,6 @@ const sortItems = (a, b) => {
const SwipeableSidebar: React.FC<Props> = props => {
const {
form,
isFormDirty,
resetEditView,
showConfirm,
classes,
Expand Down Expand Up @@ -367,7 +363,7 @@ const SwipeableSidebar: React.FC<Props> = props => {
};
}, [controlResults, resultIndex]);

const checkSelectedResult = React.useCallback(
const checkSelectedResult = useCallback(
(type, field, value) => {
if (controlResults && resultIndex >= 0) {
const selectedResult = controlResults[resultIndex];
Expand All @@ -378,19 +374,6 @@ const SwipeableSidebar: React.FC<Props> = props => {
[controlResults, resultIndex]
);

const showConfirmHandler = React.useCallback(onConfirm => {
if (isFormDirty && resetEditView) {
showConfirm(
{
onConfirm,
cancelButtonText: "DISCARD CHANGES"
}
);
} else {
onConfirm();
}
}, [isFormDirty, resetEditView]);

const groupedSortedItems = useMemo<DashboardItem[]>(() => [
...navigation.features.map(f => ({
category: f.key, url: f.link, name: f.title, id: null
Expand Down Expand Up @@ -446,7 +429,6 @@ const SwipeableSidebar: React.FC<Props> = props => {
classes={{ root: classes.searchResultsRoot }}
userSearch={userSearch}
checkSelectedResult={checkSelectedResult}
showConfirm={showConfirmHandler}
setExecMenuOpened={setExecMenuOpened}
setScriptIdSelected={setScriptIdSelected}
groupedSortedItems={groupedSortedItems}
Expand All @@ -465,8 +447,6 @@ const SwipeableSidebar: React.FC<Props> = props => {
<Favorites
classes={{ topBar: classes.favoritesTopBar }}
groupedSortedItems={groupedSortedItems}
showConfirm={showConfirmHandler}
isFormDirty={isFormDirty}
setScriptIdSelected={setScriptIdSelected}
execMenuOpened={execMenuOpened}
setExecMenuOpened={setExecMenuOpened}
Expand All @@ -483,7 +463,7 @@ const SwipeableSidebar: React.FC<Props> = props => {
setExecMenuOpened={setExecMenuOpened}
/>
<Divider variant="middle" className="mb-2" />
<SidebarLatestActivity showConfirm={showConfirmHandler} checkSelectedResult={checkSelectedResult} />
<SidebarLatestActivity checkSelectedResult={checkSelectedResult} />
</div>
</Collapse>
</div>
Expand All @@ -504,7 +484,6 @@ const SwipeableSidebar: React.FC<Props> = props => {
favorites={favorites}
favoriteScripts={favoriteScripts}
onClose={() => setSelected(null)}
showConfirm={showConfirmHandler}
setScriptIdSelected={setScriptIdSelected}
setExecMenuOpened={setExecMenuOpened}
/>
Expand Down Expand Up @@ -536,7 +515,6 @@ const mapsStateToProps = (state: State) => ({
listEntity: state.list.records.entity,
listSearchQuery: state.list.searchQuery,
selected: state.swipeableDrawer.selected,
isFormDirty: state.swipeableDrawer.isDirty,
resetEditView: state.swipeableDrawer.resetEditView,
opened: state.swipeableDrawer.opened,
variant: state.swipeableDrawer.variant,
Expand All @@ -557,4 +535,4 @@ const mapStateToDispatch = (dispatch: Dispatch<any>) => ({
showConfirm: props => dispatch(showConfirm(props))
});

export default connect<any, any, any>(mapsStateToProps, mapStateToDispatch)(withStyles(styles, { withTheme: true })(SwipeableSidebar));
export default connect<any, any, any>(mapsStateToProps, mapStateToDispatch)(withStyles(styles, { withTheme: true })(SwipeableSidebar));
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@ import { VARIANTS } from "../utils";

export const TOGGLE_SWIPEABLE_DRAWER = "common/swipeableDrawer/toggle";

export const SET_SWIPEABLE_DRAWER_DIRTY_FORM = "common/set/swipeableDrawer/dirty/form";

export const SET_SWIPEABLE_DRAWER_SELECTION = "common/set/swipeableDrawer/selection";

export const toggleSwipeableDrawer = (variant = VARIANTS.temporary) => ({
type: TOGGLE_SWIPEABLE_DRAWER,
payload: { variant }
});

export const setSwipeableDrawerDirtyForm = (isDirty?: boolean, resetEditView?: any) => ({
type: SET_SWIPEABLE_DRAWER_DIRTY_FORM,
payload: { isDirty, resetEditView }
});

export const setSwipeableDrawerSelection = (selected: number | string) => ({
type: SET_SWIPEABLE_DRAWER_SELECTION,
payload: { selected }
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const styles = (theme: AppTheme) => createStyles({
});

const SidebarLatestActivity: React.FC<any> = props => {
const { showConfirm, classes, checkSelectedResult } = props;
const { classes, checkSelectedResult } = props;
const [activities, setActivities] = React.useState(JSON.parse(LSGetItem(DASHBOARD_ACTIVITY_STORAGE_NAME) || "null"));

const updateActivity = React.useCallback(() => {
Expand Down Expand Up @@ -55,7 +55,6 @@ const SidebarLatestActivity: React.FC<any> = props => {
entityDisplayName={getEntityDisplayName(v.entity)}
entity={v.entity}
items={v.items}
showConfirm={showConfirm}
checkSelectedResult={checkSelectedResult}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const styles = theme => createStyles({

const ListLinkItem = props => {
const {
showConfirm, classes, item, url, openLink, selected, id
classes, item, url, openLink, selected, id
} = props;

return (
<ListItem
onClick={openLink ? () => openLink(item.id) : () => showConfirm(() => openInternalLink(getPrivisioningLink(url)))}
onClick={openLink ? () => openLink(item.id) : () => () => openInternalLink(getPrivisioningLink(url))}
disableGutters
className={classes.listItem}
dense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const styles = theme => createStyles({

const SearchResults = props => {
const {
showConfirm,
classes,
userSearch,
scripts,
Expand All @@ -55,7 +54,6 @@ const SearchResults = props => {
name: getHighlightedPartLabel(c.title, userSearch)
}}
id={getResultId(i, c.title)}
showConfirm={showConfirm}
/>
))}
{userSearch
Expand Down Expand Up @@ -92,7 +90,6 @@ const SearchResults = props => {
return { ...item, name };
})}
userSearch={userSearch}
showConfirm={showConfirm}
setSelected={setSelected}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

import { IAction } from "../../../../actions/IshAction";
import { SwipeableDrawer } from "../../../../../model/common/drawer/SwipeableDrawerModel";
import { SET_SWIPEABLE_DRAWER_DIRTY_FORM, SET_SWIPEABLE_DRAWER_SELECTION, TOGGLE_SWIPEABLE_DRAWER } from "../actions";
import { SET_SWIPEABLE_DRAWER_SELECTION, TOGGLE_SWIPEABLE_DRAWER } from "../actions";

const initial: SwipeableDrawer = {
opened: false,
variant: "temporary",
isDirty: false,
selected: null,
resetEditView: () => {}
};
Expand All @@ -24,14 +23,6 @@ export const swipeableDrawerReducer = (state: SwipeableDrawer = initial, action:
variant: action.payload.variant
};
}

case SET_SWIPEABLE_DRAWER_DIRTY_FORM: {
return {
...state,
isDirty: action.payload.isDirty,
resetEditView: action.payload.resetEditView
};
}

case SET_SWIPEABLE_DRAWER_SELECTION: {
return {
Expand Down
3 changes: 0 additions & 3 deletions client-html/src/js/common/components/list-view/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import {
getTagsUpdatedByIds,
setActiveFiltersBySearch
} from "./utils/listFiltersUtils";
import { setSwipeableDrawerDirtyForm } from "../layout/swipeable-sidebar/actions";
import { LSGetItem } from "../../utils/storage";
import { getCustomFieldTypes } from "../../../containers/entities/customFieldTypes/actions";
import {
Expand Down Expand Up @@ -199,7 +198,6 @@ interface Props extends Partial<ListState> {
searchQuery?: SearchQuery;
setListEditRecordFetching?: any;
search?: string;
onSwipeableDrawerDirtyForm?: (isDirty: boolean, resetEditView: any) => void;
deleteDisabledCondition?: (props) => boolean;
noListTags?: boolean;
setEntity?: (entity: EntityName) => void;
Expand Down Expand Up @@ -1288,7 +1286,6 @@ const mapDispatchToProps = (dispatch: Dispatch, ownProps) => ({
)),
onSearch: search => dispatch(setSearch(search, ownProps.rootEntity)),
setListEditRecordFetching: () => dispatch(setListEditRecordFetching()),
onSwipeableDrawerDirtyForm: (isDirty: boolean, resetEditView: any) => dispatch(setSwipeableDrawerDirtyForm(isDirty, resetEditView)),
getListViewPreferences: () => dispatch(getUserPreferences([LISTVIEW_MAIN_CONTENT_WIDTH])),
setListviewMainContentWidth: (value: string) => dispatch(setUserPreference({ key: LISTVIEW_MAIN_CONTENT_WIDTH, value })),
submitForm: () => dispatch(submit(LIST_EDIT_VIEW_FORM_NAME)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { onSubmitFail } from "../../../../utils/highlightFormClassErrors";
import FullScreenEditView from "./FullScreenEditView";
import { clearListNestedEditRecord, closeListNestedEditRecord, updateListNestedEditRecord } from "../../actions";
import { ApiMethods } from "../../../../../model/common/apiHandlers";
import { NESTED_EDIT_VIEW_FORM_NAME } from "../../../../../constants/Forms";

class NestedEditView extends React.Component<any, any> {
onClose = index => {
Expand Down Expand Up @@ -100,7 +101,7 @@ class NestedEditView extends React.Component<any, any> {
nameCondition={nameCondition}
key={index + r.record.id}
rootEntity={r.entity}
form={`NestedEditViewForm[${index}]`}
form={`${NESTED_EDIT_VIEW_FORM_NAME}[${index}]`}
fullScreenEditView={r.opened}
toogleFullScreenEditView={() => this.onClose(index)}
EditViewContent={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { Dispatch } from "redux";
import { Filter } from "@api/model";
import { createCustomFilter, setListSavingFilter } from "../../../actions";
import { SavingFilterState } from "../../../../../../model/common/ListView";
import { validateSingleMandatoryField, validateAqlFilterOrTagName } from "../../../../../utils/validation";
import { SIMPLE_SEARCH_QUOTES_REGEX, SIMPLE_SEARCH_REGEX } from "../../../../../../constants/Config";
import { validateAqlFilterOrTagName, validateSingleMandatoryField } from "../../../../../utils/validation";

const styles = theme =>
createStyles({
Expand Down Expand Up @@ -118,7 +118,7 @@ export class StubFilterItem extends React.PureComponent<any, any> {

return (
<div className={classes.root}>
<Checkbox disabled className={classes.checkbox} color={"secondary"} />
<Checkbox disabled className={classes.checkbox} color="secondary" />
<TextField
onChange={this.onFilterNameChange}
helperText={errorText}
Expand Down Expand Up @@ -149,12 +149,10 @@ export class StubFilterItem extends React.PureComponent<any, any> {

export const StubFilterItemBase = withStyles(styles)(StubFilterItem);

const mapDispatchToProps = (dispatch: Dispatch<any>) => {
return {
const mapDispatchToProps = (dispatch: Dispatch<any>) => ({
saveFilter: (filter: Filter, rootEntity: string) => dispatch(createCustomFilter(filter, rootEntity)),
setSavingFilter: (savingFilter?: SavingFilterState) => dispatch(setListSavingFilter(savingFilter))
};
};
});

export default connect<any, any, any>(
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { State } from "../../../../reducers/state";
import { GET_LIST_NESTED_EDIT_RECORD, SET_LIST_NESTED_EDIT_RECORD } from "../actions";
import { getEntityItemById } from "../../../../containers/entities/common/entityItemsService";
import { EntityName } from "../../../../model/entities/common";
import { NESTED_EDIT_VIEW_FORM_NAME } from "../../../../constants/Forms";

const request: EpicUtils.Request<any, { entity: EntityName; id: number; index?: number; threeColumn?: boolean }> = {
type: GET_LIST_NESTED_EDIT_RECORD,
Expand All @@ -20,7 +21,7 @@ const request: EpicUtils.Request<any, { entity: EntityName; id: number; index?:
return getEntityItemById(entity, id);
},
processData: (record: any, state: State, { index, entity }) => (typeof index === "number"
? [initialize(`NestedEditViewForm[${index}]`, record)]
? [initialize(`${NESTED_EDIT_VIEW_FORM_NAME}[${index}]`, record)]
: [
{
type: SET_LIST_NESTED_EDIT_RECORD,
Expand All @@ -30,7 +31,7 @@ const request: EpicUtils.Request<any, { entity: EntityName; id: number; index?:
opened: true
}
},
initialize(`NestedEditViewForm[${state.list.nestedEditRecords.length || 0}]`, record)
initialize(`${NESTED_EDIT_VIEW_FORM_NAME}[${state.list.nestedEditRecords.length || 0}]`, record)
])
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
updateEntityItemByIdErrorHandler
} from "../../../../containers/entities/common/entityItemsService";
import { EntityName } from "../../../../model/entities/common";
import { NESTED_EDIT_VIEW_FORM_NAME } from "../../../../constants/Forms";

const request: EpicUtils.Request<
any,
Expand Down Expand Up @@ -42,7 +43,7 @@ const request: EpicUtils.Request<
}
],
processError: (response, { entity, index, record }) =>
updateEntityItemByIdErrorHandler(response, entity, `NestedEditViewForm[${index}]`, record)
updateEntityItemByIdErrorHandler(response, entity, `${NESTED_EDIT_VIEW_FORM_NAME}[${index}]`, record)
};

export const EpicUpdateListNestedRecord: Epic<any, any> = EpicUtils.Create(request);
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import CatalogItem from "../layout/catalog/CatalogItem";
import { useAppDispatch, useAppSelector } from "../../utils/hooks";
import { DASHBOARD_FAVORITES_KEY, FAVORITE_SCRIPTS_KEY } from "../../../constants/Config";
import { setUserPreference } from "../../actions";
import { AnyArgFunction, BooleanArgFunction, NumberArgFunction } from "../../../model/common/CommonFunctions";
import { BooleanArgFunction, NumberArgFunction } from "../../../model/common/CommonFunctions";
import { openInternalLink } from "../../utils/links";
import { getPrivisioningLink } from "../../../routes/routesMapping";

Expand All @@ -32,7 +32,6 @@ const useStyles = makeAppStyles(theme => ({
}));

interface Props {
showConfirm: AnyArgFunction,
selected: string;
onClose: any;
favorites: string[];
Expand Down Expand Up @@ -74,7 +73,6 @@ const NavigationCategory = (
onClose,
favorites,
favoriteScripts,
showConfirm,
setScriptIdSelected,
setExecMenuOpened
}:Props
Expand Down Expand Up @@ -110,9 +108,7 @@ const NavigationCategory = (
}
};

const onOpen = (link: string) => {
showConfirm(() => openInternalLink(getPrivisioningLink(link)));
};
const onOpen = (link: string) => () => openInternalLink(getPrivisioningLink(link));

return (
<div className="flex-fill p-3 overflow-y-auto">
Expand Down
Loading

0 comments on commit a54c099

Please sign in to comment.