Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: env management commands #37

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

35C4n0r
Copy link

@35C4n0r 35C4n0r commented Nov 24, 2024

Closes #18
/claim #18

@gemanor
Copy link
Collaborator

gemanor commented Nov 25, 2024

@35C4n0r the lint has some errors..

@gemanor
Copy link
Collaborator

gemanor commented Nov 29, 2024

Hey, some functional comments:

  1. When running env select commands, and there's only one workspace or one project, it should skip the selection. For now, even if one project/environment is presented, it let's the user choose between them. Please ensure if there's only one element in a select step, it gets skipped.
  2. In copy command, it is hard to get the env id. We should keep it in the same way we did with other commands. Using the select element. Please use the same SelectEnvironment that allows the user to select the environment they want to copy from a select element. Then, just ask for the name of the new environment and copy it.
  3. In general, this ink-form makes things complex. The default should be copied to a new environment, and the form is just a wizard, the same as we do with other commands. Only in case that --existing argument is passed will the existing ID be asked for and copied.
  4. Also, in the member command, please just use a wizard as we did in the login and such. The form is making the experience complex. If someone want's a form, then they can use it in the UI.

@gemanor
Copy link
Collaborator

gemanor commented Nov 29, 2024

Please merge from main

@gemanor
Copy link
Collaborator

gemanor commented Dec 1, 2024

Hey, @35C4n0r, the copy command does not work for me. Can you please test that?

@35C4n0r
Copy link
Author

35C4n0r commented Dec 1, 2024

@gemanor, pushed a change that fixes the issue, It now handles the case when --env-name is not passed as a cli option

@gemanor
Copy link
Collaborator

gemanor commented Dec 1, 2024

@35C4n0r, the scope is redundnat (just use the default), and the description/strategy should be also in the wizard, not only as variables

@35C4n0r
Copy link
Author

35C4n0r commented Dec 1, 2024

@gemanor done!

@gemanor
Copy link
Collaborator

gemanor commented Dec 2, 2024

The tests are failing now. Also, the success message is missing from the copy command.
Please make sure it is all passed and that you're running sanity tests on all the commands before asking review.

@gemanor
Copy link
Collaborator

gemanor commented Dec 2, 2024

There are also many linting warning. Please ensure you're fixing the useEffect dependencies problems. Just use the standard practices like useCallback/useMemo and pure functions to avoid such.

@35C4n0r
Copy link
Author

35C4n0r commented Dec 2, 2024

@gemanor fixed the error

@35C4n0r
Copy link
Author

35C4n0r commented Dec 2, 2024

As for the warnings, if I don't want something to be the dependency of a useEffect, why should I add it in the dependency array?

@35C4n0r
Copy link
Author

35C4n0r commented Dec 2, 2024

@gemanor, fixed the warnings

Copy link
Collaborator

@gemanor gemanor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Appreciate the effort!

Please address the comments and attach a sanity test video for the following flows after addressing them)

  • Environment copy
    • To new one with a wizard
    • To a new one with variables provided (all provided, and partially provided - see CR)
    • To an existing environment that exists
    • To an existing environment that does not exist (fail)
  • Invite member
    • With organization-level key
    • With project-level key
    • With wrong key
    • With environment-level key
    • With provided project/environment variables (see CR)
    • With an email that is already a member
  • Environment select
    • With all optional values as variables
  • Login flow on Windows (you said something about the port?)

} from '../../components/EnvironmentSelection.js';
import SelectInput from 'ink-select-input';

export const options = zod.object({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure of the inputs needs to make true sense for consistent flow.

Here are the following variables that should be supported:

  • key(string) - API Key to be used for the environment copying (should be at least a project level key)
  • from(string) - Optional: set the environment ID to copy from. In case not set, the CLI lets you select one.
  • name(string) - Optional: The environment name to copy to. In case not set, the CLI will ask you for one.
  • description(string) - Optional: The new environment description. In case not set, the CLI will ask you for it.
  • to(string) - Optional: copy the environment to an existing environment. In case this variable is set, the 'name' and 'description' variables will be ignored'
  • conflictStrategy(enum | "fail" "overwrite") - Optional: Set the environment conflict strategy. In case not set, will use "fail"

The logic should be:

  • If all variables are provided (name/description or existing), just perform the copy
  • If any of the variables are provided, skip the step of configuring it
  • If the existing provided together with name/description, show an error
  • If the existing id is provided and it's not exist, show an error
  • Two steps now are redundant:
    • Choose existing environment (should be provided as variable, if not its mean the wizard should copy the new one)
    • Choose conflict strategy (default should be fail, if someone wants to change it, they need to pass it as a variable)

source/commands/env/copy.tsx Show resolved Hide resolved
// checks if the api_key scope >= project_level &
// sets the apiKey and sets the projectFrom

const validateApiKeyScope = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook should be external and be shared with other project-level commands such as select

source/commands/env/member.tsx Show resolved Hide resolved
}, [error, state]);

useEffect(() => {
if (apiKey && tokenType(apiKey) === TokenType.APIToken) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment in the previous component. This function should be an external hook as it's share logic between many components.

source/commands/login.tsx Show resolved Hide resolved
source/components/EnvironmentSelection.tsx Show resolved Hide resolved
source/components/EnvironmentSelection.tsx Show resolved Hide resolved
environment_id: string | null;
}

export const useApiKeyApi = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be use for all the API Key level errors etc.

@@ -0,0 +1,40 @@
import { apiCall } from '../lib/api.js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not being used anywhere

@gemanor
Copy link
Collaborator

gemanor commented Dec 11, 2024

@35C4n0r any updates on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permit Environment Management Commands
2 participants