Skip to content

Commit

Permalink
more consistency and inlien editiing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Tilsch committed Feb 11, 2024
1 parent 41c0f0d commit ac7bd51
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 82 deletions.
65 changes: 30 additions & 35 deletions apps/exhibition-live/components/content/main/TypedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,42 @@ const WithPreviewForm = ({ classIRI, entityIRI, data, children }: Props) => {
[rightDrawerOpen, rightDrawerWidth],
);

return features?.enablePreview ? (
return (
<>
{previewEnabled ? (
<Grid
container
direction={isLandscape ? "column" : "row"}
wrap="nowrap"
sx={{ height: "100%" }}
>
<Grid item flex={1}>
{children}
</Grid>
<Grid
container
direction={isLandscape ? "column" : "row"}
wrap="nowrap"
sx={{ height: "100%" }}
>
<Grid item flex={1}>
{children}
</Grid>
{features?.enablePreview && previewEnabled && (
<Grid item flex={1}>
{
<EntityDetailElement
typeIRI={classIRI}
entityIRI={entityIRI}
data={data}
/>
}
<EntityDetailElement
typeIRI={classIRI}
entityIRI={entityIRI}
data={data}
/>
</Grid>
<Grid
item
sx={{
)}
<Grid
item
sx={{
width: rightBoxWidth,
flexShrink: 0,
"& .MuiDrawer-paper": {
width: rightBoxWidth,
flexShrink: 0,
"& .MuiDrawer-paper": {
width: rightBoxWidth,
// boxSizing: 'border-box',
},
}}
/>
</Grid>
) : (
children
)}
// boxSizing: 'border-box',
},
}}
/>
</Grid>
</>
) : (
<>{children}</>
);
};

export type MainFormProps = {
typeName: string;
entityIRI?: string;
Expand Down Expand Up @@ -135,7 +130,7 @@ const TypedForm = ({ typeName, entityIRI, classIRI }: MainFormProps) => {
return (
<WithPreviewForm data={data} classIRI={classIRI} entityIRI={entityIRI}>
{loadedSchema && (
<Box sx={{ p: 2.5, display: "flex" }}>
<Box sx={{ p: 2, display: "flex" }}>
<NewSemanticJsonForm
defaultEditMode={true}
data={data}
Expand Down
112 changes: 82 additions & 30 deletions apps/exhibition-live/components/form/show/EntityDetailCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import React, { FunctionComponent, useCallback } from "react";
import React, {
FunctionComponent,
useCallback,
useMemo,
useState,
} from "react";
import useExtendedSchema from "../../state/useExtendedSchema";
import { useCRUDWithQueryClient } from "../../state/useCRUDWithQueryClient";
import { useGlobalCRUDOptions } from "../../state/useGlobalCRUDOptions";
Expand All @@ -21,6 +26,10 @@ import { encodeIRI } from "../../utils/core";

import { typeIRItoTypeName } from "../../config";
import { useSettings } from "../../state/useLocalSettings";
import NewSemanticJsonForm from "../SemanticJsonForm";
import { JSONSchema7 } from "json-schema";
import { uischemas } from "../uischemas";
import { uischemata } from "../uischemaForType";

interface OwnProps {
typeIRI: string;
Expand All @@ -39,6 +48,7 @@ export const EntityDetailCard: FunctionComponent<Props> = ({
const { t } = useTranslation();

const router = useModifiedRouter();
const [editMode, setEditMode] = useState(false);
const editEntry = useCallback(() => {
const typeName = typeIRItoTypeName(typeIRI);
router.push(`/create/${typeName}?encID=${encodeIRI(entityIRI)}`);
Expand All @@ -47,38 +57,80 @@ export const EntityDetailCard: FunctionComponent<Props> = ({
features: { enableDebug },
} = useSettings();

const editInlineEntry = useCallback(() => {
setEditMode(true);
}, []);
const [formData, setFormData] = useState<any>(data);
const typeName = typeIRItoTypeName(typeIRI);
const loadedSchema = useExtendedSchema({ typeName, classIRI: typeIRI });
const { crudOptions } = useGlobalCRUDOptions();
const uischema = useMemo(
() => uischemata[typeName] || (uischemas as any)[typeName],
[typeName],
);

return (
<>
<Card>
<CardActionArea>
{cardInfo.image && (
<CardMedia
component="img"
sx={{ maxHeight: "24em", objectFit: "contain" }}
image={cardInfo.image}
alt={cardInfo.label}
/>
)}
<CardContent>
<Typography gutterBottom variant="h5" component="div">
{cardInfo.label}
</Typography>
<Typography variant="body2" color="text.secondary">
{cardInfo.description}
</Typography>
</CardContent>
</CardActionArea>
<CardActions>
<Button size="small" color="primary" onClick={editEntry}>
{t("edit")}
</Button>
</CardActions>
</Card>
<LobidAllPropTable allProps={data} />
{enableDebug && (
{editMode ? (
<NewSemanticJsonForm
data={formData}
onChange={setFormData}
entityIRI={data["@id"]}
typeIRI={typeIRI}
crudOptions={crudOptions}
defaultPrefix={defaultPrefix}
searchText={""}
shouldLoadInitially
jsonldContext={defaultJsonldContext}
schema={loadedSchema as JSONSchema7}
jsonFormsProps={{
uischema,
uischemas: uischemas,
}}
enableSidebar={false}
disableSimilarityFinder={true}
wrapWithinCard={true}
/>
) : (
<>
<JsonView data={cardInfo} shouldInitiallyExpand={(lvl) => lvl < 3} />
<JsonView data={data} shouldInitiallyExpand={(lvl) => lvl < 3} />
<Card>
<CardActionArea>
{cardInfo.image && (
<CardMedia
component="img"
sx={{ maxHeight: "24em", objectFit: "contain" }}
image={cardInfo.image}
alt={cardInfo.label}
/>
)}
<CardContent>
<Typography gutterBottom variant="h5" component="div">
{cardInfo.label}
</Typography>
<Typography variant="body2" color="text.secondary">
{cardInfo.description}
</Typography>
</CardContent>
</CardActionArea>
<CardActions>
<Button size="small" color="primary" onClick={editEntry}>
{t("edit")}
</Button>
<Button size="small" color="primary" onClick={editInlineEntry}>
{t("edit inline")}
</Button>
</CardActions>
</Card>
<LobidAllPropTable allProps={data} />
{enableDebug && (
<>
<JsonView
data={cardInfo}
shouldInitiallyExpand={(lvl) => lvl < 3}
/>
<JsonView data={data} shouldInitiallyExpand={(lvl) => lvl < 3} />
</>
)}
</>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const EntityDetailElement = ({
}, [typeName, data]);

return (
<Box sx={{ m: 2 }}>
<Box sx={{ p: 2 }}>
<EntityDetailCard
typeIRI={classIRI}
entityIRI={entityIRI}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { defaultJsonldContext, defaultPrefix } from "../form/formConfigs";
import get from "lodash/get";
import { TabIcon } from "../theme/icons";
import { useModifiedRouter } from "../basic";
import NiceModal from "@ebay/nice-modal-react";
import { EntityDetailModal } from "../form/show";

type SimpleExpandPanelRendererProps = {
data: any;
Expand Down Expand Up @@ -77,9 +79,7 @@ export const SimpleExpandPanelRenderer = (
return {};
}, [data, typeName, entityIRI]);
const [modalIsOpen, setModalIsOpen] = useState(false);
const handleToggle = useCallback(() => {
setModalIsOpen(!modalIsOpen);
}, [setModalIsOpen, modalIsOpen]);

const subSchema = useMemo(
() =>
bringDefinitionToTop(rootSchema as JSONSchema7, typeName) as JSONSchema7,
Expand Down Expand Up @@ -130,6 +130,10 @@ export const SimpleExpandPanelRenderer = (
const router = useModifiedRouter();
const locale = router.query.locale || "";

const showDetailModal = useCallback(() => {
NiceModal.show(EntityDetailModal, { typeIRI, entityIRI, data });
}, [typeIRI, entityIRI, data]);

return (
<ListItem
secondaryAction={
Expand All @@ -149,7 +153,7 @@ export const SimpleExpandPanelRenderer = (
</Stack>
}
>
<ListItemButton onClick={!draft ? handleToggle : undefined}>
<ListItemButton onClick={!draft ? showDetailModal : undefined}>
<ListItemAvatar>
<Avatar aria-label="Index" src={image}>
{count + 1}
Expand All @@ -162,18 +166,6 @@ export const SimpleExpandPanelRenderer = (
secondary={description}
/>
</ListItemButton>
{!draft && (
<SemanticFormsModal
schema={subSchema as JsonSchema}
entityIRI={entityIRI}
typeIRI={typeIRI}
label={realLabel}
open={modalIsOpen}
askClose={() => setModalIsOpen(false)}
askCancel={() => setModalIsOpen(false)}
onChange={onChange}
/>
)}
</ListItem>
);
};
1 change: 1 addition & 0 deletions apps/exhibition-live/public/locales/de/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"edit": "bearbeiten",
"edit inline": "Inline bearbeiten",
"cancel": "abbrechen",
"settings": "Einstellungen",
"search": "Suche",
Expand Down
1 change: 1 addition & 0 deletions apps/exhibition-live/public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"edit": "edit",
"edit inline": "edit inline",
"cancel": "cancel",
"settings": "settings",
"search": "search",
Expand Down

0 comments on commit ac7bd51

Please sign in to comment.