refator(techdocs): apply review suggestions

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2022-05-23 13:03:29 +02:00
parent 816f7475ec
commit bf8219d0fe
6 changed files with 12 additions and 29 deletions
@@ -46,7 +46,7 @@ import {
scrollIntoAnchor,
transform as transformer,
copyToClipboard,
useHtmlTransformer,
useSanitizerTransformer,
} from '../../transformers';
const MOBILE_MEDIA_QUERY = 'screen and (max-width: 76.1875em)';
@@ -77,7 +77,7 @@ export const useTechDocsReaderDom = (
const sidebar = useSidebar();
const theme = useTheme<BackstageTheme>();
const isMobileMedia = useMediaQuery(MOBILE_MEDIA_QUERY);
const htmlTransformer = useHtmlTransformer();
const sanitizerTransformer = useSanitizerTransformer();
const techdocsStorageApi = useApi(techdocsStorageApiRef);
const scmIntegrationsApi = useApi(scmIntegrationsApiRef);
@@ -146,7 +146,7 @@ export const useTechDocsReaderDom = (
const preRender = useCallback(
(rawContent: string, contentPath: string) =>
transformer(rawContent, [
htmlTransformer,
sanitizerTransformer,
addBaseUrl({
techdocsStorageApi,
entityId: entityRef,
@@ -698,7 +698,7 @@ export const useTechDocsReaderDom = (
sidebar,
scmIntegrationsApi,
techdocsStorageApi,
htmlTransformer,
sanitizerTransformer,
],
);
@@ -1,18 +0,0 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { removeUnsafeLinks } from './links';
export { removeUnsafeIframes } from './iframes';
@@ -14,4 +14,5 @@
* limitations under the License.
*/
export * from './hooks';
export { removeUnsafeLinks } from './links';
export { removeUnsafeIframes } from './iframes';
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export { useHtmlTransformer } from './transformer';
export { useSanitizerTransformer } from './transformer';
@@ -21,7 +21,7 @@ import { ConfigReader } from '@backstage/core-app-api';
import { ConfigApi, configApiRef } from '@backstage/core-plugin-api';
import { TestApiProvider } from '@backstage/test-utils';
import { useHtmlTransformer } from './transformer';
import { useSanitizerTransformer } from './transformer';
const configApiMock: ConfigApi = new ConfigReader({
techdocs: {
@@ -39,7 +39,7 @@ const wrapper: FC = ({ children }) => (
describe('Transformers > Html', () => {
it('should return a function that removes unsafe links from a given dom element', async () => {
const { result } = renderHook(() => useHtmlTransformer(), { wrapper });
const { result } = renderHook(() => useSanitizerTransformer(), { wrapper });
const dirtyDom = document.createElement('html');
dirtyDom.innerHTML = `
@@ -62,7 +62,7 @@ describe('Transformers > Html', () => {
});
it('should return a function that removes unsafe iframes from a given dom element', async () => {
const { result } = renderHook(() => useHtmlTransformer(), { wrapper });
const { result } = renderHook(() => useSanitizerTransformer(), { wrapper });
const dirtyDom = document.createElement('html');
dirtyDom.innerHTML = `
@@ -19,7 +19,7 @@ import { useMemo, useCallback } from 'react';
import { useApi, configApiRef } from '@backstage/core-plugin-api';
import { Transformer } from '..';
import { Transformer } from '../transformer';
import { removeUnsafeLinks, removeUnsafeIframes } from './hooks';
/**
@@ -36,7 +36,7 @@ const useSanitizerConfig = () => {
/**
* Returns a transformer that sanitizes the dom's internal html.
*/
export const useHtmlTransformer = (): Transformer => {
export const useSanitizerTransformer = (): Transformer => {
const config = useSanitizerConfig();
return useCallback(