Skip to content

Commit

Permalink
JS-3863: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3orblade committed Apr 21, 2024
1 parent 8f25c41 commit 8450b25
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
17 changes: 11 additions & 6 deletions src/ts/component/block/dataview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,8 @@ const BlockDataview = observer(class BlockDataview extends React.Component<Props
]);

addParam.name = translate('blockDataviewCreateNewCollection');
addParam.onClick = () => {
C.ObjectCreate({ layout: I.ObjectLayout.Collection }, [], '', collectionType?.uniqueKey, commonStore.space, message => onSelect(message.details, true));
addParam.onClick = (details: any) => {
C.ObjectCreate({ ...details, layout: I.ObjectLayout.Collection }, [], '', collectionType?.uniqueKey, commonStore.space, message => onSelect(message.details, true));
};
} else {
filters = filters.concat([
Expand All @@ -953,8 +953,8 @@ const BlockDataview = observer(class BlockDataview extends React.Component<Props
]);

addParam.name = translate('blockDataviewCreateNewSet');
addParam.onClick = () => {
C.ObjectCreateSet([], {}, '', commonStore.space, message => onSelect(message.details, true));
addParam.onClick = (details: any) => {
C.ObjectCreateSet([], details, '', commonStore.space, message => onSelect(message.details, true));
};
};

Expand All @@ -970,8 +970,13 @@ const BlockDataview = observer(class BlockDataview extends React.Component<Props
window.setTimeout(() => this.loadData(message.views[0].id, 0, true), 50);
};

if (isNew) {
this.refControls?.refHead?.setEditing(true);
if (isNew && this.refControls && this.refControls.refHead) {
const ref = this.refControls.refHead;
const l = item.name.length;

ref.setValue(item.name);
ref.setRange({ from: l, to: l });
ref.setEditing(true);
};

if (isInline) {
Expand Down
14 changes: 9 additions & 5 deletions src/ts/component/block/dataview/head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const Head = observer(class Head extends React.Component<I.ViewComponent, State>
if (this.state.isEditing && this.ref) {
window.setTimeout(() => {
const l = this.getValue().length;
this.ref.setRange(this.range || { from: l, to: l });
this.setRange(this.range || { from: l, to: l });
}, 15);
};
};
Expand Down Expand Up @@ -186,8 +186,8 @@ const Head = observer(class Head extends React.Component<I.ViewComponent, State>
]);

addParam.name = translate('blockDataviewCreateNewCollection');
addParam.onClick = () => {
C.ObjectCreate({ layout: I.ObjectLayout.Collection }, [], '', Constant.typeKey.collection, commonStore.space, (message: any) => {
addParam.onClick = (details: any) => {
C.ObjectCreate({ ...details, layout: I.ObjectLayout.Collection }, [], '', Constant.typeKey.collection, commonStore.space, (message: any) => {
C.BlockDataviewCreateFromExistingObject(rootId, block.id, message.objectId, (message: any) => onCreate(message, true));
});
};
Expand All @@ -198,8 +198,8 @@ const Head = observer(class Head extends React.Component<I.ViewComponent, State>
]);

addParam.name = translate('blockDataviewCreateNewSet');
addParam.onClick = () => {
C.ObjectCreateSet([], {}, '', commonStore.space, (message: any) => {
addParam.onClick = (details: any) => {
C.ObjectCreateSet([], details, '', commonStore.space, (message: any) => {
C.BlockDataviewCreateFromExistingObject(rootId, block.id, message.objectId, (message: any) => {
$(this.node).find('#head-source-select').trigger('click');
onCreate(message, true);
Expand Down Expand Up @@ -372,6 +372,10 @@ const Head = observer(class Head extends React.Component<I.ViewComponent, State>
analytics.event('InlineSetOpenFullscreen');
};

setRange (range: I.TextRange) {
this.ref.setRange(range);
};

setEditing (v: boolean) {
this.setState({ isEditing: v });
};
Expand Down
8 changes: 4 additions & 4 deletions src/ts/component/menu/block/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,16 @@ class MenuBlockAction extends React.Component<I.Menu, State> {
name: UtilCommon.sprintf(translate('menuBlockActionsCreateNew'), name),
};
if (isCollection) {
addParam.onClick = () => {
C.ObjectCreate({ layout: I.ObjectLayout.Collection }, [], '', Constant.typeKey.collection, commonStore.space, () => onCreate());
addParam.onClick = (details: any) => {
C.ObjectCreate({ ...details, layout: I.ObjectLayout.Collection }, [], '', Constant.typeKey.collection, commonStore.space, () => onCreate());
};

filters = filters.concat([
{ operator: I.FilterOperator.And, relationKey: 'layout', condition: I.FilterCondition.Equal, value: I.ObjectLayout.Collection },
]);
} else {
addParam.onClick = () => {
C.ObjectCreateSet([], {}, '', commonStore.space, () => onCreate());
addParam.onClick = (details: any) => {
C.ObjectCreateSet([], details, '', commonStore.space, () => onCreate());
};

filters = filters.concat([
Expand Down
7 changes: 5 additions & 2 deletions src/ts/component/menu/search/object.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,16 @@ const MenuSearchObject = observer(class MenuSearchObject extends React.Component
};
};



if (item.isAdd) {
details = { name: filter, ...details };

if (addParam.onClick) {
addParam.onClick();
addParam.onClick(details);
close();
} else {
const flags = [ I.ObjectFlag.SelectType, I.ObjectFlag.SelectTemplate ];
details = { name: filter, type: commonStore.type, ...details };

UtilObject.create('', '', details, I.BlockPosition.Bottom, '', {}, flags, 'Search', (message: any) => {
process(message.details, true);
Expand Down

0 comments on commit 8450b25

Please sign in to comment.