2022-04-01 18:17:06 +00:00
|
|
|
import * as commands from 'app/client/components/commands';
|
|
|
|
import {DataTables} from 'app/client/components/DataTables';
|
|
|
|
import {DocumentUsage} from 'app/client/components/DocumentUsage';
|
|
|
|
import {GristDoc} from 'app/client/components/GristDoc';
|
|
|
|
import {printViewSection} from 'app/client/components/Printing';
|
2023-02-24 11:12:55 +00:00
|
|
|
import {ViewSectionHelper} from 'app/client/components/ViewLayout';
|
2024-02-13 17:49:00 +00:00
|
|
|
import {logTelemetryEvent} from 'app/client/lib/telemetry';
|
2024-01-30 14:49:00 +00:00
|
|
|
import {mediaSmall, theme, vars} from 'app/client/ui2018/cssVars';
|
2022-04-01 18:17:06 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
2022-04-13 17:26:59 +00:00
|
|
|
import {Computed, Disposable, dom, fromKo, makeTestId, Observable, styled} from 'grainjs';
|
2022-04-01 18:17:06 +00:00
|
|
|
import {reportError} from 'app/client/models/errors';
|
2022-08-24 11:43:15 +00:00
|
|
|
import {ViewSectionRec} from 'app/client/models/DocModel';
|
2023-02-24 11:12:55 +00:00
|
|
|
import {buildViewSectionDom} from 'app/client/components/buildViewSectionDom';
|
2024-02-13 17:49:00 +00:00
|
|
|
import {getTelemetryWidgetTypeFromVS} from 'app/client/ui/widgetTypesMap';
|
2022-04-01 18:17:06 +00:00
|
|
|
|
|
|
|
const testId = makeTestId('test-raw-data-');
|
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
export class RawDataPage extends Disposable {
|
2022-04-13 17:26:59 +00:00
|
|
|
private _lightboxVisible: Observable<boolean>;
|
2022-04-01 18:17:06 +00:00
|
|
|
constructor(private _gristDoc: GristDoc) {
|
|
|
|
super();
|
|
|
|
const commandGroup = {
|
|
|
|
printSection: () => { printViewSection(null, this._gristDoc.viewModel.activeSection()).catch(reportError); },
|
|
|
|
};
|
|
|
|
this.autoDispose(commands.createGroup(commandGroup, this, true));
|
2022-04-13 17:26:59 +00:00
|
|
|
this._lightboxVisible = Computed.create(this, use => {
|
|
|
|
const section = use(this._gristDoc.viewModel.activeSection);
|
2023-11-20 00:46:32 +00:00
|
|
|
return Boolean(use(section.id)) && (use(section.isRaw) || use(section.isRecordCard));
|
2022-04-13 17:26:59 +00:00
|
|
|
});
|
2022-04-27 17:46:24 +00:00
|
|
|
// When we are disposed, we want to clear active section in the viewModel we got (which is an empty model)
|
|
|
|
// to not restore the section when user will come back to Raw Data page.
|
|
|
|
// But by the time we are gone (disposed), active view will be changed, so here we will save the reference.
|
|
|
|
// TODO: empty view should rather have id = 0, not undefined. Should be fixed soon.
|
|
|
|
const emptyView = this._gristDoc.docModel.views.rowModels.find(x => x.id.peek() === undefined);
|
|
|
|
this.autoDispose(this._gristDoc.activeViewId.addListener(() => {
|
|
|
|
emptyView?.activeSectionId(0);
|
|
|
|
}));
|
|
|
|
// Whenever we close lightbox, clear cursor monitor state.
|
|
|
|
this.autoDispose(this._lightboxVisible.addListener(state => {
|
|
|
|
if (!state) {
|
|
|
|
this._gristDoc.cursorMonitor.clear();
|
|
|
|
}
|
|
|
|
}));
|
2022-04-01 18:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom() {
|
|
|
|
return cssContainer(
|
2023-01-20 13:53:29 +00:00
|
|
|
cssPage(
|
|
|
|
dom('div', this._gristDoc.behavioralPromptsManager.attachTip('rawDataPage', {hideArrow: true})),
|
|
|
|
dom('div',
|
|
|
|
dom.create(DataTables, this._gristDoc),
|
|
|
|
dom.create(DocumentUsage, this._gristDoc.docPageModel)
|
|
|
|
),
|
2022-04-13 17:26:59 +00:00
|
|
|
// We are hiding it, because overlay doesn't have a z-index (it conflicts with a searchbar and list buttons)
|
|
|
|
dom.hide(this._lightboxVisible)
|
|
|
|
),
|
2022-04-01 18:17:06 +00:00
|
|
|
/*************** Lightbox section **********/
|
2022-08-24 11:43:15 +00:00
|
|
|
dom.domComputed(fromKo(this._gristDoc.viewModel.activeSection), (viewSection) => {
|
2022-04-27 17:46:24 +00:00
|
|
|
const sectionId = viewSection.getRowId();
|
2023-11-20 00:46:32 +00:00
|
|
|
if (!sectionId || (!viewSection.isRaw.peek() && !viewSection.isRecordCard.peek())) {
|
2022-04-01 18:17:06 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-08-24 11:43:15 +00:00
|
|
|
return dom.create(RawDataPopup, this._gristDoc, viewSection, () => this._close());
|
2022-04-01 18:17:06 +00:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private _close() {
|
|
|
|
this._gristDoc.viewModel.activeSectionId(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
export class RawDataPopup extends Disposable {
|
|
|
|
constructor(
|
|
|
|
private _gristDoc: GristDoc,
|
|
|
|
private _viewSection: ViewSectionRec,
|
|
|
|
private _onClose: () => void,
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
const commandGroup = {
|
|
|
|
cancel: () => { this._onClose(); },
|
2023-02-24 11:12:55 +00:00
|
|
|
deleteSection: () => {
|
|
|
|
// Normally this command is disabled on the menu, but for collapsed section it is active.
|
|
|
|
if (this._viewSection.isRaw.peek()) {
|
|
|
|
throw new Error("Can't delete a raw section");
|
|
|
|
}
|
2024-02-13 17:49:00 +00:00
|
|
|
|
|
|
|
const widgetType = getTelemetryWidgetTypeFromVS(this._viewSection);
|
|
|
|
logTelemetryEvent('deletedWidget', {full: {docIdDigest: this._gristDoc.docId(), widgetType}});
|
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
this._gristDoc.docData.sendAction(['RemoveViewSection', this._viewSection.id.peek()]).catch(reportError);
|
|
|
|
},
|
2022-08-24 11:43:15 +00:00
|
|
|
};
|
|
|
|
this.autoDispose(commands.createGroup(commandGroup, this, true));
|
|
|
|
}
|
|
|
|
public buildDom() {
|
|
|
|
ViewSectionHelper.create(this, this._gristDoc, this._viewSection);
|
|
|
|
return cssOverlay(
|
|
|
|
testId('overlay'),
|
|
|
|
cssSectionWrapper(
|
|
|
|
buildViewSectionDom({
|
|
|
|
gristDoc: this._gristDoc,
|
|
|
|
sectionRowId: this._viewSection.getRowId(),
|
|
|
|
draggable: false,
|
|
|
|
focusable: false,
|
2023-11-20 00:46:32 +00:00
|
|
|
// Expanded, non-raw widgets are also rendered in RawDataPopup.
|
|
|
|
widgetNameHidden: this._viewSection.isRaw.peek(),
|
|
|
|
renamable: !this._viewSection.isRecordCard.peek(),
|
2022-08-24 11:43:15 +00:00
|
|
|
})
|
|
|
|
),
|
|
|
|
cssCloseButton('CrossBig',
|
|
|
|
testId('close-button'),
|
|
|
|
dom.on('click', () => this._onClose())
|
|
|
|
),
|
|
|
|
// Close the lightbox when user clicks exactly on the overlay.
|
|
|
|
dom.on('click', (ev, elem) => void (ev.target === elem ? this._onClose() : null))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 18:17:06 +00:00
|
|
|
const cssContainer = styled('div', `
|
2023-01-20 13:53:29 +00:00
|
|
|
height: 100%;
|
|
|
|
overflow: hidden;
|
2024-01-30 14:49:00 +00:00
|
|
|
inset: 0px;
|
|
|
|
position: absolute;
|
2023-01-20 13:53:29 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const cssPage = styled('div', `
|
|
|
|
overflow-y: auto;
|
2022-04-01 18:17:06 +00:00
|
|
|
height: 100%;
|
|
|
|
padding: 32px 64px 24px 64px;
|
|
|
|
@media ${mediaSmall} {
|
|
|
|
& {
|
|
|
|
padding: 32px 24px 24px 24px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2023-11-20 00:46:32 +00:00
|
|
|
export const cssOverlay = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.modalBackdrop};
|
2022-04-01 18:17:06 +00:00
|
|
|
inset: 0px;
|
2022-09-29 16:32:54 +00:00
|
|
|
padding: 20px 56px 20px 56px;
|
2022-04-01 18:17:06 +00:00
|
|
|
position: absolute;
|
2024-01-30 14:49:00 +00:00
|
|
|
z-index: ${vars.popupSectionBackdropZIndex};
|
2022-04-01 18:17:06 +00:00
|
|
|
@media ${mediaSmall} {
|
|
|
|
& {
|
|
|
|
padding: 22px;
|
|
|
|
padding-top: 30px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssSectionWrapper = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
background: ${theme.mainPanelBg};
|
2022-04-01 18:17:06 +00:00
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
border-radius: 5px;
|
|
|
|
border-bottom-left-radius: 0px;
|
|
|
|
border-bottom-right-radius: 0px;
|
|
|
|
& .viewsection_content {
|
|
|
|
margin: 0px;
|
2023-09-21 16:57:58 +00:00
|
|
|
margin-top: 8px;
|
2022-04-01 18:17:06 +00:00
|
|
|
}
|
|
|
|
& .viewsection_title {
|
|
|
|
padding: 0px 12px;
|
|
|
|
}
|
|
|
|
& .filter_bar {
|
|
|
|
margin-left: 6px;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2023-11-20 00:46:32 +00:00
|
|
|
export const cssCloseButton = styled(icon, `
|
2022-04-01 18:17:06 +00:00
|
|
|
position: absolute;
|
|
|
|
top: 16px;
|
|
|
|
right: 16px;
|
|
|
|
height: 24px;
|
|
|
|
width: 24px;
|
|
|
|
cursor: pointer;
|
2022-09-06 01:51:57 +00:00
|
|
|
--icon-color: ${theme.modalBackdropCloseButtonFg};
|
2022-04-01 18:17:06 +00:00
|
|
|
&:hover {
|
2022-09-06 01:51:57 +00:00
|
|
|
--icon-color: ${theme.modalBackdropCloseButtonHoverFg};
|
2022-04-01 18:17:06 +00:00
|
|
|
}
|
|
|
|
@media ${mediaSmall} {
|
|
|
|
& {
|
|
|
|
top: 6px;
|
|
|
|
right: 6px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|