Renamed NewServerData to ServerData, as it's used in other contexts too

This commit is contained in:
Alejandro Celaya 2020-08-23 10:52:37 +02:00
parent 1b7e1e2b5b
commit 294888454d
5 changed files with 11 additions and 11 deletions

View file

@ -6,7 +6,7 @@ import NoMenuLayout from '../common/NoMenuLayout';
import { StateFlagTimeout } from '../utils/helpers/hooks'; import { StateFlagTimeout } from '../utils/helpers/hooks';
import { ServerForm } from './helpers/ServerForm'; import { ServerForm } from './helpers/ServerForm';
import { ImportServersBtnProps } from './helpers/ImportServersBtn'; import { ImportServersBtnProps } from './helpers/ImportServersBtn';
import { NewServerData, ServerWithId } from './data'; import { ServerData, ServerWithId } from './data';
import './CreateServer.scss'; import './CreateServer.scss';
const SHOW_IMPORT_MSG_TIME = 4000; const SHOW_IMPORT_MSG_TIME = 4000;
@ -36,7 +36,7 @@ const CreateServer = (ImportServersBtn: FC<ImportServersBtnProps>, useStateFlagT
) => { ) => {
const [ serversImported, setServersImported ] = useStateFlagTimeout(false, SHOW_IMPORT_MSG_TIME); const [ serversImported, setServersImported ] = useStateFlagTimeout(false, SHOW_IMPORT_MSG_TIME);
const [ errorImporting, setErrorImporting ] = useStateFlagTimeout(false, SHOW_IMPORT_MSG_TIME); const [ errorImporting, setErrorImporting ] = useStateFlagTimeout(false, SHOW_IMPORT_MSG_TIME);
const handleSubmit = (serverData: NewServerData) => { const handleSubmit = (serverData: ServerData) => {
const id = uuid(); const id = uuid();
createServer({ ...serverData, id }); createServer({ ...serverData, id });

View file

@ -1,4 +1,4 @@
export interface NewServerData { export interface ServerData {
name: string; name: string;
url: string; url: string;
apiKey: string; apiKey: string;

View file

@ -1,7 +1,7 @@
import React, { useRef, RefObject, ChangeEvent, MutableRefObject } from 'react'; import React, { useRef, RefObject, ChangeEvent, MutableRefObject } from 'react';
import { UncontrolledTooltip } from 'reactstrap'; import { UncontrolledTooltip } from 'reactstrap';
import ServersImporter from '../services/ServersImporter'; import ServersImporter from '../services/ServersImporter';
import { NewServerData } from '../data'; import { ServerData } from '../data';
type Ref<T> = RefObject<T> | MutableRefObject<T>; type Ref<T> = RefObject<T> | MutableRefObject<T>;
@ -11,7 +11,7 @@ export interface ImportServersBtnProps {
} }
interface ImportServersBtnConnectProps extends ImportServersBtnProps { interface ImportServersBtnConnectProps extends ImportServersBtnProps {
createServers: (servers: NewServerData[]) => void; createServers: (servers: ServerData[]) => void;
fileRef: Ref<HTMLInputElement>; fileRef: Ref<HTMLInputElement>;
} }

View file

@ -1,7 +1,7 @@
import { handleActions } from 'redux-actions'; import { handleActions } from 'redux-actions';
import { pipe, assoc, map, reduce, dissoc } from 'ramda'; import { pipe, assoc, map, reduce, dissoc } from 'ramda';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import { NewServerData, ServerWithId } from '../data'; import { ServerData, ServerWithId } from '../data';
/* eslint-disable padding-line-between-statements */ /* eslint-disable padding-line-between-statements */
export const EDIT_SERVER = 'shlink/servers/EDIT_SERVER'; export const EDIT_SERVER = 'shlink/servers/EDIT_SERVER';
@ -13,7 +13,7 @@ export type ServersMap = Record<string, ServerWithId>;
const initialState: ServersMap = {}; const initialState: ServersMap = {};
const serverWithId = (server: ServerWithId | NewServerData): ServerWithId => { const serverWithId = (server: ServerWithId | ServerData): ServerWithId => {
if ((server as ServerWithId).id) { if ((server as ServerWithId).id) {
return server as ServerWithId; return server as ServerWithId;
} }
@ -39,7 +39,7 @@ export const createServers = pipe(
export const createServer = (server: ServerWithId) => createServers([ server ]); export const createServer = (server: ServerWithId) => createServers([ server ]);
export const editServer = (serverId: string, serverData: Partial<NewServerData>) => ({ export const editServer = (serverId: string, serverData: Partial<ServerData>) => ({
type: EDIT_SERVER, type: EDIT_SERVER,
serverId, serverId,
serverData, serverData,

View file

@ -1,12 +1,12 @@
import { CsvJson } from 'csvjson'; import { CsvJson } from 'csvjson';
import { NewServerData } from '../data'; import { ServerData } from '../data';
const CSV_MIME_TYPE = 'text/csv'; const CSV_MIME_TYPE = 'text/csv';
export default class ServersImporter { export default class ServersImporter {
public constructor(private readonly csvjson: CsvJson, private readonly fileReaderFactory: () => FileReader) {} public constructor(private readonly csvjson: CsvJson, private readonly fileReaderFactory: () => FileReader) {}
public importServersFromFile = async (file?: File | null): Promise<NewServerData[]> => { public importServersFromFile = async (file?: File | null): Promise<ServerData[]> => {
if (!file || file.type !== CSV_MIME_TYPE) { if (!file || file.type !== CSV_MIME_TYPE) {
throw new Error('No file provided or file is not a CSV'); throw new Error('No file provided or file is not a CSV');
} }
@ -16,7 +16,7 @@ export default class ServersImporter {
return new Promise((resolve) => { return new Promise((resolve) => {
reader.addEventListener('loadend', (e: ProgressEvent<FileReader>) => { reader.addEventListener('loadend', (e: ProgressEvent<FileReader>) => {
const content = e.target?.result?.toString() ?? ''; const content = e.target?.result?.toString() ?? '';
const servers = this.csvjson.toObject<NewServerData>(content); const servers = this.csvjson.toObject<ServerData>(content);
resolve(servers); resolve(servers);
}); });