Skip to content

Commit

Permalink
feat: added the share link for view widget mode
Browse files Browse the repository at this point in the history
  • Loading branch information
palashgdev committed Nov 28, 2023
1 parent 8eb2b9e commit 5b7064a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions frontend/src/constants/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export enum QueryParams {
linesPerRow = 'linesPerRow',
viewName = 'viewName',
viewKey = 'viewKey',
expandedWidgetId = 'expandedWidgetId',
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Skeleton, Typography } from 'antd';
import { ToggleGraphProps } from 'components/Graph/types';
import { SOMETHING_WENT_WRONG } from 'constants/api';
import { QueryParams } from 'constants/query';
import GridPanelSwitch from 'container/GridPanelSwitch';
import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
import { useNotifications } from 'hooks/useNotifications';
import useUrlQuery from 'hooks/useUrlQuery';
import createQueryParams from 'lib/createQueryParams';
import history from 'lib/history';
import { useDashboard } from 'providers/Dashboard/Dashboard';
Expand Down Expand Up @@ -43,11 +45,14 @@ function WidgetGraphComponent({
onDragSelect,
}: WidgetGraphComponentProps): JSX.Element {
const [deleteModal, setDeleteModal] = useState(false);
const [modal, setModal] = useState<boolean>(false);
const [hovered, setHovered] = useState(false);
const { notifications } = useNotifications();
const { pathname } = useLocation();

const params = useUrlQuery();

const isFullViewOpen = params.get(QueryParams.expandedWidgetId) === widget.id;

const lineChartRef = useRef<ToggleGraphProps>();
const graphRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -175,7 +180,14 @@ function WidgetGraphComponent({
};

const handleOnView = (): void => {
onToggleModal(setModal);
const queryParams = {
[QueryParams.expandedWidgetId]: widget.id,
};

history.push({
pathname,
search: createQueryParams(queryParams),
});
};

const handleOnDelete = (): void => {
Expand All @@ -187,7 +199,10 @@ function WidgetGraphComponent({
};

const onToggleModelHandler = (): void => {
onToggleModal(setModal);
history.push({
pathname,
search: createQueryParams({}),
});
};

if (queryResponse.isLoading || queryResponse.status === 'idle') {
Expand Down Expand Up @@ -236,7 +251,7 @@ function WidgetGraphComponent({
title={widget?.title || 'View'}
footer={[]}
centered
open={modal}
open={isFullViewOpen}
onCancel={onToggleModelHandler}
width="85%"
destroyOnClose
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/container/ListOfDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import { ButtonContainer, NewDashboardButton, TableContainer } from './styles';
import DeleteButton from './TableComponents/DeleteButton';
import Name from './TableComponents/Name';

function ListOfAllDashboard(): JSX.Element {
const { Search } = Input;
const { Search } = Input;

function ListOfAllDashboard(): JSX.Element {
const {
data: dashboardListResponse = [],
isLoading: isDashboardListLoading,
Expand Down Expand Up @@ -321,7 +321,6 @@ function ListOfAllDashboard(): JSX.Element {
</Row>
),
[
Search,
isDashboardListLoading,
handleSearch,
isFilteringDashboards,
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/createQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const createQueryParams = (params: { [x: string]: string | number }): string =>
const createQueryParams = (params: {
[x: string]: string | number | undefined;
}): string =>
Object.keys(params)
.map(
(k) => `${encodeURIComponent(k)}=${encodeURIComponent(String(params[k]))}`,
Expand Down

0 comments on commit 5b7064a

Please # to comment.