Skip to content

Commit

Permalink
Changed all instances of isNilOrEmpty with isNotPresent (#971)
Browse files Browse the repository at this point in the history
Co-authored-by: Roshan R <[email protected]>
  • Loading branch information
roshanrajeev and Roshan R authored Dec 19, 2023
1 parent 67d5b99 commit 5d64348
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
7 changes: 3 additions & 4 deletions src/components/Common/ErrorWrapper.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from "react";

import classnames from "classnames";
import { isNotPresent } from "neetocist";
import { is } from "ramda";

import { isNilOrEmpty } from "utils/common";

const ErrorWrapper = ({ error, children, className }) => {
const isError = !isNilOrEmpty(error);
const isError = !isNotPresent(error);
const wrapperClasses = classnames({
"neeto-editor-error": isError,
[className]: className,
Expand All @@ -25,7 +24,7 @@ const ErrorWrapper = ({ error, children, className }) => {
message = error.message;
}

if (isNilOrEmpty(message)) return null;
if (isNotPresent(message)) return null;

return message;
};
Expand Down
8 changes: 4 additions & 4 deletions src/components/Editor/CustomExtensions/SlashCommands/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { forwardRef } from "react";

import Tippy from "@tippyjs/react";
import classnames from "classnames";
import { isNotPresent } from "neetocist";

import { isNilOrEmpty } from "utils/common";
import { scrollHandler } from "utils/scrollhandler";

class Menu extends React.Component {
Expand Down Expand Up @@ -57,7 +57,7 @@ class Menu extends React.Component {
const { items, editor, range } = this.props;
const selectedItem = items[index];
const hasCommand = selectedItem && selectedItem.command;
const isLeafNode = isNilOrEmpty(selectedItem.items);
const isLeafNode = isNotPresent(selectedItem.items);
if (hasCommand && isLeafNode) selectedItem.command({ editor, range });
};

Expand Down Expand Up @@ -89,7 +89,7 @@ class Menu extends React.Component {
const { menuIndex, setActiveMenuIndex, items } = this.props;
const { selectedIndex } = this.state;
const selectedItem = items[selectedIndex];
const hasSubItems = selectedItem && !isNilOrEmpty(selectedItem.items);
const hasSubItems = selectedItem && !isNotPresent(selectedItem.items);
if (hasSubItems) setActiveMenuIndex(menuIndex + 1);
};

Expand All @@ -101,7 +101,7 @@ class Menu extends React.Component {
return (
<div className="neeto-editor-slash-commands__wrapper" ref={this.menuRef}>
{items.map((item, index) => {
const isLeafNode = isNilOrEmpty(item.items);
const isLeafNode = isNotPresent(item.items);

const nodeElement = (
<MenuItem
Expand Down
4 changes: 2 additions & 2 deletions src/components/Editor/MediaUploader/UnsplashImagePicker.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useState, useRef } from "react";

import { isNotPresent } from "neetocist";
import { Input, Spinner } from "neetoui";
import { useTranslation } from "react-i18next";
import MasonryInfiniteScroller from "react-masonry-infinite";

import { searchUnsplashImages } from "apis/unsplash";
import useDebounce from "hooks/useDebounce";
import { isNilOrEmpty } from "utils/common";

const UnsplashImagePicker = ({ onSubmit, unsplashApiKey }) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -85,7 +85,7 @@ const UnsplashImagePicker = ({ onSubmit, unsplashApiKey }) => {
{t("neetoEditor.unsplash.errorMessage")}
</p>
)}
{!error && !loading && isNilOrEmpty(images) && (
{!error && !loading && isNotPresent(images) && (
<p
className="neeto-editor-unsplash-gallery__text"
data-cy="neeto-editor-unsplash-image-picker-no-results-error"
Expand Down
5 changes: 2 additions & 3 deletions src/components/Editor/MediaUploader/index.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { useState } from "react";

import { isNotPresent } from "neetocist";
import { Modal, Tab } from "neetoui";
import { not } from "ramda";
import { useTranslation } from "react-i18next";

import { isNilOrEmpty } from "utils/common";

import { MEDIA_UPLOAD_OPTIONS } from "./constants";
import LocalUploader from "./LocalUploader";
import UnsplashImagePicker from "./UnsplashImagePicker";
Expand Down Expand Up @@ -60,7 +59,7 @@ const MediaUploader = ({ mediaUploader, onClose, editor, unsplashApiKey }) => {
onClose={handleClose}
>
<div className="ne-media-uploader">
{!isNilOrEmpty(tabs) && (
{!isNotPresent(tabs) && (
<Tab>
{tabs.map(({ key, title }) => (
<Tab.Item
Expand Down
4 changes: 2 additions & 2 deletions src/components/Editor/Menu/Bubble/LinkOption.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useEffect, useState } from "react";

import { isNotPresent } from "neetocist";
import { Close } from "neetoicons";
import { Button } from "neetoui";
import { useTranslation } from "react-i18next";

import { URL_REGEXP } from "common/constants";
import { isNilOrEmpty } from "utils/common";

const LinkOption = ({ editor, handleClose, handleAnimateInvalidLink }) => {
const { t } = useTranslation();
Expand All @@ -28,7 +28,7 @@ const LinkOption = ({ editor, handleClose, handleAnimateInvalidLink }) => {
if (URL_REGEXP.test(link)) {
editor.chain().focus().setLink({ href: link }).run();
handleClose();
} else if (isNilOrEmpty(link)) {
} else if (isNotPresent(link)) {
editor.chain().focus().unsetLink().run();
handleClose();
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Editor/Menu/Bubble/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React, { useState } from "react";

import { BubbleMenu as BubbleMenuTipTap } from "@tiptap/react";
import classnames from "classnames";
import { isNotPresent } from "neetocist";
import { roundArrow } from "tippy.js";
import "tippy.js/dist/svg-arrow.css";

import { EDITOR_OPTIONS } from "common/constants";
import { isNilOrEmpty } from "utils/common";

import Options from "./Options";

Expand Down Expand Up @@ -37,7 +37,7 @@ const Bubble = ({
EDITOR_OPTIONS.LINK,
];

const noTextOptions = isNilOrEmpty(
const noTextOptions = isNotPresent(
textOptions.filter(option => bubbleMenuOptions.includes(option))
);
if (!editor || (!isImageNodeSelected && noTextOptions)) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Editor/Menu/Fixed/LinkAddPopOver.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useState, useEffect, useRef } from "react";

import { isNotPresent } from "neetocist";
import { useOnClickOutside } from "neetocommons/react-utils";
import { Button, Input } from "neetoui";
import { createPortal } from "react-dom";
import { useTranslation } from "react-i18next";

import { validateAndFormatUrl } from "components/Editor/utils";
import { URL_REGEXP } from "src/common/constants";
import { isNilOrEmpty } from "utils/common";

const LinkAddPopOver = ({ isAddLinkActive, setIsAddLinkActive, editor }) => {
const { from, to } = editor.state.selection;
Expand All @@ -23,8 +23,8 @@ const LinkAddPopOver = ({ isAddLinkActive, setIsAddLinkActive, editor }) => {

const { t } = useTranslation();

const isLinkTextPresent = !isNilOrEmpty(linkText);
const isLinlUrlPresent = !isNilOrEmpty(linkUrl);
const isLinkTextPresent = !isNotPresent(linkText);
const isLinlUrlPresent = !isNotPresent(linkUrl);
const isSubmitDisabled = !isLinkTextPresent || !isLinlUrlPresent;

const popoverStyle = {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEditorWarnings.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useEffect } from "react";

import { isNilOrEmpty } from "utils/common";
import { isNotPresent } from "neetocist";

const useEditorWarnings = ({ initialValue }) => {
useEffect(() => {
const isProduction = [process.env.RAILS_ENV, process.env.NODE_ENV].includes(
"production"
);
if (!isProduction && isNilOrEmpty(initialValue)) {
if (!isProduction && isNotPresent(initialValue)) {
// eslint-disable-next-line no-console
console.warn(
`[neeto-editor]: Empty value of "initialValue" in needtoEditor is expected to be "<p></p>" instead of "${initialValue}".`
Expand Down

0 comments on commit 5d64348

Please sign in to comment.