feat: reverse list ui

This commit is contained in:
Ibrahima G. Coulibaly
2024-07-11 01:37:34 +01:00
parent e93b5c5ded
commit 2642e1de9b
3 changed files with 121 additions and 22 deletions

30
.idea/workspace.xml generated
View File

@@ -4,10 +4,10 @@
<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: find unique ui"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: group list 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-unique/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/find-unique/index.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/reverse/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/reverse/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/group/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/group/index.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/reverse/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/reverse/service.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" />
@@ -206,15 +206,7 @@
<workItem from="1720557527691" duration="3245000" /> <workItem from="1720557527691" duration="3245000" />
<workItem from="1720564427492" duration="1523000" /> <workItem from="1720564427492" duration="1523000" />
<workItem from="1720613598176" duration="8000" /> <workItem from="1720613598176" duration="8000" />
<workItem from="1720655252208" duration="1526000" /> <workItem from="1720655252208" duration="2568000" />
</task>
<task id="LOCAL-00044" summary="fix: readme">
<option name="closed" value="true" />
<created>1719187190823</created>
<option name="number" value="00044" />
<option name="presentableId" value="LOCAL-00044" />
<option name="project" value="LOCAL" />
<updated>1719187190823</updated>
</task> </task>
<task id="LOCAL-00045" summary="fix: create-tool.mjs"> <task id="LOCAL-00045" summary="fix: create-tool.mjs">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -600,7 +592,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1720565760853</updated> <updated>1720565760853</updated>
</task> </task>
<option name="localTasksCounter" value="93" /> <task id="LOCAL-00093" summary="feat: group list ui">
<option name="closed" value="true" />
<created>1720656867853</created>
<option name="number" value="00093" />
<option name="presentableId" value="LOCAL-00093" />
<option name="project" value="LOCAL" />
<updated>1720656867853</updated>
</task>
<option name="localTasksCounter" value="94" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -644,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="fix: merging branches" />
<MESSAGE value="feat: make responsive" /> <MESSAGE value="feat: make responsive" />
<MESSAGE value="feat: make tool responsive" /> <MESSAGE value="feat: make tool responsive" />
<MESSAGE value="chore: make tool examples responsive" /> <MESSAGE value="chore: make tool examples responsive" />
@@ -669,7 +668,8 @@
<MESSAGE value="fix: misc" /> <MESSAGE value="fix: misc" />
<MESSAGE value="fix: style" /> <MESSAGE value="fix: style" />
<MESSAGE value="feat: find unique ui" /> <MESSAGE value="feat: find unique ui" />
<option name="LAST_COMMIT_MESSAGE" value="feat: find unique ui" /> <MESSAGE value="feat: group list ui" />
<option name="LAST_COMMIT_MESSAGE" value="feat: group list ui" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@@ -1,11 +1,110 @@
import { Box } from '@mui/material'; import { Box } from '@mui/material';
import React from 'react'; import React, { useState } from 'react';
import ToolTextInput from '../../../components/input/ToolTextInput';
import ToolTextResult from '../../../components/result/ToolTextResult';
import * as Yup from 'yup'; import * as Yup from 'yup';
import ToolOptions from '../../../components/options/ToolOptions';
import { reverseList, SplitOperatorType } from './service';
import ToolInputAndResult from '../../../components/ToolInputAndResult';
import SimpleRadio from '../../../components/options/SimpleRadio';
import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc';
const initialValues = {
splitOperatorType: 'symbol' as SplitOperatorType,
splitSeparator: ',',
joinSeparator: '\\n'
};
const splitOperators: {
title: string;
description: string;
type: SplitOperatorType;
}[] = [
{
title: 'Use a Symbol for Splitting',
description: 'Delimit input list items with a character.',
type: 'symbol'
},
{
title: 'Use a Regex for Splitting',
type: 'regex',
description: 'Delimit input list items with a regular expression.'
}
];
const initialValues = {};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
export default function Reverse() { export default function Reverse() {
return <Box>Lorem ipsum</Box>; const [input, setInput] = useState<string>('');
const [result, setResult] = useState<string>('');
const compute = (optionsValues: typeof initialValues, input: any) => {
const { splitOperatorType, splitSeparator, joinSeparator } = optionsValues;
setResult(
reverseList(splitOperatorType, splitSeparator, joinSeparator, input)
);
};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
return (
<Box>
<ToolInputAndResult
input={
<ToolTextInput
title={'Input list'}
value={input}
onChange={setInput}
/>
}
result={<ToolTextResult title={'Reversed list'} value={result} />}
/>
<ToolOptions
compute={compute}
getGroups={({ values, updateField }) => [
{
title: 'Splitter Mode',
component: (
<Box>
{splitOperators.map(({ title, description, type }) => (
<SimpleRadio
key={type}
onClick={() => updateField('splitOperatorType', type)}
title={title}
description={description}
checked={values.splitOperatorType === type}
/>
))}
</Box>
)
},
{
title: 'Item Separator',
component: (
<Box>
<TextFieldWithDesc
description={'Set a delimiting symbol or regular expression.'}
value={values.splitSeparator}
onOwnChange={(val) => updateField('splitSeparator', val)}
/>
</Box>
)
},
{
title: 'Output List Options',
component: (
<Box>
<TextFieldWithDesc
description={'Output list item separator.'}
value={values.joinSeparator}
onOwnChange={(val) => updateField('joinSeparator', val)}
/>
</Box>
)
}
]}
initialValues={initialValues}
input={input}
validationSchema={validationSchema}
/>
</Box>
);
} }

View File

@@ -1,4 +1,4 @@
type SplitOperatorType = 'symbol' | 'regex'; export type SplitOperatorType = 'symbol' | 'regex';
export function reverseList( export function reverseList(
splitOperatorType: SplitOperatorType, splitOperatorType: SplitOperatorType,