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

Fix/default editable grid #3526

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

b4s36t4
Copy link
Contributor

@b4s36t4 b4s36t4 commented May 6, 2024

Closes #3524

  • I've read and followed the contributing guide on how to create great pull requests.
  • I've updated the relevant documentation for any new or updated feature.
  • I've linked relevant GitHub issue with "Closes #".
  • I've added a visual demonstration in the form of a screenshot or video.

@@ -479,11 +479,11 @@ function getNarrowedColType(type?: string): GridColType | undefined {
return (type && type in DEFAULT_COLUMN_TYPES ? type : undefined) as GridColType | undefined;
}

export function parseColumns(columns: SerializableGridColumns): GridColDef[] {
export function parseColumns(columns: SerializableGridColumns, isEditable?: boolean): GridColDef[] {
Copy link
Member

@Janpot Janpot May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseColumns acts as a conversion between "serializable columns" and "X grid columns". It's being reused across the codebase for this purpose. I prefer to keep this function single purpose.
How do you feel about solving this downstream instead? Where we iterate a second time to create the rendered columns:

const renderedColumns = React.useMemo<GridColDef[]>(() => {
const result = [...columns];
if (getProviderActions) {
result.push({
field: ACTIONS_COLUMN_FIELD,
type: 'actions',
align: 'right',
resizable: false,
pinnable: false,
getActions: getProviderActions,
});
}
return result;
}, [columns, getProviderActions]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Janpot , say we're having id column it shouldn't be editable at all right, should I move the isIdColumn logic to this function?

If we update the editable here id column may probably get override right?

Copy link
Member

@Janpot Janpot May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we only set isEditable if it isn't already defined? And remove isEditable: true from the baseColumn in parseColumns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, that's a good approach. Will update accordingly.

@b4s36t4 b4s36t4 force-pushed the fix/default-editable-grid branch from 2797c76 to 825b970 Compare May 6, 2024 12:02
@b4s36t4
Copy link
Contributor Author

b4s36t4 commented May 6, 2024

@Janpot I have updated the changes you suggested, can you please verify.

@Janpot Janpot added the component: data grid This is the name of the generic UI component, not the React module! label May 6, 2024
return column;
}

column.editable = isRowUpdateModelAvailable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid mutating items in .map. Perhaps something like the following would work?

return column.editable === undefined ? { ...column, editable: isRowUpdateModelAvailable } : column;

@Janpot
Copy link
Member

Janpot commented May 6, 2024

@Janpot I have updated the changes you suggested, can you please verify.

Can you look into why the tests fail?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[studio] Cell shouldn't be editable by default
2 participants