Skip to content

Commit

Permalink
feat(website): added QueriedRulesMetricsGroup to website
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaPontrandolfo committed Nov 19, 2023
1 parent 6bef05c commit 916057f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 7 deletions.
29 changes: 29 additions & 0 deletions apps/docs-website/src/components/QueriedRulesMetricsGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styles from "./RulesTable.module.css";

interface QueriedRulesMetricsGroupProps {
totalAvailableRulesAmount: number;
fetchedConfigRulesAmount: number;
filteredRulesAmount: number;
}

export const QueriedRulesMetricsGroup = ({
totalAvailableRulesAmount,
fetchedConfigRulesAmount,
filteredRulesAmount,
}: QueriedRulesMetricsGroupProps): JSX.Element => {
return (
<div className={styles.queriedRulesMetricsGroup}>
<div>
<span>Total available rules: </span>
<span>{totalAvailableRulesAmount}</span>
</div>
<div>
<span>Current config rules: </span>
<span>{fetchedConfigRulesAmount}</span>
</div>
<div>
<span>Filtered rules</span>: <span>{filteredRulesAmount}</span>
</div>
</div>
);
};
9 changes: 9 additions & 0 deletions apps/docs-website/src/components/RulesTable.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
margin-bottom: 16px;
gap: 1rem;
}

.checkboxGroupContainer {
Expand Down Expand Up @@ -97,3 +99,10 @@
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}

.queriedRulesMetricsGroup {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 2rem;
}
11 changes: 10 additions & 1 deletion apps/docs-website/src/components/RulesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import styles from "./RulesTable.module.css";
import { ConfigCombinationForm } from "./ConfigCombinationForm";
import { TableSkeleton } from "./TableSkeleton";
import { configCombinationDefaultValues } from "./constants";
import { QueriedRulesMetricsGroup } from "./QueriedRulesMetricsGroup";

const columnHelper = createColumnHelper<Entry>();

Expand Down Expand Up @@ -55,6 +56,8 @@ export const RulesTable = (): JSX.Element => {
const [data, setData] = useState<Entry[]>(() => []);
const [isLoading, setIsLoading] = useState(false);
const [pluginsNames, setPluginsNames] = useState<string[]>([]);
const [totalAvailableRulesAmount, setTotalAvailableRulesAmount] = useState(0);
const [fetchedConfigRulesAmount, setFetchedConfigRulesAmount] = useState(0);
const [configCombination, setConfigCombination] = useState<SheriffSettings>(
configCombinationDefaultValues,
);
Expand Down Expand Up @@ -95,8 +98,9 @@ export const RulesTable = (): JSX.Element => {

const fetchedData: ServerResponse = await response.json();

setTotalAvailableRulesAmount(fetchedData.totalAvailableRulesAmount);
setFetchedConfigRulesAmount(fetchedData.compiledConfig.length);
setPluginsNames(fetchedData.pluginsNames);

setData(filterDuplicateRules(fetchedData.compiledConfig));
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -213,6 +217,11 @@ export const RulesTable = (): JSX.Element => {
}}
/>
</div>
<QueriedRulesMetricsGroup
totalAvailableRulesAmount={totalAvailableRulesAmount}
fetchedConfigRulesAmount={fetchedConfigRulesAmount}
filteredRulesAmount={table.getRowModel().rows.length}
/>
</div>
{isLoading ? (
<TableSkeleton />
Expand Down
3 changes: 0 additions & 3 deletions apps/sheriff-webservices/src/generateRulesDataset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */

import lodash from 'lodash';
import { Linter } from 'eslint';
import type {
Expand Down
19 changes: 18 additions & 1 deletion apps/sheriff-webservices/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,29 @@ app.use(cors());

app.post('/api/get-new-sheriff-config', (req: Request, res: Response) => {
const newConfig: BarebonesConfigAtom[] = getSheriffConfig(req.body);
const allRulesConfig: BarebonesConfigAtom[] = getSheriffConfig(
{
react: true,
lodash: true,
next: true,
playwright: true,
jest: true,
vitest: true,
},
true,
);

console.log('Sending new config...');
const allRulesCompiledConfig =
generateRulesDataset(allRulesConfig).compiledConfig;
const { compiledConfig, pluginsNames } = generateRulesDataset(newConfig);
console.log('New config sent.');

res.send({ compiledConfig, pluginsNames });
res.send({
compiledConfig,
pluginsNames,
totalAvailableRulesAmount: allRulesCompiledConfig.length,
});
});

app.listen(port, () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/eslint-config-sheriff/src/getExportableConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ const getBaseConfig = (userConfigChoices: SheriffSettings) => {
];
};

export const getExportableConfig = (userConfigChoices: SheriffSettings) => {
export const getExportableConfig = (
userConfigChoices: SheriffSettings,
areAllRulesForced?: boolean,
) => {
if (!userConfigChoices) {
throw new Error('No settings provided.');
}
Expand All @@ -279,7 +282,11 @@ export const getExportableConfig = (userConfigChoices: SheriffSettings) => {
];
}

if (userConfigChoices.jest && userConfigChoices.vitest) {
if (
!areAllRulesForced &&
userConfigChoices.jest &&
userConfigChoices.vitest
) {
throw new Error(
'Jest and Vitest support cannot be activated at once. Please choose one or the other.',
);
Expand Down
1 change: 1 addition & 0 deletions packages/sheriff-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ export interface SheriffSettings {
export interface ServerResponse {
compiledConfig: Entry[];
pluginsNames: string[];
totalAvailableRulesAmount: number;
}

0 comments on commit 916057f

Please sign in to comment.