Skip to content

Commit 0267d11

Browse files
authored
Merge pull request #253 from ynput/OP-7391_New-folders-separate-name-and-label
Editor: New Entity Independent Label and Name Editing
2 parents d8bb682 + 4d86d55 commit 0267d11

File tree

8 files changed

+70
-37
lines changed

8 files changed

+70
-37
lines changed

src/components/Details/EntityDetailsHeader.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ const EntityDetailsHeader = ({
4242

4343
const isMultiple = values.length > 1
4444

45-
let subTitle = ''
45+
let subTitle = '',
46+
breadcrumbs = []
4647
if (isMultiple) {
47-
subTitle = values.map((v) => v?.name).join(', ')
48+
subTitle = values
49+
.map((v) => v?.name)
50+
.slice(0, 5)
51+
.join(', ')
52+
53+
if (values.length > 5) subTitle += ' +' + (values.length - 5)
4854
} else if (uri) {
4955
const [path, qs] = uri.split('://')[1].split('?')
5056
//eslint-disable-next-line
51-
const [_, ...breadcrumbs] = path.split('/').filter((p) => p)
57+
const [_, ...bc] = path.split('/').filter((p) => p)
58+
breadcrumbs = bc
5259
const qp = qs
5360
? qs.split('&').reduce((acc, curr) => {
5461
if (!curr) return acc
@@ -110,7 +117,7 @@ const EntityDetailsHeader = ({
110117
value={subTitle}
111118
style={{ left: -3 }}
112119
align="left"
113-
onClick={copyToClipboard}
120+
onClick={() => copyToClipboard(breadcrumbs.join('/'), true)}
114121
/>
115122
</div>
116123
)}

src/helpers/copyToClipboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const copyToClipboard = (message, toastMessage = false) => {
1010
.then(() => {
1111
let toastText = 'Copied To Clipboard'
1212
if (toastMessage) {
13-
toastText += `: "${message}"`
13+
toastText += `: ${message}`
1414
}
1515
toast.success(toastText)
1616
})

src/hooks/Tooltip/Tooltip.styled.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const TooltipWidget = styled.div`
1616
box-shadow: 0 0 10px 0px rgba(0, 0, 0, 0.4);
1717
user-select: none;
1818
pointer-events: none;
19-
z-index: 1000;
19+
z-index: 1200;
2020
2121
/* tooltip triangle pointer using ::after */
2222
&::after {

src/pages/EditorPage/EditorPage.jsx

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,10 @@ const EditorPage = () => {
833833
if (op.type === 'delete') {
834834
deleted.push(op.id)
835835
} else {
836-
updated.push(op.patch)
836+
const patch = { ...op.patch }
837+
// delete: __isNew
838+
delete patch.data.__isNew
839+
updated.push(patch)
837840
}
838841
}
839842

@@ -1261,17 +1264,55 @@ const EditorPage = () => {
12611264
}
12621265

12631266
const onRowClick = (event) => {
1264-
let node = event.node.data
1267+
const node = event.node.data
1268+
//
1269+
let endFolder
12651270
if (node.__entityType === 'folder') {
1266-
node = event.node.data
1271+
endFolder = node
12671272
} else if (node.__entityType === 'task') {
12681273
// find the parent folder
1269-
node = searchableFoldersSet.get(node.__parentId)
1274+
endFolder = searchableFoldersSet.get(node.__parentId)
1275+
1276+
if (!endFolder) {
1277+
// the parent could be a new node, so look in newNodes
1278+
endFolder = newNodes[node.__parentId]
1279+
}
1280+
}
1281+
1282+
const parents = endFolder?.parents || []
1283+
1284+
if (!parents?.length && endFolder?.parentId) {
1285+
// get any parents of that parent and add
1286+
let parentNode = searchableFoldersSet.get(endFolder.parentId)
1287+
1288+
// parent node could be a new node
1289+
if (!parentNode) parentNode = newNodes[endFolder.parentId]
1290+
if (parentNode) parents.push(parentNode.name)
1291+
if (parentNode?.parents?.length) {
1292+
parents.push(...parentNode.parents)
1293+
} else if (parentNode.__isNew) {
1294+
// we need to recursively find parents until we find a parent that is not new
1295+
const getParents = (node) => {
1296+
const parent = newNodes[node.parentId] || searchableFoldersSet.get(node.parentId)
1297+
if (parent) {
1298+
if (parent.__isNew) {
1299+
parents.unshift(parent.name)
1300+
getParents(parent)
1301+
} else {
1302+
parents.unshift(parent.name)
1303+
}
1304+
}
1305+
}
1306+
1307+
getParents(parentNode)
1308+
}
12701309
}
12711310

1272-
if (node?.parents) {
1311+
const pathNames = [...parents, endFolder.name]
1312+
1313+
if (pathNames.length) {
12731314
let uri = `ayon+entity://${projectName}`
1274-
uri += `/${node.parents.join('/')}/${node.name}`
1315+
uri += `/${pathNames.join('/')}`
12751316
if (event.node.data.__entityType === 'task') {
12761317
uri += `?task=${event.node?.data?.name}`
12771318
}

src/pages/EditorPage/EditorPanel.jsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const EditorPanel = ({
6666
const [localChange, setLocalChange] = useState(false)
6767
const [nodeIds, setNodeIds] = useState([])
6868
const [nodes, setNodes] = useState({})
69+
const [isNew, setIsNew] = useState(false)
6970
const [form, setForm] = useState({})
7071
// used to rebuild fields for when the type changes
7172
const [type, setType] = useState(null)
@@ -78,14 +79,16 @@ const EditorPanel = ({
7879

7980
for (const id of selected) {
8081
if (id in editorNodes) {
82+
setIsNew(false)
8183
formNodes[id] = editorNodes[id]
8284
} else if (id in newNodes) {
8385
formNodes[id] = { leaf: newNodes[id]?.__entityType !== 'folder', data: newNodes[id] }
86+
setIsNew(true)
8487
}
8588
}
8689

8790
setNodes(formNodes)
88-
}, [selected, editorNodes])
91+
}, [selected, editorNodes, newNodes])
8992

9093
const noSelection = !nodeIds.length
9194
let singleSelect = null
@@ -356,25 +359,6 @@ const EditorPanel = ({
356359
isMultiple: oldValue?.isMultiple && !isChanged,
357360
}
358361

359-
// if the label is changed and the entity is new, change the name as well
360-
// first check if all nodes are newNodes
361-
const allNewNodes = nodeIds.every((id) => nodes[id]?.data?.__isNew)
362-
if (allNewNodes && changeKey === '_label') {
363-
// replace space with underscore, set to lowercase and remove special characters and any non alphanumeric characters from the start
364-
const name = newValue
365-
.replace(/\s/g, '_')
366-
.toLowerCase()
367-
.replace(/[^a-z0-9_]/g, '')
368-
.replace(/^[^a-z]+/g, '')
369-
newForm._name = {
370-
...newForm._name,
371-
value: name,
372-
isChanged: true,
373-
isOwn: true,
374-
isMultiple: false,
375-
}
376-
}
377-
378362
setLocalChange(true)
379363

380364
if (setFormNew) return setFormNew(newForm)
@@ -542,7 +526,7 @@ const EditorPanel = ({
542526
// pick a react input
543527
let input
544528

545-
if (field === 'name') {
529+
if (field === 'name' && !isNew) {
546530
input = <InputText value={value} disabled readOnly />
547531
} else if (field.includes('Type')) {
548532
input = (

src/pages/EditorPage/NewEntity.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,14 @@ const NewEntity = ({
226226
variant="text"
227227
onClick={() => handleSubmit(false)}
228228
disabled={addDisabled}
229-
title={'Shift + Enter'}
229+
data-shortcut="Shift+Enter"
230230
/>
231231
<SaveButton
232232
label={`Add and Close`}
233233
onClick={() => handleSubmit(true)}
234234
active={!addDisabled}
235235
title="Ctrl/Cmd + Enter"
236+
data-shortcut="Ctrl/Cmd+Enter"
236237
/>
237238
</Toolbar>
238239
}

src/pages/EditorPage/NewSequence.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ const NewSequence = ({
125125
label="Add"
126126
disabled={addDisabled}
127127
onClick={() => handleSeqSubmit(false)}
128-
title={'Shift + Enter'}
128+
data-shortcut="Shift+Enter"
129129
/>
130130
<SaveButton
131131
label={'Add and Close'}
132132
onClick={() => handleSeqSubmit(true)}
133133
active={!addDisabled}
134-
title="Ctrl/Cmd + Enter"
134+
data-shortcut="Ctrl/Cmd+Enter"
135135
/>
136136
</Toolbar>
137137
}

src/styles/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ input:-webkit-autofill:focus {
139139

140140
.p-treetable .p-treetable-tbody > tr.new {
141141
border-left: 4px solid var(--color-changed);
142-
span {
142+
span:not(.changed) {
143143
color: var(--color-changed) !important;
144144
}
145145

0 commit comments

Comments
 (0)