Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column remove in compact entry edit's matrix 2d #3004

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ import {
Modal,
QuickActionButton,
} from '@the-deep/deep-ui';
import { IoChevronForward, IoOpenOutline } from 'react-icons/io5';
import {
IoChevronForward,
IoOpenOutline,
IoClose,
} from 'react-icons/io5';
import { PartialForm, Error, getErrorObject } from '@togglecorp/toggle-form';
import { useModalState } from '#hooks/stateManagement';
import { sortByOrder } from '#utils/common';
import { removeUndefinedKeys, removeEmptyObject } from '#utils/unsafeCommon';

import NonFieldError from '#components/NonFieldError';
import { Matrix2dWidget } from '#types/newAnalyticalFramework';
Expand Down Expand Up @@ -121,6 +126,19 @@ function Column(props: ColumnProps) {
value,
]);

const handleColumnRemove = useCallback((columnKey: string) => {
onSubColumnsChange(
rowId,
subRowId,
columnKey,
undefined,
);
}, [
onSubColumnsChange,
rowId,
subRowId,
]);

return (
<div className={styles.column}>
<div
Expand Down Expand Up @@ -173,15 +191,26 @@ function Column(props: ColumnProps) {
</div>
)}
{!readOnly && !suggestionMode && (
<MultiSelectInput
name={column.key}
value={value?.[column.key]}
disabled={disabled}
labelSelector={subColumnLabelSelector}
onChange={handleSubColumnValueChange}
options={orderedSubColumns}
keySelector={subColumnKeySelector}
/>
<div className={styles.subColumnSelectWrapper}>
<MultiSelectInput
className={styles.input}
name={column.key}
value={value?.[column.key]}
disabled={disabled}
labelSelector={subColumnLabelSelector}
onChange={handleSubColumnValueChange}
options={orderedSubColumns}
keySelector={subColumnKeySelector}
/>
<QuickActionButton
className={styles.button}
name={column.key}
onClick={handleColumnRemove}
variant="secondary"
>
<IoClose />
</QuickActionButton>
</div>
)}
{readOnly && (
<div className={styles.selectedValues}>
Expand Down Expand Up @@ -432,7 +461,7 @@ function Matrix2dWidgetInput<N extends string>(props: Props<N>) {
columnId: string,
newSubColValue: string[] | undefined,
) => {
const newValue = {
const newValue = removeEmptyObject(removeUndefinedKeys({
...value?.value,
[rowId]: {
...value?.value?.[rowId],
Expand All @@ -441,7 +470,7 @@ function Matrix2dWidgetInput<N extends string>(props: Props<N>) {
[columnId]: newSubColValue,
},
},
};
}));
onChange(newValue, name);
},
[value, name, onChange],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@
}
}

.sub-column-select-wrapper {
display: flex;
align-items: center;
gap: var(--dui-spacing-extra-small);

.input {
flex-grow: 1;
}

.button {
flex-shrink: 0;
}
}

.selected-values {
color: var(--dui-color-accent);
}
Expand Down
Loading