Skip to content

Commit

Permalink
get ride of lodash
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <noreply@github.com>
  • Loading branch information
twilight2294 authored Oct 14, 2024
1 parent 82f5ba0 commit 1dd6f99
Show file tree
Hide file tree
Showing 20 changed files with 21 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/CategoryGLCodePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
Expand Down Expand Up @@ -33,7 +32,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) {
const categoryName = route.params.categoryName;
const glCode = policyCategories?.[categoryName]?.['GL Code'];
const {inputCallbackRef} = useAutoFocusInput();
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const editGLCode = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/CategoryPayrollCodePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
Expand Down Expand Up @@ -33,7 +32,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) {
const categoryName = route.params.categoryName;
const payrollCode = policyCategories?.[categoryName]?.['Payroll Code'];
const {inputCallbackRef} = useAutoFocusInput();
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const editPayrollCode = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/CategorySettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -54,7 +53,7 @@ function CategorySettingsPage({
const policyCategoryExpenseLimitType = policyCategory?.expenseLimitType ?? CONST.POLICY.EXPENSE_LIMIT_TYPES.EXPENSE;

const areCommentsRequired = policyCategory?.areCommentsRequired ?? false;
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const navigateBack = () => {
Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined);
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/CreateCategoryPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {FormOnyxValues} from '@components/Form/types';
Expand All @@ -24,7 +23,7 @@ function CreateCategoryPage({route}: CreateCategoryPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const backTo = route.params?.backTo;
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const createCategory = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/EditCategoryPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
Expand All @@ -25,7 +24,7 @@ function EditCategoryPage({route}: EditCategoryPageProps) {
const {translate} = useLocalize();
const currentCategoryName = route.params.categoryName;
const backTo = route.params?.backTo;
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/ImportCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React from 'react';
import ImportSpreedsheet from '@components/ImportSpreadsheet';
import usePolicy from '@hooks/usePolicy';
Expand All @@ -16,7 +15,7 @@ function ImportCategoriesPage({route}: ImportCategoriesPageProps) {
const backTo = route.params.backTo;
const policy = usePolicy(policyID);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

if (hasAccountingConnections) {
return <NotFoundPage />;
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/ImportedCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import ConfirmModal from '@components/ConfirmModal';
Expand Down Expand Up @@ -35,7 +34,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) {
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const policy = usePolicy(policyID);
const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const getColumnRoles = (): ColumnRole[] => {
const roles = [];
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/categories/WorkspaceCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import lodashSortBy from 'lodash/sortBy';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
Expand Down Expand Up @@ -76,7 +75,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`);
const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0;
const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import isEmpty from 'lodash/isEmpty';
import React, {useMemo, useState} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -48,7 +47,7 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet
const [isSelectorModalVisible, setIsSelectorModalVisible] = useState(false);
const [categoryID, setCategoryID] = useState<string>();
const [groupID, setGroupID] = useState<string>();
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = backTo;

const toggleSubtitle = isConnectedToAccounting && currentConnectionName ? `${translate('workspace.categories.needCategoryForExportToIntegration')} ${currentConnectionName}.` : undefined;

Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/EditTagPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback} from 'react';
import {Keyboard} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -33,7 +32,7 @@ function EditTagPage({route}: EditTagPageProps) {
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();
const currentTagName = PolicyUtils.getCleanedTagName(route.params.tagName);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_TAG_FORM>) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/ImportTagsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React from 'react';
import ImportSpreedsheet from '@components/ImportSpreadsheet';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
Expand All @@ -11,7 +10,7 @@ type ImportTagsPageProps = StackScreenProps<SettingsNavigatorParamList, typeof S
function ImportTagsPage({route}: ImportTagsPageProps) {
const policyID = route.params.policyID;
const backTo = route.params.backTo;
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

return (
<ImportSpreedsheet
Expand Down
5 changes: 2 additions & 3 deletions src/pages/workspace/tags/ImportedTagsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback, useMemo, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import ConfirmModal from '@components/ConfirmModal';
Expand Down Expand Up @@ -36,7 +35,7 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) {
const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]);
const policy = usePolicy(policyID);
const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const getColumnRoles = (): ColumnRole[] => {
const roles = [];
Expand Down Expand Up @@ -129,7 +128,7 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) {
>
<HeaderWithBackButton
title={translate('workspace.tags.importTags')}
onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID))}
onBackButtonPress={() => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID))}
/>
<ImportSpreadsheetColumns
spreadsheetColumns={spreadsheetColumns}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/TagApproverPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
Expand All @@ -24,7 +23,7 @@ function TagApproverPage({route}: TagApproverPageProps) {
const {translate} = useLocalize();

const tagApprover = PolicyUtils.getTagApproverRule(policyID, tagName)?.approver;
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const goBack = () => {
Navigation.goBack(
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/TagGLCodePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
Expand Down Expand Up @@ -37,7 +36,7 @@ function TagGLCodePage({route}: EditTagGLCodePageProps) {
const orderWeight = route.params.orderWeight;
const {tags} = PolicyUtils.getTagList(policyTags, orderWeight);
const glCode = tags?.[route.params.tagName]?.['GL Code'];
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const goBack = useCallback(() => {
Navigation.goBack(
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/TagSettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useEffect, useMemo} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -42,7 +41,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) {
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
const {canUseCategoryAndTagApprovers} = usePermissions();
const [isDeleteTagModalOpen, setIsDeleteTagModalOpen] = React.useState(false);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const currentPolicyTag = policyTag.tags[tagName] ?? Object.values(policyTag.tags ?? {}).find((tag) => tag.previousTagName === tagName);

Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/WorkspaceCreateTagPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback} from 'react';
import {Keyboard} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -33,7 +32,7 @@ function CreateTagPage({route}: CreateTagPageProps) {
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();
const backTo = route.params.backTo;
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_TAG_FORM>) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/WorkspaceEditTagsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -32,7 +31,7 @@ function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) {
const taglistName = useMemo(() => PolicyUtils.getTagListName(policyTags, route.params.orderWeight), [policyTags, route.params.orderWeight]);
const {inputCallbackRef} = useAutoFocusInput();
const backTo = route.params.backTo;
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const validateTagName = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.POLICY_TAG_NAME_FORM>) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import lodashSortBy from 'lodash/sortBy';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
Expand Down Expand Up @@ -75,7 +74,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const fetchTags = useCallback(() => {
Tag.openPolicyTagsPage(policyID);
}, [policyID]);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const {isOffline} = useNetwork({onReconnect: fetchTags});

Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -67,7 +66,7 @@ function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) {
},
[policyID],
);
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const getTagsSettings = (policy: OnyxEntry<OnyxTypes.Policy>) => (
<View style={styles.flexGrow1}>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/tags/WorkspaceViewTagsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -60,7 +59,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
const {selectionMode} = useMobileSelectionMode();
const currentTagListName = useMemo(() => PolicyUtils.getTagListName(policyTags, route.params.orderWeight), [policyTags, route.params.orderWeight]);
const currentPolicyTag = policyTags?.[currentTagListName];
const isQuickSettingsFlow = !isEmpty(backTo);
const isQuickSettingsFlow = !!backTo;

const fetchTags = useCallback(() => {
Tag.openPolicyTagsPage(policyID);
Expand Down

0 comments on commit 1dd6f99

Please sign in to comment.