Skip to content

Commit

Permalink
H-3545: make readonly array display in editor the same as in editing …
Browse files Browse the repository at this point in the history
…mode
  • Loading branch information
CiaranMn committed Feb 7, 2025
1 parent a70f56d commit 0417555
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const renderValueCell: CustomRenderer<ValueCell> = {
return undefined;
},
provideEditor: ({ data }) => {
if (data.readonly) {
if (data.readonly && !data.propertyRow.isArray) {
return {
disableStyling: true,
disablePadding: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const ArrayEditor: ValueCellEditorComponent = ({
onChange,
}) => {
const listWrapperRef = useRef<HTMLDivElement>(null);

const { readonly } = cell.data;

const {
value: propertyValue,
valueMetadata,
Expand Down Expand Up @@ -291,7 +294,8 @@ export const ArrayEditor: ValueCellEditorComponent = ({
updateItem(index, value);
};

const canAddMore = isNumber(maxItems) ? items.length < maxItems : true;
const canAddMore =
!readonly && (isNumber(maxItems) ? items.length < maxItems : true);
const isAddingDraft = editingRow === DRAFT_ROW_KEY;

const hasConstraints = minItems !== undefined || maxItems !== undefined;
Expand All @@ -308,9 +312,10 @@ export const ArrayEditor: ValueCellEditorComponent = ({
onDragEnd={handleDragEnd}
>
<SortableContext items={items} strategy={verticalListSortingStrategy}>
{items.map((item) => (
{items.map((item, index) => (
<SortableRow
key={item.id}
isLastRow={index === items.length - 1}
item={item}
onRemove={removeItem}
onEditClicked={(id) => setEditingRow(id)}
Expand All @@ -320,6 +325,7 @@ export const ArrayEditor: ValueCellEditorComponent = ({
selected={selectedRow === item.id}
onSelect={toggleSelectedRow}
expectedTypes={permittedDataTypes}
readonly={readonly}
/>
))}
</SortableContext>
Expand All @@ -343,7 +349,7 @@ export const ArrayEditor: ValueCellEditorComponent = ({
/>
)}

{!canAddMore && hasConstraints && (
{!canAddMore && !readonly && hasConstraints && (
<ItemLimitInfo min={minItems} max={maxItems} />
)}
</GridEditorWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ interface SortableRowProps {
onEditClicked?: (id: string) => void;
editing: boolean;
expectedTypes: ClosedDataTypeDefinition[];
isLastRow: boolean;
onSaveChanges: (index: number, value: unknown) => void;
onDiscardChanges: () => void;
readonly: boolean;
}

export const SortableRow = ({
isLastRow,
item,
onRemove,
selected,
Expand All @@ -45,6 +48,7 @@ export const SortableRow = ({
onSaveChanges,
onDiscardChanges,
editing,
readonly,
}: SortableRowProps) => {
const { id, value, index, dataType } = item;
const {
Expand Down Expand Up @@ -80,7 +84,7 @@ export const SortableRow = ({
const { arrayEditException } = editorSpec;

const shouldShowActions =
!isDragging && !isSorting && (hovered || selected || editing);
!readonly && !isDragging && !isSorting && (hovered || selected || editing);

if (prevEditing !== editing) {
setPrevEditing(editing);
Expand Down Expand Up @@ -177,7 +181,7 @@ export const SortableRow = ({
minHeight: 48,
display: "flex",
alignItems: "center",
borderBottom: "1px solid",
borderBottom: isLastRow ? "none" : "1px solid",
borderColor: isDragging ? "transparent" : "gray.20",
position: "relative",
outline: "none",
Expand All @@ -186,23 +190,26 @@ export const SortableRow = ({
onMouseLeave={() => setHovered(false)}
onClick={() => onSelect?.(id)}
>
<Box
{...listeners}
sx={{
cursor: isDragging || isSorting ? "grabbing" : "grab",
px: 1.5,
height: "100%",
display: "flex",
alignItems: "center",
}}
>
<DragIndicatorIcon sx={{ fontSize: 14, color: "gray.50" }} />
</Box>
{!readonly && (
<Box
{...listeners}
sx={{
cursor: isDragging || isSorting ? "grabbing" : "grab",
pl: 1.5,
height: "100%",
display: "flex",
alignItems: "center",
}}
>
<DragIndicatorIcon sx={{ fontSize: 14, color: "gray.50" }} />
</Box>
)}

<Typography
variant="smallTextLabels"
sx={{
color: "gray.50",
ml: 1.5,
mr: 1,
}}
>
Expand Down

0 comments on commit 0417555

Please sign in to comment.