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 Workspace Menu #5921

Merged
merged 33 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4d20e55
fix(workspace-popup-menu): Added more options and hide close button b…
mananjadhav Sep 15, 2021
21e630e
Merge branch 'main' of https://github.com/mananjadhav/App into fix/wo…
mananjadhav Oct 8, 2021
713e7a0
fix(wkspace-popup-menu): Added icons and triggers
mananjadhav Oct 17, 2021
a39816d
feat(wkspace-popup-menu): Basic version of the popup menu added
mananjadhav Oct 17, 2021
82ea2ca
feat(wkspace-popup-menu): Moved with menu structure and items
mananjadhav Oct 17, 2021
e95d231
feat(wkspace-popup-menu): Fixed menu items from header
mananjadhav Oct 17, 2021
19ad6d0
fix(workspace-popup-menu): Added create call
mananjadhav Oct 17, 2021
f4dc5c3
fix(wkspace-popup-menu): Changed function call
mananjadhav Oct 17, 2021
409fc3d
feat(wkspace-popup-menu): Made offset to props
mananjadhav Oct 17, 2021
67812fa
Merge branch 'main' of https://github.com/mananjadhav/App into fix/wo…
mananjadhav Nov 2, 2021
06a39c9
fix(wkspace-popup-menu): Discarded extra Header component
mananjadhav Nov 2, 2021
ffa5b9c
fix(wkspace-popup-menu): Removed hook and replaced with getPathFromState
mananjadhav Nov 2, 2021
90d0453
fix(wkspace-popup-menu): Changed function component to class component
mananjadhav Nov 2, 2021
0fb02ff
fix(wkspace-popup-menu): Added Confirm delete handling
mananjadhav Nov 2, 2021
6f36f93
fix(wkspace-popup-menu): Fixed keys for Delete modal
mananjadhav Nov 2, 2021
03c0676
fix(wkspace-popup-menu): Added delete policy API
mananjadhav Nov 2, 2021
4b88a10
fix(wkspace-popup-menu): Added comments to the policy
mananjadhav Nov 2, 2021
ddced90
Merge branch 'main' of https://github.com/mananjadhav/App into fix/wo…
mananjadhav Nov 8, 2021
6a3b23d
fix(wkspace-popup-menu): Converted from function to class component
mananjadhav Nov 8, 2021
9dbfbf1
fix(wkspace-popup-menu): Fixed create and delete functions
mananjadhav Nov 8, 2021
c38131f
fix(wkspace-popup-menu): Added growl on delete success
mananjadhav Nov 8, 2021
ea91fbb
fix(wkspace-popup-menu): Changed PopoverMenu component
mananjadhav Nov 8, 2021
9492c40
fix(wkspace-popup-menu): Code cleanup
mananjadhav Nov 8, 2021
c62b284
fix(wkspace-popup-menu): code cleanup
mananjadhav Nov 8, 2021
4057e10
fix(wkspace-popup-menu): code cleanup
mananjadhav Nov 8, 2021
27891cf
Merge branch 'fix/workspace-popup-menu' of https://github.com/mananja…
mananjadhav Nov 8, 2021
4eadb71
fix(wkspace-popup-menu): Fixed Item onSelected
mananjadhav Nov 8, 2021
20ea9d2
Merge branch 'main' of https://github.com/mananjadhav/App into fix/wo…
mananjadhav Nov 20, 2021
d50cdd9
fix(wkspace-popup-menu): Fixed lint issues and typos
mananjadhav Nov 20, 2021
89d35b5
fix(wkspace-popup-menu): Removed extra params from deletePolicy
mananjadhav Nov 20, 2021
f9a0bcc
Merge branch 'main' of https://github.com/mananjadhav/App into fix/wo…
mananjadhav Nov 30, 2021
5d37753
fix(wkspace-popup-menu): Lint fixes
mananjadhav Nov 30, 2021
39d8a14
fix(wkspace-popup-menu): Removed Navigation.dismissModal
mananjadhav Nov 30, 2021
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
7 changes: 7 additions & 0 deletions assets/images/three-dots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions src/components/HeaderWithCloseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Close, Download, BackArrow} from './Icon/Expensicons';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import Tooltip from './Tooltip';
import InboxCallButton from './InboxCallButton';
import ThreeDotsMenu, {ThreeDotsMenuItemPropTypes} from './ThreeDotsMenu';

const propTypes = {
/** Title of the Header */
Expand All @@ -24,6 +25,9 @@ const propTypes = {
/** Method to trigger when pressing back button of the header */
onBackButtonPress: PropTypes.func,

/** Method to trigger when pressing more options button of the header */
onThreeDotsButtonPress: PropTypes.func,

/** Whether we should show a back icon */
shouldShowBackButton: PropTypes.bool,

Expand All @@ -36,6 +40,23 @@ const propTypes = {
/** Whether we should show a inbox call button */
shouldShowInboxCallButton: PropTypes.bool,

/** Whether we should show a more options (threedots) button */
shouldShowThreeDotsButton: PropTypes.bool,

/** List of menu items for more(three dots) menu */
threeDotsMenuItems: ThreeDotsMenuItemPropTypes,

/** The anchor position of the menu */
threeDotsAnchorPosition: PropTypes.shape({
top: PropTypes.number,
right: PropTypes.number,
bottom: PropTypes.number,
left: PropTypes.number,
}),

/** Whether we should show a close button */
shouldShowCloseButton: PropTypes.bool,

/** Whether we should show the step counter */
shouldShowStepCounter: PropTypes.bool,

Expand All @@ -56,13 +77,21 @@ const defaultProps = {
onDownloadButtonPress: () => {},
onCloseButtonPress: () => {},
onBackButtonPress: () => {},
onThreeDotsButtonPress: () => {},
shouldShowBackButton: false,
shouldShowBorderBottom: false,
shouldShowDownloadButton: false,
shouldShowInboxCallButton: false,
shouldShowThreeDotsButton: false,
shouldShowCloseButton: true,
shouldShowStepCounter: true,
inboxCallTaskID: '',
stepCounter: null,
threeDotsMenuItems: [],
threeDotsAnchorPosition: {
top: 0,
left: 0,
},
};

const HeaderWithCloseButton = props => (
Expand Down Expand Up @@ -107,6 +136,17 @@ const HeaderWithCloseButton = props => (

{props.shouldShowInboxCallButton && <InboxCallButton taskID={props.inboxCallTaskID} />}

{props.shouldShowThreeDotsButton && (
<ThreeDotsMenu
menuItems={props.threeDotsMenuItems}
onIconPress={props.onThreeDotsButtonPress}
iconStyles={[styles.mr0]}
anchorPosition={props.threeDotsAnchorPosition}
/>
)}

{props.shouldShowCloseButton
&& (
<Tooltip text={props.translate('common.close')}>
<TouchableOpacity
onPress={props.onCloseButtonPress}
Expand All @@ -117,6 +157,7 @@ const HeaderWithCloseButton = props => (
<Icon src={Close} />
</TouchableOpacity>
</Tooltip>
)}
</View>
</View>
</View>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/Expensicons.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import Users from '../../../assets/images/users.svg';
import Venmo from '../../../assets/images/venmo.svg';
import Wallet from '../../../assets/images/wallet.svg';
import Workspace from '../../../assets/images/workspace-default-avatar.svg';
import ThreeDots from '../../../assets/images/three-dots.svg';

export {
Android,
Expand Down Expand Up @@ -126,4 +127,5 @@ export {
Venmo,
Wallet,
Workspace,
ThreeDots,
};
11 changes: 11 additions & 0 deletions src/components/ThreeDotsMenu/ThreeDotsMenuItemPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PropTypes from 'prop-types';


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra line break

const menuItemProps = PropTypes.arrayOf(PropTypes.shape({
icon: PropTypes.oneOfType([PropTypes.elementType, PropTypes.string]),
text: PropTypes.string,
onPress: PropTypes.func,
}));


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra line break

export default menuItemProps;
112 changes: 112 additions & 0 deletions src/components/ThreeDotsMenu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React, {Component} from 'react';
import {
View, Pressable,
} from 'react-native';
import PropTypes from 'prop-types';
import Icon from '../Icon';
import PopoverMenu from '../PopoverMenu';
import styles from '../../styles/styles';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import Tooltip from '../Tooltip';
import {ThreeDots} from '../Icon/Expensicons';
import ThreeDotsMenuItemPropTypes from './ThreeDotsMenuItemPropTypes';

const propTypes = {
...withLocalizePropTypes,

/** Tooltip for the popup icon */
iconTooltip: PropTypes.string,

/** icon for the popup trigger */
icon: PropTypes.oneOfType([PropTypes.elementType, PropTypes.string]),

/** Any additional styles to pass to the icon container. */
iconStyles: PropTypes.arrayOf(PropTypes.object),

/** The fill color to pass into the icon. */
iconFill: PropTypes.string,

/** Function to call on icon press */
onIconPress: PropTypes.func,

/** menuItems that'll show up on toggle of the popup menu */
menuItems: ThreeDotsMenuItemPropTypes.isRequired,

/** The anchor position of the menu */
anchorPosition: PropTypes.shape({
top: PropTypes.number,
right: PropTypes.number,
bottom: PropTypes.number,
left: PropTypes.number,
}).isRequired,
};

const defaultProps = {
iconTooltip: 'common.more',
iconFill: undefined,
iconStyles: [],
icon: ThreeDots,
onIconPress: () => {},
};


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a line break should just be 1 line break and not 2. Remove the extra line break.

class ThreeDotsMenu extends Component {
constructor(props) {
super(props);

this.togglePopupMenu = this.togglePopupMenu.bind(this);
this.state = {
isPopupMenuVisible: false,
};
}

/**
* Toggles the popup menu visibility
*/
togglePopupMenu() {
this.setState(prevState => ({
isPopupMenuVisible: !prevState.isPopupMenuVisible,
}));
}

render() {
return (
<>
<View>
<Tooltip text={this.props.translate(this.props.iconTooltip)}>
<Pressable
onPress={() => {
this.togglePopupMenu();
if (this.props.onIconPress) {
this.props.onIconPress();
}
}}
style={[styles.touchableButtonImage, ...this.props.iconStyles]}
>
<Icon
src={this.props.icon}
fill={this.props.iconFill}
/>
</Pressable>
</Tooltip>
</View>
<PopoverMenu
onClose={this.togglePopupMenu}
isVisible={this.state.isPopupMenuVisible}
anchorPosition={this.props.anchorPosition}
onItemSelected={() => this.togglePopupMenu()}
animationIn="fadeInDown"
animationOut="fadeOutUp"
menuItems={this.props.menuItems}
/>
</>
);
}
}

ThreeDotsMenu.propTypes = propTypes;
ThreeDotsMenu.defaultProps = defaultProps;
ThreeDotsMenu.displayName = 'ThreeDotsMenu';
export default withLocalize(ThreeDotsMenu);

export {ThreeDotsMenuItemPropTypes};
5 changes: 5 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default {
confirm: 'Confirm',
reset: 'Reset',
done: 'Done',
more: 'More',
debitCard: 'Debit card',
payPalMe: 'PayPal.me',
},
Expand Down Expand Up @@ -645,6 +646,8 @@ export default {
common: {
card: 'Issue corporate cards',
workspace: 'Workspace',
edit: 'Edit workspace',
delete: 'Delete Workspace',
settings: 'General settings',
reimburse: 'Reimburse receipts',
bills: 'Pay bills',
Expand All @@ -655,6 +658,8 @@ export default {
issueAndManageCards: 'Issue and manage cards',
reconcileCards: 'Reconcile cards',
growlMessageOnSave: 'Your workspace settings were successfully saved!',
deleteConfirmation: 'Are you sure you want to delete this workspace?',
growlMessageOnDelete: 'Workspace deleted',
},
new: {
newWorkspace: 'New workspace',
Expand Down
5 changes: 5 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default {
confirm: 'Confirmar',
reset: 'Restablecer',
done: 'Listo',
more: 'Más',
debitCard: 'Tarjeta de débito',
payPalMe: 'PayPal.me',
},
Expand Down Expand Up @@ -647,6 +648,8 @@ export default {
common: {
card: 'Emitir tarjetas corporativas',
workspace: 'Espacio de trabajo',
edit: 'Editar espacio de trabajo',
delete: 'Eliminar espacio de trabajo',
settings: 'Configuración general',
reimburse: 'Reembolsar recibos',
bills: 'Pagar facturas',
Expand All @@ -657,6 +660,8 @@ export default {
issueAndManageCards: 'Emitir y gestionar tarjetas',
reconcileCards: 'Reconciliar tarjetas',
growlMessageOnSave: '¡La configuración del espacio de trabajo se ha guardado correctamente!',
growlMessageOnDelete: 'Espacio de trabajo eliminado',
deleteConfirmation: '¿Estás seguro de que quieres eliminar este espacio de trabajo?',
},
new: {
newWorkspace: 'Nuevo espacio de trabajo',
Expand Down
11 changes: 11 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,16 @@ function Policy_Create(parameters) {
return Network.post(commandName, parameters);
}

/**
* @param {Object} parameters
* @param {String} [parameters.policyID]
* @returns {Promise}
*/
function Policy_Delete(parameters) {
const commandName = 'Policy_Delete';
return Network.post(commandName, parameters);
}

/**
* @param {Object} parameters
* @param {String} parameters.policyID
Expand Down Expand Up @@ -1173,4 +1183,5 @@ export {
Policy_Create,
Policy_Employees_Remove,
PreferredLocale_Update,
Policy_Delete,
};
12 changes: 4 additions & 8 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {Keyboard} from 'react-native';
import {
StackActions,
DrawerActions,
useLinkBuilder,
createNavigationContainerRef,
getPathFromState,
} from '@react-navigation/native';
import PropTypes from 'prop-types';
import Onyx from 'react-native-onyx';
Expand All @@ -15,6 +15,7 @@ import ROUTES from '../../ROUTES';
import SCREENS from '../../SCREENS';
import CustomActions from './CustomActions';
import ONYXKEYS from '../../ONYXKEYS';
import linkingConfig from './linkingConfig';

let isLoggedIn = false;
Onyx.connect({
Expand Down Expand Up @@ -149,21 +150,16 @@ function dismissModal(shouldOpenDrawer = false) {
/**
* Check whether the passed route is currently Active or not.
*
* Building path with useLinkBuilder since navigationRef.current.getCurrentRoute().path
* Building path with getPathFromState since navigationRef.current.getCurrentRoute().path
* is undefined in the first navigation.
*
* @param {String} routePath Path to check
* @return {Boolean} is active
*/
function isActiveRoute(routePath) {
const buildLink = useLinkBuilder();

// We remove First forward slash from the URL before matching
const path = navigationRef.current && navigationRef.current.getCurrentRoute().name
? buildLink(
navigationRef.current.getCurrentRoute().name,
navigationRef.current.getCurrentRoute().params,
).substring(1)
? getPathFromState(navigationRef.current.getState(), linkingConfig.config).substring(1)
: '';
return path === routePath;
}
Expand Down
Loading