Skip to content

Commit aa29a02

Browse files
committed
TSJR-314 - work for bulk edit
1 parent 0fc9fa3 commit aa29a02

File tree

14 files changed

+181
-39
lines changed

14 files changed

+181
-39
lines changed

src/apps/admin/src/skills-manager/SkillsManager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Outlet, Routes } from 'react-router-dom'
44
import { routerContext, RouterContextData } from '~/libs/core'
55

66
import { skillsManagerRoutes } from './skills-manager.routes'
7-
import { SkillsManagerContext } from './skills-manager.context'
7+
import { SkillsManagerContext } from './context'
88

99
const SkillsManager: FC<{}> = () => {
1010
const { getRouteElement }: RouterContextData = useContext(routerContext)

src/apps/admin/src/skills-manager/components/actions-menu/ActionsMenu.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
padding: $sp-1;
1111
margin: -$sp-1;
12+
13+
+ * {
14+
z-index: 9;
15+
}
1216
}
1317

1418
.menu {

src/apps/admin/src/skills-manager/components/categories-accordion/CategoriesAccordion.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FC } from 'react'
22

33
import { Accordion, AccordionItem } from '../accordion'
44
import { SkillsList } from '../skills-list'
5-
import { SkillsManagerContextValue, useSkillsManagerContext } from '../../skills-manager.context'
5+
import { SkillsManagerContextValue, useSkillsManagerContext } from '../../context'
66
import { StandardizedSkillCategory } from '../../services'
77
import { CATEGORY_ITEM_ACTIONS, MENU_ACTIONS } from '../../config'
88

@@ -16,13 +16,20 @@ const CategoriesAccordion: FC<CategoriesAccordionProps> = props => {
1616
setEditCategory,
1717
categories,
1818
groupedSkills,
19+
isBulkEditing,
20+
toggleEditMode,
21+
toggleEditSkill,
22+
isSkillSelected,
1923
}: SkillsManagerContextValue = useSkillsManagerContext()
2024

2125
function handleMenuActions(action: string, category: StandardizedSkillCategory): void {
2226
switch (action) {
2327
case MENU_ACTIONS.editCategory.action:
2428
setEditCategory(category)
2529
break
30+
case MENU_ACTIONS.bulkEditSkills.action:
31+
toggleEditMode(category)
32+
break
2633
default: break
2734
}
2835
}
@@ -35,20 +42,30 @@ const CategoriesAccordion: FC<CategoriesAccordionProps> = props => {
3542
key={category.id}
3643
label={category.name}
3744
badgeCount={categorySkills.length}
38-
open={props.defaultOpen}
45+
open={props.defaultOpen || !!isBulkEditing}
3946
menuActions={CATEGORY_ITEM_ACTIONS}
4047
onMenuAction={function handle(action: string) { handleMenuActions(action, category) }}
4148
>
4249
{() => (
43-
<SkillsList skills={categorySkills} key={`cat-${category.id}-list`} />
50+
<SkillsList
51+
skills={categorySkills}
52+
key={`cat-${category.id}-list`}
53+
onSelect={toggleEditSkill}
54+
isSelected={isSkillSelected}
55+
editMode={!!isBulkEditing}
56+
/>
4457
)}
4558
</AccordionItem>
4659
) : <></>
4760
}
4861

4962
return (
5063
<Accordion defaultOpen={props.defaultOpen}>
51-
{categories.map(renderCategoryAccordion)}
64+
{isBulkEditing ? (
65+
renderCategoryAccordion(isBulkEditing)
66+
) : (
67+
categories.map(renderCategoryAccordion)
68+
)}
5269
</Accordion>
5370
)
5471
}

src/apps/admin/src/skills-manager/components/more-actions-menu/MoreActionsMenu.module.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
top: 0;
66
right: 0;
77
height: 100%;
8+
width: 0;
89
&::before {
910
content: '';
1011
display: block;
@@ -17,3 +18,14 @@
1718
right: 0;
1819
bottom: $sp-4;
1920
}
21+
22+
.triggerBtn.triggerBtn {
23+
padding-left: $sp-4;
24+
padding-right: $sp-4;
25+
}
26+
27+
.menu {
28+
position: absolute;
29+
right: 0;
30+
bottom: 0;
31+
}

src/apps/admin/src/skills-manager/components/more-actions-menu/MoreActionsMenu.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Button, IconOutline } from '~/libs/ui'
55
import { GLOBAL_ACTIONS, MENU_ACTIONS } from '../../config'
66
import { ActionsMenu } from '../actions-menu'
77
import { StandardizedSkill, StandardizedSkillCategory } from '../../services'
8-
import { SkillsManagerContextValue, useSkillsManagerContext } from '../../skills-manager.context'
8+
import { SkillsManagerContextValue, useSkillsManagerContext } from '../../context'
99

1010
import styles from './MoreActionsMenu.module.scss'
1111

@@ -39,8 +39,9 @@ const MoreActionsMenu: FC<{}> = () => {
3939
>
4040
<Button
4141
primary
42-
color='blue'
42+
variant='linkblue'
4343
size='xl'
44+
className={styles.triggerBtn}
4445
>
4546
<IconOutline.PlusIcon className='icon-xxl' />
4647
</Button>

src/apps/admin/src/skills-manager/components/skills-list/SkillsList.module.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@
1111

1212
.skillItem {
1313
padding: $sp-2 $sp-2;
14+
display: flex;
15+
align-items: center;
16+
gap: $sp-2;
17+
18+
.isEditMode & {
19+
cursor: pointer;
20+
}
1421
}
Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,48 @@
11
import { FC } from 'react'
2+
import CheckBox from 'rc-checkbox'
3+
import classNames from 'classnames'
24

35
import { StandardizedSkill } from '../../services'
46

57
import styles from './SkillsList.module.scss'
68

79
interface SkillsListProps {
810
skills: StandardizedSkill[]
11+
editMode?: boolean
12+
onSelect: (skill: StandardizedSkill) => void
13+
isSelected: (skill: StandardizedSkill) => boolean
914
}
1015

11-
const SkillsList: FC<SkillsListProps> = props => (
12-
<div className={styles.wrap}>
13-
<ul className={styles.listWrap}>
14-
{props.skills.map(skill => (
15-
<li className={styles.skillItem} key={skill.id}>
16-
<div className='body-main'>
17-
{skill.name}
18-
</div>
19-
</li>
20-
))}
21-
</ul>
22-
</div>
23-
)
16+
const SkillsList: FC<SkillsListProps> = props => {
17+
function handleToggle(skill: StandardizedSkill): void {
18+
if (!props.editMode) {
19+
return
20+
}
21+
22+
props.onSelect(skill)
23+
}
24+
25+
return (
26+
<div className={classNames(styles.wrap, props.editMode && styles.isEditMode)}>
27+
<ul className={styles.listWrap}>
28+
{props.skills.map(skill => (
29+
<li className={styles.skillItem} key={skill.id}>
30+
{props.editMode && (
31+
<div className={styles.checkbox}>
32+
<CheckBox
33+
checked={props.isSelected(skill)}
34+
onChange={function toggl() { handleToggle(skill) }}
35+
/>
36+
</div>
37+
)}
38+
<div className='body-main' onClick={function toggl() { handleToggle(skill) }}>
39+
{skill.name}
40+
</div>
41+
</li>
42+
))}
43+
</ul>
44+
</div>
45+
)
46+
}
2447

2548
export default SkillsList

src/apps/admin/src/skills-manager/config/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ export const MENU_ACTIONS = {
3434

3535
export const CATEGORY_ITEM_ACTIONS: ActionsMenuItem[] = [
3636
EDIT_CATEGORY_ACTION,
37-
// BULK_EDIT_SKILLS_ACTION,
37+
BULK_EDIT_SKILLS_ACTION,
3838
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './skills-manager.context'

src/apps/admin/src/skills-manager/skills-manager.context.tsx renamed to src/apps/admin/src/skills-manager/context/skills-manager.context.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { createContext, FC, ReactNode, useContext, useMemo, useState } from 'react'
2-
import { noop, orderBy } from 'lodash'
2+
import { orderBy } from 'lodash'
33
import { SWRResponse } from 'swr'
44

5-
import { StandardizedSkill, StandardizedSkillCategory, useFetchCategories, useFetchSkills } from './services'
6-
import { findSkillsMatches, GroupedSkills, groupSkillsByCategory } from './lib'
5+
import { StandardizedSkill, StandardizedSkillCategory, useFetchCategories, useFetchSkills } from '../services'
6+
import { findSkillsMatches, GroupedSkills, groupSkillsByCategory } from '../lib'
77

8-
export interface SkillsManagerContextValue {
8+
import { SkillsBulkEditorValue, useSkillsBulkEditor } from './use-skills-bulk-editor'
9+
10+
export interface SkillsManagerContextValue extends SkillsBulkEditorValue {
911
categories: StandardizedSkillCategory[]
1012
skillsFilter: string
1113
setSkillsFilter: (filter: string) => void
@@ -20,18 +22,7 @@ export interface SkillsManagerContextValue {
2022
}
2123

2224
const SkillsManagerRC = createContext<SkillsManagerContextValue>({
23-
categories: [],
24-
editCategory: undefined,
25-
editSkill: undefined,
26-
groupedSkills: {},
27-
refetchCategories: noop,
28-
refetchSkills: noop,
29-
setEditCategory: noop,
30-
setEditSkill: noop,
31-
setSkillsFilter: noop,
32-
skillsFilter: '',
33-
skillsList: [],
34-
})
25+
} as SkillsManagerContextValue)
3526

3627
interface SkillsManagerContextProps {
3728
children?: ReactNode
@@ -46,6 +37,7 @@ export const SkillsManagerContext: FC<SkillsManagerContextProps> = props => {
4637
data: allSkills,
4738
mutate: refetchSkills,
4839
}: SWRResponse<StandardizedSkill[]> = useFetchSkills()
40+
4941
const {
5042
data: allCategories,
5143
mutate: refetchCategories,
@@ -54,7 +46,10 @@ export const SkillsManagerContext: FC<SkillsManagerContextProps> = props => {
5446
const skills = useMemo(() => findSkillsMatches(allSkills ?? [], skillsFilter), [allSkills, skillsFilter])
5547
const groupedSkills = useMemo(() => groupSkillsByCategory(skills), [skills])
5648

49+
const skillsBulkEditor = useSkillsBulkEditor(skills)
50+
5751
const contextValue = useMemo(() => ({
52+
...skillsBulkEditor,
5853
categories: orderBy(allCategories ?? [], 'name', 'asc'),
5954
editCategory,
6055
editSkill,
@@ -67,6 +62,7 @@ export const SkillsManagerContext: FC<SkillsManagerContextProps> = props => {
6762
skillsFilter,
6863
skillsList: skills,
6964
}), [
65+
skillsBulkEditor,
7066
allCategories,
7167
editCategory,
7268
editSkill,

0 commit comments

Comments
 (0)