mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 23:43:55 +01:00
Template Tag Function Editor (#67)

This commit is contained in:
24
src-web/hooks/useActiveEnvironmentVariables.ts
Normal file
24
src-web/hooks/useActiveEnvironmentVariables.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { EnvironmentVariable } from '@yaakapp/api';
|
||||
import { useMemo } from 'react';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
|
||||
export function useActiveEnvironmentVariables() {
|
||||
const workspace = useActiveWorkspace();
|
||||
const [environment] = useActiveEnvironment();
|
||||
|
||||
const variables = useMemo(() => {
|
||||
const varMap: Record<string, EnvironmentVariable> = {};
|
||||
|
||||
const allVariables = [...(workspace?.variables ?? []), ...(environment?.variables ?? [])];
|
||||
|
||||
for (const v of allVariables) {
|
||||
if (!v.enabled || !v.name) continue;
|
||||
varMap[v.name] = v;
|
||||
}
|
||||
|
||||
return Object.values(varMap);
|
||||
}, [workspace, environment]);
|
||||
|
||||
return variables;
|
||||
}
|
||||
Reference in New Issue
Block a user