feat(ui): add integration delete optiofeat(ui): add integration delete
optionn
This commit is contained in:
parent
1caac72771
commit
a13a21a67d
@ -1,4 +1,4 @@
|
|||||||
function Integration({ id, name }) {
|
function Integration({ id, name } = {}) {
|
||||||
let _id = id;
|
let _id = id;
|
||||||
let _name = name;
|
let _name = name;
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ const Serializer = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deserializeIntegrations(objects) {
|
function deserializeIntegrations(objects) {
|
||||||
|
if (!objects) return [];
|
||||||
return objects.map((object) => deserializeIntegration(object));
|
return objects.map((object) => deserializeIntegration(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
69
www/src/modals/delete-integration-modal.jsx
Normal file
69
www/src/modals/delete-integration-modal.jsx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { createEffect, createSignal } from "solid-js";
|
||||||
|
import Modal from "./modal.jsx";
|
||||||
|
import UserService from "../services/user-service.js";
|
||||||
|
import EventEmitter from "../tools/event-emitter.js";
|
||||||
|
import User from "../data/user.js";
|
||||||
|
import ValidatedTextInput from "../modules/validated-text-input.jsx";
|
||||||
|
import ModalHandler from "./modal-handler.js";
|
||||||
|
import Integration from "../data/integration.js";
|
||||||
|
import DeviceService from "../services/device-service.js";
|
||||||
|
|
||||||
|
const [integration, setIntegration] = createSignal(new Integration());
|
||||||
|
const eventEmitter = new EventEmitter();
|
||||||
|
const INTEGRATION_DELETED_EVENT = "success";
|
||||||
|
|
||||||
|
function DeleteIntegrationModal(props) {
|
||||||
|
const [error, setError] = createSignal("");
|
||||||
|
|
||||||
|
async function handleDeleteIntegration() {
|
||||||
|
try {
|
||||||
|
await DeviceService.deleteIntegration(integration().getId());
|
||||||
|
} catch (e) {
|
||||||
|
setError(e.message);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
DeleteIntegrationModal.Handler.hide();
|
||||||
|
eventEmitter.dispatchEvent(INTEGRATION_DELETED_EVENT, integration);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
ref={props.ref}
|
||||||
|
id="deleteIntegrationModal"
|
||||||
|
modalTitle="Delete integration"
|
||||||
|
centered={true}
|
||||||
|
>
|
||||||
|
<div class="modal-body">
|
||||||
|
<Show when={error() !== ""}>
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
{error()}
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
<div class="mb-3 row">
|
||||||
|
<span>
|
||||||
|
Do you really want to delete the integration {integration().getName()}?
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleDeleteIntegration}
|
||||||
|
class="btn btn-danger"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteIntegrationModal.Handler = new ModalHandler();
|
||||||
|
DeleteIntegrationModal.setIntegration = setIntegration;
|
||||||
|
DeleteIntegrationModal.onIntegrationDeleted = (callback) =>
|
||||||
|
eventEmitter.on(INTEGRATION_DELETED_EVENT, callback);
|
||||||
|
|
||||||
|
export default DeleteIntegrationModal;
|
||||||
@ -5,6 +5,7 @@ import DeleteUserModal from "./delete-user-modal.jsx";
|
|||||||
import UserSettingsModal from "./user-settings-modal.jsx";
|
import UserSettingsModal from "./user-settings-modal.jsx";
|
||||||
import CreateDeviceModal from "./create-device-modal.jsx";
|
import CreateDeviceModal from "./create-device-modal.jsx";
|
||||||
import ShowRegistrationCodeModal from "./show-registration-code-modal.jsx";
|
import ShowRegistrationCodeModal from "./show-registration-code-modal.jsx";
|
||||||
|
import DeleteIntegrationModal from "./delete-integration-modal.jsx";
|
||||||
|
|
||||||
const ModalRegistry = (function () {
|
const ModalRegistry = (function () {
|
||||||
const modals = [
|
const modals = [
|
||||||
@ -33,6 +34,11 @@ const ModalRegistry = (function () {
|
|||||||
component: ShowRegistrationCodeModal,
|
component: ShowRegistrationCodeModal,
|
||||||
ref: null,
|
ref: null,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "deleteIntegrationModal",
|
||||||
|
component: DeleteIntegrationModal,
|
||||||
|
ref: null,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
function getModals(props) {
|
function getModals(props) {
|
||||||
|
|||||||
@ -93,6 +93,18 @@ function DeviceService() {
|
|||||||
integrations = Serializer.deserializeIntegrations(integrations);
|
integrations = Serializer.deserializeIntegrations(integrations);
|
||||||
return integrations;
|
return integrations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteIntegration(id) {
|
||||||
|
let response = await Net.sendJsonRequest({
|
||||||
|
method: "DELETE",
|
||||||
|
url: "/api/integrations/" + id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
|
let responseData = JSON.parse(response.data);
|
||||||
|
throw new Error(responseData.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getDevices,
|
getDevices,
|
||||||
@ -101,6 +113,7 @@ function DeviceService() {
|
|||||||
deleteDevice,
|
deleteDevice,
|
||||||
getRegistrationCode,
|
getRegistrationCode,
|
||||||
getIntegrations,
|
getIntegrations,
|
||||||
|
deleteIntegration,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import List from "../modules/list";
|
|||||||
import CreateDeviceModal from "../modals/create-device-modal";
|
import CreateDeviceModal from "../modals/create-device-modal";
|
||||||
import DeviceService from "../services/device-service";
|
import DeviceService from "../services/device-service";
|
||||||
import ShowRegistrationCodeModal from "../modals/show-registration-code-modal";
|
import ShowRegistrationCodeModal from "../modals/show-registration-code-modal";
|
||||||
|
import DeleteIntegrationModal from "../modals/delete-integration-modal";
|
||||||
|
|
||||||
function DevicesView(props) {
|
function DevicesView(props) {
|
||||||
const DEVICES_LIST_TYPE = "devices";
|
const DEVICES_LIST_TYPE = "devices";
|
||||||
@ -11,7 +12,9 @@ function DevicesView(props) {
|
|||||||
|
|
||||||
const [listType, setListType] = createSignal(DEVICES_LIST_TYPE);
|
const [listType, setListType] = createSignal(DEVICES_LIST_TYPE);
|
||||||
const [devices, setDevices] = createSignal([]);
|
const [devices, setDevices] = createSignal([]);
|
||||||
const [integrations] = createResource(DeviceService.getIntegrations);
|
const [integrations, { refetch: refetchIntegrations }] = createResource(
|
||||||
|
DeviceService.getIntegrations
|
||||||
|
);
|
||||||
|
|
||||||
CreateDeviceModal.onDeviceCreated(() => {
|
CreateDeviceModal.onDeviceCreated(() => {
|
||||||
handleRefreshDevices();
|
handleRefreshDevices();
|
||||||
@ -19,6 +22,9 @@ function DevicesView(props) {
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
handleRefreshDevices();
|
handleRefreshDevices();
|
||||||
|
DeleteIntegrationModal.onIntegrationDeleted(() => {
|
||||||
|
refetchIntegrations();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleNewDevice() {
|
function handleNewDevice() {
|
||||||
@ -29,11 +35,16 @@ function DevicesView(props) {
|
|||||||
let devices = await DeviceService.getDevices();
|
let devices = await DeviceService.getDevices();
|
||||||
setDevices(devices);
|
setDevices(devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRegisterIntegration() {
|
function handleRegisterIntegration() {
|
||||||
ShowRegistrationCodeModal.Handler.show();
|
ShowRegistrationCodeModal.Handler.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleDeleteIntegration(integration) {
|
||||||
|
DeleteIntegrationModal.setIntegration(integration);
|
||||||
|
DeleteIntegrationModal.Handler.show();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={
|
class={
|
||||||
@ -76,7 +87,10 @@ function DevicesView(props) {
|
|||||||
</button>
|
</button>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={listType() === INTEGRATION_LIST_TYPE}>
|
<Show when={listType() === INTEGRATION_LIST_TYPE}>
|
||||||
<button class="btn btn-dark me-2 mb-3" onClick={handleRegisterIntegration}>
|
<button
|
||||||
|
class="btn btn-dark me-2 mb-3"
|
||||||
|
onClick={handleRegisterIntegration}
|
||||||
|
>
|
||||||
<i class="bi bi-plus-square me-2"></i>
|
<i class="bi bi-plus-square me-2"></i>
|
||||||
Register
|
Register
|
||||||
</button>
|
</button>
|
||||||
@ -127,6 +141,18 @@ function DevicesView(props) {
|
|||||||
name: {
|
name: {
|
||||||
text: integration.getName(),
|
text: integration.getName(),
|
||||||
},
|
},
|
||||||
|
options: {
|
||||||
|
html: (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
class="btn btn-outline-secondary me-2"
|
||||||
|
onClick={() => handleDeleteIntegration(integration)}
|
||||||
|
>
|
||||||
|
<i class="bi bi-trash-fill"></i>
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
integration: integration,
|
integration: integration,
|
||||||
}))}
|
}))}
|
||||||
class={"flex-fill"}
|
class={"flex-fill"}
|
||||||
@ -140,6 +166,11 @@ function DevicesView(props) {
|
|||||||
id: "name",
|
id: "name",
|
||||||
name: "Name",
|
name: "Name",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "options",
|
||||||
|
name: "",
|
||||||
|
width: 4,
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
></List>
|
></List>
|
||||||
</Show>
|
</Show>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user