Skip to content
Open
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
31 changes: 30 additions & 1 deletion packages/ui/src/ui-component/dialog/ShareWithWorkspaceDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { enqueueSnackbar as enqueueSnackbarAction, closeSnackbar as closeSnackba
import { cloneDeep } from 'lodash'

// Material
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Box, Stack, OutlinedInput, Typography } from '@mui/material'
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Box, Stack, OutlinedInput, Typography, Checkbox, FormControlLabel } from '@mui/material'

// Project imports
import { StyledButton } from '@/ui-component/button/StyledButton'
Expand Down Expand Up @@ -47,6 +47,28 @@ const ShareWithWorkspaceDialog = ({ show, dialogProps, onCancel, setError }) =>
const [outputSchema, setOutputSchema] = useState([])

const [name, setName] = useState('')
const [selectAll, setSelectAll] = useState(false)

// Handle select all / deselect all
const handleSelectAllChange = (event) => {
const checked = event.target.checked
setSelectAll(checked)
setOutputSchema((prevRows) => {
return prevRows.map((row) => ({
...row,
shared: checked
}))
})
}

// Update selectAll state when individual rows change
useEffect(() => {
if (outputSchema.length > 0) {
const allSelected = outputSchema.every((row) => row.shared)
const noneSelected = outputSchema.every((row) => !row.shared)
setSelectAll(allSelected ? true : noneSelected ? false : false)
Comment on lines +67 to +69
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic for setting selectAll can be simplified. The current ternary expression allSelected ? true : noneSelected ? false : false is equivalent to just allSelected, as both branches of the inner ternary return false. Additionally, consider implementing the indeterminate state for the checkbox (using the indeterminate prop) to provide better visual feedback when only some workspaces are selected.

Suggested change
const allSelected = outputSchema.every((row) => row.shared)
const noneSelected = outputSchema.every((row) => !row.shared)
setSelectAll(allSelected ? true : noneSelected ? false : false)
const allSelected = outputSchema.every((row) => row.shared)
setSelectAll(allSelected)

}
}, [outputSchema])

const onRowUpdate = (newRow) => {
setTimeout(() => {
Expand Down Expand Up @@ -187,6 +209,13 @@ const ShareWithWorkspaceDialog = ({ show, dialogProps, onCancel, setError }) =>
<OutlinedInput id='name' type='string' disabled={true} fullWidth placeholder={name} value={name} name='name' />
</Box>
<Box sx={{ p: 2 }}>
<Stack direction='row' alignItems='center' justifyContent='space-between' sx={{ mb: 1 }}>
<Typography variant='overline'>Workspaces</Typography>
<FormControlLabel
control={<Checkbox checked={selectAll} onChange={handleSelectAllChange} size='small' />}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The "Select All" checkbox should be disabled if there are no workspaces available to select (e.g., when the user only has one workspace, which is filtered out from this list). This prevents confusing UI interactions where the checkbox can be toggled despite having no effect.

Suggested change
control={<Checkbox checked={selectAll} onChange={handleSelectAllChange} size='small' />}
control={<Checkbox checked={selectAll} onChange={handleSelectAllChange} size='small' disabled={outputSchema.length === 0} />}

label={<Typography variant='body2'>Select All</Typography>}
/>
</Stack>
<Grid columns={columns} rows={outputSchema} onRowUpdate={onRowUpdate} />
</Box>
</DialogContent>
Expand Down