Skip to content

Schema: Wire add field at end of model #1743

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

Merged
merged 1 commit into from
Jan 19, 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
6 changes: 5 additions & 1 deletion src/apps/schema/src/appRevamp/components/FieldList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ type Params = {
id: string;
};

export const FieldList = () => {
interface Props {
onNewFieldModalClick: () => void;
}
export const FieldList = ({ onNewFieldModalClick }: Props) => {
const params = useParams<Params>();
const { id } = params;
const [search, setSearch] = useState("");
Expand Down Expand Up @@ -175,6 +178,7 @@ export const FieldList = () => {
variant="outlined"
startIcon={<AddRoundedIcon />}
fullWidth
onClick={onNewFieldModalClick}
>
Add Another Field to {model?.label}
</Button>
Expand Down
13 changes: 5 additions & 8 deletions src/apps/schema/src/appRevamp/components/ModelHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import moment from "moment";
import SplitscreenRoundedIcon from "@mui/icons-material/SplitscreenRounded";
import RemoveRedEyeRoundedIcon from "@mui/icons-material/RemoveRedEyeRounded";

import { AddFieldModal } from "../AddFieldModal";

type Params = {
id: string;
};
Expand All @@ -23,8 +21,10 @@ const modelTypeName = {
dataset: "Headless Data Item",
};

export const ModelHeader = () => {
const [isAddFieldModalOpen, setAddFieldModalOpen] = useState(false);
interface Props {
onNewFieldModalClick: () => void;
}
export const ModelHeader = ({ onNewFieldModalClick }: Props) => {
const params = useParams<Params>();
const { id } = params;
const { data: models } = useGetContentModelsQuery();
Expand Down Expand Up @@ -58,7 +58,7 @@ export const ModelHeader = () => {
size="small"
variant="contained"
startIcon={<AddRoundedIcon />}
onClick={() => setAddFieldModalOpen(true)}
onClick={onNewFieldModalClick}
disabled={!isFieldsLoaded}
>
Add Field
Expand Down Expand Up @@ -103,9 +103,6 @@ export const ModelHeader = () => {
</Tabs>
</Box>
</Box>
{isAddFieldModalOpen && (
<AddFieldModal mode="fields_list" onModalClose={setAddFieldModalOpen} />
)}
</>
);
};
17 changes: 15 additions & 2 deletions src/apps/schema/src/appRevamp/views/Model.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
import { Box } from "@mui/material";
import { Redirect, Route, Switch, useParams, useHistory } from "react-router";
import { useGetContentModelsQuery } from "../../../../../shell/services/instance";
Expand All @@ -9,15 +10,24 @@ type Params = {
id: string;
};
export const Model = () => {
const [isAddFieldModalOpen, setAddFieldModalOpen] = useState(false);
const history = useHistory();
const params = useParams<Params>();
const { id } = params;

return (
<Box flex="1" display="flex" height="100%" flexDirection="column">
<ModelHeader />
<ModelHeader onNewFieldModalClick={() => setAddFieldModalOpen(true)} />
<Switch>
<Route exact path="/schema/:id/fields" render={() => <FieldList />} />
<Route
exact
path="/schema/:id/fields"
render={() => (
<FieldList
onNewFieldModalClick={() => setAddFieldModalOpen(true)}
/>
)}
/>
<Route
exact
path="/schema/:id/fields/:fieldId"
Expand All @@ -35,6 +45,9 @@ export const Model = () => {
/>
<Redirect to="/schema/:id/fields" />
</Switch>
{isAddFieldModalOpen && (
<AddFieldModal mode="fields_list" onModalClose={setAddFieldModalOpen} />
)}
</Box>
);
};