From 7dff20cbde71a5ed10865ed5dc8c22f5aba04514 Mon Sep 17 00:00:00 2001 From: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Sat, 27 May 2023 00:13:04 +0300 Subject: [PATCH] [ENG-650] - Blacklist/whitelist each rule (#872) * Blacklist/whitelist each rule * update tooltip wording * tweaks * get rid of 'magic string' value --- .../settings/library/locations/$id.tsx | 2 +- .../IndexerRuleEditor/RuleButton.tsx | 6 +- .../locations/IndexerRuleEditor/RulesForm.tsx | 98 ++++++++++--------- .../locations/IndexerRuleEditor/index.tsx | 3 +- packages/ui/src/Dialog.tsx | 1 + 5 files changed, 56 insertions(+), 54 deletions(-) diff --git a/interface/app/$libraryId/settings/library/locations/$id.tsx b/interface/app/$libraryId/settings/library/locations/$id.tsx index 111169fff..80a075eec 100644 --- a/interface/app/$libraryId/settings/library/locations/$id.tsx +++ b/interface/app/$libraryId/settings/library/locations/$id.tsx @@ -207,7 +207,7 @@ export const Component = () => { field={field} label="Indexer rules" editable={true} - infoText="Indexer rules allow you to specify paths to ignore using RegEx." + infoText="Indexer rules allow you to specify paths to ignore using globs." className="flex flex-col rounded-md border border-app-line bg-app-overlay p-5" /> )} diff --git a/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RuleButton.tsx b/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RuleButton.tsx index d6bc5c10d..253853435 100644 --- a/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RuleButton.tsx +++ b/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RuleButton.tsx @@ -51,13 +51,13 @@ function RuleButton({ }) } className={clsx( - 'hover:brightness-125', - ruleEnabled ? '!text-green-500' : 'text-red-500' + 'px-2 hover:brightness-110', + ruleEnabled ? '!bg-accent !text-white' : 'text-ink' )} > {ruleEnabled ? 'Enabled' : 'Disabled'} - {rule.default && System} + {rule.default && System} diff --git a/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RulesForm.tsx b/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RulesForm.tsx index 3d660eda0..b7008894d 100644 --- a/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RulesForm.tsx +++ b/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/RulesForm.tsx @@ -22,11 +22,11 @@ const ruleKindEnum = z.enum(ruleKinds); const schema = z.object({ name: z.string().min(3), - kind: ruleKindEnum, rules: z.array( z.object({ type: z.string(), - value: z.string().min(1, { message: 'Value required' }) + value: z.string().min(1, { message: 'Value required' }), + kind: ruleKindEnum }) ) }); @@ -42,17 +42,21 @@ const RulesForm = ({ onSubmitted }: Props) => { const REMOTE_ERROR_FORM_FIELD = 'root.serverError'; const createIndexerRules = useLibraryMutation(['locations.indexer_rules.create']); const formId = useId(); + const modeOptions: { value: RuleKind; label: string }[] = [ + { value: 'RejectFilesByGlob', label: 'Reject files by glob' }, + { value: 'AcceptFilesByGlob', label: 'Accept files by glob' } + ]; const form = useZodForm({ schema, mode: 'onBlur', reValidateMode: 'onBlur', defaultValues: { name: '', - kind: 'RejectFilesByGlob', rules: [ { type: selectValues[0], - value: '' + value: '', + kind: modeOptions[0]?.value } ] } @@ -91,15 +95,15 @@ const RulesForm = ({ onSubmitted }: Props) => { const formatData = { name: data.name, dry_run: false, - rules: data.rules.map(({ type, value }) => { + rules: data.rules.map(({ type, value, kind }) => { switch (type) { case 'Name': - return [data.kind, [`**/${value}`]]; + return [kind, [`**/${value}`]]; case 'Extension': // .tar should work for .tar.gz, .tar.bz2, etc. - return [data.kind, [`**/*${value}`, `**/*${value}.*`]]; + return [kind, [`**/*${value}`, `**/*${value}.*`]]; default: - return [data.kind, [value]]; + return [kind, [value]]; } }) } as IndexerRuleCreateArgs; @@ -139,17 +143,23 @@ const RulesForm = ({ onSubmitted }: Props) => {

Rules

-
-

Type

-

Value

+
+

Type

+

Value

+

+ Mode + + + +

{fields.map((field, index) => { return ( { render={({ field }) => ( { + field.onChange(value); + }} + > + {modeOptions.map(({ label, value }) => ( + + {label} + + ))} + + )} + control={form.control} + /> {index !== 0 && (
-
-
-

Blacklist

- ( - { - // TODO: These rule kinds are broken right now in the backend and this UI doesn't make much sense for them - // kind.AcceptIfChildrenDirectoriesArePresent - // kind.RejectIfChildrenDirectoriesArePresent - const kind = ruleKindEnum.enum; - field.onChange( - checked - ? kind.AcceptFilesByGlob - : kind.RejectFilesByGlob - ); - }} - size="md" - /> - )} - control={form.control} - /> -

Whitelist

- - - -
-
diff --git a/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/index.tsx b/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/index.tsx index 2edd2f3f8..0505740b1 100644 --- a/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/index.tsx +++ b/interface/app/$libraryId/settings/library/locations/IndexerRuleEditor/index.tsx @@ -34,7 +34,7 @@ export default function IndexerRuleEditor({ const [toggleNewRule, setToggleNewRule] = useState(false); const deleteIndexerRule = useLibraryMutation(['locations.indexer_rules.delete']); - const deleteRule: MouseEventHandler = (e) => { + const deleteRule: MouseEventHandler = () => { if (!selectedRule) return; showAlertDialog({ @@ -43,7 +43,6 @@ export default function IndexerRuleEditor({ label: 'Confirm', onSubmit: async () => { setIsDeleting(true); - try { await deleteIndexerRule.mutateAsync(selectedRule.id); } catch (error) { diff --git a/packages/ui/src/Dialog.tsx b/packages/ui/src/Dialog.tsx index e60a0023a..5c9eb2ea8 100644 --- a/packages/ui/src/Dialog.tsx +++ b/packages/ui/src/Dialog.tsx @@ -167,6 +167,7 @@ export function Dialog({
{ + e?.preventDefault(); await onSubmit?.(e); dialog.onSubmit?.(); setOpen(false);