Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("useMutateListingData", () => {
setUpdateMetadataOnRelease: jest.fn(),
shouldShowUpdateMetadataWarning: jest.fn(),
snapName: "test-snap",
setShowUpdateMetadataMessage: jest.fn(),
}),
);
expect(ReactQuery.useMutation).toHaveBeenCalled();
Expand Down
8 changes: 8 additions & 0 deletions static/js/publisher-pages/hooks/useMutateListingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Options = {
setUpdateMetadataOnRelease: Dispatch<SetStateAction<boolean>>;
shouldShowUpdateMetadataWarning: (arg: FieldValues) => boolean;
snapName: string | undefined;
setShowUpdateMetadataMessage: Dispatch<SetStateAction<boolean>>;
};

function useMutateListingData({
Expand All @@ -27,6 +28,7 @@ function useMutateListingData({
setUpdateMetadataOnRelease,
shouldShowUpdateMetadataWarning,
snapName,
setShowUpdateMetadataMessage,
}: Options) {
return useMutation({
mutationFn: async (values: FieldValues) => {
Expand Down Expand Up @@ -83,6 +85,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: () => {
const mainPanel = document.querySelector(".l-main") as HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ 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);

Expand All @@ -68,6 +71,7 @@ function ListingForm({ data, refetch }: Props): JSX.Element {
setUpdateMetadataOnRelease,
shouldShowUpdateMetadataWarning,
snapName: snapId,
setShowUpdateMetadataMessage,
});

return (
Expand Down Expand Up @@ -140,6 +144,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
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
Loading