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

✨ Archetype form for Create and Edit #1343

Merged
merged 8 commits into from
Sep 12, 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 client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"newTag": "New Tag",
"newTagCategory": "New tag category",
"update": "Update {{what}}",
"updateArchetype": "Update archetype",
"updateApplication": "Update application",
"updateBusinessService": "Update business service",
"updateJobFunction": "Update job function",
Expand Down
7 changes: 5 additions & 2 deletions client/src/app/components/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

export interface IAutocompleteProps {
onChange: (selections: string[]) => void;
id?: string;
allowUserOptions?: boolean;
options?: string[];
placeholderText?: string;
Expand All @@ -27,6 +28,7 @@ export interface IAutocompleteProps {
}

export const Autocomplete: React.FC<IAutocompleteProps> = ({
id = "",
onChange,
options = [],
allowUserOptions = false,
Expand Down Expand Up @@ -258,6 +260,7 @@ export const Autocomplete: React.FC<IAutocompleteProps> = ({
const inputGroup = (
<div ref={searchInputRef}>
<SearchInput
id={id}
value={inputValue}
hint={hint}
onChange={handleInputChange}
Expand Down Expand Up @@ -285,7 +288,7 @@ export const Autocomplete: React.FC<IAutocompleteProps> = ({

return (
<Flex direction={{ default: "column" }}>
<FlexItem>
<FlexItem key="input">
<Popper
trigger={inputGroup}
triggerRef={searchInputRef}
Expand All @@ -296,7 +299,7 @@ export const Autocomplete: React.FC<IAutocompleteProps> = ({
onDocumentClick={handleClick}
/>
</FlexItem>
<FlexItem>
<FlexItem key="chips">
<Flex spaceItems={{ default: "spaceItemsXs" }}>
{Array.from(currentChips).map((currentChip) => (
<FlexItem key={currentChip}>
Expand Down
42 changes: 38 additions & 4 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import {
Expand All @@ -9,6 +9,7 @@ import {
EmptyStateFooter,
EmptyStateHeader,
EmptyStateIcon,
Modal,
PageSection,
PageSectionVariants,
Text,
Expand Down Expand Up @@ -46,6 +47,7 @@ import {

import ArchetypeApplicationsColumn from "./components/archetype-applications-column";
import ArchetypeDescriptionColumn from "./components/archetype-description-column";
import ArchetypeForm from "./components/archetype-form";
import ArchetypeMaintainersColumn from "./components/archetype-maintainers-column";
import ArchetypeTagsColumn from "./components/archetype-tags-column";
import { Archetype } from "@app/api/models";
Expand All @@ -58,6 +60,13 @@ const Archetypes: React.FC = () => {
const history = useHistory();
const { pushNotification } = React.useContext(NotificationsContext);

const [openCreateArchetype, setOpenCreateArchetype] =
useState<boolean>(false);

const [archetypeToEdit, setArchetypeToEdit] = useState<Archetype | null>(
null
);

const { archetypes, isFetching, error: fetchError } = useFetchArchetypes();

const onError = (error: AxiosError) => {
Expand Down Expand Up @@ -143,7 +152,7 @@ const Archetypes: React.FC = () => {
id="create-new-archetype"
aria-label="Create new archetype"
variant={ButtonVariant.primary}
onClick={() => {}} // TODO: Add create archetype modal
onClick={() => setOpenCreateArchetype(true)}
>
{t("dialog.title.newArchetype")}
</Button>
Expand Down Expand Up @@ -247,7 +256,7 @@ const Archetypes: React.FC = () => {
},
{
title: t("actions.edit"),
onClick: () => alert("TODO"),
onClick: () => setArchetypeToEdit(archetype),
},
{ isSeparator: true },
{
Expand All @@ -270,8 +279,33 @@ const Archetypes: React.FC = () => {
</ConditionalRender>
</PageSection>

{/* TODO: Add create/edit modal */}
{/* Create modal */}
<Modal
title={t("dialog.title.newArchetype")}
variant="medium"
isOpen={openCreateArchetype}
onClose={() => setOpenCreateArchetype(false)}
>
<ArchetypeForm onClose={() => setOpenCreateArchetype(false)} />
</Modal>

{/* Edit modal */}
<Modal
title={t("dialog.title.updateArchetype")}
variant="medium"
isOpen={!!archetypeToEdit}
onClose={() => setArchetypeToEdit(null)}
>
<ArchetypeForm
key={archetypeToEdit?.id ?? -1}
toEdit={archetypeToEdit}
onClose={() => setArchetypeToEdit(null)}
/>
</Modal>

{/* TODO: Add duplicate confirm modal */}

{/* Delete confirm modal */}
<ConfirmDialog
title={t("dialog.title.deleteWithName", {
what: t("terms.archetype").toLowerCase(),
Expand Down
Loading