Skip to content

Commit

Permalink
PR reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine THEBAUD <antoine.thebaud@yahoo.fr>
  • Loading branch information
AntoineThebaud committed Feb 28, 2024
1 parent f1236ee commit 3f9df46
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface Row {
version: number;
createdAt: string;
updatedAt: string;
expireAt: Date;
expireAt: string;
}

function NoEphemeralDashboardRowOverlay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {
getDashboardDisplayName,
EphemeralDashboardResource,
DashboardResource,
parseDurationString,
} from '@perses-dev/core';
import { getDashboardDisplayName, EphemeralDashboardResource, parseDurationString } from '@perses-dev/core';
import { Box, Stack, Tooltip } from '@mui/material';
import { GridColDef, GridRowParams, GridValueGetterParams } from '@mui/x-data-grid';
import DeleteIcon from 'mdi-material-ui/DeleteOutline';
Expand Down Expand Up @@ -55,11 +50,11 @@ export function EphemeralDashboardList(props: EphemeralDashboardListProperties)
[ephemeralDashboardList]
);

const getExpirationDate = useCallback((ephemeralDashboard: EphemeralDashboardResource): Date => {
const getExpirationDate = useCallback((ephemeralDashboard: EphemeralDashboardResource): string => {
return add(
ephemeralDashboard.metadata.updatedAt ? new Date(ephemeralDashboard.metadata.updatedAt) : new Date(),
parseDurationString(ephemeralDashboard.spec.ttl)
);
).toLocaleString();
}, []);

const rows = useMemo(() => {
Expand All @@ -68,7 +63,7 @@ export function EphemeralDashboardList(props: EphemeralDashboardListProperties)
({
project: ephemeralDashboard.metadata.project,
name: ephemeralDashboard.metadata.name,
displayName: getDashboardDisplayName(ephemeralDashboard as unknown as DashboardResource),
displayName: getDashboardDisplayName(ephemeralDashboard),
expireAt: getExpirationDate(ephemeralDashboard),
version: ephemeralDashboard.metadata.version,
createdAt: ephemeralDashboard.metadata.createdAt,
Expand Down Expand Up @@ -118,6 +113,7 @@ export function EphemeralDashboardList(props: EphemeralDashboardListProperties)
type: 'dateTime',
flex: 3,
minWidth: 150,
valueGetter: (params: GridValueGetterParams) => new Date(params.row.expireAt),
renderCell: (params) => (
<Tooltip title={params.value.toUTCString()} placement="top">
<span>{intlFormatDistance(params.value, new Date())}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import { Button, Stack, TextField } from '@mui/material';
import { Dialog } from '@perses-dev/components';
import { Controller, FormProvider, SubmitHandler, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { EphemeralDashboardSelector } from '@perses-dev/core';
import { EphemeralDashboardInfo } from '@perses-dev/core';
import { CreateEphemeralDashboardValidationType, useEphemeralDashboardValidationSchema } from '../../validation';

interface CreateEphemeralDashboardProps {
open: boolean;
projectOptions: string[];
onClose: DispatchWithoutAction;
onSuccess?: Dispatch<EphemeralDashboardSelector>;
onSuccess?: Dispatch<EphemeralDashboardInfo>;
}

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ export const CreateEphemeralDashboardDialog = (props: CreateEphemeralDashboardPr
project: data.projectName,
dashboard: data.dashboardName,
ttl: data.ttl,
} as EphemeralDashboardSelector);
} as EphemeralDashboardInfo);
}
};

Expand Down
11 changes: 4 additions & 7 deletions ui/app/src/components/dialogs/DeleteEphemeralDashboardDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { Dispatch, DispatchWithoutAction, useCallback } from 'react';
import { Button } from '@mui/material';
import { Dialog, useSnackbar } from '@perses-dev/components';
import { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';
import { EphemeralDashboardResource } from '@perses-dev/core';
import { getDashboardExtendedDisplayName } from '@perses-dev/core/dist/utils/text';
import { useDeleteEphemeralDashboardMutation } from '../../model/ephemeral-dashboard-client';

Expand All @@ -41,9 +41,7 @@ export const DeleteEphemeralDashboardDialog = (props: DeleteEphemeralDashboardDi
return deleteEphemeralDashboardMutation.mutate(ephemeralDashboard, {
onSuccess: (deletedEphemeralDashboard: EphemeralDashboardResource) => {
successSnackbar(
`Ephemeral dashboard ${getDashboardExtendedDisplayName(
deletedEphemeralDashboard as unknown as DashboardResource
)} was successfully deleted`
`Ephemeral Dashboard ${getDashboardExtendedDisplayName(deletedEphemeralDashboard)} was successfully deleted`
);
onClose();
if (onSuccess) {
Expand All @@ -61,9 +59,8 @@ export const DeleteEphemeralDashboardDialog = (props: DeleteEphemeralDashboardDi
<Dialog open={open} onClose={onClose}>
<Dialog.Header>Delete Ephemeral Dashboard</Dialog.Header>
<Dialog.Content>
Are you sure you want to delete the ephemeral dashboard{' '}
{getDashboardExtendedDisplayName(ephemeralDashboard as unknown as DashboardResource)}? This action cannot be be
be undone.
Are you sure you want to delete the ephemeral dashboard {getDashboardExtendedDisplayName(ephemeralDashboard)}?
This action cannot be be be undone.
</Dialog.Content>
<Dialog.Actions>
<Button variant="contained" type="submit" onClick={handleSubmit}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Dispatch, DispatchWithoutAction } from 'react';
import { Button, TextField } from '@mui/material';
import { Dialog, useSnackbar } from '@perses-dev/components';
import {
DashboardResource,
DurationString,
EphemeralDashboardResource,
getDashboardDisplayName,
Expand Down Expand Up @@ -49,7 +48,7 @@ export const UpdateEphemeralDashboardDialog = (props: UpdateEphemeralDashboardDi
resolver: zodResolver(updateEphemeralDashboardDialogValidationSchema),
mode: 'onBlur',
defaultValues: {
dashboardName: getDashboardDisplayName(ephemeralDashboard as unknown as DashboardResource),
dashboardName: getDashboardDisplayName(ephemeralDashboard),
ttl: ephemeralDashboard.spec.ttl,
},
});
Expand All @@ -67,8 +66,8 @@ export const UpdateEphemeralDashboardDialog = (props: UpdateEphemeralDashboardDi
updateEphemeralDashboardMutation.mutate(ephemeralDashboard, {
onSuccess: (updatedEphemeralDashboard: EphemeralDashboardResource) => {
successSnackbar(
`Ephemeral dashboard ${getDashboardExtendedDisplayName(
updatedEphemeralDashboard as unknown as DashboardResource
`Ephemeral Dashboard ${getDashboardExtendedDisplayName(
updatedEphemeralDashboard
)} has been successfully updated`
);
onClose();
Expand Down
2 changes: 1 addition & 1 deletion ui/app/src/validation/ephemeraldashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function useEphemeralDashboardValidationSchema(projectName?: string) {
);
},
(schema) => ({
message: `Ephemeral dashboard name '${schema.dashboardName}' already exists in '${schema.projectName}' project!`,
message: `Ephemeral Dashboard name '${schema.dashboardName}' already exists in '${schema.projectName}' project!`,
path: ['dashboardName'],
})
);
Expand Down
13 changes: 7 additions & 6 deletions ui/app/src/views/projects/ProjectTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
RoleResource,
RoleBindingResource,
SecretResource,
EphemeralDashboardSelector,
EphemeralDashboardInfo,
} from '@perses-dev/core';
import { useNavigate, useParams } from 'react-router-dom';
import { useSnackbar } from '@perses-dev/components';
Expand Down Expand Up @@ -93,9 +93,9 @@ function TabButton({ index, projectName, ...props }: TabButtonProps) {
navigate(`/projects/${dashboardSelector.project}/dashboard/new`, { state: dashboardSelector.dashboard });
};

const handleEphemeralDashboardCreation = (dashboardSelector: EphemeralDashboardSelector) => {
navigate(`/projects/${dashboardSelector.project}/ephemeraldashboard/new`, {
state: { name: dashboardSelector.dashboard, ttl: dashboardSelector.ttl },
const handleEphemeralDashboardCreation = (dashboardInfo: EphemeralDashboardInfo) => {
navigate(`/projects/${dashboardInfo.project}/ephemeraldashboard/new`, {
state: { name: dashboardInfo.dashboard, ttl: dashboardInfo.ttl },
});
};

Expand Down Expand Up @@ -446,7 +446,8 @@ export function ProjectTabs(props: DashboardVariableTabsProps) {

const navigate = useNavigate();
const isMobileSize = useIsMobileSize();
const hasEphemeralDashboards = (useEphemeralDashboardList(projectName).data ?? []).length > 0;
const { data } = useEphemeralDashboardList(projectName);
const hasEphemeralDashboards = (data ?? []).length > 0;

const [value, setValue] = useState((initialTab ?? dashboardsTabIndex).toLowerCase());

Expand Down Expand Up @@ -478,7 +479,7 @@ export function ProjectTabs(props: DashboardVariableTabsProps) {
{...a11yProps(dashboardsTabIndex)}
value={dashboardsTabIndex}
/>
{(hasEphemeralDashboards || tab == 'ephemeraldashboards') && (
{(hasEphemeralDashboards || tab == ephemeralDashboardsTabIndex) && (
<MenuTab
label="Ephemeral Dashboards"
icon={<ViewDashboardIcon />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function CreateEphemeralDashboardView() {
return createEphemeralDashboardMutation.mutateAsync(data, {
onSuccess: (createdEphemeralDashboard: EphemeralDashboardResource) => {
successSnackbar(
`EphemeralDashboard ${getDashboardExtendedDisplayName(
createdEphemeralDashboard as unknown as DashboardResource
`Ephemeral Dashboard ${getDashboardExtendedDisplayName(
createdEphemeralDashboard
)} has been successfully created`
);
navigate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function EphemeralDashboardView() {
return updateEphemeralDashboardMutation.mutateAsync(data, {
onSuccess: (updatedEphemeralDashboard: EphemeralDashboardResource) => {
successSnackbar(
`EphemeralDashboard ${getDashboardExtendedDisplayName(
updatedEphemeralDashboard as unknown as DashboardResource
`Ephemeral Dashboard ${getDashboardExtendedDisplayName(
updatedEphemeralDashboard
)} has been successfully updated`
);
return updatedEphemeralDashboard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function HelperDashboardView(props: GenericDashboardViewProps) {
externalVariableDefinitions={externalVariableDefinitions}
dashboardTitleComponent={
<ProjectBreadcrumbs
dashboardName={getDashboardDisplayName(dashboardResource as unknown as DashboardResource)}
dashboardName={getDashboardDisplayName(dashboardResource)}
projectName={dashboardResource.metadata.project}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion ui/core/src/model/ephemeraldashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export interface EphemeralDashboardSpec extends DashboardSpec {
ttl: DurationString;
}

export interface EphemeralDashboardSelector extends DashboardSelector {
export interface EphemeralDashboardInfo extends DashboardSelector {
ttl: DurationString;
}
6 changes: 3 additions & 3 deletions ui/core/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { DashboardResource, Variable, Datasource } from '../model';
import { DashboardResource, Variable, Datasource, EphemeralDashboardResource } from '../model';

/**
* If the dashboard has a display name, return the dashboard display name
* Else, only return the dashboard name
* @param dashboard
*/
export function getDashboardDisplayName(dashboard: DashboardResource) {
export function getDashboardDisplayName(dashboard: DashboardResource | EphemeralDashboardResource) {
return dashboard.spec.display?.name ?? dashboard.metadata.name;
}

Expand All @@ -45,7 +45,7 @@ export function getDatasourceDisplayName(datasource: Datasource) {
* Else, only return the dashboard name
* @param dashboard
*/
export function getDashboardExtendedDisplayName(dashboard: DashboardResource) {
export function getDashboardExtendedDisplayName(dashboard: DashboardResource | EphemeralDashboardResource) {
if (dashboard.spec.display?.name) {
return `${dashboard.spec.display.name} (Name: ${dashboard.metadata.name})`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const EditJsonDialogForm = (props: EditJsonDialogProps) => {
</Alert>
)}
{draftDashboard.kind === 'EphemeralDashboard' && (
<Alert sx={{ marginBottom: (theme) => theme.spacing(1) }} severity="warning">
<Alert sx={{ marginBottom: 1 }} severity="warning">
Time-to-live cannot be modified or saved from here. Go to the project view to modify it.
</Alert>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface DashboardStoreState
refreshInterval: DurationString;
display?: Display;
datasources?: Record<string, DatasourceSpec>;
ttl: DurationString | undefined;
ttl?: DurationString;
}

export interface DashboardStoreProps {
Expand Down

0 comments on commit 3f9df46

Please sign in to comment.