fix: misc

This commit is contained in:
Ibrahima G. Coulibaly
2024-07-09 21:58:08 +01:00
parent f3e5c0dec7
commit e4c726c7b5
6 changed files with 173 additions and 113 deletions

107
.idea/workspace.xml generated
View File

@@ -4,11 +4,13 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: sort list"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: find most popular ui">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/find-most-popular/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/find-most-popular/index.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/components/options/SelectWithDesc.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/options/SelectWithDesc.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/find-most-popular/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/find-most-popular/service.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/components/result/ToolTextResult.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/result/ToolTextResult.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/find-most-popular/find-most-popular.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/find-most-popular/find-most-popular.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/string.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/string.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -45,44 +47,44 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"ASKED_ADD_EXTERNAL_FILES": "true", &quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true", &quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
"Playwright.JoinText Component.executor": "Run", &quot;Playwright.JoinText Component.executor&quot;: &quot;Run&quot;,
"Playwright.JoinText Component.should merge text pieces with specified join character.executor": "Run", &quot;Playwright.JoinText Component.should merge text pieces with specified join character.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"Vitest.compute function (1).executor": "Run", &quot;Vitest.compute function (1).executor&quot;: &quot;Run&quot;,
"Vitest.compute function.executor": "Run", &quot;Vitest.compute function.executor&quot;: &quot;Run&quot;,
"Vitest.mergeText.executor": "Run", &quot;Vitest.mergeText.executor&quot;: &quot;Run&quot;,
"Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run", &quot;Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor&quot;: &quot;Run&quot;,
"Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run", &quot;Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor&quot;: &quot;Run&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"kotlin-language-version-configured": "true", &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
"last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/components/options", &quot;last_opened_file_path&quot;: &quot;C:/Users/HP/IdeaProjects/omni-tools/src/components/options&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"npm.dev.executor": "Run", &quot;npm.dev.executor&quot;: &quot;Run&quot;,
"npm.lint.executor": "Run", &quot;npm.lint.executor&quot;: &quot;Run&quot;,
"npm.prebuild.executor": "Run", &quot;npm.prebuild.executor&quot;: &quot;Run&quot;,
"npm.script:create:tool.executor": "Run", &quot;npm.script:create:tool.executor&quot;: &quot;Run&quot;,
"npm.test.executor": "Run", &quot;npm.test.executor&quot;: &quot;Run&quot;,
"npm.test:e2e.executor": "Run", &quot;npm.test:e2e.executor&quot;: &quot;Run&quot;,
"npm.test:e2e:run.executor": "Run", &quot;npm.test:e2e:run.executor&quot;: &quot;Run&quot;,
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier", &quot;prettierjs.PrettierConfiguration.Package&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier&quot;,
"project.structure.last.edited": "Problems", &quot;project.structure.last.edited&quot;: &quot;Problems&quot;,
"project.structure.proportion": "0.0", &quot;project.structure.proportion&quot;: &quot;0.0&quot;,
"project.structure.side.proportion": "0.2", &quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
"settings.editor.selected.configurable": "settings.typescriptcompiler", &quot;settings.editor.selected.configurable&quot;: &quot;settings.typescriptcompiler&quot;,
"ts.external.directory.path": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib", &quot;ts.external.directory.path&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="ReactDesignerToolWindowState"> <component name="ReactDesignerToolWindowState">
<option name="myId2Visible"> <option name="myId2Visible">
<map> <map>
@@ -203,15 +205,8 @@
<workItem from="1719475764139" duration="14903000" /> <workItem from="1719475764139" duration="14903000" />
<workItem from="1719492452780" duration="8000" /> <workItem from="1719492452780" duration="8000" />
<workItem from="1719496624579" duration="6148000" /> <workItem from="1719496624579" duration="6148000" />
<workItem from="1720542757452" duration="4048000" /> <workItem from="1720542757452" duration="5355000" />
</task> <workItem from="1720557527691" duration="1135000" />
<task id="LOCAL-00040" summary="chore: CODEOWNERS">
<option name="closed" value="true" />
<created>1719184899883</created>
<option name="number" value="00040" />
<option name="presentableId" value="LOCAL-00040" />
<option name="project" value="LOCAL" />
<updated>1719184899883</updated>
</task> </task>
<task id="LOCAL-00041" summary="ci: fix"> <task id="LOCAL-00041" summary="ci: fix">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -597,7 +592,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1720545582958</updated> <updated>1720545582958</updated>
</task> </task>
<option name="localTasksCounter" value="89" /> <task id="LOCAL-00089" summary="feat: find most popular ui">
<option name="closed" value="true" />
<created>1720546921899</created>
<option name="number" value="00089" />
<option name="presentableId" value="LOCAL-00089" />
<option name="project" value="LOCAL" />
<updated>1720546921899</updated>
</task>
<option name="localTasksCounter" value="90" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -641,7 +644,6 @@
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" /> <option name="CHECK_NEW_TODO" value="false" />
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="feat: create transparent png" />
<MESSAGE value="fix: ToolFileInput.tsx" /> <MESSAGE value="fix: ToolFileInput.tsx" />
<MESSAGE value="fix: generate numbers" /> <MESSAGE value="fix: generate numbers" />
<MESSAGE value="fix: merging branches" /> <MESSAGE value="fix: merging branches" />
@@ -666,7 +668,8 @@
<MESSAGE value="feat: playwright report" /> <MESSAGE value="feat: playwright report" />
<MESSAGE value="chore: idea config" /> <MESSAGE value="chore: idea config" />
<MESSAGE value="feat: sort list" /> <MESSAGE value="feat: sort list" />
<option name="LAST_COMMIT_MESSAGE" value="feat: sort list" /> <MESSAGE value="feat: find most popular ui" />
<option name="LAST_COMMIT_MESSAGE" value="feat: find most popular ui" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@@ -24,7 +24,11 @@ const SelectWithDesc = <T extends string | boolean>({
description: string; description: string;
}) => { }) => {
const handleChange = (event: SelectChangeEvent<T>) => { const handleChange = (event: SelectChangeEvent<T>) => {
onChange(event.target.value as T); const newValue =
typeof selected === 'boolean'
? event.target.value === 'true'
: event.target.value;
onChange(newValue as T);
}; };
return ( return (

View File

@@ -1,8 +1,9 @@
import { Box, TextField } from '@mui/material'; import { Box, TextField } from '@mui/material';
import React, { useContext } from 'react'; import React, { useContext, useEffect } from 'react';
import { CustomSnackBarContext } from '../../contexts/CustomSnackBarContext'; import { CustomSnackBarContext } from '../../contexts/CustomSnackBarContext';
import InputHeader from '../InputHeader'; import InputHeader from '../InputHeader';
import ResultFooter from './ResultFooter'; import ResultFooter from './ResultFooter';
import { replaceSpecialCharacters } from '../../utils/string';
export default function ToolTextResult({ export default function ToolTextResult({
title = 'Result', title = 'Result',
@@ -37,7 +38,7 @@ export default function ToolTextResult({
<Box> <Box>
<InputHeader title={title} /> <InputHeader title={title} />
<TextField <TextField
value={value} value={replaceSpecialCharacters(value)}
fullWidth fullWidth
multiline multiline
rows={10} rows={10}

View File

@@ -1,65 +1,105 @@
import { expect, describe, it } from 'vitest'; import { expect, describe, it } from 'vitest';
import { TopItemsList, SplitOperatorType, SortingMethod, DisplayFormat } from './service'; import {
TopItemsList,
SplitOperatorType,
SortingMethod,
DisplayFormat
} from './service';
describe('TopItemsList function', () => { describe('TopItemsList function', () => {
it('should handle sorting alphabetically ignoring case', () => { it('should handle sorting alphabetically ignoring case', () => {
const input = 'Apple,banana,apple,Orange,Banana,apple'; const input = 'Apple,banana,apple,Orange,Banana,apple';
const result = TopItemsList('symbol', 'alphabetic', 'count', ',', input, false, true, false); const result = TopItemsList(
expect(result).toEqual( 'symbol',
'apple: 3\n' + 'alphabetic',
'banana: 2\n' + 'count',
'orange: 1' ',',
); input,
}); false,
true,
false
);
expect(result).toEqual('apple: 3\n' + 'banana: 2\n' + 'orange: 1');
});
it('should handle sorting by count and not ignoring case', () => { it('should handle sorting by count and not ignoring case', () => {
const input = 'apple,banana,apple,orange,banana,apple,Banana'; const input = 'apple,banana,apple,orange,banana,apple,Banana';
const result = TopItemsList('symbol', 'count', 'count', ',', input, false, false, false); const result = TopItemsList(
expect(result).toEqual( 'symbol',
'apple: 3\n' + 'count',
'banana: 2\n' + 'count',
'orange: 1\n' + ',',
'Banana: 1' input,
); false,
}); false,
false
);
expect(result).toEqual(
'apple: 3\n' + 'banana: 2\n' + 'orange: 1\n' + 'Banana: 1'
);
});
it('should handle regex split operator', () => { it('should handle regex split operator', () => {
const input = 'apple123banana456apple789orange012banana345apple678'; const input = 'apple123banana456apple789orange012banana345apple678';
const result = TopItemsList('regex', 'count', 'count', '\\d+', input, false, false, false); const result = TopItemsList(
expect(result).toEqual( 'regex',
'apple: 3\n' + 'count',
'banana: 2\n' + 'count',
'orange: 1' '\\d+',
); input,
}); false,
false,
false
);
expect(result).toEqual('apple: 3\n' + 'banana: 2\n' + 'orange: 1');
});
it('should handle percentage display format', () => { it('should handle percentage display format', () => {
const input = 'apple,banana,apple,orange,banana,apple'; const input = 'apple,banana,apple,orange,banana,apple';
const result = TopItemsList('symbol', 'count', 'percentage', ',', input, false, false, false); const result = TopItemsList(
expect(result).toEqual( 'symbol',
'apple: 3 (50.00%)\n' + 'count',
'banana: 2 (33.33%)\n' + 'percentage',
'orange: 1 (16.67%)' ',',
); input,
}); false,
false,
false
);
expect(result).toEqual(
'apple: 3 (50.00%)\n' + 'banana: 2 (33.33%)\n' + 'orange: 1 (16.67%)'
);
});
it('should handle total display format', () => { it('should handle total display format', () => {
const input = 'apple,banana,apple,orange,banana,apple'; const input = 'apple,banana,apple,orange,banana,apple';
const result = TopItemsList('symbol', 'count', 'total', ',', input, false, false, false); const result = TopItemsList(
expect(result).toEqual( 'symbol',
'apple: 3 (3 / 6)\n' + 'count',
'banana: 2 (2 / 6)\n' + 'total',
'orange: 1 (1 / 6)' ',',
); input,
}); false,
false,
false
);
expect(result).toEqual(
'apple: 3 (3 / 6)\n' + 'banana: 2 (2 / 6)\n' + 'orange: 1 (1 / 6)'
);
});
it('should handle trimming and ignoring empty items', () => { it('should handle trimming and ignoring empty items', () => {
const input = ' apple , banana , apple , orange , banana , apple '; const input = ' apple , banana , apple , orange , banana , apple ';
const result = TopItemsList('symbol', 'count', 'count', ',', input, true, false, true); const result = TopItemsList(
expect(result).toEqual( 'symbol',
'apple: 3\n' + 'count',
'banana: 2\n' + 'count',
'orange: 1' ',',
); input,
}); true,
false,
true
);
expect(result).toEqual('apple: 3\n' + 'banana: 2\n' + 'orange: 1');
});
}); });

View File

@@ -124,7 +124,9 @@ export default function SplitText() {
{ label: 'Increasing order', value: true }, { label: 'Increasing order', value: true },
{ label: 'Decreasing order', value: false } { label: 'Decreasing order', value: false }
]} ]}
onChange={(value) => updateField('increasing', value)} onChange={(value) => {
updateField('increasing', value);
}}
description={'Select a sorting order.'} description={'Select a sorting order.'}
/> />
<CheckboxWithDesc <CheckboxWithDesc

View File

@@ -6,3 +6,13 @@ export function capitalizeFirstLetter(string: string | undefined) {
export function isNumber(number: any) { export function isNumber(number: any) {
return !isNaN(parseFloat(number)) && isFinite(number); return !isNaN(parseFloat(number)) && isFinite(number);
} }
export const replaceSpecialCharacters = (str: string) => {
return str
.replace(/\\n/g, '\n')
.replace(/\\t/g, '\t')
.replace(/\\r/g, '\r')
.replace(/\\b/g, '\b')
.replace(/\\f/g, '\f')
.replace(/\\v/g, '\v');
};