mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 21:53:36 +01:00
26 lines
915 B
TypeScript
26 lines
915 B
TypeScript
import type { EnvironmentVariable } from '@yaakapp-internal/models';
|
|
import { environmentsAtom } from '@yaakapp-internal/models';
|
|
import { useAtomValue } from 'jotai';
|
|
import { useMemo } from 'react';
|
|
import { useEnvironmentsBreakdown } from './useEnvironmentsBreakdown';
|
|
|
|
export function useEnvironmentVariables(environmentId: string | null) {
|
|
const { baseEnvironment } = useEnvironmentsBreakdown();
|
|
const activeEnvironment =
|
|
useAtomValue(environmentsAtom).find((e) => e.id === environmentId) ?? null;
|
|
return useMemo(() => {
|
|
const varMap: Record<string, EnvironmentVariable> = {};
|
|
const allVariables = [
|
|
...(baseEnvironment?.variables ?? []),
|
|
...(activeEnvironment?.variables ?? []),
|
|
];
|
|
|
|
for (const v of allVariables) {
|
|
if (!v.enabled || !v.name) continue;
|
|
varMap[v.name] = v;
|
|
}
|
|
|
|
return Object.values(varMap);
|
|
}, [activeEnvironment, baseEnvironment]);
|
|
}
|