mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
feat: updated the UI to enable editing of provider URLs (#234)
* feat: updated the UI to enable editing of provider URLs --------- Co-authored-by: foxx-tech <robin.foxx.tech@gmail.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Empty, Table, Button } from '@douyinfe/semi-ui';
|
import { Empty, Table, Button } from '@douyinfe/semi-ui';
|
||||||
import { IconDelete } from '@douyinfe/semi-icons';
|
import { IconDelete, IconEdit } from '@douyinfe/semi-icons';
|
||||||
|
|
||||||
export default function ProviderTable({ providerData = [], onRemove } = {}) {
|
export default function ProviderTable({ providerData = [], onRemove, onEdit } = {}) {
|
||||||
return (
|
return (
|
||||||
<Table
|
<Table
|
||||||
pagination={false}
|
pagination={false}
|
||||||
@@ -30,6 +30,8 @@ export default function ProviderTable({ providerData = [], onRemove } = {}) {
|
|||||||
render: (_, record) => {
|
render: (_, record) => {
|
||||||
return (
|
return (
|
||||||
<div style={{ float: 'right' }}>
|
<div style={{ float: 'right' }}>
|
||||||
|
<Button type="secondary" icon={<IconEdit />} onClick={() => onEdit(record)} />
|
||||||
|
<div style={{ display: 'inline-block', width: '16px' }} />
|
||||||
<Button type="danger" icon={<IconDelete />} onClick={() => onRemove(record.url)} />
|
<Button type="danger" icon={<IconDelete />} onClick={() => onRemove(record.url)} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export default function JobMutator() {
|
|||||||
const defaultNotificationAdapter = jobToBeEdit?.notificationAdapter || [];
|
const defaultNotificationAdapter = jobToBeEdit?.notificationAdapter || [];
|
||||||
const defaultEnabled = jobToBeEdit?.enabled ?? true;
|
const defaultEnabled = jobToBeEdit?.enabled ?? true;
|
||||||
|
|
||||||
|
const [providerToEdit, setProviderToEdit] = useState(null);
|
||||||
const [providerCreationVisible, setProviderCreationVisibility] = useState(false);
|
const [providerCreationVisible, setProviderCreationVisibility] = useState(false);
|
||||||
const [notificationCreationVisible, setNotificationCreationVisibility] = useState(false);
|
const [notificationCreationVisible, setNotificationCreationVisibility] = useState(false);
|
||||||
const [editNotificationAdapter, setEditNotificationAdapter] = useState(null);
|
const [editNotificationAdapter, setEditNotificationAdapter] = useState(null);
|
||||||
@@ -50,6 +51,12 @@ export default function JobMutator() {
|
|||||||
return Boolean(notificationAdapterData.length && providerData.length && name);
|
return Boolean(notificationAdapterData.length && providerData.length && name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleProviderEdit = (data) => {
|
||||||
|
setProviderData(
|
||||||
|
providerData.map((provider) => (provider.url === data.oldProviderToEdit.url ? data.newData : provider)),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const mutateJob = async () => {
|
const mutateJob = async () => {
|
||||||
try {
|
try {
|
||||||
await xhrPost('/api/jobs', {
|
await xhrPost('/api/jobs', {
|
||||||
@@ -78,6 +85,8 @@ export default function JobMutator() {
|
|||||||
onData={(data) => {
|
onData={(data) => {
|
||||||
setProviderData([...providerData, data]);
|
setProviderData([...providerData, data]);
|
||||||
}}
|
}}
|
||||||
|
onEditData={handleProviderEdit}
|
||||||
|
providerToEdit={providerToEdit}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{notificationCreationVisible && (
|
{notificationCreationVisible && (
|
||||||
@@ -127,7 +136,10 @@ export default function JobMutator() {
|
|||||||
type="primary"
|
type="primary"
|
||||||
icon={<IconPlusCircle />}
|
icon={<IconPlusCircle />}
|
||||||
className="jobMutation__newButton"
|
className="jobMutation__newButton"
|
||||||
onClick={() => setProviderCreationVisibility(true)}
|
onClick={() => {
|
||||||
|
setProviderToEdit(null);
|
||||||
|
setProviderCreationVisibility(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Add new Provider
|
Add new Provider
|
||||||
</Button>
|
</Button>
|
||||||
@@ -137,6 +149,10 @@ export default function JobMutator() {
|
|||||||
onRemove={(providerUrl) => {
|
onRemove={(providerUrl) => {
|
||||||
setProviderData(providerData.filter((provider) => provider.url !== providerUrl));
|
setProviderData(providerData.filter((provider) => provider.url !== providerUrl));
|
||||||
}}
|
}}
|
||||||
|
onEdit={(provider) => {
|
||||||
|
setProviderCreationVisibility(true);
|
||||||
|
setProviderToEdit(provider);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</SegmentPart>
|
</SegmentPart>
|
||||||
<Divider margin="1rem" />
|
<Divider margin="1rem" />
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
import { Banner, Modal, Select, Input } from '@douyinfe/semi-ui';
|
import { Banner, Modal, Select, Input } from '@douyinfe/semi-ui';
|
||||||
import { transform } from '../../../../../services/transformer/providerTransformer';
|
import { transform } from '../../../../../services/transformer/providerTransformer';
|
||||||
@@ -17,12 +17,32 @@ const sortProvider = (a, b) => {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ProviderMutator({ onVisibilityChanged, visible = false, onData } = {}) {
|
const returnOriginalSelectedProvider = (providerToEdit, provider) => {
|
||||||
|
return provider.find((pro) => pro.id === providerToEdit.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ProviderMutator({
|
||||||
|
onVisibilityChanged,
|
||||||
|
visible = false,
|
||||||
|
onData,
|
||||||
|
onEditData,
|
||||||
|
providerToEdit,
|
||||||
|
} = {}) {
|
||||||
const provider = useSelector((state) => state.provider);
|
const provider = useSelector((state) => state.provider);
|
||||||
const [selectedProvider, setSelectedProvider] = useState(null);
|
const [selectedProvider, setSelectedProvider] = useState(null);
|
||||||
const [providerUrl, setProviderUrl] = useState(null);
|
const [providerUrl, setProviderUrl] = useState(null);
|
||||||
const [validationMessage, setValidationMessage] = useState(null);
|
const [validationMessage, setValidationMessage] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (providerToEdit) {
|
||||||
|
setSelectedProvider(returnOriginalSelectedProvider(providerToEdit, provider));
|
||||||
|
setProviderUrl(providerToEdit.url);
|
||||||
|
} else {
|
||||||
|
setSelectedProvider(null);
|
||||||
|
setProviderUrl(null);
|
||||||
|
}
|
||||||
|
}, [providerToEdit, visible]);
|
||||||
|
|
||||||
const width = useScreenWidth();
|
const width = useScreenWidth();
|
||||||
const isMobile = width <= 850;
|
const isMobile = width <= 850;
|
||||||
|
|
||||||
@@ -46,13 +66,24 @@ export default function ProviderMutator({ onVisibilityChanged, visible = false,
|
|||||||
if (doStore) {
|
if (doStore) {
|
||||||
const validationResult = validate();
|
const validationResult = validate();
|
||||||
if (validationResult == null) {
|
if (validationResult == null) {
|
||||||
onData(
|
if (providerToEdit != null) {
|
||||||
transform({
|
onEditData({
|
||||||
url: providerUrl,
|
newData: transform({
|
||||||
id: selectedProvider.id,
|
url: providerUrl,
|
||||||
name: selectedProvider.name,
|
id: selectedProvider.id,
|
||||||
}),
|
name: selectedProvider.name,
|
||||||
);
|
}),
|
||||||
|
oldProviderToEdit: providerToEdit,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
onData(
|
||||||
|
transform({
|
||||||
|
url: providerUrl,
|
||||||
|
id: selectedProvider.id,
|
||||||
|
name: selectedProvider.name,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
setProviderUrl(null);
|
setProviderUrl(null);
|
||||||
setSelectedProvider(null);
|
setSelectedProvider(null);
|
||||||
onVisibilityChanged(false);
|
onVisibilityChanged(false);
|
||||||
@@ -68,7 +99,7 @@ export default function ProviderMutator({ onVisibilityChanged, visible = false,
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title="Adding a new Provider"
|
title={providerToEdit ? 'Editing an existing Provider' : 'Adding a new Provider'}
|
||||||
visible={visible}
|
visible={visible}
|
||||||
onOk={() => onSubmit(true)}
|
onOk={() => onSubmit(true)}
|
||||||
onCancel={() => onSubmit(false)}
|
onCancel={() => onSubmit(false)}
|
||||||
@@ -85,19 +116,26 @@ export default function ProviderMutator({ onVisibilityChanged, visible = false,
|
|||||||
description={validationMessage}
|
description={validationMessage}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{providerToEdit != null ? (
|
||||||
<p>
|
<p>
|
||||||
Provider are the <IconLikeHeart style={{ color: '#ff0000' }} /> of Fredy. We're supporting multiple Provider
|
You can now edit the <strong>{providerToEdit.name}</strong> provider's URL in the input field below.
|
||||||
such as Immowelt, Kalaydo etc. Select a provider from the list below.
|
</p>
|
||||||
<br />
|
) : (
|
||||||
Fredy will then open the provider's url in a new tab.
|
<>
|
||||||
</p>
|
<p>
|
||||||
<p>
|
Provider are the <IconLikeHeart style={{ color: '#ff0000' }} /> of Fredy. We're supporting multiple Provider
|
||||||
You will need to configure your search parameter like you would do when you do a regular search on the
|
such as Immowelt, Kalaydo etc. Select a provider from the list below.
|
||||||
provider's website.
|
<br />
|
||||||
<br />
|
Fredy will then open the provider's url in a new tab.
|
||||||
When the search results are shown on the website, copy the url and paste it into the textfield below.
|
</p>
|
||||||
</p>
|
<p>
|
||||||
|
You will need to configure your search parameter like you would do when you do a regular search on the
|
||||||
|
provider's website.
|
||||||
|
<br />
|
||||||
|
When the search results are shown on the website, copy the url and paste it into the textfield below.
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Banner
|
<Banner
|
||||||
fullMode={false}
|
fullMode={false}
|
||||||
type="warning"
|
type="warning"
|
||||||
@@ -117,6 +155,7 @@ export default function ProviderMutator({ onVisibilityChanged, visible = false,
|
|||||||
filter
|
filter
|
||||||
placeholder="Select a provider"
|
placeholder="Select a provider"
|
||||||
className="providerMutator__fields"
|
className="providerMutator__fields"
|
||||||
|
disabled={providerToEdit != null}
|
||||||
optionList={provider
|
optionList={provider
|
||||||
.map((pro) => {
|
.map((pro) => {
|
||||||
return {
|
return {
|
||||||
@@ -131,7 +170,6 @@ export default function ProviderMutator({ onVisibilityChanged, visible = false,
|
|||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
const selectedProvider = provider.find((pro) => pro.id === value);
|
const selectedProvider = provider.find((pro) => pro.id === value);
|
||||||
setSelectedProvider(selectedProvider);
|
setSelectedProvider(selectedProvider);
|
||||||
|
|
||||||
window.open(selectedProvider.baseUrl);
|
window.open(selectedProvider.baseUrl);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -142,7 +180,8 @@ export default function ProviderMutator({ onVisibilityChanged, visible = false,
|
|||||||
placeholder="Provider Url"
|
placeholder="Provider Url"
|
||||||
width={10}
|
width={10}
|
||||||
className="providerMutator__fields"
|
className="providerMutator__fields"
|
||||||
onBlur={(e) => {
|
value={providerUrl}
|
||||||
|
onInput={(e) => {
|
||||||
setProviderUrl(e.target.value);
|
setProviderUrl(e.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user