Skip to content

Commit

Permalink
feat: fixed test cases and added multiple variable formats
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarRajput-7 committed Dec 26, 2024
1 parent f2bb467 commit 1ee2cc7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ describe('VariableItem', () => {
onValueUpdate={mockOnValueUpdate}
variablesToGetUpdated={[]}
setVariablesToGetUpdated={(): void => {}}
dependencyData={{
order: [],
graph: {},
parentDependencyGraph: {},
}}
/>
</MockQueryClientProvider>,
);
Expand All @@ -65,6 +70,11 @@ describe('VariableItem', () => {
onValueUpdate={mockOnValueUpdate}
variablesToGetUpdated={[]}
setVariablesToGetUpdated={(): void => {}}
dependencyData={{
order: [],
graph: {},
parentDependencyGraph: {},
}}
/>
</MockQueryClientProvider>,
);
Expand All @@ -80,6 +90,11 @@ describe('VariableItem', () => {
onValueUpdate={mockOnValueUpdate}
variablesToGetUpdated={[]}
setVariablesToGetUpdated={(): void => {}}
dependencyData={{
order: [],
graph: {},
parentDependencyGraph: {},
}}
/>
</MockQueryClientProvider>,
);
Expand Down Expand Up @@ -109,6 +124,11 @@ describe('VariableItem', () => {
onValueUpdate={mockOnValueUpdate}
variablesToGetUpdated={[]}
setVariablesToGetUpdated={(): void => {}}
dependencyData={{
order: [],
graph: {},
parentDependencyGraph: {},
}}
/>
</MockQueryClientProvider>,
);
Expand All @@ -133,6 +153,11 @@ describe('VariableItem', () => {
onValueUpdate={mockOnValueUpdate}
variablesToGetUpdated={[]}
setVariablesToGetUpdated={(): void => {}}
dependencyData={{
order: [],
graph: {},
parentDependencyGraph: {},
}}
/>
</MockQueryClientProvider>,
);
Expand All @@ -149,6 +174,11 @@ describe('VariableItem', () => {
onValueUpdate={mockOnValueUpdate}
variablesToGetUpdated={[]}
setVariablesToGetUpdated={(): void => {}}
dependencyData={{
order: [],
graph: {},
parentDependencyGraph: {},
}}
/>
</MockQueryClientProvider>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('dashboardVariables - utilities and processors', () => {
it('should return true when parentDependencyGraph is empty', () => {
expect(
checkAPIInvocation(variablesToGetUpdated, variableData, {}),
).toBeTruthy();
).toBeFalsy();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ export const convertVariablesToDbFormat = (
}, {});

const getDependentVariables = (queryValue: string): string[] => {
const variableRegexPattern = /\{\{\s*?\.([^\s}]+)\s*?\}\}/g;
// Combined pattern for all formats:
// {{.variable_name}} - original format
// $variable_name - dollar prefix format
// [[variable_name]] - square bracket format
// {{variable_name}} - without dot format
const variableRegexPattern = /(?:\{\{\s*\.?([^\s}]+)\s*\}\}|\$([^\s\W]+)|\[\[([^\]]+)\]\])/g;

const matches = queryValue.match(variableRegexPattern);

// Extract variable names from the matches array without {{ . }}
// Extract variable names from the matches array, handling all formats
return matches
? matches.map((match) => match.replace(variableRegexPattern, '$1'))
? matches.map((match) => {
if (match.startsWith('$')) {
return match.slice(1); // Remove $ prefix
}
if (match.startsWith('[[')) {
return match.slice(2, -2); // Remove [[ and ]]
}
// Handle both {{.var}} and {{var}} formats
return match.replace(/\{\{\s*\.?([^\s}]+)\s*\}\}/, '$1');
})
: [];
};
export type VariableGraph = Record<string, string[]>;
Expand Down

0 comments on commit 1ee2cc7

Please sign in to comment.