kopia lustrzana https://github.com/bellingcat/auto-archiver
Add a bit of typescripting
rodzic
2ec44f4170
commit
15da907e81
|
@ -24,6 +24,8 @@ import {
|
||||||
import type { DragStartEvent, DragEndEvent, UniqueIdentifier } from "@dnd-kit/core";
|
import type { DragStartEvent, DragEndEvent, UniqueIdentifier } from "@dnd-kit/core";
|
||||||
|
|
||||||
|
|
||||||
|
import { Module } from './types';
|
||||||
|
|
||||||
import { modules, steps, module_types } from './schema.json';
|
import { modules, steps, module_types } from './schema.json';
|
||||||
import {
|
import {
|
||||||
Stack,
|
Stack,
|
||||||
|
@ -34,14 +36,6 @@ import Grid from '@mui/material/Grid2';
|
||||||
import { parseDocument, Document } from 'yaml'
|
import { parseDocument, Document } from 'yaml'
|
||||||
import StepCard from './StepCard';
|
import StepCard from './StepCard';
|
||||||
|
|
||||||
// create a Typescript interface for module
|
|
||||||
interface Module<T> {
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
configs: object;
|
|
||||||
manifest: object;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function FileDrop({ setYamlFile }: { setYamlFile: React.Dispatch<React.SetStateAction<Document>> }) {
|
function FileDrop({ setYamlFile }: { setYamlFile: React.Dispatch<React.SetStateAction<Document>> }) {
|
||||||
|
|
||||||
|
@ -174,7 +168,7 @@ function ModuleTypes({ stepType, setEnabledModules, enabledModules, configValues
|
||||||
<Grid container spacing={1} key={stepType}>
|
<Grid container spacing={1} key={stepType}>
|
||||||
<SortableContext items={items} strategy={rectSortingStrategy}>
|
<SortableContext items={items} strategy={rectSortingStrategy}>
|
||||||
{items.map((name: string) => {
|
{items.map((name: string) => {
|
||||||
let m = modules[name];
|
let m: Module = modules[name];
|
||||||
return (
|
return (
|
||||||
<StepCard key={name} type={stepType} module={m} toggleModule={toggleModule} enabledModules={enabledModules} configValues={configValues} />
|
<StepCard key={name} type={stepType} module={m} toggleModule={toggleModule} enabledModules={enabledModules} configValues={configValues} />
|
||||||
);
|
);
|
||||||
|
@ -203,7 +197,12 @@ function ModuleTypes({ stepType, setEnabledModules, enabledModules, configValues
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [yamlFile, setYamlFile] = useState<Document>(new Document());
|
const [yamlFile, setYamlFile] = useState<Document>(new Document());
|
||||||
const [enabledModules, setEnabledModules] = useState<{}>(Object.fromEntries(Object.keys(steps).map(type => [type, steps[type].map((name: string) => [name, false])])));
|
const [enabledModules, setEnabledModules] = useState<{}>(Object.fromEntries(Object.keys(steps).map(type => [type, steps[type].map((name: string) => [name, false])])));
|
||||||
const [configValues, setConfigValues] = useState<{}>(
|
const [configValues, setConfigValues] = useState<{
|
||||||
|
[key: string]: {
|
||||||
|
[key: string
|
||||||
|
]: any
|
||||||
|
}
|
||||||
|
}>(
|
||||||
Object.keys(modules).reduce((acc, module) => {
|
Object.keys(modules).reduce((acc, module) => {
|
||||||
acc[module] = {};
|
acc[module] = {};
|
||||||
return acc;
|
return acc;
|
||||||
|
@ -218,7 +217,7 @@ export default function App() {
|
||||||
|
|
||||||
// create a yaml file from
|
// create a yaml file from
|
||||||
const finalYaml = {
|
const finalYaml = {
|
||||||
'steps': Object.keys(steps).reduce((acc, stepType) => {
|
'steps': Object.keys(steps).reduce((acc, stepType: string) => {
|
||||||
acc[stepType] = stepsConfig[stepType].filter(([name, enabled]: [string, boolean]) => enabled).map(([name, enabled]: [string, boolean]) => name);
|
acc[stepType] = stepsConfig[stepType].filter(([name, enabled]: [string, boolean]) => enabled).map(([name, enabled]: [string, boolean]) => name);
|
||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
|
|
|
@ -6,7 +6,6 @@ import { CSS } from "@dnd-kit/utilities";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
|
||||||
CardActions,
|
CardActions,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
Button,
|
Button,
|
||||||
|
@ -20,7 +19,6 @@ import {
|
||||||
MenuItem,
|
MenuItem,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormControlLabel,
|
FormControlLabel,
|
||||||
Textarea,
|
|
||||||
FormHelperText,
|
FormHelperText,
|
||||||
TextField,
|
TextField,
|
||||||
Stack,
|
Stack,
|
||||||
|
@ -28,8 +26,7 @@ import {
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import Grid from '@mui/material/Grid2';
|
import Grid from '@mui/material/Grid2';
|
||||||
import DragIndicatorIcon from '@mui/icons-material/DragIndicator';
|
import DragIndicatorIcon from '@mui/icons-material/DragIndicator';
|
||||||
import { set } from "yaml/dist/schema/yaml-1.1/set";
|
import { Module } from "./types";
|
||||||
|
|
||||||
|
|
||||||
Object.defineProperty(String.prototype, 'capitalize', {
|
Object.defineProperty(String.prototype, 'capitalize', {
|
||||||
value: function() {
|
value: function() {
|
||||||
|
@ -46,7 +43,7 @@ const StepCard = ({
|
||||||
configValues
|
configValues
|
||||||
}: {
|
}: {
|
||||||
type: string,
|
type: string,
|
||||||
module: object,
|
module: Module,
|
||||||
toggleModule: any,
|
toggleModule: any,
|
||||||
enabledModules: any,
|
enabledModules: any,
|
||||||
configValues: any
|
configValues: any
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
export interface Config {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
type: string?;
|
||||||
|
default: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Manifest {
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Module {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
configs: { [key: string]: Config };
|
||||||
|
manifest: Manifest;
|
||||||
|
display_name: string;
|
||||||
|
}
|
Ładowanie…
Reference in New Issue