Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/865.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix notify on failure not being toggleable in the feeds widget interface.
5 changes: 4 additions & 1 deletion src/Connections/FeedConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
static readonly ServiceCategory = "feeds";


public static createConnectionForState(roomId: string, event: StateEvent<any>, {config, intent}: InstantiateConnectionOpts) {

Check warning on line 57 in src/Connections/FeedConnection.ts

View workflow job for this annotation

GitHub Actions / lint-node

Unexpected any. Specify a different type
if (!config.feeds?.enabled) {
throw Error('RSS/Atom feeds are not configured');
}
Expand Down Expand Up @@ -97,8 +97,11 @@
}
}

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) {
Expand Down
10 changes: 6 additions & 4 deletions web/components/roomConfig/FeedsConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -46,12 +47,13 @@ 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} />}
Expand All @@ -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} />
Expand Down
Loading