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

WEB: Implement accout level secrets #331

Merged
merged 2 commits into from
Nov 19, 2024
Merged

Conversation

nxtcoder19
Copy link
Contributor

@nxtcoder19 nxtcoder19 commented Nov 19, 2024

Resloves #330

Summary by Sourcery

Implement account-level secret management by adding GraphQL queries and mutations for secret variables. Refactor router queries for better readability and enhance managed service settings with safer property access.

New Features:

  • Introduce account-level secret management with GraphQL queries and mutations for listing, creating, updating, and deleting secret variables.

Enhancements:

  • Refactor router queries to improve code readability and maintainability by reordering imports and simplifying mutation and query definitions.
  • Enhance managed service settings and logs by adding optional chaining to access nested properties safely.

Copy link

sourcery-ai bot commented Nov 19, 2024

Reviewer's Guide by Sourcery

This PR implements account-level secrets functionality by adding new GraphQL queries and mutations for secret variables management, along with corresponding UI components for creating, viewing, editing and deleting secret variables. The implementation includes a dedicated secrets page in account settings and detailed secret variable management views.

Class diagram for secret variable management

classDiagram
    class SecretVariable {
        +String id
        +String accountName
        +User createdBy
        +DateTime creationTime
        +String displayName
        +User lastUpdatedBy
        +Boolean markedForDeletion
        +String name
        +String recordVersion
        +Map stringData
        +DateTime updateTime
    }
    class User {
        +String userEmail
        +String userId
        +String userName
    }
    SecretVariable o-- User: createdBy
    SecretVariable o-- User: lastUpdatedBy
    class SecretVariableQueries {
        +listSecretVariables(pq: CursorPaginationIn, search: SearchSecretVariables)
        +createSecretVariable(secretVariable: SecretVariableIn)
        +getSecretVariable(name: String)
        +updateSecretVariable(secretVariable: SecretVariableIn)
        +deleteSecretVariable(name: String)
    }
    SecretVariableQueries --> SecretVariable: manages
Loading

File-Level Changes

Change Details Files
Added GraphQL queries and mutations for secret variables management
  • Added query for listing secret variables with pagination and search
  • Added mutation for creating new secret variables
  • Added query for getting individual secret variable details
  • Added mutation for updating secret variables
  • Added mutation for deleting secret variables
gql-queries-generator/doc/queries.graphql
Implemented secret variables management UI components
  • Created secret variable resource list view component
  • Added secret variable creation/edit dialog component
  • Implemented secret variable detail view with entry management
  • Added tools component for search and view mode controls
src/apps/console/routes/_main+/$account+/settings+/secrets-variables/secret-variable-resource.tsx
src/apps/console/routes/_main+/$account+/settings+/secrets-variables/handle-secret-variable.tsx
src/apps/console/routes/_main+/$account+/svar+/$secvar+/route.tsx
src/apps/console/routes/_main+/$account+/svar+/$secvar+/tools.tsx
Added secret variables section to account settings
  • Added 'Secrets & variables' navigation item to settings menu
  • Implemented main secrets listing page
  • Added secret variables API integration
src/apps/console/routes/_main+/$account+/settings+/_layout.tsx
src/apps/console/routes/_main+/$account+/settings+/secrets-variables/route.tsx
src/apps/console/server/gql/queries/secret-variables-queries.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @nxtcoder19 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

const [showHandleConfig, setShowHandleConfig] =
useState<IShowDialog<IModifiedItem>>(null);

const [originalItems, setOriginalItems] = useState<IConfigOrSecretData>({});
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider consolidating secret entry state management into a dedicated custom hook

The current implementation uses parallel state tracking that makes updates and change detection unnecessarily complex. Consider extracting this logic into a custom hook that provides a cleaner interface:

interface SecretEntry {
  value: string;
  status: 'unchanged' | 'modified' | 'added' | 'deleted';
}

function useSecretEntries(initialData: Record<string, string>) {
  const [entries, setEntries] = useState<Record<string, SecretEntry>>(() => 
    Object.entries(initialData).reduce((acc, [key, value]) => ({
      ...acc,
      [key]: { value, status: 'unchanged' }
    }), {})
  );

  const addEntry = (key: string, value: string) => 
    setEntries(prev => ({...prev, [key]: { value, status: 'added' }}));

  const updateEntry = (key: string, value: string) =>
    setEntries(prev => ({
      ...prev,
      [key]: { value, status: prev[key].status === 'added' ? 'added' : 'modified' }
    }));

  const deleteEntry = (key: string) =>
    setEntries(prev => {
      if (prev[key].status === 'added') {
        const { [key]: _, ...rest } = prev;
        return rest;
      }
      return { ...prev, [key]: { ...prev[key], status: 'deleted' }};
    });

  const hasChanges = () => Object.values(entries).some(e => e.status !== 'unchanged');

  const getModifiedData = () => 
    Object.entries(entries)
      .filter(([_, e]) => e.status !== 'deleted')
      .reduce((acc, [k, e]) => ({...acc, [k]: e.value}), {});

  return { entries, addEntry, updateEntry, deleteEntry, hasChanges, getModifiedData };
}

This simplifies the component by:

  1. Consolidating state management into a single source of truth
  2. Providing clear, intention-revealing methods for state updates
  3. Eliminating complex nested state transformations
  4. Making change tracking more explicit

The component can then focus on rendering and user interaction rather than state manipulation logic.

Comment on lines 294 to 299
if (isUpdate)
return getManagedTemplate({
templates,
apiVersion: props.data.spec?.msvcSpec.serviceTemplate.apiVersion || '',
kind: props.data.spec?.msvcSpec.serviceTemplate.kind || '',
apiVersion: props.data.spec?.msvcSpec.serviceTemplate?.apiVersion || '',
kind: props.data.spec?.msvcSpec.serviceTemplate?.kind || '',
});
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (isUpdate)
return getManagedTemplate({
templates,
apiVersion: props.data.spec?.msvcSpec.serviceTemplate.apiVersion || '',
kind: props.data.spec?.msvcSpec.serviceTemplate.kind || '',
apiVersion: props.data.spec?.msvcSpec.serviceTemplate?.apiVersion || '',
kind: props.data.spec?.msvcSpec.serviceTemplate?.kind || '',
});
if (isUpdate) {
return getManagedTemplate({
templates,
apiVersion: props.data.spec?.msvcSpec.serviceTemplate?.apiVersion || '',
kind: props.data.spec?.msvcSpec.serviceTemplate?.kind || '',
});
}


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

onClick(i);
setSelected(id);
},
pressed: !linkComponent ? selected === id : false,
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Invert ternary operator to remove negation (invert-ternary)

Suggested change
pressed: !linkComponent ? selected === id : false,
pressed: linkComponent ? false : selected === id,


ExplanationNegated conditions are more difficult to read than positive ones, so it is best
to avoid them where we can. By inverting the ternary condition and swapping the
expressions we can simplify the code.

Comment on lines +330 to +332
message: showSecret.data?.value.newvalue
? showSecret.data?.value.newvalue
: showSecret.data?.value.value,
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Avoid unneeded ternary statements (simplify-ternary)

Suggested change
message: showSecret.data?.value.newvalue
? showSecret.data?.value.newvalue
: showSecret.data?.value.value,
message: showSecret.data?.value.newvalue || showSecret.data?.value.value,


ExplanationIt is possible to simplify certain ternary statements into either use of an || or !.
This makes the code easier to read, since there is no conditional logic.

}
return {
...acc,
[key]: val.newvalue ? val.newvalue : val.value,
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Avoid unneeded ternary statements (simplify-ternary)

Suggested change
[key]: val.newvalue ? val.newvalue : val.value,
[key]: val.newvalue || val.value,


ExplanationIt is possible to simplify certain ternary statements into either use of an || or !.
This makes the code easier to read, since there is no conditional logic.

@nxtcoder19 nxtcoder19 merged commit ff8c477 into release-v1.1.1 Nov 19, 2024
5 checks passed
@nxtcoder19 nxtcoder19 deleted the impl/accounts-secrets branch November 19, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant