chore: remove getFileExtension and replace it with its code where used (#19762)

* chore: remove getFileExtension and replace it with its code where used

* chore: create a getFileExtension util in upload with its test
This commit is contained in:
Simone 2024-03-13 22:54:00 +01:00 committed by GitHub
parent d9f9c0cd21
commit 794f5522b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 20 additions and 18 deletions

View File

@ -1,7 +1,7 @@
import * as React from 'react';
import { Avatar, AvatarGroup, Flex, Tooltip, Typography } from '@strapi/design-system';
import { getFileExtension, prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import styled from 'styled-components';
import type { Entity } from '@strapi/types';
@ -26,6 +26,8 @@ interface MediaFile {
interface MediaSingleProps extends MediaFile {}
const getFileExtension = (ext: string) => (ext && ext[0] === '.' ? ext.substring(1) : ext);
const MediaSingle = ({ url, mime, alternativeText, name, ext, formats }: MediaSingleProps) => {
const fileURL = prefixFileUrlWithBackendUrl(url)!;

View File

@ -437,6 +437,10 @@ This util has been removed and not replaced, use async / await with try / catch
This util has been removed and not replaced. If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.
### getFileExtension
This util has been removed and not replaced. If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.
### setHexOpacity
This util has been removed and not replaced, use the native CSS opacity property instead. If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.

View File

@ -48,7 +48,6 @@ export * from './hooks/useSelectionState';
export * from './utils/auth';
export * from './utils/getAPIInnerErrors';
export * from './utils/getFetchClient';
export * from './utils/getFileExtension';
export * from './utils/getYupInnerErrors';
export * from './utils/hasPermissions';
export * from './utils/normalizeAPIError';

View File

@ -1,6 +0,0 @@
/**
* Get the file extension of value passed in.
*
* This hook is used to create URL aware of the backend. Practical to resolve assets.
*/
export const getFileExtension = (ext: string) => (ext && ext[0] === '.' ? ext.substr(1) : ext);

View File

@ -1,10 +1,10 @@
import React from 'react';
import { getFileExtension, prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import PropTypes from 'prop-types';
import { AssetDefinition, AssetType } from '../../constants';
import { createAssetUrl } from '../../utils';
import { createAssetUrl, getFileExtension } from '../../utils';
import { AudioAssetCard } from './AudioAssetCard';
import { DocAssetCard } from './DocAssetCard';

View File

@ -19,7 +19,7 @@ import {
TextInput,
VisuallyHidden,
} from '@strapi/design-system';
import { getFileExtension, pxToRem, useTracking } from '@strapi/helper-plugin';
import { pxToRem, useTracking } from '@strapi/helper-plugin';
import { Form, Formik } from 'formik';
import isEqual from 'lodash/isEqual';
import PropTypes from 'prop-types';
@ -30,7 +30,7 @@ import * as yup from 'yup';
import { AssetDefinition } from '../../constants';
import { useEditAsset } from '../../hooks/useEditAsset';
import { useFolderStructure } from '../../hooks/useFolderStructure';
import { findRecursiveFolderByValue, getTrad } from '../../utils';
import { findRecursiveFolderByValue, getTrad, getFileExtension } from '../../utils';
import formatBytes from '../../utils/formatBytes';
import { ContextInfo } from '../ContextInfo';
import SelectTree from '../SelectTree';

View File

@ -1,12 +1,11 @@
import React from 'react';
import { Typography } from '@strapi/design-system';
import { getFileExtension } from '@strapi/helper-plugin';
import parseISO from 'date-fns/parseISO';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { formatBytes } from '../../utils';
import { formatBytes, getFileExtension } from '../../utils';
import { PreviewCell } from './PreviewCell';

View File

@ -1,13 +1,13 @@
import React from 'react';
import { Avatar, Box, Icon, Initials } from '@strapi/design-system';
import { getFileExtension, prefixFileUrlWithBackendUrl, pxToRem } from '@strapi/helper-plugin';
import { prefixFileUrlWithBackendUrl, pxToRem } from '@strapi/helper-plugin';
import { Folder } from '@strapi/icons';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { AssetType } from '../../constants';
import { createAssetUrl } from '../../utils';
import { createAssetUrl, getFileExtension } from '../../utils';
import { VideoPreview } from '../AssetCard/VideoPreview';
const VideoPreviewWrapper = styled(Box)`

View File

@ -0,0 +1,3 @@
const getFileExtension = (ext) => (ext && ext[0] === '.' ? ext.substring(1) : ext);
export default getFileExtension;

View File

@ -11,3 +11,4 @@ export { default as getFolderParents } from './getFolderParents';
export { default as getFolderURL } from './getFolderURL';
export { default as getTrad } from './getTrad';
export { default as toSingularTypes } from './toSingularTypes';
export { default as getFileExtension } from './getFileExtension';

View File

@ -1,6 +1,6 @@
import { getFileExtension } from '../getFileExtension';
import getFileExtension from '../getFileExtension';
describe('HELPER PLUGIN | utils | getFileExtension', () => {
describe('getFileExtension', () => {
it('should return undefined if ext does not exits', () => {
const ext = null;
const expected = null;