TWNTY-3794 - ESLint rule: only take explicit boolean predicates in if statements (#4354)
* ESLint rule: only take explicit boolean predicates in if statements Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Merge main Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Fix frontend linter errors Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Fix jest Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> * Fix lint on new code Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br>
This commit is contained in:
committed by
GitHub
parent
40bea0d95e
commit
17511be0cf
@ -1,5 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { isNonEmptyString, isNumber } from '@sniptt/guards';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { SubTitle } from '@/auth/components/SubTitle.tsx';
|
||||
@ -17,6 +18,7 @@ import {
|
||||
useCheckoutSessionMutation,
|
||||
useGetProductPricesQuery,
|
||||
} from '~/generated/graphql.tsx';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const StyledChoosePlanContainer = styled.div`
|
||||
display: flex;
|
||||
@ -57,7 +59,7 @@ export const ChooseYourPlan = () => {
|
||||
|
||||
const handlePlanChange = (type?: string) => {
|
||||
return () => {
|
||||
if (type && planSelected !== type) {
|
||||
if (isNonEmptyString(type) && planSelected !== type) {
|
||||
setPlanSelected(type);
|
||||
}
|
||||
};
|
||||
@ -73,7 +75,13 @@ export const ChooseYourPlan = () => {
|
||||
const monthPrice = prices.filter(
|
||||
(price) => price.recurringInterval === 'month',
|
||||
)?.[0];
|
||||
if (monthPrice && monthPrice.unitAmount && price.unitAmount) {
|
||||
if (
|
||||
isNonNullable(monthPrice) &&
|
||||
isNumber(monthPrice.unitAmount) &&
|
||||
monthPrice.unitAmount > 0 &&
|
||||
isNumber(price.unitAmount) &&
|
||||
price.unitAmount > 0
|
||||
) {
|
||||
return `Save $${(12 * monthPrice.unitAmount - price.unitAmount) / 100}`;
|
||||
}
|
||||
return 'Cancel anytime';
|
||||
|
||||
@ -21,6 +21,7 @@ import { MainButton } from '@/ui/input/button/components/MainButton';
|
||||
import { TextInput } from '@/ui/input/components/TextInput';
|
||||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
||||
import { useActivateWorkspaceMutation } from '~/generated/graphql';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const StyledContentContainer = styled.div`
|
||||
width: 100%;
|
||||
@ -81,7 +82,7 @@ export const CreateWorkspace = () => {
|
||||
include: [FIND_MANY_OBJECT_METADATA_ITEMS],
|
||||
});
|
||||
|
||||
if (result.errors) {
|
||||
if (isNonNullable(result.errors)) {
|
||||
throw result.errors ?? new Error('Unknown error');
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import styled from '@emotion/styled';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { motion } from 'framer-motion';
|
||||
import { z } from 'zod';
|
||||
|
||||
@ -112,7 +113,7 @@ export const PasswordReset = () => {
|
||||
}
|
||||
},
|
||||
onCompleted: (data) => {
|
||||
if (data?.validatePasswordResetToken?.email) {
|
||||
if (isNonEmptyString(data?.validatePasswordResetToken?.email)) {
|
||||
setEmail(data.validatePasswordResetToken.email);
|
||||
}
|
||||
},
|
||||
|
||||
@ -8,6 +8,7 @@ import { currentUserState } from '@/auth/states/currentUserState';
|
||||
import { tokenPairState } from '@/auth/states/tokenPairState';
|
||||
import { AppPath } from '@/types/AppPath';
|
||||
import { useImpersonateMutation } from '~/generated/graphql';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
export const ImpersonateEffect = () => {
|
||||
const navigate = useNavigate();
|
||||
@ -29,7 +30,7 @@ export const ImpersonateEffect = () => {
|
||||
variables: { userId },
|
||||
});
|
||||
|
||||
if (impersonateResult.errors) {
|
||||
if (isNonNullable(impersonateResult.errors)) {
|
||||
throw impersonateResult.errors;
|
||||
}
|
||||
|
||||
@ -47,7 +48,11 @@ export const ImpersonateEffect = () => {
|
||||
}, [userId, impersonate, setCurrentUser, setTokenPair]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isLogged && currentUser?.canImpersonate && isNonEmptyString(userId)) {
|
||||
if (
|
||||
isLogged &&
|
||||
currentUser?.canImpersonate === true &&
|
||||
isNonEmptyString(userId)
|
||||
) {
|
||||
handleImpersonate();
|
||||
} else {
|
||||
// User is not allowed to impersonate or not logged in
|
||||
|
||||
@ -60,7 +60,7 @@ export const RecordShowPage = () => {
|
||||
const handleFavoriteButtonClick = async () => {
|
||||
if (!objectNameSingular || !record) return;
|
||||
|
||||
if (isFavorite && record) {
|
||||
if (isFavorite && isNonNullable(record)) {
|
||||
deleteFavorite(correspondingFavorite.id);
|
||||
} else {
|
||||
createFavorite(record, objectNameSingular);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus.ts';
|
||||
@ -17,6 +18,7 @@ import { Button } from '@/ui/input/button/components/Button.tsx';
|
||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
|
||||
import { Section } from '@/ui/layout/section/components/Section.tsx';
|
||||
import { useBillingPortalSessionQuery } from '~/generated/graphql.tsx';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const StyledH1Title = styled(H1Title)`
|
||||
margin-bottom: 0;
|
||||
@ -44,13 +46,13 @@ export const SettingsBilling = () => {
|
||||
onboardingStatus === OnboardingStatus.Canceled;
|
||||
|
||||
const openBillingPortal = () => {
|
||||
if (data) {
|
||||
if (isNonNullable(data)) {
|
||||
window.location.replace(data.billingPortalSession.url);
|
||||
}
|
||||
};
|
||||
|
||||
const openChat = () => {
|
||||
if (supportChat.supportDriver) {
|
||||
if (isNonEmptyString(supportChat.supportDriver)) {
|
||||
window.FrontChat?.('show');
|
||||
} else {
|
||||
window.location.href =
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import styled from '@emotion/styled';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import { useFieldMetadataItem } from '@/object-metadata/hooks/useFieldMetadataItem';
|
||||
import { useGetRelationMetadata } from '@/object-metadata/hooks/useGetRelationMetadata';
|
||||
@ -154,12 +155,12 @@ export const SettingsObjectFieldEdit = () => {
|
||||
try {
|
||||
if (
|
||||
validatedFormValues.type === FieldMetadataType.Relation &&
|
||||
relationFieldMetadataItem?.id &&
|
||||
isNonEmptyString(relationFieldMetadataItem?.id) &&
|
||||
hasRelationFormChanged
|
||||
) {
|
||||
await editMetadataField({
|
||||
icon: validatedFormValues.relation.field.icon,
|
||||
id: relationFieldMetadataItem.id,
|
||||
id: relationFieldMetadataItem?.id,
|
||||
label: validatedFormValues.relation.field.label,
|
||||
});
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
||||
import { View } from '@/views/types/View';
|
||||
import { ViewType } from '@/views/types/ViewType';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isNullable } from '~/utils/isNullable';
|
||||
|
||||
const StyledSettingsObjectFieldTypeSelect = styled(
|
||||
SettingsDataModelFieldTypeSelect,
|
||||
@ -95,7 +96,7 @@ export const SettingsObjectNewFieldStep2 = () => {
|
||||
onCompleted: async (data: ObjectRecordConnection<View>) => {
|
||||
const views = data.edges;
|
||||
|
||||
if (!views) return;
|
||||
if (isNullable(views)) return;
|
||||
|
||||
setObjectViews(data.edges.map(({ node }) => node));
|
||||
},
|
||||
@ -111,7 +112,7 @@ export const SettingsObjectNewFieldStep2 = () => {
|
||||
onCompleted: async (data: ObjectRecordConnection<View>) => {
|
||||
const views = data.edges;
|
||||
|
||||
if (!views) return;
|
||||
if (isNullable(views)) return;
|
||||
|
||||
setRelationObjectViews(data.edges.map(({ node }) => node));
|
||||
},
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import styled from '@emotion/styled';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { DateTime } from 'luxon';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
@ -25,6 +26,7 @@ import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer'
|
||||
import { Section } from '@/ui/layout/section/components/Section';
|
||||
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
||||
import { useGenerateApiKeyTokenMutation } from '~/generated/graphql';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
const StyledInfo = styled.span`
|
||||
color: ${({ theme }) => theme.font.color.light};
|
||||
@ -101,15 +103,15 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
};
|
||||
|
||||
const regenerateApiKey = async () => {
|
||||
if (apiKeyData?.name) {
|
||||
if (isNonEmptyString(apiKeyData?.name)) {
|
||||
const newExpiresAt = computeNewExpirationDate(
|
||||
apiKeyData.expiresAt,
|
||||
apiKeyData.createdAt,
|
||||
apiKeyData?.expiresAt,
|
||||
apiKeyData?.createdAt,
|
||||
);
|
||||
const apiKey = await createIntegration(apiKeyData.name, newExpiresAt);
|
||||
const apiKey = await createIntegration(apiKeyData?.name, newExpiresAt);
|
||||
await deleteIntegration(false);
|
||||
|
||||
if (apiKey && apiKey.token) {
|
||||
if (isNonEmptyString(apiKey?.token)) {
|
||||
setGeneratedApi(apiKey.id, apiKey.token);
|
||||
navigate(`/settings/developers/api-keys/${apiKey.id}`);
|
||||
}
|
||||
@ -117,7 +119,7 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (apiKeyData) {
|
||||
if (isNonNullable(apiKeyData)) {
|
||||
return () => {
|
||||
setGeneratedApi(apiKeyId, null);
|
||||
};
|
||||
|
||||
@ -18,6 +18,7 @@ import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer'
|
||||
import { Section } from '@/ui/layout/section/components/Section';
|
||||
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
||||
import { useGenerateApiKeyTokenMutation } from '~/generated/graphql';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
export const SettingsDevelopersApiKeysNew = () => {
|
||||
const [generateOneApiKeyToken] = useGenerateApiKeyTokenMutation();
|
||||
@ -54,7 +55,7 @@ export const SettingsDevelopersApiKeysNew = () => {
|
||||
expiresAt: expiresAt,
|
||||
},
|
||||
});
|
||||
if (tokenData.data?.generateApiKeyToken) {
|
||||
if (isNonNullable(tokenData.data?.generateApiKeyToken)) {
|
||||
setGeneratedApi(newApiKey.id, tokenData.data.generateApiKeyToken.token);
|
||||
navigate(`/settings/developers/api-keys/${newApiKey.id}`);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import { useRecoilValue } from 'recoil';
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
|
||||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
import { tasksFilterDefinitions } from './tasks-filter-definitions';
|
||||
|
||||
@ -26,7 +27,7 @@ export const TasksEffect = ({ filterDropdownId }: TasksEffectProps) => {
|
||||
}, [setAvailableFilterDefinitions]);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentWorkspaceMember) {
|
||||
if (isNonNullable(currentWorkspaceMember)) {
|
||||
setSelectedFilter({
|
||||
fieldMetadataId: 'assigneeId',
|
||||
value: JSON.stringify(currentWorkspaceMember.id),
|
||||
|
||||
Reference in New Issue
Block a user