-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhouwenxuan
authored and
zhouwenxuan
committed
Oct 29, 2024
1 parent
6c4f344
commit 3ef5c79
Showing
7 changed files
with
102 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useState, useCallback, useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Icon } from '@seafile/sf-metadata-ui-component'; | ||
import { gettext } from '../../../../utils/constants'; | ||
import AddListPopover from '../../../components/popover/add-list-popover'; | ||
import { COLUMN_DATA_OPERATION_TYPE } from '../../../store/operations'; | ||
import { useMetadataView } from '../../../hooks/metadata-view'; | ||
|
||
const AddList = ({ groupByColumn }) => { | ||
const [isShowAddListPopover, setShowAddListPopover] = useState(false); | ||
const { store } = useMetadataView(); | ||
|
||
const options = useMemo(() => groupByColumn.data.options, [groupByColumn]); | ||
|
||
const handleAddListButtonClick = useCallback(() => { | ||
setShowAddListPopover(true); | ||
}, []); | ||
|
||
const handleAddNewList = useCallback((option) => { | ||
const oldData = groupByColumn.data; | ||
const options = [...oldData.options, option]; | ||
const optionModifyType = COLUMN_DATA_OPERATION_TYPE.ADD_OPTION; | ||
store.modifyColumnData(groupByColumn.key, { options }, { options: oldData.options }, { optionModifyType }); | ||
setShowAddListPopover(false); | ||
}, [store, groupByColumn]); | ||
|
||
const handleCancelAddList = useCallback(() => { | ||
setShowAddListPopover(false); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<div | ||
id="add-list-button" | ||
className='add-list-button' | ||
onClick={handleAddListButtonClick} | ||
> | ||
<Icon iconName="add-table" /> | ||
<span className="btn-text">{gettext('Add a new list')}</span> | ||
</div> | ||
{isShowAddListPopover && ( | ||
<AddListPopover | ||
options={options} | ||
onCancel={handleCancelAddList} | ||
onSubmit={handleAddNewList} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
AddList.propTypes = { | ||
groupByColumn: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default AddList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters