Display fetched data in environment variables tab panel (#26)

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
prathamesh0 2024-01-19 12:05:06 +05:30 committed by Ashwin Phatak
parent d2d26885ce
commit 63b7f4e7de
3 changed files with 18 additions and 3 deletions

View File

@ -13,9 +13,9 @@ import {
import AddEnvironmentVariableRow from './AddEnvironmentVariableRow'; import AddEnvironmentVariableRow from './AddEnvironmentVariableRow';
import DisplayEnvironmentVariables from './DisplayEnvironmentVariables'; import DisplayEnvironmentVariables from './DisplayEnvironmentVariables';
import environmentVariablesData from '../../../../assets/environment-variables.json';
import { EnvironmentVariable, Environments } from '../../../../types/project'; import { EnvironmentVariable, Environments } from '../../../../types/project';
import HorizontalLine from '../../../HorizontalLine'; import HorizontalLine from '../../../HorizontalLine';
import { useOutletContext, useParams } from 'react-router-dom';
export type EnvironmentVariablesFormValues = { export type EnvironmentVariablesFormValues = {
variables: { variables: {
@ -30,6 +30,15 @@ export type EnvironmentVariablesFormValues = {
}; };
export const EnvironmentVariablesTabPanel = () => { export const EnvironmentVariablesTabPanel = () => {
const { id } = useParams();
// @ts-expect-error create context type for projects
const { projects } = useOutletContext();
const currProject = useMemo(() => {
return projects.find((data: any) => Number(data.id) === Number(id));
}, [id]);
const { const {
handleSubmit, handleSubmit,
register, register,
@ -63,8 +72,8 @@ export const EnvironmentVariablesTabPanel = () => {
}, [isSubmitSuccessful, reset]); }, [isSubmitSuccessful, reset]);
const getEnvironmentVariable = useCallback((environment: Environments) => { const getEnvironmentVariable = useCallback((environment: Environments) => {
return (environmentVariablesData as EnvironmentVariable[]).filter((item) => return (currProject.environmentVariables as EnvironmentVariable[]).filter(
item.environments.includes(environment), (item) => item.environments.includes(environment),
); );
}, []); }, []);

View File

@ -18,6 +18,7 @@ export interface ProjectDetails {
repositoryId: number; repositoryId: number;
members: MemberPermission[]; members: MemberPermission[];
ownerId: number; ownerId: number;
environmentVariables: EnvironmentVariable[];
} }
export interface MemberPermission { export interface MemberPermission {

View File

@ -44,6 +44,11 @@ query {
} }
environmentVariables { environmentVariables {
id id
environments
key
value
createdAt
updatedAt
} }
createdAt createdAt
updatedAt updatedAt