-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
Reviewer's Guide by SourceryThis 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 managementclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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
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>({}); |
There was a problem hiding this comment.
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:
- Consolidating state management into a single source of truth
- Providing clear, intention-revealing methods for state updates
- Eliminating complex nested state transformations
- Making change tracking more explicit
The component can then focus on rendering and user interaction rather than state manipulation logic.
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 || '', | ||
}); |
There was a problem hiding this comment.
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
)
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 || '', | |
}); | |
} | |
Explanation
It 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, |
There was a problem hiding this comment.
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
)
pressed: !linkComponent ? selected === id : false, | |
pressed: linkComponent ? false : selected === id, |
Explanation
Negated conditions are more difficult to read than positive ones, so it is bestto avoid them where we can. By inverting the ternary condition and swapping the
expressions we can simplify the code.
message: showSecret.data?.value.newvalue | ||
? showSecret.data?.value.newvalue | ||
: showSecret.data?.value.value, |
There was a problem hiding this comment.
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
)
message: showSecret.data?.value.newvalue | |
? showSecret.data?.value.newvalue | |
: showSecret.data?.value.value, | |
message: showSecret.data?.value.newvalue || showSecret.data?.value.value, | |
Explanation
It 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, |
There was a problem hiding this comment.
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
)
[key]: val.newvalue ? val.newvalue : val.value, | |
[key]: val.newvalue || val.value, |
Explanation
It 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.
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:
Enhancements: