From a0fcf2fb15cb431aceca5acda6d3f2b88724ce2c Mon Sep 17 00:00:00 2001 From: Pavel Date: Sun, 28 Apr 2024 23:06:48 -0700 Subject: [PATCH 1/4] feat: add support for scheduled emulator in config and UI --- firebase.json | 3 + src/components/Home/index.tsx | 9 +++ src/components/Scheduled/List/List.tsx | 42 +++++++++++ .../ScheduledTable/ScheduledTable.module.scss | 19 +++++ .../List/ScheduledTable/ScheduledTable.tsx | 42 +++++++++++ .../ScheduledTableRow.module.scss | 48 ++++++++++++ .../List/ScheduledTable/ScheduledTableRow.tsx | 75 +++++++++++++++++++ .../Scheduled/List/ZeroState.module.scss | 23 ++++++ src/components/Scheduled/List/ZeroState.tsx | 33 ++++++++ .../api/internal/useScheduledFunctions.tsx | 51 +++++++++++++ src/components/Scheduled/api/useScheduled.tsx | 36 +++++++++ src/components/Scheduled/index.tsx | 62 +++++++++++++++ src/components/Scheduled/models.ts | 25 +++++++ src/components/common/icons.tsx | 29 +++++++ src/routes.ts | 11 +++ src/store/config/types.ts | 2 + 16 files changed, 510 insertions(+) create mode 100644 src/components/Scheduled/List/List.tsx create mode 100644 src/components/Scheduled/List/ScheduledTable/ScheduledTable.module.scss create mode 100644 src/components/Scheduled/List/ScheduledTable/ScheduledTable.tsx create mode 100644 src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.module.scss create mode 100644 src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.tsx create mode 100644 src/components/Scheduled/List/ZeroState.module.scss create mode 100644 src/components/Scheduled/List/ZeroState.tsx create mode 100644 src/components/Scheduled/api/internal/useScheduledFunctions.tsx create mode 100644 src/components/Scheduled/api/useScheduled.tsx create mode 100644 src/components/Scheduled/index.tsx create mode 100644 src/components/Scheduled/models.ts diff --git a/firebase.json b/firebase.json index a3d95a51a..15db462f6 100644 --- a/firebase.json +++ b/firebase.json @@ -28,6 +28,9 @@ }, "pubsub": { "port": 8085 + }, + "scheduled": { + "port": 8086 } }, "extensions": { diff --git a/src/components/Home/index.tsx b/src/components/Home/index.tsx index a4af30800..b4be7ca3e 100644 --- a/src/components/Home/index.tsx +++ b/src/components/Home/index.tsx @@ -38,6 +38,7 @@ import { FunctionsIcon, HostingIcon, PubSubIcon, + ScheduledIcon, StorageIcon, } from '../common/icons'; import { Spinner } from '../common/Spinner'; @@ -124,6 +125,14 @@ const Overview: React.FC< config={config.pubsub} testId="emulator-info-pubsub" /> + } + config={config.scheduled} + testId="emulator-info-scheduled" + linkTo="/scheduled" + linkLabel="Go to scheduled emulator" + /> } diff --git a/src/components/Scheduled/List/List.tsx b/src/components/Scheduled/List/List.tsx new file mode 100644 index 000000000..639d47c33 --- /dev/null +++ b/src/components/Scheduled/List/List.tsx @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Google LLC + * + * 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 { Card } from '@rmwc/card'; +import { Elevation } from '@rmwc/elevation'; +import { GridCell } from '@rmwc/grid'; +import React from 'react'; + +import { useScheduled } from '../api/useScheduled'; +import { ScheduledTable } from './ScheduledTable/ScheduledTable'; +import { ZeroState } from './ZeroState'; + +export const ScheduledList: React.FC> = () => { + const specs = useScheduled(); + + return ( + + + + {specs.length ? ( + + ) : ( + + )} + + + + ); +}; diff --git a/src/components/Scheduled/List/ScheduledTable/ScheduledTable.module.scss b/src/components/Scheduled/List/ScheduledTable/ScheduledTable.module.scss new file mode 100644 index 000000000..93ea7e747 --- /dev/null +++ b/src/components/Scheduled/List/ScheduledTable/ScheduledTable.module.scss @@ -0,0 +1,19 @@ +/** + * Copyright 2022 Google LLC + * + * 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. + */ + +.scheduledTable { + border-radius: 8px; +} diff --git a/src/components/Scheduled/List/ScheduledTable/ScheduledTable.tsx b/src/components/Scheduled/List/ScheduledTable/ScheduledTable.tsx new file mode 100644 index 000000000..39bf56f05 --- /dev/null +++ b/src/components/Scheduled/List/ScheduledTable/ScheduledTable.tsx @@ -0,0 +1,42 @@ +/** + * Copyright 2022 Google LLC + * + * 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 { DataTable, DataTableBody, DataTableContent } from '@rmwc/data-table'; +import React from 'react'; + +import { ScheduledFunction } from '../../models'; +import styles from './ScheduledTable.module.scss'; +import { ScheduledTableRow } from './ScheduledTableRow'; + +export interface ScheduledTableProps { + functions: ScheduledFunction[]; +} + +export const ScheduledTable: React.FC< + React.PropsWithChildren +> = ({ functions }) => { + return ( + + + + {functions.map((func) => ( + + ))} + + + + ); +}; diff --git a/src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.module.scss b/src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.module.scss new file mode 100644 index 000000000..6059e11ae --- /dev/null +++ b/src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.module.scss @@ -0,0 +1,48 @@ +/** + * Copyright 2022 Google LLC + * + * 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. + */ + +.infoCell { + padding: 8px 16px; +} + +.iconCell { + padding-left: 16px; + padding-right: 0px; + align-items: center; + justify-content: center; + display: flex; + height: 100px; + width: 72px; + + svg { + color: var(--mdc-theme-primary); + scale: 1.5; + } +} + +.infoHeader { + align-items: center; + display: flex; + + img { + height: 16px; + width: 16px; + } +} + +.infoCell { + width: 100%; +} diff --git a/src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.tsx b/src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.tsx new file mode 100644 index 000000000..00fb56849 --- /dev/null +++ b/src/components/Scheduled/List/ScheduledTable/ScheduledTableRow.tsx @@ -0,0 +1,75 @@ +/** + * Copyright 2022 Google LLC + * + * 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 { Button } from '@rmwc/button'; +import { DataTableCell, DataTableRow } from '@rmwc/data-table'; +import { Typography } from '@rmwc/typography'; +import React, { useCallback } from 'react'; + +import { useEmulatorConfig } from '../../../common/EmulatorConfigProvider'; +import { ScheduledIcon } from '../../../common/icons'; +import { forceRunScheduledFunction } from '../../api/internal/useScheduledFunctions'; +import { ScheduledFunction } from '../../models'; +import styles from './ScheduledTableRow.module.scss'; + +export interface ScheduledTableRowProps { + scheduledFunc: ScheduledFunction; +} + +export const ScheduledTableRow: React.FC< + React.PropsWithChildren +> = ({ scheduledFunc }) => { + const { hostAndPort } = useEmulatorConfig('functions'); + + const handleClick = useCallback( + () => forceRunScheduledFunction(scheduledFunc.id, hostAndPort), + [scheduledFunc, hostAndPort] + ); + + return ( + + + {} + + +
+ + {scheduledFunc.name} + +
+
+ + {scheduledFunc.scheduleTrigger.schedule} + +
+
+ +