Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api with technical id for col #694

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
27 changes: 27 additions & 0 deletions app/server/lib/ActiveDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,9 @@ export class ActiveDoc extends EventEmitter {
private async _fetchQueryFromDB(query: ServerQuery, onDemand: boolean): Promise<TableDataAction> {
// Expand query to compute formulas (or include placeholders for them).
const expandedQuery = expandQuery(query, this.docData!, onDemand);
console.log("--------------fetchQueryFromDB----------------------");
console.log(expandedQuery);
console.log(this.docData!);
const marshalled = await this.docStorage.fetchQuery(expandedQuery);
const table = this.docStorage.decodeMarshalledData(marshalled, query.tableId);

Expand All @@ -2524,6 +2527,8 @@ export class ActiveDoc extends EventEmitter {
}

private async _fetchQueryFromDataEngine(query: ServerQuery): Promise<TableDataAction> {
console.log("--------------_fetchQueryFromDataEngine----------------------");
console.log(await this._pyCall('fetch_table', query.tableId, true, query.filters));
return this._pyCall('fetch_table', query.tableId, true, query.filters);
}

Expand Down Expand Up @@ -2829,6 +2834,28 @@ export async function getRealTableId(
return tableId;
}

// Helper that check if colRef is used instead of colId and return real colId
export async function getRealColId(
tableId: string,
colId: string,
options: MetaTables | ActiveDocAndReq
): Promise<string> {
if(parseInt(colId)){
const metaTables = "metaTables" in options
? options.metaTables
: await getMetaTables(options.activeDoc, options.req);
const tableRef = tableIdToRef(metaTables, tableId);
const [, , colRefs, columnData] = metaTables._grist_Tables_column;
const colRowIndex = colRefs.findIndex((_, i) => (
colRefs[i] === parseInt(colId) && columnData.parentId[i] === tableRef
));
if(colRowIndex >= 0) {
return columnData.colId[colRowIndex]!.toString();
}
}
return colId;
}

export function sanitizeApplyUAOptions(options?: ApplyUAOptions): ApplyUAOptions {
return pick(options||{}, ['desc', 'otherId', 'linkId', 'parseStrings']);
}
24 changes: 19 additions & 5 deletions app/server/lib/DocApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ import {
TableOperationsImpl,
TableOperationsPlatform
} from 'app/plugin/TableOperationsImpl';
import {ActiveDoc, colIdToRef as colIdToReference, getRealTableId, tableIdToRef} from "app/server/lib/ActiveDoc";
import {
ActiveDoc,
colIdToRef as colIdToReference,
getRealColId,
getRealTableId,
tableIdToRef
} from "app/server/lib/ActiveDoc";
import {appSettings} from "app/server/lib/AppSettings";
import {sendForCompletion} from 'app/server/lib/Assistance';
import {
Expand Down Expand Up @@ -207,6 +213,9 @@ export class DocWorkerApi {
session, {tableId, filters}, !immediate));
// For metaTables we don't need to specify columns, search will infer it from the sort expression.
const isMetaTable = tableId.startsWith('_grist');
console.log("////////////////////////////// in getTableData");
console.log("---- tableData");
console.log(tableData);
const columns = isMetaTable ? null :
await handleSandboxError('', [], activeDoc.getTableCols(session, tableId, true));
const params = getQueryParameters(req);
Expand All @@ -216,9 +225,13 @@ export class DocWorkerApi {
}

async function getTableRecords(
activeDoc: ActiveDoc, req: RequestWithLogin, opts?: { optTableId?: string; includeHidden?: boolean }
activeDoc: ActiveDoc,
req: RequestWithLogin,
opts?: { optTableId?: string; includeHidden?: boolean, useColRef?: boolean }
): Promise<TableRecordValue[]> {
const columnData = await getTableData(activeDoc, req, opts?.optTableId);
console.log("------------------- colummnDATA in getTableRecords");
console.log(columnData);
const fieldNames = Object.keys(columnData).filter((k) => {
if (k === "id") {
return false;
Expand Down Expand Up @@ -256,7 +269,7 @@ export class DocWorkerApi {
this._app.get('/api/docs/:docId/tables/:tableId/records', canView,
withDoc(async (activeDoc, req, res) => {
const records = await getTableRecords(activeDoc, req,
{ includeHidden: isAffirmative(req.query.hidden) }
{ includeHidden: isAffirmative(req.query.hidden), useColRef: isAffirmative(req.query.use_col_ref) }
);
res.json({records});
})
Expand Down Expand Up @@ -781,8 +794,9 @@ export class DocWorkerApi {

this._app.delete('/api/docs/:docId/tables/:tableId/columns/:colId', canEdit,
withDoc(async (activeDoc, req, res) => {
const {colId} = req.params;
const tableId = await getRealTableId(req.params.tableId, {activeDoc, req});
const metaTables = await getMetaTables(activeDoc, req);
const tableId = await getRealTableId(req.params.tableId, {metaTables});
const colId = await getRealColId(tableId, req.params.colId, {metaTables});
const actions = [ [ 'RemoveColumn', tableId, colId ] ];
await handleSandboxError(tableId, [colId],
activeDoc.applyUserActions(docSessionFromRequest(req), actions)
Expand Down
1 change: 1 addition & 0 deletions sandbox/grist/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def fetch_table(self, table_id, formulas=True, private=False, query=None):
"""
Returns TableData object representing all data in this table.
"""
print("Je suis dans le fichier de PYTHON YOUHOUUUUUUU", file=sys.stderr)
table = self.tables[table_id]
column_values = {}

Expand Down
Loading