Skip to content

Commit

Permalink
[Content | Schema] VQA Round 2 updates for the one-to-one/many revamp (
Browse files Browse the repository at this point in the history
  • Loading branch information
finnar-bin authored Feb 12, 2025
1 parent 1b4a85f commit 78cf4c8
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ export const Field = ({
relatedModelZUID={relatedModelZUID}
relatedFieldZUID={relatedFieldZUID}
onChange={onChange}
fieldLabel={fieldData?.label}
/>
{/**
<FieldTypeOneToOne
Expand Down Expand Up @@ -877,6 +878,7 @@ export const Field = ({
relatedModelZUID={relatedModelZUID}
relatedFieldZUID={relatedFieldZUID}
onChange={onChange}
fieldLabel={fieldData?.label}
/>
{/**
<FieldTypeOneToMany
Expand Down
5 changes: 5 additions & 0 deletions src/apps/content-editor/src/app/views/ItemEdit/ItemEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ import { FreestyleWrapper } from "./FreestyleWrapper";
import { Meta } from "./Meta";
import { FieldError } from "../../components/Editor/FieldError";
import { AIGeneratorProvider } from "../../../../../../shell/components/withAi/AIGeneratorProvider";
import {
fetchItemPublishings,
fetchItems,
} from "../../../../../../shell/store/content";

const selectItemHeadTags = createSelector(
(state) => state.headTags,
Expand Down Expand Up @@ -416,6 +420,7 @@ export default function ItemEdit() {
} finally {
if (isMounted.current) {
setSaving(false);
dispatch(fetchItemPublishings());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const ItemEditHeaderActions = ({
const [isConfirmPublishModalOpen, setIsConfirmPublishModalOpen] =
useState(false);
const [relatedItemsToPublish, setRelatedItemsToPublish] = useState<
ContentItem[]
ContentItemWithDirtyAndPublishing[]
>([]);
const [isPublishing, setIsPublishing] = useState(false);
const item = useSelector(
Expand Down Expand Up @@ -184,10 +184,11 @@ export const ItemEditHeaderActions = ({
if (!!item) {
const draftVersion = item?.meta?.version;
const publishedVersion = item?.publishing?.version || 0;
const scheduledVersion = item?.scheduling?.version || 0;

if (
draftVersion > publishedVersion &&
!item?.scheduling?.isScheduled
draftVersion > publishedVersion ||
scheduledVersion > publishedVersion
) {
return {
...item,
Expand Down Expand Up @@ -225,45 +226,60 @@ export const ItemEditHeaderActions = ({

const handlePublish = async () => {
setIsPublishing(true);
// If item is scheduled, delete the scheduled publishing first
if (itemState === ITEM_STATES.scheduled) {
await deleteItemPublishing({
modelZUID,
itemZUID,
publishingZUID: item?.scheduling?.ZUID,
});
}
try {
// Delete scheduled publishings first
const deleteScheduledPromises = [
// Delete main item's scheduled publishing if it exists
itemState === ITEM_STATES.scheduled &&
deleteItemPublishing({
modelZUID,
itemZUID,
publishingZUID: item?.scheduling?.ZUID,
}),
// Delete related items' scheduled publishings if they exist
...relatedItemsToPublish
.filter((item) => !!item.scheduling?.ZUID)
.map((item) =>
deleteItemPublishing({
modelZUID: item.meta.contentModelZUID,
itemZUID: item.meta.ZUID,
publishingZUID: item.scheduling.ZUID,
})
),
].filter((item) => !!item);

await Promise.all(deleteScheduledPromises);

Promise.allSettled([
createPublishing({
modelZUID,
itemZUID,
body: {
version: item?.meta.version,
publishAt: "now",
unpublishAt: "never",
},
}),
relatedItemsToPublish.map((item) => {
return createPublishing({
modelZUID: item.meta.contentModelZUID,
itemZUID: item.meta.ZUID,
// Proceed with publishing
await Promise.allSettled([
createPublishing({
modelZUID,
itemZUID,
body: {
version: item.meta.version,
version: item?.meta.version,
publishAt: "now",
unpublishAt: "never",
},
});
}),
])
.then(() => {
// Retain non rtk-query fetch of item publishing for legacy code
dispatch(fetchItemPublishings());
})
.finally(() => {
setIsPublishing(false);
setIsConfirmPublishModalOpen(false);
});
}),
...relatedItemsToPublish.map((item) =>
createPublishing({
modelZUID: item.meta.contentModelZUID,
itemZUID: item.meta.ZUID,
body: {
version: item.meta.version,
publishAt: "now",
unpublishAt: "never",
},
})
),
]);

// Retain non rtk-query fetch of item publishing for legacy code
dispatch(fetchItemPublishings());
} finally {
setIsPublishing(false);
setIsConfirmPublishModalOpen(false);
}
};

const handleUnpublish = async () => {
Expand Down Expand Up @@ -649,15 +665,15 @@ export const ItemEditHeaderActions = ({
<Typography variant="body2" fontWeight={600}>
Also publish related items
</Typography>
<Typography variant="body3">
<Typography variant="body3" color="text.secondary">
This will publish all items selected in the list below
</Typography>
<List disablePadding sx={{ mt: 1 }}>
{unpublishedRelatedItems.map((item, index) => (
<UnpublishedRelatedItem
key={item.meta.ZUID}
contentItem={item}
divider={unpublishedRelatedItems?.length > index + 1}
divider
selected={relatedItemsToPublish.some(
(i) => i.meta.ZUID === item.meta.ZUID
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type UnpublishedRelatedItemProps = {
contentItem: ContentItemWithRelatedZUIDs;
onChange: (payload: {
action: "add" | "remove";
contentItem: ContentItem;
contentItem: ContentItemWithDirtyAndPublishing;
}) => void;
selected: boolean;
divider?: boolean;
Expand Down Expand Up @@ -79,15 +79,27 @@ export const UnpublishedRelatedItem = ({

return (
<ListItem disableGutters dense divider={divider}>
<ListItemIcon>
<ListItemIcon
sx={{
minWidth: 0,
}}
>
<Checkbox
checked={selected}
disableRipple
onChange={(evt) =>
onChange({
contentItem,
action: evt.target.checked ? "add" : "remove",
})
}
sx={{
pl: 0,
pr: 2,
"&:hover": {
bgcolor: "transparent",
},
}}
/>
</ListItemIcon>
{!!imageFieldName &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type DefaultValueProps = {
};
options: FieldSettingsOptions[];
currency?: string;
fieldLabel: string;
};

export const DefaultValue = ({
Expand All @@ -41,6 +42,7 @@ export const DefaultValue = ({
relationshipFields,
options,
currency,
fieldLabel,
}: DefaultValueProps) => {
return (
<Box>
Expand Down Expand Up @@ -91,6 +93,7 @@ export const DefaultValue = ({
relationshipFields={relationshipFields}
options={options}
currency={currency}
fieldLabel={fieldLabel}
/>
<FormHelperText>
<Box display="flex" justifyContent="space-between">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type DefaultValueInputProps = {
};
options: FieldSettingsOptions[];
currency?: string;
fieldLabel: string;
};

export const DefaultValueInput = ({
Expand All @@ -67,6 +68,7 @@ export const DefaultValueInput = ({
relationshipFields: { relatedModelZUID, relatedFieldZUID },
options,
currency,
fieldLabel,
}: DefaultValueInputProps) => {
const [imageModal, setImageModal] = useState(null);
const dispatch = useDispatch();
Expand Down Expand Up @@ -308,6 +310,7 @@ export const DefaultValueInput = ({
relatedModelZUID={relatedModelZUID}
relatedFieldZUID={relatedFieldZUID}
onChange={(value) => onChange(value)}
fieldLabel={fieldLabel}
/>
);
case "one_to_many":
Expand All @@ -319,6 +322,7 @@ export const DefaultValueInput = ({
relatedModelZUID={relatedModelZUID}
relatedFieldZUID={relatedFieldZUID}
onChange={(value) => onChange(value)}
fieldLabel={fieldLabel}
/>
);
case "link":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const Rules = ({
}}
options={formData["options"] as FieldSettingsOptions[]}
currency={(formData["currency"] as string) || "USD"}
fieldLabel={formData["label"] as string}
/>

{type === "images" && (
Expand Down
6 changes: 1 addition & 5 deletions src/shell/components/ConfirmPublishModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from "@mui/material";
import CloudUploadRoundedIcon from "@mui/icons-material/CloudUploadRounded";
import { LoadingButton } from "@mui/lab";
import pluralizeWord from "../../utility/pluralizeWord";

export type ConfirmPublishModal = {
contentTitle: string;
Expand Down Expand Up @@ -90,10 +89,7 @@ export const ConfirmPublishModal = ({
onClick={onConfirm}
data-cy="ConfirmPublishButton"
>
Publish{" "}
{!!altText
? pluralizeWord(altText, relatedItemsToPublishCount)
: pluralizeWord("Item", relatedItemsToPublishCount)}{" "}
Publish {altText || !!relatedItemsToPublishCount ? "Items " : "Item "}
{!!relatedItemsToPublishCount &&
`(${relatedItemsToPublishCount + 1})`}
</LoadingButton>
Expand Down
4 changes: 3 additions & 1 deletion src/shell/components/NoSearchResults/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Props = {
hideBackButton?: boolean;
onSearchAgain?: () => void;
imageHeight?: number;
isFilter?: boolean;
};

export const NoSearchResults: FC<Props> = ({
Expand All @@ -26,6 +27,7 @@ export const NoSearchResults: FC<Props> = ({
ignoreFilters,
hideBackButton,
imageHeight = 200,
isFilter,
}) => {
const history = useHistory();
const [params, setParams] = useParams();
Expand Down Expand Up @@ -68,7 +70,7 @@ export const NoSearchResults: FC<Props> = ({
"No results that matched your filters could be found"
) : (
<>
Your search
Your {isFilter ? "filter" : "search"}
<Box component="strong" fontWeight="bold">
{" "}
"{query}"{" "}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ActiveItemLoading = ({ draggable }: ActiveItemLoadingProps) => {
direction="row"
sx={{
bgcolor: "background.paper",
height: 64,
height: 62,
width: "100%",
border: 1,
borderColor: "border",
Expand All @@ -20,7 +20,7 @@ export const ActiveItemLoading = ({ draggable }: ActiveItemLoadingProps) => {
>
<Stack direction="row" alignItems="center" flexGrow={1}>
{draggable && (
<IconButton size="xsmall" sx={{ cursor: "grab", mx: 0.5 }} disabled>
<IconButton size="xsmall" sx={{ cursor: "grab", mx: 0.25 }} disabled>
<DragIndicatorRounded fontSize="small" />
</IconButton>
)}
Expand Down
Loading

0 comments on commit 78cf4c8

Please sign in to comment.