Fix feeds config UI not allowing notifyOnFailure to be toggled. (#865)

* Fix feeds config UI not allowing notifyOnFailure to be toggled.

* changelog

* amend changelog to be cohierent

* Actual fixes.
This commit is contained in:
Will Hunt 2023-12-27 15:25:30 +00:00 committed by GitHub
parent 1db6f60776
commit 066d908b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

1
changelog.d/865.bugfix Normal file
View File

@ -0,0 +1 @@
Fix notify on failure not being toggleable in the feeds widget interface.

View File

@ -97,8 +97,11 @@ export class FeedConnection extends BaseConnection implements IConnection {
}
}
if (typeof data.notifyOnFailure !== 'undefined' && typeof data.notifyOnFailure !== 'boolean') {
throw new ApiError('notifyOnFailure must be a boolean', ErrCode.BadValue);
}
return { url, label: data.label, template: data.template };
return { url, label: data.label, template: data.template, notifyOnFailure: data.notifyOnFailure };
}
static async provisionConnection(roomId: string, _userId: string, data: Record<string, unknown> = {}, { intent, config }: ProvisionConnectionOpts) {

View File

@ -32,9 +32,10 @@ const ConnectionConfiguration: FunctionComponent<ConnectionConfigurationProps<Se
const urlRef = createRef<HTMLInputElement>();
const labelRef = createRef<HTMLInputElement>();
const templateRef = createRef<HTMLInputElement>();
const notifyRef = createRef<HTMLInputElement>();
const canSave = !existingConnection?.id || (existingConnection?.canEdit ?? false);
const canEdit = canSave && !isMigrationCandidate;
const [notifyOnFailure, setNotifyOnFailure] = useState<boolean>(existingConnection?.config.notifyOnFailure ?? false);
const handleSave = useCallback((evt: Event) => {
evt.preventDefault();
if (!canSave) {
@ -46,13 +47,14 @@ const ConnectionConfiguration: FunctionComponent<ConnectionConfigurationProps<Se
url,
label: labelRef?.current?.value || existingConnection?.config.label,
template: templateRef.current?.value || existingConnection?.config.template,
notifyOnFailure: notifyRef.current?.checked || existingConnection?.config.notifyOnFailure,
notifyOnFailure,
})
}
}, [canSave, onSave, urlRef, labelRef, templateRef, notifyRef, existingConnection]);
}, [canSave, onSave, urlRef, labelRef, templateRef, notifyOnFailure, existingConnection]);
const onlyVisibleOnExistingConnection = !!existingConnection;
return <form onSubmit={handleSave}>
{ existingConnection && <FeedRecentResults item={existingConnection} />}
@ -63,7 +65,7 @@ const ConnectionConfiguration: FunctionComponent<ConnectionConfigurationProps<Se
<input ref={labelRef} disabled={!canSave} type="text" value={existingConnection?.config.label} />
</InputField>
<InputField visible={onlyVisibleOnExistingConnection} label="Send a notice on read failure" noPadding={true}>
<input ref={notifyRef} disabled={!canSave} type="checkbox" checked={existingConnection?.config.notifyOnFailure} />
<input disabled={!canSave} type="checkbox" checked={notifyOnFailure} onChange={useCallback(() => setNotifyOnFailure(v => !v), [])} />
</InputField>
<InputField visible={onlyVisibleOnExistingConnection} label="Template" noPadding={true}>
<input ref={templateRef} disabled={!canSave} type="text" value={existingConnection?.config.template} placeholder={DEFAULT_TEMPLATE} />