Skip to content

Commit

Permalink
CB-6181 fix: show save/cancel buttons in json docs (#3222)
Browse files Browse the repository at this point in the history
* CB-6181 fix: show save/cancel buttons in json docs

* CB-6181 refactor: change condition for SAVE/CANCEL buttons

The problem is that for select 1 in TE we get different result from other product, because in CE/EE we use ResultSetFooterMenuService, while for TE we use regular TableFooterMenuService. model.source.isReadOnly flag doesn't return true anymore since we extracted hasRowIdentifier flag from it, so we get redundant buttons in tables like that in TE.

Since the only difference is products where we are executing this script, it's quite hard to detect it inside a component. I decided to check editor's features, they are empty in this case (select 1) in all products, so we can be 100% sure that if there are no features, we don't need any buttons.

The other problem that for Document type of data format we also don't have features (and we use the same footer menu service). If it's not read-only, we need to have those buttons to save/cancel edits. The first solution is to check data format is Document (or check the editor type or to try get action with needed type). The other solution that I used is to check hasRowIdentifier flag(hasElementIdentifier) because editable documents will have it true, while datasets like select 1 don't have them. It looks more generic for me and should work in more cases in future

* СB-6181 refactor: update isReadonly flag for resultset

---------

Co-authored-by: Evgenia <[email protected]>
  • Loading branch information
SychevAndrey and EvgeniaBzzz authored Feb 6, 2025
1 parent 4388491 commit 107436a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export abstract class ResultSetDataSource<TOptions = IDatabaseDataOptions> exten
}

override isReadonly(resultIndex: number): boolean {
return super.isReadonly(resultIndex) || !this.executionContext?.context;
return (
super.isReadonly(resultIndex) ||
!this.executionContext?.context ||
!!this.getResult(resultIndex)?.data?.columns?.every(column => column.readOnly)
);
}

override async cancel(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ export class TableFooterMenuService {
case ACTION_REVERT: {
return editor.hasFeature('revert');
}
case ACTION_SAVE:
case ACTION_CANCEL: {
return editor.hasFeature('add') || editor.hasFeature('delete') || editor.hasFeature('revert');
}
}
return true;
},
Expand Down

0 comments on commit 107436a

Please sign in to comment.