Skip to content

Commit

Permalink
Merge pull request #3584 from LiteFarmOrg/show-action-menu-for-worker
Browse files Browse the repository at this point in the history
Show action menu for worker
  • Loading branch information
Duncan-Brain authored Dec 10, 2024
2 parents 7d87bf7 + daf2c40 commit 38c3533
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
17 changes: 10 additions & 7 deletions packages/webapp/src/components/ActionMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface action {

export interface iconAction extends action {
iconName: IconName;
visible: boolean;
}

export interface ActionMenuProps {
Expand Down Expand Up @@ -54,14 +55,16 @@ const ActionMenu = ({ headerLeftText, textActions = [], iconActions }: ActionMen
</div>
</div>
<div className={styles.iconButtons}>
{iconActions.map(({ iconName, label, onClick }) => {
{iconActions.map(({ iconName, label, onClick, visible }) => {
return (
<div key={label} className={clsx(styles.iconGroup, iconCountClassName)}>
<TextButton onClick={onClick}>
<Icon iconName={iconName} className={styles.icon} />
</TextButton>
<div className={styles.iconLabel}>{label}</div>
</div>
visible && (
<div key={label} className={clsx(styles.iconGroup, iconCountClassName)}>
<TextButton onClick={onClick}>
<Icon iconName={iconName} className={styles.icon} />
</TextButton>
<div className={styles.iconLabel}>{label}</div>
</div>
)
);
})}
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/webapp/src/components/Animals/Inventory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type PureAnimalInventoryProps = {
history: History;
tableMaxHeight?: number;
tableSpacerRowHeight: number;
showInventorySelection: boolean;
showInventorySelection?: boolean;
showSearchBarAndFilter?: boolean;
alternatingRowColor?: boolean;
showTableHeader: boolean;
Expand All @@ -81,7 +81,7 @@ const PureAnimalInventory = ({
history,
tableMaxHeight,
tableSpacerRowHeight,
showInventorySelection,
showInventorySelection = true,
showSearchBarAndFilter = true,
alternatingRowColor = true,
showTableHeader,
Expand Down
13 changes: 5 additions & 8 deletions packages/webapp/src/containers/Animals/Inventory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ const SelectedAnimalsSummaryInventory = ({
};

const TaskAnimalInventory = ({
isAdmin,
isCompleteView,
...commonProps
}: { isAdmin: boolean; isCompleteView?: boolean } & CommonPureAnimalInventoryProps) => {
}: { isCompleteView?: boolean } & CommonPureAnimalInventoryProps) => {
return (
<FixedHeaderContainer
header={null}
Expand All @@ -176,7 +175,6 @@ const TaskAnimalInventory = ({
commonProps.onSelectInventory(event, row);
}}
tableSpacerRowHeight={0}
showInventorySelection={isAdmin}
showSearchBarAndFilter={true}
alternatingRowColor={true}
showTableHeader={commonProps.isDesktop}
Expand Down Expand Up @@ -219,7 +217,6 @@ const MainAnimalInventory = ({
history.push(row.path);
}}
tableSpacerRowHeight={commonProps.isDesktop ? 96 : 120}
showInventorySelection={isAdmin}
showSearchBarAndFilter={true}
alternatingRowColor={true}
showTableHeader={commonProps.isDesktop}
Expand Down Expand Up @@ -417,11 +414,13 @@ export default function AnimalInventory({
label: t(`common:CREATE_A_TASK`),
iconName: 'TASK_CREATION',
onClick: () => onAddTask(dispatch, history, { animal_ids: selectedInventoryIds })(),
visible: true,
},
{
label: t(`ANIMAL.REMOVE_ANIMAL`),
iconName: 'REMOVE_ANIMAL',
onClick: () => setRemovalModalOpen(true),
visible: isAdmin,
},
];

Expand All @@ -442,7 +441,7 @@ export default function AnimalInventory({

const actionMenuAndRemoveModal = (
<>
{isAdmin && selectedInventoryIds.length ? (
{selectedInventoryIds.length ? (
<FloatingContainer isCompactSideMenu={isCompactSideMenu}>
<ActionMenu
headerLeftText={t('common:SELECTED_COUNT', { count: selectedInventoryIds.length })}
Expand Down Expand Up @@ -479,9 +478,7 @@ export default function AnimalInventory({
};

if (view == View.TASK) {
return (
<TaskAnimalInventory isAdmin={isAdmin} isCompleteView={isCompleteView} {...commonProps} />
);
return <TaskAnimalInventory isCompleteView={isCompleteView} {...commonProps} />;
}
if (view == View.TASK_SUMMARY) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ export default meta;

type Story = StoryObj<typeof ActionMenu>;

const createLabelAndOnClick = (label: string): { label: string; onClick: () => void } => {
const createLabelAndOnClick = (
label: string,
): { label: string; onClick: () => void; visible: boolean } => {
return {
label,
onClick: () => console.log(`${label} clicked!`),
visible: true,
};
};

Expand Down

0 comments on commit 38c3533

Please sign in to comment.