Skip to content

Commit

Permalink
Merge branch 'development' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
megalinter-bot committed Jul 26, 2023
2 parents 21cece8 + da9e393 commit 104468c
Show file tree
Hide file tree
Showing 55 changed files with 1,297 additions and 119 deletions.
3 changes: 1 addition & 2 deletions cypress/e2e/02-analysis.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("analysis", () => {
cy.visit("/");

// submit button disabled by default
cy.get(`[data-cy="snippet-submit"]`).should("be.disabled");
cy.get(`[data-cy="submit"]`).should("be.disabled");

submitSnippet();

Expand All @@ -15,4 +15,3 @@ describe("analysis", () => {
});
});
});

4 changes: 2 additions & 2 deletions cypress/e2e/utils/submit-snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ export const submitSnippet = () => {
cy.get(`[data-cy="snippet-input"]`).type(snippetCode, { delay: 1 });

// assert the button is enabled
cy.get(`[data-cy="snippet-submit"]`).should("be.visible");
cy.get(`[data-cy="submit"]`).should("be.visible");

// submit the snippet
cy.get(`[data-cy="snippet-submit"]`).click();
cy.get(`[data-cy="submit"]`).click();
};

const snippetCode = `
Expand Down
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
content="CodeTotal by OX Security, a megalinter UI"
/>
<link rel="icon" href="/favicon.png" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css"
/>
<meta name="theme-color" content="#6837FF" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Code Total By OX Security</title>
Expand Down
5 changes: 5 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
"@mui/material": "^5.13.5",
"axios": "^1.4.0",
"filesize": "^10.0.7",
"lodash-es": "^4.17.21",
"md5": "^2.3.0",
"monaco-editor": "^0.40.0",
"react": "^18.2.0",
"react-countup": "^6.4.2",
"react-csv": "^2.2.2",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-icons": "^4.10.1",
Expand All @@ -29,8 +32,10 @@
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/lodash-es": "^4.17.8",
"@types/md5": "^2.3.2",
"@types/react": "^18.0.37",
"@types/react-csv": "^1.1.3",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
Expand Down
9 changes: 7 additions & 2 deletions packages/app/src/analysis/actions/analysis-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const startAnalysis = async (navigate: NavigateFunction) => {
};

const createRequestData = (): Analysis | undefined => {
const { inputType, repositoryURL, file, snippet } = AnalysisStore.getState();
const { inputType, repositoryURL, file, snippet, language } =
AnalysisStore.getState();
const sharedVariables = {
name: "Lint",
inputType,
Expand All @@ -55,6 +56,10 @@ const createRequestData = (): Analysis | undefined => {
case AnalysisType.File:
return { ...sharedVariables, file } as FileAnalysis;
case AnalysisType.Snippet:
return { ...sharedVariables, snippet } as SnippetAnalysis;
return {
...sharedVariables,
snippet,
language,
} as SnippetAnalysis;
}
};
56 changes: 44 additions & 12 deletions packages/app/src/analysis/components/CodeSnippetForm.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { Button, TextField, Theme } from "@mui/material";
import { TextField, Theme, Typography } from "@mui/material";
import { FC, useCallback } from "react";
import { useNavigate } from "react-router-dom";
import { makeStyles } from "tss-react/mui";
import { LanguageIcon } from "../../common/LanguageIcon";
import { fetchDetect } from "../../common/utils/detect-lanauge-utils";
import { startAnalysis } from "../actions/analysis-actions";
import { AnalysisStore, useAnalysisStore } from "../stores/analysis-store";
import { SubmitButton } from "./SubmitButton";

export const CodeSnippetForm: FC = () => {
const { classes } = useStyles();
const { snippet, snippetEnabled } = useAnalysisStore();
const { snippet, snippetEnabled, sending, language } = useAnalysisStore();
const navigate = useNavigate();

const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
AnalysisStore.setState({ snippet: e.target.value });
const snippet = e.target.value;
AnalysisStore.setState({ snippet });
fetchDetect(snippet);
}, []);

const handleSubmit = () => {
Expand All @@ -33,15 +38,31 @@ export const CodeSnippetForm: FC = () => {
"data-cy": "snippet-input",
}}
/>
<Button
variant="contained"
color="primary"
onClick={handleSubmit}
disabled={!snippetEnabled()}
data-cy="snippet-submit"
>
Check Snippet
</Button>
<div className={classes.footer}>
<div>
{language && language.name && (
<div className={classes.language}>
{language.icon ? (
<LanguageIcon language={language} />
) : (
<Typography variant="body2" color="text.secondary">
{language.name}
</Typography>
)}
</div>
)}
</div>
<SubmitButton
variant="contained"
color="primary"
onClick={handleSubmit}
disabled={!snippetEnabled() || sending === "loading"}
loading={sending === "loading"}
data-cy="submit"
>
Send Snippet
</SubmitButton>
</div>
</div>
);
};
Expand All @@ -54,4 +75,15 @@ const useStyles = makeStyles()((theme: Theme) => ({
gap: theme.spacing(2),
padding: theme.spacing(1),
},
language: {
display: "flex",
gap: theme.spacing(1),
alignSelf: "flex-start",
},
footer: {
display: "flex",
gap: theme.spacing(1),
alignSelf: "stretch",
justifyContent: "space-between",
},
}));
Loading

0 comments on commit 104468c

Please sign in to comment.