Skip to content

Commit bab9cf8

Browse files
authored
Merge pull request #151 from sametcodes/108-replace-linttsc-script-to-tslint
refactor(#108): replace linttsc script to tslint
2 parents bf279c1 + 9f6dcde commit bab9cf8

File tree

44 files changed

+327
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+327
-310
lines changed

app/build/[...ids]/page.tsx

+20-18
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ import NextImage from "next/image";
1616
import Link from "next/link";
1717
import { AnyObject } from "yup";
1818

19-
export default async function Build({ params }: { params: { ids: string[] } }) {
19+
export default async function Build({
20+
params,
21+
}: {
22+
params: { ids: Array<string> };
23+
}) {
2024
if (!params.ids || Array.isArray(params.ids) === false)
2125
return <p>Invalid params</p>;
22-
const [query_id, query_config_id] = params.ids;
26+
const [queryId, queryConfigId] = params.ids;
2327
const session = await getServerSession(authOptions);
2428

2529
const query = await prisma.platformQuery.findUnique({
26-
where: { id: query_id },
30+
where: { id: queryId },
2731
include: {
2832
platform: true,
2933
securedPlatformQuery: true,
@@ -33,16 +37,18 @@ export default async function Build({ params }: { params: { ids: string[] } }) {
3337

3438
if (!query) return <p>Query not found</p>;
3539

36-
let queryConfigs: (PlatformQueryConfig & {
37-
platform: Platform;
38-
platformQuery: PlatformQuery;
39-
})[] = [];
40+
let queryConfigs: Array<
41+
PlatformQueryConfig & {
42+
platform: Platform;
43+
platformQuery: PlatformQuery;
44+
}
45+
> = [];
4046
let connectionProfile: ConnectionProfile | null = null;
4147

4248
if (session) {
4349
queryConfigs = await prisma.platformQueryConfig.findMany({
4450
where: {
45-
platformQueryId: query_id,
51+
platformQueryId: queryId,
4652
userId: session.user.id,
4753
},
4854
include: { platform: true, platformQuery: true },
@@ -66,15 +72,11 @@ export default async function Build({ params }: { params: { ids: string[] } }) {
6672
const schema = mergeSchemas(validation.query, validation.view);
6773
const allowMultipleCreate = Object.keys(schema?.fields || {}).length > 0;
6874

69-
if (
70-
allowMultipleCreate === false &&
71-
!query_config_id &&
72-
queryConfigs.length
73-
) {
74-
return redirect(`/build/${query_id}/${queryConfigs[0].id}`);
75+
if (allowMultipleCreate === false && !queryConfigId && queryConfigs.length) {
76+
return redirect(`/build/${queryId}/${queryConfigs[0].id}`);
7577
}
7678

77-
const query_view = query.query_type.toLowerCase();
79+
const queryView = query.query_type.toLowerCase();
7880

7981
return (
8082
<div className="flex mx-auto flex-col justify-center lg:w-2/3 px-8 lg:px-0">
@@ -120,14 +122,14 @@ export default async function Build({ params }: { params: { ids: string[] } }) {
120122
</div>
121123
</div>
122124

123-
{query_view === "public" && <ConfigForm.Public platformQuery={query} />}
124-
{query_view === "private" && (
125+
{queryView === "public" && <ConfigForm.Public platformQuery={query} />}
126+
{queryView === "private" && (
125127
<>
126128
<ConfigForm.Private
127129
platformQuery={query}
128130
connectionProfile={connectionProfile}
129131
queryConfigs={queryConfigs || []}
130-
activeQueryConfigId={query_config_id}
132+
activeQueryConfigId={queryConfigId}
131133
>
132134
<ConnectAccount
133135
platformQuery={query}

app/build/list/page.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default async function QueryList() {
2323
}
2424

2525
type IPlatformQueries = {
26-
platform: Platform & { queries: PlatformQuery[] };
26+
platform: Platform & { queries: Array<PlatformQuery> };
2727
};
2828

2929
const PlatformQueries = async ({ platform }: IPlatformQueries, key: string) => {
@@ -67,10 +67,10 @@ const PlatformQueryView = async (
6767
key: string
6868
) => {
6969
const getView = template[query.name as keyof typeof template];
70-
const sample_data = sample[query.name as keyof typeof samples];
71-
if (!sample_data) return <></>;
70+
const sampleData = sample[query.name as keyof typeof samples];
71+
if (!sampleData) return <></>;
7272

73-
const view = await getView(sample_data.result, sample_data.config);
73+
const view = await getView(sampleData.result, sampleData.config);
7474
return (
7575
<li key={key} className="flex justify-between my-3 items-center">
7676
<Link href={`/build/${query.id}`}>

app/connect/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type IConnectionWithPlatforms = {
1818

1919
export default async function Connect() {
2020
const session = await getServerSession(authOptions);
21-
let connectionWithPlatforms: IConnectionWithPlatforms[] = [];
21+
let connectionWithPlatforms: Array<IConnectionWithPlatforms> = [];
2222

2323
if (!session) redirect("/");
2424

components/connects/index.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ import { IConnectionWithPlatforms } from "@/app/connect/page";
1818

1919
type IConnects = {
2020
session: Session | null;
21-
connectionWithPlatforms: IConnectionWithPlatforms[];
22-
noAuthRequiredPlatforms: (Platform & {
23-
_count: { queries: number };
24-
})[];
25-
allPlatforms: (Platform & {
26-
_count: { queries: number };
27-
})[];
21+
connectionWithPlatforms: Array<IConnectionWithPlatforms>;
22+
noAuthRequiredPlatforms: Array<
23+
Platform & {
24+
_count: { queries: number };
25+
}
26+
>;
27+
allPlatforms: Array<
28+
Platform & {
29+
_count: { queries: number };
30+
}
31+
>;
2832
};
2933

3034
export const Connects: React.FC<IConnects> = ({

components/form/private.tsx

+19-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useState, useCallback, useMemo, useRef } from "react";
44
import { buildFormWithYupSchema } from "./builder";
5-
import { mergeSchemas } from "@/utils";
5+
import { mergeSchemas, cn } from "@/utils";
66
import { useToast } from "@/components/hooks/toast";
77

88
import {
@@ -24,7 +24,6 @@ import {
2424
PlatformQuery,
2525
PlatformQueryConfig,
2626
} from "@prisma/client";
27-
import { cn } from "@/utils";
2827
import { Image, CopyButton } from "@/components/ui";
2928
import { validations } from "@/platforms";
3029
import Link from "next/link";
@@ -33,11 +32,12 @@ import { useRouter } from "next/navigation";
3332

3433
type IConfigFormProps = {
3534
platformQuery: PlatformQuery & { platform: Platform };
36-
queryConfigs:
37-
| (PlatformQueryConfig & {
38-
platform: Platform;
39-
platformQuery: PlatformQuery;
40-
})[];
35+
queryConfigs: Array<
36+
PlatformQueryConfig & {
37+
platform: Platform;
38+
platformQuery: PlatformQuery;
39+
}
40+
>;
4141
connectionProfile: ConnectionProfile | null;
4242
activeQueryConfigId: string | null;
4343
children?: React.ReactNode;
@@ -82,29 +82,29 @@ export default function PrivateConfigForm({
8282
);
8383

8484
const readValidationFormValues = (
85-
validation: AnyObject,
85+
validationForm: AnyObject,
8686
prefix: string,
8787
data: FormData
8888
) => {
89-
const fields = validation.fields;
90-
const field_keys = Object.keys(fields);
89+
const fields = validationForm.fields;
90+
const fieldKeys = Object.keys(fields);
9191

92-
return field_keys.reduce((acc: any, field_key: string) => {
93-
const field = fields[field_key];
92+
return fieldKeys.reduce((acc: any, fieldKey: string) => {
93+
const field = fields[fieldKey];
9494

9595
if (field.type === "string") {
96-
acc[field_key] = data.get(prefix + "__" + field_key);
96+
acc[fieldKey] = data.get(prefix + "__" + fieldKey);
9797
}
9898

9999
if (field.type === "number") {
100-
const num_value = data.get(prefix + "__" + field_key);
101-
if (Number.isFinite(Number(num_value))) {
102-
acc[field_key] = Number(num_value);
100+
const numValue = data.get(prefix + "__" + fieldKey);
101+
if (Number.isFinite(Number(numValue))) {
102+
acc[fieldKey] = Number(numValue);
103103
}
104104
}
105105

106106
if (field.type === "boolean") {
107-
acc[field_key] = data.get(prefix + "__" + field_key) === "on";
107+
acc[fieldKey] = data.get(prefix + "__" + fieldKey) === "on";
108108
}
109109

110110
return acc;
@@ -226,13 +226,13 @@ export default function PrivateConfigForm({
226226
};
227227
} catch (error) {
228228
if (error instanceof ValidationError) {
229-
const errors = error.inner
229+
const validationErrors = error.inner
230230
.map((err) => ({ name: err.path, message: err.message }))
231231
.reduce(
232232
(acc: any, err: any) => ({ ...acc, [err.name]: err.message }),
233233
{}
234234
);
235-
setErrors(errors);
235+
setErrors(validationErrors);
236236
}
237237
}
238238

components/form/public.tsx

+19-18
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ export default function PublicConfigForm({
2424
const $form = useRef<HTMLFormElement>(null);
2525

2626
const readValidationFormValues = (
27-
validation: AnyObject,
27+
validationForm: AnyObject,
2828
prefix: string,
2929
data: FormData
3030
) => {
31-
const fields = validation.fields;
32-
const field_keys = Object.keys(fields);
31+
const fields = validationForm.fields;
32+
const fieldKeys = Object.keys(fields);
3333

34-
return field_keys.reduce((acc: any, field_key: string) => {
35-
const field = fields[field_key];
34+
return fieldKeys.reduce((acc: any, fieldKey: string) => {
35+
const field = fields[fieldKey];
3636

3737
if (field.type === "string") {
38-
acc[field_key] = data.get(prefix + "__" + field_key);
38+
acc[fieldKey] = data.get(prefix + "__" + fieldKey);
3939
}
4040

4141
if (field.type === "number") {
42-
const num_value = data.get(prefix + "__" + field_key);
43-
if (Number.isFinite(Number(num_value))) {
44-
acc[field_key] = Number(num_value);
42+
const numValue = data.get(prefix + "__" + fieldKey);
43+
if (Number.isFinite(Number(numValue))) {
44+
acc[fieldKey] = Number(numValue);
4545
}
4646
}
4747

4848
if (field.type === "boolean") {
49-
acc[field_key] = data.get(prefix + "__" + field_key) === "on";
49+
acc[fieldKey] = data.get(prefix + "__" + fieldKey) === "on";
5050
}
5151

5252
return acc;
@@ -85,8 +85,8 @@ export default function PublicConfigForm({
8585
const formDataValues = { ...(query || {}), ...(view || {}) };
8686
if (Object.keys(formDataValues).length === 0)
8787
return { queryConfig: query || {}, viewConfig: view || {} };
88-
const validations = [queryValidation, viewValidation].filter(Boolean);
89-
const schema = mergeSchemas(...validations);
88+
const validationsForm = [queryValidation, viewValidation].filter(Boolean);
89+
const schema = mergeSchemas(...validationsForm);
9090
schema.validateSync(formDataValues, { abortEarly: false });
9191

9292
return {
@@ -95,13 +95,13 @@ export default function PublicConfigForm({
9595
};
9696
} catch (error) {
9797
if (error instanceof ValidationError) {
98-
const errors = error.inner
98+
const errorsValidation = error.inner
9999
.map((err) => ({ name: err.path, message: err.message }))
100100
.reduce(
101101
(acc: any, err: any) => ({ ...acc, [err.name]: err.message }),
102102
{}
103103
);
104-
setErrors(errors);
104+
setErrors(errorsValidation);
105105
}
106106
}
107107

@@ -126,10 +126,11 @@ export default function PublicConfigForm({
126126
const formData = readFormData(new FormData($form.current));
127127
if (!formData) return;
128128

129-
const query_string = objectToQueryString(
130-
Object.assign({}, formData, { id: platformQuery.id })
131-
);
132-
setQueryString(query_string);
129+
const _queryString = objectToQueryString({
130+
...formData,
131+
...{ id: platformQuery.id },
132+
});
133+
setQueryString(_queryString);
133134
};
134135

135136
return (

components/form/select.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export const SelectQuery = ({
1212
queryId,
1313
session,
1414
}: {
15-
platforms: (Platform & {
16-
queries: PlatformQuery[];
17-
})[];
15+
platforms: Array<
16+
Platform & {
17+
queries: Array<PlatformQuery>;
18+
}
19+
>;
1820
platformId: string | undefined;
1921
queryId: string | undefined;
2022
session?: Session | null;

components/hooks/toast.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Action =
4747
};
4848

4949
interface State {
50-
toasts: ToasterToast[];
50+
toasts: Array<ToasterToast>;
5151
}
5252

5353
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
@@ -61,7 +61,7 @@ const addToRemoveQueue = (toastId: string) => {
6161
toastTimeouts.delete(toastId);
6262
dispatch({
6363
type: "REMOVE_TOAST",
64-
toastId: toastId,
64+
toastId,
6565
});
6666
}, TOAST_REMOVE_DELAY);
6767

@@ -92,8 +92,8 @@ export const reducer = (state: State, action: Action): State => {
9292
if (toastId) {
9393
addToRemoveQueue(toastId);
9494
} else {
95-
state.toasts.forEach((toast) => {
96-
addToRemoveQueue(toast.id);
95+
state.toasts.forEach((_toast) => {
96+
addToRemoveQueue(_toast.id);
9797
});
9898
}
9999

@@ -139,10 +139,10 @@ interface Toast extends Omit<ToasterToast, "id"> {}
139139
function toast({ ...props }: Toast) {
140140
const id = genId();
141141

142-
const update = (props: ToasterToast) =>
142+
const update = (_props: ToasterToast) =>
143143
dispatch({
144144
type: "UPDATE_TOAST",
145-
toast: { ...props, id },
145+
toast: { ..._props, id },
146146
});
147147
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
148148

@@ -159,7 +159,7 @@ function toast({ ...props }: Toast) {
159159
});
160160

161161
return {
162-
id: id,
162+
id,
163163
dismiss,
164164
update,
165165
};

0 commit comments

Comments
 (0)