All files / modules/45-dashboards/pages/home HomePage.tsx

0% Statements 0/185
0% Branches 0/217
0% Functions 0/56
0% Lines 0/182

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
/*
 * Copyright 2022 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import React, { useState } from 'react'
import cx from 'classnames'
 
import {
  Layout,
  Text,
  Container,
  Card,
  Button,
  CardBody,
  Heading,
  Icon,
  Formik,
  FormikForm as Form,
  ExpandingSearchInput,
  Pagination,
  SelectOption,
  TableV2,
  FormInput
} from '@wings-software/uicore'
import { useModalHook } from '@harness/use-modal'
import type { Breadcrumb } from '@harness/uicore'
import { FontVariation, Color } from '@harness/design-system'
import { Select } from '@blueprintjs/select'
 
import { Classes, Menu, Dialog } from '@blueprintjs/core'
import * as Yup from 'yup'
import { useParams, useHistory } from 'react-router-dom'
import { useGet, useMutate } from 'restful-react'
import type { CellProps, Renderer, Column } from 'react-table'
 
import { Page } from '@common/exports'
import RbacButton from '@rbac/components/Button/Button'
import RbacMenuItem from '@rbac/components/MenuItem/MenuItem'
import { PermissionIdentifier } from '@rbac/interfaces/PermissionIdentifier'
import { ResourceType } from '@rbac/interfaces/ResourceType'
import ModuleTagsFilter from '@dashboards/components/ModuleTagsFilter/ModuleTagsFilter'
 
import routes from '@common/RouteDefinitions'
 
import { useStrings } from 'framework/strings'
 
import { useDeleteDashboard, useCloneDashboard } from '@dashboards/services/CustomDashboardsService'
import { useDashboardsContext } from '../DashboardsContext'
import FilterTagsSideBar from './FilterTagsSideBar'
import moduleTagCss from '@dashboards/common/ModuleTags.module.scss'
import css from './HomePage.module.scss'
 
export const PAGE_SIZE = 20
 
enum LayoutViews {
  LIST,
  GRID
}
 
const dashboardType: { [key: string]: string } = {
  SHARED: 'SHARED',
  ACCOUNT: 'ACCOUNT'
}
 
interface DashboardInterface {
  id: string
  type: string
  description: string
  title: string
  view_count: number
  favorite_count: number
  created_at: string
  data_source: string[]
  last_accessed_at: string
  resourceIdentifier: string
}
 
interface Permission {
  resource: {
    resourceType: ResourceType
    resourceIdentifier?: string
  }
  permission: PermissionIdentifier
}
 
const DEFAULT_FILTER: { [key: string]: boolean } = {
  HARNESS: false,
  CE: false,
  CD: false,
  CI: false,
  CF: false,
  CG_CD: false
}
 
type CustomColumn<T extends Record<string, any>> = Column<T>
 
const CustomSelect = Select.ofType<SelectOption>()
 
const NewDashboardForm = (props: any): JSX.Element => {
  const { getString } = useStrings()
  const { accountId, folderId } = useParams<{ accountId: string; folderId: string }>()
 
  const [errorMessage, setErrorMessage] = React.useState('')
  const history = useHistory()
  const folderListItems = [
    {
      value: 'shared',
      label: 'Organization Shared Folder'
    }
  ]
 
  const { data: foldersList } = useGet({
    // Inferred from RestfulProvider in index.js
    path: 'gateway/dashboard/folder',
    queryParams: { accountId: accountId, page: 1, pageSize: 1000 }
  })
 
  const { mutate: createDashboard, loading } = useMutate({
    verb: 'POST',
    path: folderId ? 'gateway/dashboard/v2/create' : 'gateway/dashboard/create',
    queryParams: { accountId: accountId }
  })
 
  if (foldersList && foldersList?.resource) {
    foldersList?.resource?.map((folder: { id: string; name: string }) => {
      const _f = {
        value: folder?.id,
        label: folder?.name
      }
      folderListItems.push(_f)
    })
  }
 
  const submitForm = async (formData: { name: string; description: string; folderId: string }) => {
    const description = Object.keys(formData?.description).toString()
    const cloneFormData = formData
    cloneFormData['description'] = description
    const response = await createDashboard(cloneFormData)
    return response
  }
 
  return (
    <Layout.Horizontal>
      <Layout.Vertical padding="xxlarge" width="50%">
        <Heading level={3} font={{ variation: FontVariation.H3 }} padding={{ bottom: 'large' }}>
          {getString('dashboards.createModal.stepOne')}
        </Heading>
        <Formik
          formName={'createDashboardForm'}
          initialValues={{ name: '', description: '', folderId: folderId }}
          validationSchema={Yup.object().shape({
            name: Yup.string().trim().required(getString('dashboards.createModal.nameValidation'))
          })}
          onSubmit={(formData: { name: string; description: string; folderId: string }) => {
            setErrorMessage('')
            const response = submitForm(formData)
            response
              .then(data => {
                if (data?.resource) {
                  history.push({
                    pathname: routes.toViewCustomDashboard({
                      viewId: data?.resource,
                      accountId: accountId,
                      folderId
                    })
                  })
                  props?.hideModal?.()
                }
              })
              .catch(() => {
                setErrorMessage(getString('dashboards.createModal.submitFail'))
              })
          }}
        >
          {() => (
            <Form>
              <Layout.Vertical width="100%">
                <FormInput.Select
                  name="folderId"
                  placeholder={getString('dashboards.homePage.chooseTheFolder')}
                  label={getString('dashboards.homePage.folder')}
                  items={folderListItems}
                />
                <FormInput.Text
                  name="name"
                  label={getString('name')}
                  placeholder={getString('dashboards.createModal.namePlaceholder')}
                />
 
                <FormInput.KVTagInput name="description" label={getString('tagsLabel')} />
                <Layout.Vertical spacing="medium">
                  <Button
                    type="submit"
                    intent="primary"
                    width="150px"
                    text={getString('continue')}
                    disabled={loading}
                    className={css.button}
                  />
                  {errorMessage && <Text intent="danger">{errorMessage}</Text>}
                </Layout.Vertical>
              </Layout.Vertical>
            </Form>
          )}
        </Formik>
      </Layout.Vertical>
      <Container width="50%" flex={{ align: 'center-center' }} className={css.videoContainer}>
        <iframe
          src="//fast.wistia.net/embed/iframe/38m8yricif"
          scrolling="no"
          frameBorder={0}
          allowFullScreen={true}
          className="wistia_embed"
          name="wistia_embed"
          width="350"
          height="200"
        ></iframe>
      </Container>
    </Layout.Horizontal>
  )
}
 
const TagsRenderer = (data: DashboardInterface) => {
  const { getString } = useStrings()
  return (
    <Container className={css.predefinedTags}>
      {data.type === dashboardType.SHARED && (
        <section className={moduleTagCss.harnessTag}>{getString('dashboards.modules.harness')}</section>
      )}
      {data.data_source.map((tag: string) => {
        if (tag === 'CE') {
          return <section className={moduleTagCss.ceTag}>{getString('common.purpose.ce.cloudCost')}</section>
        }
        if (tag === 'CI') {
          return <section className={moduleTagCss.ciTag}>{getString('buildsText')}</section>
        }
        if (tag === 'CD') {
          return <section className={moduleTagCss.cdTag}>{getString('deploymentsText')}</section>
        }
        if (tag === 'CF') {
          return <section className={moduleTagCss.cfTag}>{getString('common.purpose.cf.continuous')}</section>
        }
        if (tag === 'CG_CD') {
          return <section className={moduleTagCss.cgCdTag}>{getString('dashboards.modules.cgDeployments')}</section>
        }
        return <></>
      })}
      {data?.description &&
        data.type === dashboardType.ACCOUNT &&
        data?.description.split(',').map((tag: string, index: number) => {
          return (
            <section className={css.customTag} key={tag + index}>
              {tag}
            </section>
          )
        })}
    </Container>
  )
}
 
const RenderDashboardName: Renderer<CellProps<DashboardInterface>> = ({ row }) => {
  const data = row.original
  const { accountId, folderId } = useParams<{ accountId: string; folderId: string }>()
  const history = useHistory()
  return (
    <Text
      color={Color.BLACK}
      lineClamp={1}
      onClick={() => {
        history.push({
          pathname: routes.toViewCustomDashboard({
            viewId: row.id,
            accountId: accountId,
            folderId: folderId === 'shared' ? 'shared' : data.resourceIdentifier
          })
        })
      }}
    >
      {data.title}
    </Text>
  )
}
 
const RenderDashboardTags: Renderer<CellProps<DashboardInterface>> = ({ row }) => {
  const data = row.original
  return TagsRenderer(data)
}
 
const getBreadcrumbLinks = (
  folderDetail: { resource: string },
  accountId: string,
  folderId: string,
  folderString: string
): Breadcrumb[] => {
  if (folderDetail?.resource) {
    return [
      {
        url: routes.toCustomFolderHome({ accountId }),
        label: folderString
      },
      {
        url: routes.toViewCustomFolder({ folderId, accountId }),
        label: folderDetail.resource
      }
    ]
  }
  return []
}
 
export interface DashboardCardInterface {
  dashboard: DashboardInterface
  clone: (dashboardId: string) => Promise<void>
  deleteById: (dashboardId: string) => Promise<void>
}
 
const DashboardCard: React.FC<DashboardCardInterface> = ({ dashboard, clone, deleteById }) => {
  const { getString } = useStrings()
  const { accountId, folderId } = useParams<{ accountId: string; folderId: string }>()
  const history = useHistory()
  const [menuOpen, setMenuOpen] = useState(false)
 
  const onCardClick = (): void => {
    history.push({ pathname: cardPath })
  }
 
  const onCardLinkClick = (event: React.MouseEvent<HTMLAnchorElement>): void => {
    event.preventDefault()
  }
 
  const onCloneClick = (event: React.MouseEvent<HTMLElement>): void => {
    event.stopPropagation()
    setMenuOpen(false)
    clone(dashboard.id)
  }
 
  const onDeleteClick = (event: React.MouseEvent<HTMLElement>): void => {
    event.stopPropagation()
    setMenuOpen(false)
    deleteById(dashboard.id)
  }
 
  const cardPath = routes.toViewCustomDashboard({
    viewId: dashboard.id,
    accountId: accountId,
    folderId: folderId === 'shared' ? 'shared' : dashboard?.resourceIdentifier
  })
 
  return (
    <a onClick={onCardLinkClick} href={cardPath}>
      <Card interactive className={cx(css.dashboardCard)} onClick={onCardClick}>
        <Container>
          <CardBody.Menu
            menuContent={
              <Menu>
                <RbacMenuItem
                  text={getString('projectCard.clone')}
                  onClick={onCloneClick}
                  permission={{
                    permission: PermissionIdentifier.EDIT_DASHBOARD,
                    resource: {
                      resourceType: ResourceType.DASHBOARDS
                    }
                  }}
                />
                {dashboard?.type === dashboardType.ACCOUNT && (
                  <RbacMenuItem
                    text={getString('delete')}
                    onClick={onDeleteClick}
                    permission={{
                      permission: PermissionIdentifier.EDIT_DASHBOARD,
                      resource: {
                        resourceType: ResourceType.DASHBOARDS
                      }
                    }}
                  />
                )}
              </Menu>
            }
            menuPopoverProps={{
              className: Classes.DARK,
              isOpen: menuOpen,
              onInteraction: nextOpenState => {
                setMenuOpen(nextOpenState)
              }
            }}
          />
 
          <Layout.Vertical spacing="large">
            <Text font={{ variation: FontVariation.CARD_TITLE }}>{dashboard?.title}</Text>
            {TagsRenderer(dashboard)}
 
            {dashboard?.type !== dashboardType.SHARED && (
              <Layout.Horizontal spacing="small">
                <Text
                  icon="eye-open"
                  iconProps={{ padding: { right: 'small' } }}
                  font={{ variation: FontVariation.CARD_TITLE }}
                >
                  {dashboard?.view_count}
                </Text>
                <Text
                  icon="star-empty"
                  iconProps={{ padding: { right: 'small' } }}
                  font={{ variation: FontVariation.CARD_TITLE }}
                >
                  {dashboard?.favorite_count}
                </Text>
              </Layout.Horizontal>
            )}
          </Layout.Vertical>
        </Container>
      </Card>
    </a>
  )
}
 
const HomePage: React.FC = () => {
  const { getString } = useStrings()
  const { accountId, folderId } = useParams<{ accountId: string; folderId: string }>()
  const history = useHistory()
  const { includeBreadcrumbs } = useDashboardsContext()
  // const [_dashboardList, _setDashboardList] = React.useState<DashboardInterface[]>([])
  const [filteredDashboardList, setFilteredList] = React.useState<DashboardInterface[]>([])
 
  const [filteredTags, setFilteredTags] = React.useState<string[]>([])
  const [selectedFilter, setCheckboxFilter] = React.useState(DEFAULT_FILTER)
  const [searchTerm, setSearchTerm] = useState<string | undefined>()
  const [page, setPage] = useState(0)
  const [layoutView, setLayoutView] = useState(LayoutViews.GRID)
  const defaultSortBy: SelectOption = {
    label: 'Select Option',
    value: ''
  }
 
  const sortingOptions: SelectOption[] = [
    {
      label: 'Name',
      value: 'title'
    },
    {
      label: 'Recently Viewed',
      value: 'last_viewed_at desc'
    },
    {
      label: 'Recently Created',
      value: 'created_at desc'
    },
    {
      label: 'Most Viewed',
      value: 'view_count desc'
    },
    {
      label: 'Most Liked',
      value: 'favorite_count desc'
    }
  ]
 
  const [sortby, setSortingFilter] = useState<SelectOption>(defaultSortBy)
 
  const RenderMenu: Renderer<CellProps<DashboardInterface>> = ({ row }) => {
    const data = row.original
    return (
      <CardBody.Menu
        menuContent={
          <Menu>
            <RbacMenuItem
              text={getString('projectCard.clone')}
              onClick={() => clone(data.id)}
              permission={{
                permission: PermissionIdentifier.EDIT_DASHBOARD,
                resource: {
                  resourceType: ResourceType.DASHBOARDS
                }
              }}
            />
            <RbacMenuItem
              text={getString('delete')}
              onClick={() => deleteById(data.id)}
              permission={{
                permission: PermissionIdentifier.EDIT_DASHBOARD,
                resource: {
                  resourceType: ResourceType.DASHBOARDS
                }
              }}
            />
          </Menu>
        }
        menuPopoverProps={{
          className: Classes.DARK
        }}
      />
    )
  }
 
  const columns: CustomColumn<DashboardInterface>[] = [
    {
      Header: 'Name',
      id: 'name',
      accessor: row => row.title,
      width: '30%',
      Cell: RenderDashboardName
    },
    {
      Header: 'Tags',
      id: 'tags',
      accessor: row => row.description,
      width: '30%',
      Cell: RenderDashboardTags
    },
    {
      Header: 'View Count',
      id: 'view_count',
      accessor: row => row.view_count,
      width: '15%'
    },
    {
      Header: 'Favorite Count',
      id: 'favorite_count',
      accessor: row => row.favorite_count,
      width: '10%'
    },
    {
      Header: '',
      id: 'menu',
      accessor: row => row.id,
      width: '10%',
      Cell: RenderMenu
    }
  ]
 
  const serialize = (obj: { [key: string]: boolean }) => {
    return new URLSearchParams(Object.entries(obj).map(([k, v]) => [k, v.toString()])).toString()
  }
 
  const folderIdOrBlank = () => {
    return folderId.replace('shared', '')
  }
 
  React.useEffect(() => {
    const script = document.createElement('script')
 
    script.src = 'https://fast.wistia.com/assets/external/E-v1.js'
    script.async = true
 
    document.body.appendChild(script)
  }, [])
 
  const {
    data: dashboardList,
    loading,
    refetch,
    error
  } = useGet({
    // Inferred from RestfulProvider in index.js
    path: 'gateway/dashboard/v1/search',
    debounce: true,
    queryParams: {
      accountId: accountId,
      folderId: folderIdOrBlank(),
      searchTerm,
      page: page + 1,
      pageSize: PAGE_SIZE,
      tags: serialize(selectedFilter),
      sortBy: sortby?.value,
      customTag: filteredTags.join('%')
    }
  })
 
  const { mutate: cloneDashboard, loading: cloning } = useCloneDashboard(accountId)
 
  const clone = async (dashboardId: string) => {
    const clonedDashboard = await cloneDashboard({ dashboardId })
    if (clonedDashboard) {
      history.push({
        pathname: routes.toViewCustomDashboard({
          viewId: clonedDashboard?.id,
          accountId: accountId,
          folderId: clonedDashboard?.folder_id
        })
      })
    }
  }
 
  const { mutate: deleteDashboard, loading: deleting } = useDeleteDashboard(accountId)
 
  const deleteById = async (dashboardId: string) => {
    await deleteDashboard({ dashboardId })
    refetch()
  }
 
  const { data: folderDetail } = useGet({
    path: 'gateway/dashboard/folderDetail',
    queryParams: { accountId: accountId, folderId: folderIdOrBlank() }
  })
 
  React.useEffect(() => {
    if (searchTerm || selectedFilter || sortby?.value || filteredTags?.length > 0) setPage(0)
  }, [searchTerm, selectedFilter, sortby?.value, filteredTags])
 
  const setPredefinedFilter = (filterType: string, isChecked: boolean) => {
    const updatedValue: any = {}
    updatedValue[filterType] = isChecked
    setCheckboxFilter({ ...selectedFilter, ...updatedValue })
  }
 
  React.useEffect(() => {
    setFilteredList(dashboardList?.resource)
  }, [dashboardList])
 
  const [showModal, hideModal] = useModalHook(
    () => (
      <Dialog
        isOpen={true}
        enforceFocus={false}
        onClose={() => {
          hideModal()
        }}
        className={cx(css.dashboardDialog, Classes.DIALOG, css.create)}
      >
        <NewDashboardForm
          formData={{}}
          handleViewChange={{}}
          hideModal={hideModal}
          name={getString('dashboards.createModal.stepOne')}
        />
 
        <Button
          minimal
          icon="cross"
          iconProps={{ size: 18 }}
          onClick={() => {
            hideModal()
          }}
          className={css.crossIcon}
        />
      </Dialog>
    ),
    []
  )
 
  const permissionObj: Permission = {
    permission: PermissionIdentifier.EDIT_DASHBOARD,
    resource: {
      resourceType: ResourceType.DASHBOARDS
    }
  }
 
  if (folderId !== 'shared') {
    permissionObj['resource']['resourceIdentifier'] = folderId
  }
 
  React.useEffect(() => {
    includeBreadcrumbs(getBreadcrumbLinks(folderDetail, accountId, folderId, getString('dashboards.homePage.folders')))
  }, [folderDetail, accountId, folderId])
 
  return (
    <Page.Body loading={loading || cloning || deleting} error={error?.data?.message}>
      <Layout.Horizontal>
        <Layout.Horizontal
          padding="large"
          background={Color.GREY_0}
          spacing="medium"
          flex={{ justifyContent: 'space-between', alignItems: 'center' }}
          border={{ bottom: true, color: 'grey100' }}
          width="100%"
        >
          <RbacButton
            intent="primary"
            text={getString('dashboardLabel')}
            onClick={() => showModal()}
            icon="plus"
            className={css.createButton}
            permission={permissionObj}
          />
          <Container className={cx(css.predefinedTags, css.mainNavTag)}>
            <ModuleTagsFilter selectedFilter={selectedFilter} setPredefinedFilter={setPredefinedFilter} />
          </Container>
          <Layout.Horizontal>
            <CustomSelect
              items={sortingOptions}
              filterable={false}
              itemRenderer={(item, { handleClick }) => <Menu.Item text={item.label} onClick={handleClick} />}
              onItemSelect={item => {
                setSortingFilter(item)
              }}
              popoverProps={{ minimal: true, popoverClassName: '' }}
            >
              <Button
                inline
                round
                rightIcon="chevron-down"
                className={css.customSelect}
                text={
                  <Text color={Color.BLACK}>
                    {getString('dashboards.sortBy')} {sortby?.label}
                  </Text>
                }
              />
            </CustomSelect>
            <Layout.Horizontal>
              <Button
                minimal
                aria-label={getString('dashboards.switchToGridView')}
                icon="grid-view"
                intent={layoutView === LayoutViews.GRID ? 'primary' : 'none'}
                onClick={() => {
                  setLayoutView(LayoutViews.GRID)
                }}
              />
              <Button
                minimal
                aria-label={getString('dashboards.switchToListView')}
                icon="list"
                intent={layoutView === LayoutViews.LIST ? 'primary' : 'none'}
                onClick={() => {
                  setLayoutView(LayoutViews.LIST)
                }}
              />
            </Layout.Horizontal>
          </Layout.Horizontal>
        </Layout.Horizontal>
      </Layout.Horizontal>
 
      <FilterTagsSideBar setFilteredTags={setFilteredTags} />
 
      <Layout.Vertical className={css.homeContent}>
        <Layout.Horizontal padding={{ top: 'large', right: 'xxxlarge', bottom: 'large', left: 'xxxlarge' }}>
          <ExpandingSearchInput
            placeholder={getString('dashboards.homePage.searchPlaceholder')}
            onChange={(text: string) => {
              setSearchTerm(text)
            }}
            className={css.search}
          />
        </Layout.Horizontal>
        <Layout.Horizontal
          margin={{ left: 'xxxlarge' }}
          flex={{ justifyContent: 'flex-start', alignItems: 'baseline' }}
        >
          <Container>
            {filteredTags.map((tag: string, index: number) => {
              return (
                <Container className={cx(css.customTag, css.filteredTags)} key={tag + index}>
                  {tag}
                  <Button
                    minimal
                    aria-title={getString('dashboards.homePage.removeTagFromFilter')}
                    icon="cross"
                    className={css.clearTagButton}
                    onClick={() => {
                      const filterTags = filteredTags.filter(v => v !== tag)
                      setFilteredTags(filterTags)
                    }}
                  />
                </Container>
              )
            })}
          </Container>
          {filteredTags?.length > 0 && (
            <Button minimal intent="primary" onClick={() => setFilteredTags([])}>
              {getString('filters.clearAll')}
            </Button>
          )}
        </Layout.Horizontal>
        {!!filteredDashboardList?.length && layoutView === LayoutViews.GRID && (
          <Container className={css.masonry}>
            <Layout.Masonry
              gutter={25}
              items={filteredDashboardList}
              renderItem={(dashboard: DashboardInterface) => (
                <DashboardCard dashboard={dashboard} clone={clone} deleteById={deleteById} />
              )}
              keyOf={dashboard => dashboard?.id}
            />
          </Container>
        )}
 
        {!!filteredDashboardList?.length && layoutView === LayoutViews.LIST && (
          <Container className={css.masonry}>
            <TableV2<DashboardInterface> className={css.table} columns={columns} data={filteredDashboardList || []} />
          </Container>
        )}
 
        {!filteredDashboardList?.length && !loading && (
          <Container height="calc(100vh - 226px)" flex={{ align: 'center-center' }}>
            <Layout.Vertical spacing="medium" width={470} flex={{ alignItems: 'center' }} margin={{ top: '-48px' }}>
              <Icon name="dashboard" color={Color.GREY_300} size={35} />
              <Heading level={2} font={{ align: 'center' }} color={Color.GREY_500}>
                {getString('dashboards.homePage.noDashboardsAvailable')}
              </Heading>
            </Layout.Vertical>
          </Container>
        )}
      </Layout.Vertical>
 
      {!loading && (
        <Layout.Vertical padding={{ left: 'medium', right: 'medium' }}>
          <Pagination
            itemCount={dashboardList?.items || 1}
            pageSize={PAGE_SIZE}
            pageCount={dashboardList?.pages || 1}
            pageIndex={page}
            gotoPage={(pageNumber: number) => setPage(pageNumber)}
          />
        </Layout.Vertical>
      )}
    </Page.Body>
  )
}
 
export default HomePage