# Introduction closes https://github.com/twentyhq/core-team-issues/issues/591 Same than for `twenty-shared` made in https://github.com/twentyhq/twenty/pull/11083. ## TODO - [x] Manual migrate twenty-website twenty-ui imports ## What's next: - Generate barrel and migration script factorization within own package + tests - Refactoring using preconstruct ? TimeBox - Lint circular dependencies - Lint import from barrel and forbid them ### Preconstruct We need custom rollup plugins addition, but preconstruct does not expose its rollup configuration. It might be possible to handle this using the babel overrides. But was a big tunnel. We could give it a try afterwards ! ( allowing cjs interop and stuff like that ) Stuck to vite lib app Closed related PRs: - https://github.com/twentyhq/twenty/pull/11294 - https://github.com/twentyhq/twenty/pull/11203
137 lines
4.1 KiB
TypeScript
137 lines
4.1 KiB
TypeScript
import { EnvironmentVariable } from '@/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTabEnvironmentVariablesSection';
|
|
import { TextInputV2 } from '@/ui/input/components/TextInputV2';
|
|
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
|
|
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
|
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
|
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
|
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
|
import styled from '@emotion/styled';
|
|
import { useState } from 'react';
|
|
import {
|
|
IconCheck,
|
|
IconDotsVertical,
|
|
IconPencil,
|
|
IconTrash,
|
|
IconX,
|
|
OverflowingTextWithTooltip,
|
|
} from 'twenty-ui/display';
|
|
import { LightIconButton } from 'twenty-ui/input';
|
|
import { MenuItem } from 'twenty-ui/navigation';
|
|
|
|
const StyledEditModeTableRow = styled(TableRow)`
|
|
grid-template-columns: 180px auto 56px;
|
|
`;
|
|
|
|
const StyledTableRow = styled(TableRow)`
|
|
grid-template-columns: 180px 300px 32px;
|
|
`;
|
|
|
|
export const SettingsServerlessFunctionTabEnvironmentVariableTableRow = ({
|
|
envVariable,
|
|
onChange,
|
|
onDelete,
|
|
initialEditMode = false,
|
|
}: {
|
|
envVariable: EnvironmentVariable;
|
|
onChange: (newEnvVariable: EnvironmentVariable) => void;
|
|
onDelete: () => void;
|
|
initialEditMode?: boolean;
|
|
}) => {
|
|
const [editedEnvVariable, setEditedEnvVariable] = useState(envVariable);
|
|
const [editMode, setEditMode] = useState(initialEditMode);
|
|
const dropDownId = `settings-environment-variable-dropdown-${envVariable.id}`;
|
|
const { closeDropdown } = useDropdown(dropDownId);
|
|
|
|
return editMode ? (
|
|
<StyledEditModeTableRow>
|
|
<TableCell>
|
|
<TextInputV2
|
|
autoFocus
|
|
value={editedEnvVariable.key}
|
|
onChange={(newKey) =>
|
|
setEditedEnvVariable({ ...editedEnvVariable, key: newKey })
|
|
}
|
|
placeholder="Name"
|
|
fullWidth
|
|
/>
|
|
</TableCell>
|
|
<TableCell>
|
|
<TextInputV2
|
|
value={editedEnvVariable.value}
|
|
onChange={(newValue) =>
|
|
setEditedEnvVariable({ ...editedEnvVariable, value: newValue })
|
|
}
|
|
placeholder="Value"
|
|
fullWidth
|
|
/>
|
|
</TableCell>
|
|
<TableCell>
|
|
<LightIconButton
|
|
accent={'tertiary'}
|
|
Icon={IconX}
|
|
onClick={() => {
|
|
if (envVariable.key === '' && envVariable.value === '') {
|
|
onDelete();
|
|
}
|
|
setEditedEnvVariable(envVariable);
|
|
setEditMode(false);
|
|
}}
|
|
/>
|
|
<LightIconButton
|
|
accent={'tertiary'}
|
|
Icon={IconCheck}
|
|
disabled={
|
|
editedEnvVariable.key === '' || editedEnvVariable.value === ''
|
|
}
|
|
onClick={() => {
|
|
onChange(editedEnvVariable);
|
|
setEditMode(false);
|
|
}}
|
|
/>
|
|
</TableCell>
|
|
</StyledEditModeTableRow>
|
|
) : (
|
|
<StyledTableRow onClick={() => setEditMode(true)}>
|
|
<TableCell>
|
|
<OverflowingTextWithTooltip text={envVariable.key} />
|
|
</TableCell>
|
|
<TableCell>
|
|
<OverflowingTextWithTooltip text={envVariable.value} />
|
|
</TableCell>
|
|
<TableCell>
|
|
<Dropdown
|
|
dropdownId={dropDownId}
|
|
clickableComponent={
|
|
<LightIconButton
|
|
aria-label="Env Variable Options"
|
|
Icon={IconDotsVertical}
|
|
accent="tertiary"
|
|
/>
|
|
}
|
|
dropdownComponents={
|
|
<DropdownMenuItemsContainer>
|
|
<MenuItem
|
|
text={'Edit'}
|
|
LeftIcon={IconPencil}
|
|
onClick={() => {
|
|
setEditMode(true);
|
|
closeDropdown();
|
|
}}
|
|
/>
|
|
<MenuItem
|
|
text={'Delete'}
|
|
LeftIcon={IconTrash}
|
|
onClick={() => {
|
|
onDelete();
|
|
closeDropdown();
|
|
}}
|
|
/>
|
|
</DropdownMenuItemsContainer>
|
|
}
|
|
dropdownHotkeyScope={{ scope: dropDownId }}
|
|
/>
|
|
</TableCell>
|
|
</StyledTableRow>
|
|
);
|
|
};
|