Skip to content

Commit

Permalink
#118 - Delete isActive-Flag on variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Giek committed Jan 17, 2025
1 parent f9310d8 commit 5f2963f
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 46 deletions.
20 changes: 3 additions & 17 deletions src/main/environment/service/environment-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class EnvironmentService implements Initializable {
if (variable !== undefined) {
variable.value = value;
} else {
this.currentCollection.variables[key] = { key, value, isActive: true };
this.currentCollection.variables[key] = { key, value };
}
}

Expand All @@ -59,18 +59,6 @@ export class EnvironmentService implements Initializable {
this.currentCollection.variables = {};
variables.forEach((variable) => (this.currentCollection.variables[variable.key] = variable));
}

/**
* Enables or disables a variable in the current collection.
*
* @param key The key of the variable.
* @param enabled Whether the variable should be enabled or disabled.
*/
public setCollectionVariableEnabled(key: string, enabled: boolean) {
const variable = this.currentCollection.variables[key];
if (variable !== undefined) variable.isActive = enabled;
}

/**
* Changes the current collection to the one at the specified path.
*
Expand All @@ -84,10 +72,8 @@ export class EnvironmentService implements Initializable {
* Returns all active variables in the current collection. This also includes system
* variables.
*/
public getActiveVariables() {
return Object.values(this.currentCollection.variables)
.filter((variable) => variable.isActive)
.concat(getSystemVariables());
public getVariables() {
return Object.values(this.currentCollection.variables).concat(getSystemVariables());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/event/main-event-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class MainEventService implements IEventService {
}

async getActiveEnvironmentVariables() {
return environmentService.getActiveVariables();
return environmentService.getVariables();
}

async getVariable(key: string) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/persistence/service/default-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ export function generateDefaultCollection(dirPath: string): Collection {
[
{
key: 'variable1',
isActive: true,
value: 'value-1',
},
{
key: 'variable2',
isActive: true,
value: 'value2',
},
].map((variable) => [variable.key, variable])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Divider } from '@/components/shared/Divider';
import { Button } from '@/components/ui/button';
import { AddIcon, CheckedIcon, DeleteIcon } from '@/components/icons';
import { AddIcon, DeleteIcon } from '@/components/icons';
import {
Table,
TableBody,
Expand All @@ -9,7 +9,6 @@ import {
TableHeader,
TableRow,
} from '@/components/ui/table';
import { cn } from '@/lib/utils';
import { useVariableStore } from '@/state/variableStore';

export const VariableTab = () => {
Expand Down Expand Up @@ -78,24 +77,6 @@ export const VariableTab = () => {
</TableCell>
<TableCell className="w-16 text-right">
<div className="flex items-center justify-center gap-2">
<div className="relative h-4 z-10 cursor-pointer">
<input
type="checkbox"
checked={variable.isActive}
onChange={(e) => update(index, e.target.checked, 'isActive')}
className={cn(
'form-checkbox h-4 w-4 appearance-none border rounded-[2px]',
variable.isActive
? 'border-[rgba(107,194,224,1)] bg-[rgba(25,54,65,1)]'
: 'border-[rgba(238,238,238,1)] bg-transparent'
)}
/>
{variable.isActive && (
<div className="absolute left-0 top-0 h-4 w-4 flex items-center justify-center pointer-events-none rotate-6">
<CheckedIcon size={16} viewBox="0 0 16 16" color="rgba(107,194,224,1)" />
</div>
)}
</div>
<Button
variant="ghost"
size="icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const completionItemsProvider = new TemplateVariableCompletionItemsProvider();
describe('TemplateVariableCompletionItemsProvider', () => {
// Arrange
const variables: VariableObject[] = [
{ key: 'variable', value: '123', isActive: true },
{ key: '$randomUuid', description: 'Description 2', value: '321', isActive: true },
{ key: 'variable', value: '123' },
{ key: '$randomUuid', description: 'Description 2', value: '321' },
];
jest
.mocked(RendererEventService.instance.getActiveEnvironmentVariables)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/state/variableStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useVariableStore = create<VariableState & VariableStateAction>()(
},
addNewVariable: () => {
set((state) => {
state.variables.push({ key: '', value: '', description: '', isActive: false });
state.variables.push({ key: '', value: '', description: '' });
});
},
deleteVariable: (index: number) => {
Expand Down
3 changes: 0 additions & 3 deletions src/shim/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export type VariableObject = {
/** The value of the variable. Might change on each call for dynamic variables */
value: string;

/** Whether the variable is active. */
isActive: boolean;

/** A description of the variable. */
description?: string;
};

0 comments on commit 5f2963f

Please sign in to comment.