Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: added search field to rule list

Elijah Potterb4b44bd81f2e
diff --git a/src/harper/LintSettingList.tsx b/src/harper/LintSettingList.tsx
index 442586a43..079a5b5eb 100644
--- a/src/harper/LintSettingList.tsx
+++ b/src/harper/LintSettingList.tsx
@@ -1,27 +1,41 @@
-import React, { useEffect } from 'react';
+import React, { useState } from 'react';
import LintSettingRow from './LintSettingRow';
import useLintConfig, { useDefaultLintConfig } from './useLintConfig';
import { useLintDescriptions } from './LinterProvider';
+import { SearchControl } from '@wordpress/components';
export default function LintSettingList() {
const [lintConfig, setLintConfig] = useLintConfig();
const defaultConfig = useDefaultLintConfig();
const descriptions = useLintDescriptions();
+ const [query, setQuery] = useState('');
return (
<div className="harper-lint-config-cont">
- {Object.entries(lintConfig).map(([key, value]) => (
- <LintSettingRow
- key={key}
- name={key}
- description={descriptions[key]}
- value={value}
- defaultValue={defaultConfig[key]!}
- setValue={(newValue) =>
- setLintConfig({ ...lintConfig, [key]: newValue })
- }
- />
- ))}
+ <SearchControl
+ value={query}
+ onChange={setQuery}
+ placeholder="Search for a rule..."
+ />
+
+ {Object.entries(lintConfig)
+ .filter(
+ ([key]) =>
+ key.includes(query) ||
+ descriptions[key]?.includes(query)
+ )
+ .map(([key, value]) => (
+ <LintSettingRow
+ key={key}
+ name={key}
+ description={descriptions[key]}
+ value={value}
+ defaultValue={defaultConfig[key]!}
+ setValue={(newValue) =>
+ setLintConfig({ ...lintConfig, [key]: newValue })
+ }
+ />
+ ))}
</div>
);
}