From d975022811f33c1e9dc0bcaf539ad2f91a0b0028 Mon Sep 17 00:00:00 2001 From: DudaGod Date: Wed, 17 Jul 2024 20:17:13 +0300 Subject: [PATCH] feat: add "timestamp" field to redux storage --- lib/report-builder/gui.ts | 10 +++++++--- lib/server-utils.ts | 7 ++++++- lib/static/components/controls/report-info.jsx | 6 +++--- lib/static/modules/reducers/date.js | 1 + lib/static/modules/reducers/index.js | 4 +++- lib/static/modules/reducers/timestamp.js | 17 +++++++++++++++++ 6 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 lib/static/modules/reducers/timestamp.js diff --git a/lib/report-builder/gui.ts b/lib/report-builder/gui.ts index f195e8b53..58c0feced 100644 --- a/lib/report-builder/gui.ts +++ b/lib/report-builder/gui.ts @@ -24,8 +24,9 @@ export interface GuiReportBuilderResult { tree: Tree; skips: SkipItem[]; config: ConfigForStaticFile & {customGui: ReporterConfig['customGui']}; - date: string; + timestamp: number; apiValues?: HtmlReporterValues; + date: string; } export class GuiReportBuilder extends StaticReportBuilder { @@ -62,13 +63,16 @@ export class GuiReportBuilder extends StaticReportBuilder { const config = {...getConfigForStaticFile(this._reporterConfig), customGui}; this._testsTree.sortTree(); + const timestamp = Date.now(); return { tree: this._testsTree.tree, skips: this._skips, config, - date: new Date().toString(), - apiValues: this._apiValues + apiValues: this._apiValues, + timestamp, + // TODO: remove in next major (should use timestamp instead) + date: new Date(timestamp).toString() }; } diff --git a/lib/server-utils.ts b/lib/server-utils.ts index 690c2c6fb..96833b13c 100644 --- a/lib/server-utils.ts +++ b/lib/server-utils.ts @@ -230,15 +230,20 @@ export interface DataForStaticFile { skips: object[]; config: ConfigForStaticFile; apiValues: HtmlReporter['values']; + timestamp: number; date: string; } export function getDataForStaticFile(htmlReporter: HtmlReporter, pluginConfig: ReporterConfig): DataForStaticFile { + const timestamp = Date.now(); + return { skips: [], config: getConfigForStaticFile(pluginConfig), apiValues: htmlReporter.values, - date: new Date().toString() + timestamp, + // TODO: remove in next major (should use timestamp instead) + date: new Date(timestamp).toString() }; } diff --git a/lib/static/components/controls/report-info.jsx b/lib/static/components/controls/report-info.jsx index b905920bd..34b005b22 100644 --- a/lib/static/components/controls/report-info.jsx +++ b/lib/static/components/controls/report-info.jsx @@ -5,7 +5,7 @@ import { Label } from '@gravity-ui/uikit'; class ReportInfo extends Component { render() { - const {gui, date} = this.props; + const {gui, timestamp} = this.props; return (
@@ -15,7 +15,7 @@ class ReportInfo extends Component { {!gui && }
); @@ -23,5 +23,5 @@ class ReportInfo extends Component { } export default connect( - ({gui, date}) => ({gui, date}) + ({gui, timestamp}) => ({gui, timestamp}) )(ReportInfo); diff --git a/lib/static/modules/reducers/date.js b/lib/static/modules/reducers/date.js index 65791ccfa..159791a4c 100644 --- a/lib/static/modules/reducers/date.js +++ b/lib/static/modules/reducers/date.js @@ -1,6 +1,7 @@ import actionNames from '../action-names'; import {dateToLocaleString} from '../utils'; +// TODO: remove in next major (should use timestamp instead) export default (state, action) => { switch (action.type) { case actionNames.INIT_GUI_REPORT: diff --git a/lib/static/modules/reducers/index.js b/lib/static/modules/reducers/index.js index 7e70ebc49..1945fb461 100644 --- a/lib/static/modules/reducers/index.js +++ b/lib/static/modules/reducers/index.js @@ -7,6 +7,7 @@ import running from './running'; import processing from './processing'; import loading from './loading'; import gui from './gui'; +import timestamp from './timestamp'; import date from './date'; import autoRun from './auto-run'; import apiValues from './api-values'; @@ -37,7 +38,8 @@ export default reduceReducers( stopping, loading, gui, - date, + timestamp, + date, // TODO: remove in next major (should use timestamp instead) autoRun, apiValues, modals, diff --git a/lib/static/modules/reducers/timestamp.js b/lib/static/modules/reducers/timestamp.js new file mode 100644 index 000000000..a674b276d --- /dev/null +++ b/lib/static/modules/reducers/timestamp.js @@ -0,0 +1,17 @@ +import actionNames from '../action-names'; + +export default (state, action) => { + switch (action.type) { + case actionNames.INIT_GUI_REPORT: + case actionNames.INIT_STATIC_REPORT: { + const {timestamp} = action.payload; + + console.log('timestamp:', timestamp); + + return {...state, timestamp}; + } + + default: + return state; + } +};