Skip to content

Commit

Permalink
Added edit options for services
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Sep 3, 2022
1 parent 66a69fd commit 0a224aa
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
21 changes: 21 additions & 0 deletions ui/src/recoil/atoms/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ export const services = atom({
effects_UNSTABLE: [persistAtom],
});

export const servicesFilter = selectorFamily({
key: "service/default",
get:
(id: string) =>
({ get }) => {
const servs = get(services);
return servs.find((x: Service) => x.id === id);
},
set:
(id: string) =>
({ get, set }, newValue) => {
const servs: any = get(services);
const servInd = servs.findIndex((x: Service) => x.id === id);

var cp = [...servs];
cp[servInd] = { ...cp[servInd], ...newValue };

return set(services, cp);
},
});

export const servicesList = selector({
key: "servicesListSelector",
get: ({ get }) => get(services),
Expand Down
2 changes: 1 addition & 1 deletion ui/src/routes/profiles/ProfilesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const EditProfile = ({ profile }: { profile: Profile }) => {
// Create the form with the default values as they currently are
const content = (
<SimpleForm
create={true}
create={false}
defaultValues={profile}
errors={profileFormFieldErrors}
onSubmit={onSubmit}
Expand Down
3 changes: 2 additions & 1 deletion ui/src/routes/services/ServiceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export const ServiceFormFields = [
},
{
name: "network",
help: "Network layer protocol",
readOnly: true,
type: "select",
help: "Network layer protocol",
fieldattrs: {
options: NetworkOptions,
},
Expand Down
45 changes: 43 additions & 2 deletions ui/src/routes/services/ServicesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
import {
Address,
DeleteDropdownItem,
EditDropdownItem,
InteractionBadge,
NetworkBadge,
OptionsDropdown,
} from "../../components/utils/Common";
import { getPage } from "../../constants/globals";
import Table from "../../components/table/Table";
import { services, Service } from "../../recoil/atoms/services";
import { useRecoilState, useRecoilValue } from "recoil";
import {
services,
Service,
serviceFormFieldErrors,
servicesFilter,
} from "../../recoil/atoms/services";
import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil";
import { removeFromList } from "../../recoil/atoms/common";
import { ServiceFormFields } from "./ServiceForm";
import { SimpleForm } from "../../components/forms/Form";

const EditService = ({ service }: { service: Service }) => {
const pageName = "Services";

// Get the page to set the icon
const page = getPage(pageName);

// Get the current values of the profile
const setter = useSetRecoilState(servicesFilter(service.id));

// Create a setter for the submit
const onSubmit = (newElement: any) => {
setter(newElement);
};

// Create the form with the default values as they currently are
const content = (
<SimpleForm
create={false}
defaultValues={service}
errors={serviceFormFieldErrors}
onSubmit={onSubmit}
page={pageName}
fields={ServiceFormFields}
/>
);

// Get the form with the update tag
return (
<EditDropdownItem form={content} icon={page?.icon} title={"profile"} />
);
};

const ServiceRowOptions = ({ service }: { service: Service }) => {
// Services
Expand All @@ -24,6 +64,7 @@ const ServiceRowOptions = ({ service }: { service: Service }) => {

return (
<OptionsDropdown>
<EditService service={service} />
{page && (
<DeleteDropdownItem
page={page}
Expand Down

0 comments on commit 0a224aa

Please sign in to comment.