Skip to content

Commit

Permalink
chore: fix some lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
drodil committed Sep 18, 2024
1 parent fa2b1a7 commit 4cda849
Show file tree
Hide file tree
Showing 33 changed files with 93 additions and 82 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
- '5432:5432'
24 changes: 9 additions & 15 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,22 @@ yarn --cwd packages/app add @drodil/backstage-plugin-toolbox

Expose the toolbox page:

```ts
```tsx
// packages/app/src/App.tsx
import {ToolboxPage} from '@drodil/backstage-plugin-toolbox';

// ...
import { ToolboxPage } from '@drodil/backstage-plugin-toolbox';

const AppRoutes = () => (
<FlatRoutes>
// ...
<Route path = "/toolbox"
element = { < ToolboxPage / >
}
/>
// ...
< /FlatRoutes>
)
;
<Route path="/toolbox" element={<ToolboxPage />} />
// ...
</FlatRoutes>
);
```

Add the navigation in the frontend:

```ts
```tsx
// packages/app/src/components/Root/Root.tsx
import CardTravel from '@mui/icons-material/CardTravel';

Expand All @@ -52,7 +46,7 @@ An interface for toolbox is now available at `/toolbox`.

You can also add your own tools to the plugin by passing them to the ToolboxPage as a property:

```ts
```tsx
import { ToolboxPage, Tool } from '@drodil/backstage-plugin-toolbox';

const extraToolExample: Tool = {
Expand All @@ -65,7 +59,7 @@ const extraToolExample: Tool = {

Also lazy loading is supported:

```ts
```tsx
import React, { lazy } from 'react';
import { ToolboxPage, Tool } from '@drodil/backstage-plugin-toolbox';

Expand Down
10 changes: 6 additions & 4 deletions plugins/toolbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ _This plugin was created through the Backstage CLI_

## Getting started

Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/toolbox](http://localhost:3000/toolbox).
Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running
`yarn start` in the root directory, and then navigating to [/toolbox](http://localhost:3000/toolbox).

You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
Expand All @@ -22,7 +23,7 @@ cd packages/app && yarn add @drodil/backstage-plugin-toolbox

Expose the questions page:

```ts
```tsx
// packages/app/src/App.tsx
import { ToolboxPage } from '@drodil/backstage-plugin-toolbox';

Expand All @@ -43,7 +44,7 @@ An interface for toolbox is now available at `/toolbox`.

You can also add your own tools to the plugin by passing them to the ToolboxPage as a property:

```ts
```tsx
import { ToolboxPage, Tool } from '@drodil/backstage-plugin-toolbox';

const extraToolExample: Tool = {
Expand All @@ -56,9 +57,10 @@ const extraToolExample: Tool = {

Also lazy loading is supported:

```ts
```tsx
import React, { lazy } from 'react';
import { ToolboxPage, Tool } from '@drodil/backstage-plugin-toolbox';

const MyTool = lazy(() => import('./MyTool'));

const extraToolExample: Tool = {
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/dev/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { CustomHomepageGrid } from '@backstage/plugin-home';
import { ToolboxHomepageCard } from '../src/plugin';
import { ToolboxHomepageCard } from '../src';
import { Content, Page } from '@backstage/core-components';

export const HomePage = () => {
Expand Down
12 changes: 4 additions & 8 deletions plugins/toolbox/src/api/ToolboxClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ export class ToolboxClient implements ToolboxApi {
request: ToolRequest,
): Promise<ToolResponse> {
const url = `${await this.getBaseUrl()}/${toolName}`;
try {
const response = await this.fetchApi.fetch(url, request);
if (response.ok) {
return response;
}
throw new Error(`Request failed with status ${response.status}`);
} catch (error) {
throw new Error(`Request failed: ${error}`);
const response = await this.fetchApi.fetch(url, request);
if (response.ok) {
return response;
}
throw new Error(`Request failed with status ${response.status}`);
}

async toolJsonRequest(toolName: string, data: any): Promise<unknown> {
Expand Down
15 changes: 13 additions & 2 deletions plugins/toolbox/src/components/Buttons/CopyToClipboardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Tooltip from '@mui/material/Tooltip';
import Button from '@mui/material/Button';
import FileCopy from '@mui/icons-material/FileCopy';
import { useToolboxTranslation } from '../../hooks';
import { alertApiRef, useApi } from '@backstage/core-plugin-api';

type Props = {
output: string | number;
Expand All @@ -11,10 +12,20 @@ type Props = {

export const CopyToClipboardButton = (props: Props) => {
const { t } = useToolboxTranslation();
const alertApi = useApi(alertApiRef);

const copyToClipboard = () => {
navigator.clipboard.writeText(props.output.toString());
// TODO: handle success and error
navigator.clipboard
.writeText(props.output.toString())
.then(() => {
alertApi.post({ message: 'Copied to clipboard!', severity: 'success' });
})
.catch(() => {
alertApi.post({
message: 'Failed to copy to clipboard!',
severity: 'error',
});
});
};

return (
Expand Down
10 changes: 6 additions & 4 deletions plugins/toolbox/src/components/Converters/ColorConverter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import {
LCH,
RGB,
} from 'color-convert/conversions';
import { PasteFromClipboardButton } from '../Buttons/PasteFromClipboardButton';
import { ClearValueButton } from '../Buttons/ClearValueButton';
import { CopyToClipboardButton } from '../Buttons/CopyToClipboardButton';
import {
ClearValueButton,
CopyToClipboardButton,
PasteFromClipboardButton,
SampleButton,
} from '../Buttons';
import TextField from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import Divider from '@mui/material/Divider';
import Box from '@mui/material/Box';
import { useToolboxTranslation } from '../../hooks';
import { SampleButton } from '../Buttons';

export const ColorConverter = () => {
const { classes } = useStyles();
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Converters/CsvToJson.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import csvToJson from 'csvtojson';
import { JsonSpaceSelector } from '../DefaultEditor/JsonSpaceSelector';

Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Converters/JsonToCsv.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import { Parser } from '@json2csv/plainjs';

export const JsonToCsv = () => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Converters/JsonToYaml.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import YAML from 'yaml';

export const JsonToYaml = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import { MarkdownContent } from '@backstage/core-components';
import { useStyles } from '../../utils/hooks';
import beautify from 'js-beautify';
Expand Down
8 changes: 5 additions & 3 deletions plugins/toolbox/src/components/Converters/NumberBase.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { useStyles } from '../../utils/hooks';
import { PasteFromClipboardButton } from '../Buttons/PasteFromClipboardButton';
import { ClearValueButton } from '../Buttons/ClearValueButton';
import { CopyToClipboardButton } from '../Buttons/CopyToClipboardButton';
import {
ClearValueButton,
CopyToClipboardButton,
PasteFromClipboardButton,
} from '../Buttons';
import FormControl from '@mui/material/FormControl';
import Typography from '@mui/material/Typography';
import TextField from '@mui/material/TextField';
Expand Down
10 changes: 6 additions & 4 deletions plugins/toolbox/src/components/Converters/SLACalculator.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { useStyles } from '../../utils/hooks';
import React from 'react';
import { PasteFromClipboardButton } from '../Buttons/PasteFromClipboardButton';
import { ClearValueButton } from '../Buttons/ClearValueButton';
import { CopyToClipboardButton } from '../Buttons/CopyToClipboardButton';
import {
ClearValueButton,
CopyToClipboardButton,
PasteFromClipboardButton,
SampleButton,
} from '../Buttons';
import TextField from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import Divider from '@mui/material/Divider';
import Alert from '@mui/material/Alert';
import { useToolboxTranslation } from '../../hooks';
import { SampleButton } from '../Buttons';

export const SLACalculator = () => {
const { classes } = useStyles();
Expand Down
4 changes: 2 additions & 2 deletions plugins/toolbox/src/components/Converters/StringUtilities.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useCallback } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import React, { useCallback, useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor';
import {
camelCase,
capitalize,
Expand Down
8 changes: 5 additions & 3 deletions plugins/toolbox/src/components/Converters/TimeConverter.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useStyles } from '../../utils/hooks';
import React from 'react';
import { DateTime } from 'luxon';
import { PasteFromClipboardButton } from '../Buttons/PasteFromClipboardButton';
import { ClearValueButton } from '../Buttons/ClearValueButton';
import { CopyToClipboardButton } from '../Buttons/CopyToClipboardButton';
import {
ClearValueButton,
CopyToClipboardButton,
PasteFromClipboardButton,
} from '../Buttons';
import TextField from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
import Typography from '@mui/material/Typography';
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Converters/XmlToJson.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import { xml2json } from 'xml-js';
import { JsonSpaceSelector } from '../DefaultEditor/JsonSpaceSelector';
import { useToolboxTranslation } from '../../hooks';
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Converters/YamlToJson.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import YAML from 'yaml';
import { JsonSpaceSelector } from '../DefaultEditor/JsonSpaceSelector';

Expand Down
12 changes: 7 additions & 5 deletions plugins/toolbox/src/components/DefaultEditor/DefaultEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { ReactElement } from 'react';
import { useStyles } from '../../utils/hooks';
import { CopyToClipboardButton } from '../Buttons/CopyToClipboardButton';
import { PasteFromClipboardButton } from '../Buttons/PasteFromClipboardButton';
import { ClearValueButton } from '../Buttons/ClearValueButton';
import { SampleButton } from '../Buttons/SampleButton';
import { FileUploadButton } from '../Buttons';
import {
ClearValueButton,
CopyToClipboardButton,
FileUploadButton,
PasteFromClipboardButton,
SampleButton,
} from '../Buttons';
import { FileDownloadButton } from '../Buttons/FileDownloadButton';
import Grid from '@mui/material/Grid';
import ButtonGroup from '@mui/material/ButtonGroup';
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Encoders/Backslash.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';

const charCodeMap = {
'\\n': 13,
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Encoders/Base64Encode.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';

export const Base64Encode = () => {
const [input, setInput] = React.useState('');
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Encoders/HtmlEntities.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';

const decode = (value: string): string => {
const textArea = document.createElement('textarea');
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Encoders/UrlEncode.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';

export const UrlEncode = () => {
const [input, setInput] = React.useState('');
Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Formatters/CSSBeautify.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import beautify from 'js-beautify';
import { useToolboxTranslation } from '../../hooks';

Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Formatters/HTMLBeautify.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import beautify from 'js-beautify';
import { useToolboxTranslation } from '../../hooks';

Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Formatters/JSBeautify.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import beautify from 'js-beautify';
import { useToolboxTranslation } from '../../hooks';

Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Formatters/SQLBeautify.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import { format } from 'sql-formatter';
import { useToolboxTranslation } from '../../hooks';

Expand Down
2 changes: 1 addition & 1 deletion plugins/toolbox/src/components/Generators/Hash.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { DefaultEditor } from '../DefaultEditor/DefaultEditor';
import { DefaultEditor } from '../DefaultEditor';
import { faker } from '@faker-js/faker';
import { sha1, sha256, sha384, sha512 } from 'crypto-hash';
import { Md5 } from 'ts-md5';
Expand Down
Loading

0 comments on commit 4cda849

Please sign in to comment.