form view - find by ID

This commit is contained in:
Jan Prochazka
2021-01-14 19:36:03 +01:00
parent ad4fa77e46
commit 4328107a1d
4 changed files with 103 additions and 30 deletions

View File

@@ -73,4 +73,44 @@ export class FormViewDisplay {
refreshTime: new Date().getTime(),
}));
}
getKeyValue(columnName) {
const { formViewKey, formViewKeyRequested } = this.config;
if (formViewKeyRequested && formViewKeyRequested[columnName]) return formViewKeyRequested[columnName];
if (formViewKey && formViewKey[columnName]) return formViewKey[columnName];
return null;
}
requestKeyValue(columnName, value) {
if (this.getKeyValue(columnName) == value) return;
this.setConfig((cfg) => ({
...cfg,
formViewKeyRequested: {
...cfg.formViewKey,
...cfg.formViewKeyRequested,
[columnName]: value,
},
}));
this.reload();
}
extractKey(row) {
if (!row || !this.baseTable || !this.baseTable.primaryKey) {
return null;
}
const formViewKey = _.pick(
row,
this.baseTable.primaryKey.columns.map((x) => x.columnName)
);
return formViewKey;
}
cancelRequestKey(rowData) {
this.setConfig((cfg) => ({
...cfg,
formViewKeyRequested: null,
formViewKey: rowData ? this.extractKey(rowData) : cfg.formViewKey,
}));
}
}