-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored the WorkflowCard component
- Loading branch information
1 parent
d87c13b
commit 67ad9b2
Showing
4 changed files
with
101 additions
and
64 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
assets/js/src/core/components/workflow-card/components/dropdown-button/dropdown-button.tsx
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,74 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React, { type ReactNode, useState, useEffect } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { Dropdown, type DropdownMenuProps } from '@Pimcore/components/dropdown/dropdown' | ||
import { Button } from '@Pimcore/components/button/button' | ||
import { useSubmitWorkflow } from '@Pimcore/modules/asset/editor/toolbar/workflow-log-modal/hooks/use-submit-workflow' | ||
import { useWorkflow } from '@Pimcore/modules/asset/editor/toolbar/workflow-log-modal/hooks/use-workflow' | ||
import { type IWorkflowCardProps } from '../../types' | ||
|
||
export const DropdownButton = ({ workflow }: IWorkflowCardProps): ReactNode => { | ||
const [items, setItems] = useState<DropdownMenuProps['items']>([]) | ||
const { t } = useTranslation() | ||
|
||
const { submitWorkflowAction, submissionLoading } = useSubmitWorkflow(workflow.workflowName) | ||
const { openModal } = useWorkflow() | ||
|
||
const setWorkflowData = (): void => { | ||
const items: DropdownMenuProps['items'] = [] | ||
|
||
workflow.allowedTransitions?.forEach((status) => { | ||
items.push({ | ||
key: Number(items.length + 1).toString(), | ||
label: t(`${status.label}`), | ||
onClick: () => { | ||
submitWorkflowAction(status.name, 'transition', workflow.workflowName, {}) | ||
} | ||
}) | ||
}) | ||
|
||
workflow.globalActions?.forEach((status) => { | ||
items.push({ | ||
key: Number(items.length + 1).toString(), | ||
label: t(`${status.label}`), | ||
onClick: () => { | ||
openModal({ transition: 'global', action: status.name, workflowName: workflow.workflowName }) | ||
} | ||
}) | ||
}) | ||
|
||
setItems(items) | ||
} | ||
|
||
useEffect(() => { | ||
setWorkflowData() | ||
}, []) | ||
|
||
return ( | ||
<Dropdown | ||
menu={ { items } } | ||
placement="bottom" | ||
> | ||
{submissionLoading | ||
? ( | ||
<Button | ||
loading | ||
type={ 'link' } | ||
/> | ||
) | ||
: <Button>{t('component.workflow-card.action-btn')}</Button>} | ||
</Dropdown> | ||
) | ||
} |
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,20 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import type { | ||
WorkflowDetails | ||
} from '@Pimcore/modules/element/editor/shared-tab-manager/tabs/workflow/workflow-api-slice.gen' | ||
|
||
export interface IWorkflowCardProps { | ||
workflow: WorkflowDetails | ||
} |
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