adjust share command prompt (#2965)
* adjust share command prompt * use lower case "y" for console.ask, keep order consistent as "y" then "n" * share command update: do not suggest demo URL is mandatory, also move to the last question; when checking if user has permission to upsert package, do POST to record this package (if first time sharing) * clean up prompt for preview image
This commit is contained in:
parent
7e4668f5ca
commit
df5489807d
@ -564,7 +564,7 @@ def _ensure_dist_dir(version_to_publish: str, build: bool):
|
|||||||
needs_rebuild = (
|
needs_rebuild = (
|
||||||
console.ask(
|
console.ask(
|
||||||
"Distribution files for the version to be published already exist. Do you want to rebuild?",
|
"Distribution files for the version to be published already exist. Do you want to rebuild?",
|
||||||
choices=["n", "y"],
|
choices=["y", "n"],
|
||||||
default="n",
|
default="n",
|
||||||
)
|
)
|
||||||
== "y"
|
== "y"
|
||||||
@ -668,10 +668,10 @@ def publish(
|
|||||||
if validate_project_info and (
|
if validate_project_info and (
|
||||||
console.ask(
|
console.ask(
|
||||||
"Would you like to interactively review the package information?",
|
"Would you like to interactively review the package information?",
|
||||||
choices=["Y", "n"],
|
choices=["y", "n"],
|
||||||
default="Y",
|
default="y",
|
||||||
)
|
)
|
||||||
== "Y"
|
== "y"
|
||||||
):
|
):
|
||||||
_validate_project_info()
|
_validate_project_info()
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ def publish(
|
|||||||
if (
|
if (
|
||||||
console.ask(
|
console.ask(
|
||||||
"Would you like to include your published component on our gallery?",
|
"Would you like to include your published component on our gallery?",
|
||||||
choices=["n", "y"],
|
choices=["y", "n"],
|
||||||
default="y",
|
default="y",
|
||||||
)
|
)
|
||||||
== "n"
|
== "n"
|
||||||
@ -807,11 +807,6 @@ def _collect_details_for_gallery():
|
|||||||
"""
|
"""
|
||||||
from reflex.reflex import _login
|
from reflex.reflex import _login
|
||||||
|
|
||||||
console.print("We recommend that you deploy a demo app showcasing the component.")
|
|
||||||
console.print("If not already, please deploy it first.")
|
|
||||||
if console.ask("Continue?", choices=["y", "n"], default="y") != "y":
|
|
||||||
return
|
|
||||||
|
|
||||||
console.rule("[bold]Authentication with Reflex Services")
|
console.rule("[bold]Authentication with Reflex Services")
|
||||||
console.print("First let's log in to Reflex backend services.")
|
console.print("First let's log in to Reflex backend services.")
|
||||||
access_token = _login()
|
access_token = _login()
|
||||||
@ -829,47 +824,30 @@ def _collect_details_for_gallery():
|
|||||||
)
|
)
|
||||||
package_name = console.ask("[ Published python package name ]")
|
package_name = console.ask("[ Published python package name ]")
|
||||||
console.print(f"[ Custom component package name ] : {package_name}")
|
console.print(f"[ Custom component package name ] : {package_name}")
|
||||||
|
params["package_name"] = package_name
|
||||||
|
|
||||||
# Check the backend services if the user is allowed to update information of this package is already shared.
|
# Check the backend services if the user is allowed to update information of this package is already shared.
|
||||||
expected_status_code = False
|
|
||||||
try:
|
try:
|
||||||
console.debug(
|
console.debug(
|
||||||
f"Checking if user has permission to modify information for {package_name} if already exists."
|
f"Checking if user has permission to upsert information for {package_name} by POST."
|
||||||
)
|
)
|
||||||
response = httpx.get(
|
# Send a POST request to achieve two things at once:
|
||||||
f"{GET_CUSTOM_COMPONENTS_GALLERY_BY_NAME_ENDPOINT}/{package_name}",
|
# 1. Check if the package is already shared by the user. If not, the backend will return 403.
|
||||||
|
# 2. If this package is not shared before, this request records the package name in the backend.
|
||||||
|
response = httpx.post(
|
||||||
|
POST_CUSTOM_COMPONENTS_GALLERY_ENDPOINT,
|
||||||
headers={"Authorization": f"Bearer {access_token}"},
|
headers={"Authorization": f"Bearer {access_token}"},
|
||||||
|
data=params,
|
||||||
)
|
)
|
||||||
if response.status_code == httpx.codes.FORBIDDEN:
|
if response.status_code == httpx.codes.FORBIDDEN:
|
||||||
console.error(
|
console.error(
|
||||||
f"{package_name} is owned by another user. Unable to update the information for it."
|
f"{package_name} is owned by another user. Unable to update the information for it."
|
||||||
)
|
)
|
||||||
raise typer.Exit(code=1)
|
raise typer.Exit(code=1)
|
||||||
elif response.status_code == httpx.codes.NOT_FOUND:
|
|
||||||
console.debug(f"{package_name} is not found. This is a new share.")
|
|
||||||
expected_status_code = True
|
|
||||||
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
console.debug(f"{package_name} is found. This is an update.")
|
|
||||||
except httpx.HTTPError as he:
|
except httpx.HTTPError as he:
|
||||||
if not expected_status_code:
|
console.error(f"Unable to complete request due to {he}.")
|
||||||
console.error(f"Unable to complete request due to {he}.")
|
raise typer.Exit(code=1) from he
|
||||||
raise typer.Exit(code=1) from he
|
|
||||||
|
|
||||||
params["package_name"] = package_name
|
|
||||||
|
|
||||||
demo_url = None
|
|
||||||
while True:
|
|
||||||
demo_url = (
|
|
||||||
console.ask(
|
|
||||||
"[ Full URL of deployed demo app, e.g. `https://my-app.reflex.run` ] (enter to skip)"
|
|
||||||
)
|
|
||||||
or None
|
|
||||||
)
|
|
||||||
if _validate_url_with_protocol_prefix(demo_url):
|
|
||||||
break
|
|
||||||
if demo_url:
|
|
||||||
params["demo_url"] = demo_url
|
|
||||||
|
|
||||||
display_name = (
|
display_name = (
|
||||||
console.ask("[ Friendly display name for your component ] (enter to skip)")
|
console.ask("[ Friendly display name for your component ] (enter to skip)")
|
||||||
@ -884,6 +862,19 @@ def _collect_details_for_gallery():
|
|||||||
("files", (image_file_and_extension[1], image_file_and_extension[0]))
|
("files", (image_file_and_extension[1], image_file_and_extension[0]))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
demo_url = None
|
||||||
|
while True:
|
||||||
|
demo_url = (
|
||||||
|
console.ask(
|
||||||
|
"[ Full URL of deployed demo app, e.g. `https://my-app.reflex.run` ] (enter to skip)"
|
||||||
|
)
|
||||||
|
or None
|
||||||
|
)
|
||||||
|
if _validate_url_with_protocol_prefix(demo_url):
|
||||||
|
break
|
||||||
|
if demo_url:
|
||||||
|
params["demo_url"] = demo_url
|
||||||
|
|
||||||
# Now send the post request to Reflex backend services.
|
# Now send the post request to Reflex backend services.
|
||||||
try:
|
try:
|
||||||
console.debug(f"Sending custom component data: {params}")
|
console.debug(f"Sending custom component data: {params}")
|
||||||
@ -919,7 +910,7 @@ def _get_file_from_prompt_in_loop() -> Tuple[bytes, str] | None:
|
|||||||
image_file = file_extension = None
|
image_file = file_extension = None
|
||||||
while image_file is None:
|
while image_file is None:
|
||||||
image_filepath = console.ask(
|
image_filepath = console.ask(
|
||||||
f"Local path to a preview gif or image (enter to skip)"
|
f"Upload a preview image of your demo app (enter to skip)"
|
||||||
)
|
)
|
||||||
if not image_filepath:
|
if not image_filepath:
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user