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

Bdomen react api utils #1143

Merged
merged 36 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a6801ea
adding api calls
bdomen-ggl Jul 31, 2023
8ca07cf
linting
bdomen-ggl Jul 31, 2023
39ec7f8
missed license header
bdomen-ggl Jul 31, 2023
cc44535
some API tweaks
bdomen-ggl Jul 31, 2023
156e64b
changing name
bdomen-ggl Aug 2, 2023
16fe19f
updating async/await and then
bdomen-ggl Aug 2, 2023
3b1f7f9
moving memoization into a class so it's not global
bdomen-ggl Aug 2, 2023
c3f3dfc
renamed some files and classes and removed utils
bdomen-ggl Aug 2, 2023
f513812
simplifying Promise.resolve
bdomen-ggl Aug 2, 2023
c5484b5
freezing server responses
bdomen-ggl Aug 2, 2023
41f4a93
renaming files to fit style guide
bdomen-ggl Aug 2, 2023
aa9250c
moving fake to test and starting to add app config management
bdomen-ggl Aug 3, 2023
49da168
adding all the BUILD files
bdomen-ggl Aug 4, 2023
a59dccc
fixed an issue with a BUILD
bdomen-ggl Aug 4, 2023
9ffacc7
fixing linting
bdomen-ggl Aug 4, 2023
296285d
missing license header
bdomen-ggl Aug 4, 2023
82909dc
formatting BAZEL files
bdomen-ggl Aug 4, 2023
99c434f
fixing some BUILD files and adding rest in tests
bdomen-ggl Aug 4, 2023
ae5346a
trying to fix BUILD
bdomen-ggl Aug 4, 2023
2b1d53d
removing ts_project from BUILD, not needed
bdomen-ggl Aug 7, 2023
6034640
fixing __mocks__ name change error
bdomen-ggl Aug 7, 2023
93a7d4b
fixing BUILD lint
bdomen-ggl Aug 7, 2023
ad82422
moving file structure
bdomen-ggl Aug 8, 2023
3f47ded
fixing linting
bdomen-ggl Aug 8, 2023
0b70496
moving files
bdomen-ggl Aug 8, 2023
d044189
fixing a BUILD target path
bdomen-ggl Aug 8, 2023
f8c8f13
trying to fix BUILD lint
bdomen-ggl Aug 8, 2023
25bb157
fixing test
bdomen-ggl Aug 8, 2023
923032c
moving files and removing client base
bdomen-ggl Aug 9, 2023
3726a72
fixing BUILD lint
bdomen-ggl Aug 9, 2023
eecb6ee
fixing BUILD lint
bdomen-ggl Aug 9, 2023
2703a1d
removing generic memoization and updating a name
bdomen-ggl Aug 9, 2023
3f16129
missed license header
bdomen-ggl Aug 9, 2023
9f551c6
fixing test file naming standards
bdomen-ggl Aug 10, 2023
7ffeb2e
fixing global constant style
bdomen-ggl Aug 14, 2023
4d59852
forgot to save the other file updates
bdomen-ggl Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions experimental/reporting-ui/src/main/react/reporting-ui/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@ load("@aspect_rules_webpack//webpack:defs.bzl", "webpack_bundle", "webpack_devse
npm_link_all_packages()

js_library(
name = "build_node_deps",
name = "app",
srcs = [
"app.css",
"app.tsx",
"index.css",
"index.tsx",
"logo.tsx",
"report_web_vitals.ts",
],
visibility = [
"//experimental/reporting-ui/src/main/react/reporting-ui:__subpackages__",
"//experimental/reporting-ui/src/test/react/reporting-ui:__subpackages__",
],
)

js_library(
name = "node_deps",
srcs = [
"//:node_modules/babel-loader",
"//:node_modules/css-loader",
Expand Down Expand Up @@ -37,26 +53,30 @@ js_library(
webpack_bundle(
name = "webpack_bundle",
srcs = [
":app",
":webpack_config",
"//:tsconfig",
"//experimental/reporting-ui/src/main/react/reporting-ui/client",
"//experimental/reporting-ui/src/main/react/reporting-ui/model/reporting",
"//experimental/reporting-ui/src/main/react/reporting-ui/public",
"//experimental/reporting-ui/src/main/react/reporting-ui/src:src_files",
],
node_modules = "//:node_modules",
output_dir = True,
webpack_config = ":webpack_config",
deps = [
":build_node_deps",
":node_deps",
],
)

webpack_devserver(
name = "webpack_devserver",
data = [
":build_node_deps",
":app",
":node_deps",
"//:tsconfig",
"//experimental/reporting-ui/src/main/react/reporting-ui/client",
"//experimental/reporting-ui/src/main/react/reporting-ui/model/reporting",
"//experimental/reporting-ui/src/main/react/reporting-ui/public",
"//experimental/reporting-ui/src/main/react/reporting-ui/src:src_files",
],
node_modules = "//:node_modules",
webpack_config = ":webpack_config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import React from 'react';
import Logo from './logo';
import './App.css';
import './app.css';

function App() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")

package(
default_visibility = [
"//experimental/reporting-ui/src/main/react/reporting-ui:__subpackages__",
"//experimental/reporting-ui/src/test/react/reporting-ui:__subpackages__",
],
)

js_library(
name = "client",
srcs = [
"initialize.ts",
],
deps = [
"//experimental/reporting-ui/src/main/react/reporting-ui/client/reporting",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023 The Cross-Media Measurement Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { ReportingClient } from "./reporting/client"

type ConfigProps = {
reportingClient: ReportingClient;
}

class AppConfig {
reportingApi?: ReportingClient;

initialize(props:ConfigProps) {
this.reportingApi = props.reportingClient;
}
}

const appConfig = new AppConfig();
export default appConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")

package(
default_visibility = [
"//experimental/reporting-ui/src/main/react/reporting-ui:__subpackages__",
],
)

js_library(
name = "reporting",
srcs = [
"client.ts",
"client_impl.ts",
],
deps = [
"//experimental/reporting-ui/src/main/react/reporting-ui/model/reporting",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 The Cross-Media Measurement Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {
GetReportRequest,
GetReportResponse,
ListReportsResponse,
} from '../../model/reporting';

export interface ReportingClient {
listReports(): Promise<ListReportsResponse>;
getReport(req: GetReportRequest): Promise<GetReportResponse>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2023 The Cross-Media Measurement Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {
GetReportRequest,
GetReportResponse,
InitApiProps,
ListReportsResponse,
Report,
TERMINAL_STATES,
} from '../../model/reporting';

export class ReportingClientImpl {
// eslint-disable-next-line node/no-unsupported-features/node-builtins
baseUrl: URL;
cache: Map<string, any> = new Map();

constructor(props: InitApiProps) {
this.baseUrl = props.endpoint;
}

async listReports(): Promise<ListReportsResponse> {
const res = await fetch(this.baseUrl.toString() + '/api/reports');
const reports = await res.json();
const response = Object.freeze({
reports,
});
return response;
}

async getReport(req: GetReportRequest): Promise<GetReportResponse> {
const key = JSON.stringify(req);

if (this.cache.has(key)) {
return this.cache.get(key);
}

const res = await fetch(this.baseUrl.toString() + '/api/reports' + req.id);
const report: Report = await res.json();
const response = Object.freeze({
report,
});

if (TERMINAL_STATES.includes(report.status)) {
this.cache.set(key, response);
}

return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_webpack//webpack:defs.bzl", "webpack_devserver")

package(
default_testonly = True,
)

js_library(
name = "fake_app",
srcs = [
"fake_reporting_client.ts",
"index.tsx",
],
deps = [
"//:node_modules/react",
"//:node_modules/react-dom",
"//experimental/reporting-ui/src/main/react/reporting-ui/client",
"//experimental/reporting-ui/src/main/react/reporting-ui/model/reporting",
],
)

webpack_devserver(
name = "webpack_testserver",
data = [
":fake_app",
"//:tsconfig",
"//experimental/reporting-ui/src/main/react/reporting-ui:app",
"//experimental/reporting-ui/src/main/react/reporting-ui:node_deps",
"//experimental/reporting-ui/src/main/react/reporting-ui/model/reporting",
"//experimental/reporting-ui/src/main/react/reporting-ui/public",
],
node_modules = "//:node_modules",
webpack_config = ":webpack.config.js",
)
Loading