Skip to content

Commit

Permalink
EditDialog: enable adding more rows in TagsEditor (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz authored Dec 27, 2024
1 parent 566a12a commit c390fd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ const useIsError = (index: number) => {
const { tagsEntries } = useFeatureEditData();
const [currentKey, currentValue] = tagsEntries[index];

const isEmptyKey = !!currentValue && !currentKey;
const isDuplicateKey = tagsEntries.some(
([key], idx) => key && key === currentKey && index !== idx,
);
const isLastIndex = index === tagsEntries.length - 1;
const emptyKeyCondition = isLastIndex
? !currentKey && !!currentValue
: !currentKey;

return emptyKeyCondition || isDuplicateKey;
return isEmptyKey || isDuplicateKey;
};

export const KeyInput = ({ index }: { index: number }) => {
Expand All @@ -62,15 +59,6 @@ export const KeyInput = ({ index }: { index: number }) => {
autoCapitalize="none"
maxLength={255}
error={isError}
// slotProps={{
// input: {
// endAdornment: isError ? (
// <InputAdornment position="end">
// <WarningIcon color="error" />
// </InputAdornment>
// ) : undefined,
// },
// }}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,17 @@ const TagsEditorInfo = () => (
</tr>
);

const lastKeyAndValueSet = (tagsEntries: TagsEntries) => {
const [lastKey, lastValue] = tagsEntries[tagsEntries.length - 1];
return lastKey && lastValue;
};

const AddButton = () => {
const { tagsEntries, setTagsEntries } = useFeatureEditData();
const active = tagsEntries.length === 0 || lastKeyAndValueSet(tagsEntries);

return (
<tr>
<td />
<td>
<Button
variant="contained"
color="secondary"
disableElevation
onClick={() => setTagsEntries((state) => [...state, ['', '']])}
disabled={!active}
>
<AddIcon />
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ export const FastInput = styled.input<{ error?: boolean }>`
height: 32px;
padding: 0 8px;
font-size: 13px;
color: ${({ theme }) => theme.palette.text.primary};
background-color: ${({ theme }) => theme.palette.background.paper};
border: 1px solid ${({ theme }) => theme.palette.action.disabled};
${({ theme, error }) => error && `border-color: ${theme.palette.error.main};`}
border-radius: 4px;
${({ error }) =>
${({ error, theme }) =>
error &&
`background: ${WarningSvgDataUrl} no-repeat right 8px center; padding-right: 35px;`}
`padding-right: 35px;
border-color: ${theme.palette.error.main};
background: ${WarningSvgDataUrl} no-repeat right 8px center;`}
&:hover {
border-color: ${({ theme }) => theme.palette.secondary.main};
Expand All @@ -35,6 +34,7 @@ export const FastInput = styled.input<{ error?: boolean }>`
outline: none;
border-color: ${({ theme }) => theme.palette.primary.main};
border-width: 2px;
background-position: right 7px center;
}
transition: border-color 0.2s;
Expand Down

0 comments on commit c390fd0

Please sign in to comment.