Skip to content

Commit

Permalink
feat: Show message when making metadata changes
Browse files Browse the repository at this point in the history
  • Loading branch information
steverydz committed Oct 15, 2024
1 parent a707cdb commit 2488b94
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
16 changes: 14 additions & 2 deletions static/js/publisher/listing/components/ListingForm/ListingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ function ListingForm({ data, refetch }: Props): JSX.Element {
const [showSuccessNotification, setShowSuccessNotification] =
useState<boolean>(false);

const [showUpdateMetadataMessage, setShowUpdateMetadataMessage] =
useState<boolean>(false);

const [updateMetadataOnRelease, setUpdateMetadataOnRelease] =
useState<boolean>(data.update_metadata_on_release);

const [showMetadataWarningModal, setShowMetadataWarningModal] =
useState<boolean>(false);

const [formValues, setFormValues] = useState<{ [key: string]: any } | null>(
null
null,
);

const { mutate, isLoading } = useMutateListingData({
Expand All @@ -64,11 +67,12 @@ function ListingForm({ data, refetch }: Props): JSX.Element {
setUpdateMetadataOnRelease,
shouldShowUpdateMetadataWarning,
snapName,
setShowUpdateMetadataMessage,
});

useEffect(() => {
const tourContainer = document.getElementById(
"tour-container"
"tour-container",
) as HTMLElement;

if (snapName) {
Expand Down Expand Up @@ -157,6 +161,14 @@ function ListingForm({ data, refetch }: Props): JSX.Element {
</Strip>
)}

{showUpdateMetadataMessage && (
<Strip shallow className="u-no-padding--bottom">
<Notification severity="information">
Metadata updates will be processed and applied shortly
</Notification>
</Strip>
)}

<Strip shallow>
<ListingDetails
data={data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe("useMutateListingData", () => {
setUpdateMetadataOnRelease: jest.fn(),
shouldShowUpdateMetadataWarning: jest.fn(),
snapName: "test-snap",
})
setShowUpdateMetadataMessage: jest.fn(),
}),
);
expect(ReactQuery.useMutation).toHaveBeenCalled();
});
Expand Down
10 changes: 9 additions & 1 deletion static/js/publisher/listing/hooks/useMutateListingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Options = {
setUpdateMetadataOnRelease: Function;
shouldShowUpdateMetadataWarning: Function;
snapName: string | undefined;
setShowUpdateMetadataMessage: Function;
};

function useMutateListingData({
Expand All @@ -26,6 +27,7 @@ function useMutateListingData({
setUpdateMetadataOnRelease,
shouldShowUpdateMetadataWarning,
snapName,
setShowUpdateMetadataMessage,
}: Options) {
return useMutation({
mutationFn: async (values: any) => {
Expand Down Expand Up @@ -53,7 +55,7 @@ function useMutateListingData({
formData.append("screenshots", newFile);

const imageIndex = changes.images.findIndex(
(image: any) => image.name === oldName
(image: any) => image.name === oldName,
);
changes.images[imageIndex].name = newFile.name;
changes.images[imageIndex].url = URL.createObjectURL(newFile);
Expand All @@ -75,6 +77,12 @@ function useMutateListingData({
if (!response.ok) {
throw new Error("There was a problem saving listing data");
}

const responseData = await response.json();

if (!responseData.data.text_fields_updated) {
setShowUpdateMetadataMessage(true);
}
},
onSuccess: async () => {
setShowSuccessNotification(true);
Expand Down
9 changes: 7 additions & 2 deletions webapp/publisher/snaps/listing_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def get_listing_snap(snap_name):

@login_required
def post_listing_data(snap_name):
res = {}
changes = None
changed_fields = flask.request.form.get("changes")

Expand Down Expand Up @@ -230,7 +231,11 @@ def post_listing_data(snap_name):
)

try:
publisher_api.snap_metadata(snap_id, flask.session, body_json)
response = publisher_api.snap_metadata(
snap_id, flask.session, body_json
)
res["success"] = True
res["data"] = response
except StoreApiResponseErrorList as api_response_error_list:
if api_response_error_list.status_code != 404:
error_list = error_list + api_response_error_list.errors
Expand Down Expand Up @@ -266,7 +271,7 @@ def post_listing_data(snap_name):

return flask.make_response(res, 200)

return flask.make_response({}, 200)
return flask.make_response(res, 200)


@login_required
Expand Down

0 comments on commit 2488b94

Please sign in to comment.