Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8bffec1
feat: add support for state based collapsible list
arunjaindev Sep 27, 2024
4f408af
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 7, 2024
da3edaa
feat: add key for drift in Node
arunjaindev Oct 8, 2024
a2e1a61
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 8, 2024
40330c2
Merge branch 'feat/collapsible-list-state' of https://github.com/devt…
arunjaindev Oct 8, 2024
02b5542
feat: add filter for drifted nodes in status filter button
arunjaindev Oct 9, 2024
df994f6
chore: use enum for drifted node
arunjaindev Oct 9, 2024
9551c44
chore: version bump
arunjaindev Oct 9, 2024
7115262
chore: edit typing for collapsible list
arunjaindev Oct 9, 2024
03ce4a3
Merge branch 'feat/collapsible-list-state' of https://github.com/devt…
arunjaindev Oct 9, 2024
858e259
chore: version bump
arunjaindev Oct 9, 2024
3ddb76c
chore: version bump
arunjaindev Oct 9, 2024
3e119ee
chore: rename Drifted filter to drifted
arunjaindev Oct 10, 2024
69cab58
chore: version bump
arunjaindev Oct 10, 2024
620dee4
feat: remove selected tab state from status filter button
arunjaindev Oct 16, 2024
eca0ef1
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 16, 2024
3dd60a4
Merge branch 'feat/config-drift' of https://github.com/devtron-labs/d…
arunjaindev Oct 16, 2024
1189cdc
chore: version bump
arunjaindev Oct 16, 2024
3ec13ae
feat: add flag for config drift feature
arunjaindev Oct 17, 2024
16e71b5
Merge pull request #361 from devtron-labs/feat/config-drift-flag
arunjaindev Oct 17, 2024
4f98578
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 17, 2024
da74177
Merge branch 'feat/collapsible-list-state' of https://github.com/devt…
arunjaindev Oct 17, 2024
5df60eb
Merge branch 'feat/config-drift' of https://github.com/devtron-labs/d…
arunjaindev Oct 17, 2024
4a6ca3d
chore: version bump
arunjaindev Oct 17, 2024
2e4f158
chore: version bump
arunjaindev Oct 17, 2024
387d6e4
fix: hide drift filter when flag is off
arunjaindev Oct 18, 2024
fe512a6
Merge pull request #342 from devtron-labs/feat/config-drift
arunjaindev Oct 21, 2024
d7a667d
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 21, 2024
ae14f5c
chore: version bump
arunjaindev Oct 21, 2024
a0e2669
Merge pull request #325 from devtron-labs/feat/collapsible-list-state
arunjaindev Oct 21, 2024
3fcfff0
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 22, 2024
296593a
feat: add all resource kind constant
arunjaindev Oct 22, 2024
3558214
feat: add support for local storage ilters in use url filters
arunjaindev Oct 25, 2024
489cfaf
chore: version bump
arunjaindev Oct 25, 2024
596572b
Merge branch 'main' of https://github.com/devtron-labs/devtron-fe-com…
arunjaindev Oct 28, 2024
90d6c8c
Merge pull request #371 from devtron-labs/chore/sync-dt21
arunjaindev Oct 28, 2024
361b449
chore: version bump
arunjaindev Oct 28, 2024
1204e6e
Merge pull request #372 from devtron-labs/chore/bumpv-0.6.1
arunjaindev Oct 28, 2024
331167b
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 28, 2024
017ea72
feat: update full screen key to shift + f
arunjaindev Oct 28, 2024
e84a946
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Oct 28, 2024
cf3d299
chore: version bump
arunjaindev Oct 28, 2024
9cc7f98
feat: add support for resizable table config
eshankvaish Oct 29, 2024
be4b1b6
fix: drag behaviour
eshankvaish Oct 29, 2024
5c289b8
fix: clickable part
eshankvaish Oct 29, 2024
004e73f
fix: improve typing and styling for sortable table header cell
eshankvaish Oct 29, 2024
61dcf15
feat: add conditional isCellResizable
eshankvaish Oct 29, 2024
5434900
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
eshankvaish Oct 29, 2024
ca8d45d
chore: bump version
eshankvaish Oct 29, 2024
75013e2
feat: add prop for isResizable
eshankvaish Oct 29, 2024
5a1902a
refactor: styling
eshankvaish Oct 29, 2024
457ed64
fix: not to update url from local storage in case of primary params
arunjaindev Oct 29, 2024
ddf378e
fix: hover and dragging states
eshankvaish Oct 29, 2024
58dd157
feat: update local storage acc to search string
arunjaindev Oct 29, 2024
4c2b2af
feat: add transition on drag hover
eshankvaish Oct 29, 2024
b2a78b3
refactor: code clean up
eshankvaish Oct 29, 2024
f55d4ed
doc: update the ts doc
eshankvaish Nov 4, 2024
581c9ba
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
eshankvaish Nov 4, 2024
94014f2
Merge pull request #381 from devtron-labs/chore/sync-develop-with-main
eshankvaish Nov 4, 2024
74dea0d
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Nov 4, 2024
746148b
chore: version bump
arunjaindev Nov 4, 2024
fbd1c9d
Merge pull request #358 from devtron-labs/feat/app-status-filters
arunjaindev Nov 4, 2024
c8b805b
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Nov 4, 2024
ed19bfd
chore: version bump
arunjaindev Nov 4, 2024
0d92225
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
eshankvaish Nov 4, 2024
908b905
Merge pull request #377 from devtron-labs/feat/resizable-columns
eshankvaish Nov 4, 2024
c7bd6fd
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Nov 4, 2024
55fa6ff
chore: version bump
arunjaindev Nov 4, 2024
a3d478b
chore: version bump
arunjaindev Nov 5, 2024
9eeb2f3
fix: add check for parseSearchParams
arunjaindev Nov 5, 2024
41d024c
chore: version bump
arunjaindev Nov 5, 2024
14961ac
Merge pull request #370 from devtron-labs/feat/local-storage-filters
arunjaindev Nov 5, 2024
0b0d348
Merge branch 'develop' of https://github.com/devtron-labs/devtron-fe-…
arunjaindev Nov 5, 2024
58f92af
Merge pull request #385 from devtron-labs/chore/sync-persist-filters
arunjaindev Nov 5, 2024
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
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtron-labs/devtron-fe-common-lib",
"version": "0.6.0-patch-1",
"version": "0.6.5",
"description": "Supporting common component library",
"type": "module",
"main": "dist/index.js",
Expand Down Expand Up @@ -84,7 +84,6 @@
"react-draggable": "^4.4.5",
"react-ga4": "^1.4.1",
"react-mde": "^11.5.0",
"react-router": "^5.3.0",
"react-router-dom": "^5.3.0",
"react-select": "5.8.0",
"rxjs": "^7.8.1",
Expand Down
1 change: 1 addition & 0 deletions src/Common/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const URLS = {
GLOBAL_CONFIG_SCOPED_VARIABLES: '/global-config/scoped-variables',
GLOBAL_CONFIG_DEPLOYMENT_CHARTS_LIST: '/global-config/deployment-charts',
NETWORK_STATUS_INTERFACE: '/network-status-interface',
CONFIG_DRIFT: 'config-drift',
}

export const ROUTES = {
Expand Down
1 change: 1 addition & 0 deletions src/Common/Hooks/useUrlFilters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface UseUrlFiltersProps<T, K> {
* Callback function for parsing the search params
*/
parseSearchParams?: (searchParams: URLSearchParams) => K
localStorageKey?: `${string}__${string}`
}

export type UseUrlFiltersReturnType<T, K = unknown> = K & {
Expand Down
29 changes: 27 additions & 2 deletions src/Common/Hooks/useUrlFilters/useUrlFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/

import { useMemo } from 'react'
import { useEffect, useMemo } from 'react'
import { useHistory, useLocation } from 'react-router-dom'
import { DEFAULT_BASE_PAGE_SIZE, EXCLUDED_FALSY_VALUES, SortingOrder } from '../../Constants'
import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
import { setItemInLocalStorageIfKeyExists } from './utils'

const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_KEYS

Expand All @@ -42,11 +43,20 @@ const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_K
const useUrlFilters = <T = string, K = unknown>({
initialSortKey,
parseSearchParams,
localStorageKey,
}: UseUrlFiltersProps<T, K> = {}): UseUrlFiltersReturnType<T, K> => {
const location = useLocation()
const history = useHistory()
const searchParams = new URLSearchParams(location.search)

const getParsedSearchParams: UseUrlFiltersProps<T, K>['parseSearchParams'] = (searchParamsToParse) => {
if (parseSearchParams) {
return parseSearchParams(searchParamsToParse)
}

return {} as K
}

const { pageSize, pageNumber, searchKey, sortBy, sortOrder, parsedParams } = useMemo(() => {
const _pageSize = searchParams.get(PAGE_SIZE)
const _pageNumber = searchParams.get(PAGE_NUMBER)
Expand All @@ -58,7 +68,7 @@ const useUrlFilters = <T = string, K = unknown>({
// Fallback to ascending order
const sortByOrder = Object.values(SortingOrder).includes(_sortOrder) ? _sortOrder : SortingOrder.ASC

const _parsedParams = parseSearchParams ? parseSearchParams(searchParams) : ({} as K)
const _parsedParams = getParsedSearchParams(searchParams)

return {
pageSize: Number(_pageSize) || DEFAULT_BASE_PAGE_SIZE,
Expand Down Expand Up @@ -126,6 +136,7 @@ const useUrlFilters = <T = string, K = unknown>({

const clearFilters = () => {
history.replace({ search: '' })
setItemInLocalStorageIfKeyExists(localStorageKey, '')
}

const updateSearchParams = (paramsToSerialize: Partial<K>) => {
Expand All @@ -143,10 +154,24 @@ const useUrlFilters = <T = string, K = unknown>({
searchParams.delete(key)
}
})
// Skipping primary params => pageSize, pageNumber, searchKey, sortBy, sortOrder
setItemInLocalStorageIfKeyExists(localStorageKey, JSON.stringify(getParsedSearchParams(searchParams)))
// Not replacing the params as it is being done by _resetPageNumber
_resetPageNumber()
}

useEffect(() => {
// if we have search string, set secondary params in local storage accordingly
if (location.search) {
localStorage.setItem(localStorageKey, JSON.stringify(parsedParams))
return
}
const localStorageValue = localStorage.getItem(localStorageKey)
if (localStorageValue) {
updateSearchParams(JSON.parse(localStorageValue))
}
}, [])

return {
pageSize,
changePage,
Expand Down
5 changes: 5 additions & 0 deletions src/Common/Hooks/useUrlFilters/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const setItemInLocalStorageIfKeyExists = (localStorageKey: string, value: string) => {
if (localStorageKey) {
localStorage.setItem(localStorageKey, value)
}
}
78 changes: 65 additions & 13 deletions src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/

import { Tooltip } from '@Common/Tooltip'
import { ReactComponent as SortIcon } from '../../Assets/Icon/ic-arrow-up-down.svg'
import { ReactComponent as SortArrowDown } from '../../Assets/Icon/ic-sort-arrow-down.svg'
import Draggable, { DraggableProps } from 'react-draggable'
import { ReactComponent as SortIcon } from '@Icons/ic-arrow-up-down.svg'
import { ReactComponent as SortArrowDown } from '@Icons/ic-sort-arrow-down.svg'
import { SortingOrder } from '../Constants'
import { noop } from '../Helper'
import { SortableTableHeaderCellProps } from './types'
import './sortableTableHeaderCell.scss'

/**
* Reusable component for the table header cell with support for sorting icons
Expand All @@ -34,6 +36,23 @@ import { SortableTableHeaderCellProps } from './types'
* disabled={isDisabled}
* />
* ```
*
* @example Non-sortable cell
* ```tsx
* <SortableTableHeaderCell
* isSortable={false}
* title="Header Cell"
* />
* ```
*
* * @example Resizable cell (Layout to be controlled externally using useResizableTableConfig)
* ```tsx
* <SortableTableHeaderCell
* isSortable={false}
* isResizable
* title="Header Cell"
* />
* ```
*/
const SortableTableHeaderCell = ({
isSorted,
Expand All @@ -43,7 +62,12 @@ const SortableTableHeaderCell = ({
disabled,
isSortable = true,
showTippyOnTruncate = false,
id,
handleResize,
isResizable,
}: SortableTableHeaderCellProps) => {
const isCellResizable = !!(isResizable && id && handleResize)

const renderSortIcon = () => {
if (!isSortable) {
return null
Expand All @@ -60,18 +84,46 @@ const SortableTableHeaderCell = ({
return <SortIcon className="icon-dim-12 mw-12 scn-7 dc__no-shrink" />
}

const handleDrag: DraggableProps['onDrag'] = (_, data) => {
if (isCellResizable) {
handleResize(id, data.deltaX)
}
}

return (
<button
type="button"
className={`dc__transparent p-0 cn-7 flex dc__content-start dc__gap-4 dc__select-text ${!isSortable ? 'cursor-default' : ''}`}
onClick={isSortable ? triggerSorting : noop}
disabled={disabled}
>
<Tooltip showOnTruncate={showTippyOnTruncate} content={title}>
<span className="dc__uppercase dc__ellipsis-right">{title}</span>
</Tooltip>
{renderSortIcon()}
</button>
<div className="flex dc__content-space dc__gap-6 dc__position-rel">
<button
type="button"
className={`dc__transparent p-0 cn-7 flex dc__content-start dc__gap-4 dc__select-text ${!isSortable ? 'cursor-default' : ''} dc__position-rel`}
onClick={isSortable ? triggerSorting : noop}
disabled={disabled}
>
<Tooltip showOnTruncate={showTippyOnTruncate} content={title}>
<span className="dc__uppercase dc__truncate">{title}</span>
</Tooltip>
{renderSortIcon()}
</button>
{isCellResizable && (
<Draggable
handle=".sortable-table-header__resize-btn"
defaultClassNameDragging="sortable-table-header__resize-btn--dragging"
position={{
x: 0,
y: 0,
}}
axis="none"
onDrag={handleDrag}
bounds={{
top: 0,
bottom: 0,
}}
>
<div className="sortable-table-header__resize-btn flex h-100 dc__no-shrink px-2 dc__position-abs dc__cursor-col-resize dc__right-3--neg">
<div className="dc__divider h-16" />
</div>
</Draggable>
)}
</div>
)
}

Expand Down
3 changes: 3 additions & 0 deletions src/Common/SortableTableHeaderCell/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DEFAULT_MINIMUM_HEADER_WIDTH = 70

export const DEFAULT_MAXIMUM_HEADER_WIDTH = 600
1 change: 1 addition & 0 deletions src/Common/SortableTableHeaderCell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
*/

export { default as SortableTableHeaderCell } from './SortableTableHeaderCell'
export { default as useResizableTableConfig } from './useResizableTableConfig'
export type { SortableTableHeaderCellProps } from './types'
14 changes: 14 additions & 0 deletions src/Common/SortableTableHeaderCell/sortableTableHeaderCell.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.sortable-table-header {
&__resize-btn {
> div {
transition: all 0.1s ease-out;
}

&:hover, &--dragging {
> div {
height: 100% !important;
background-color: var(--B500);
}
}
}
}
89 changes: 65 additions & 24 deletions src/Common/SortableTableHeaderCell/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,78 @@

import { SortingOrder } from '../Constants'

export interface SortableTableHeaderCellProps {
/**
* If true, the cell is sorted
*/
isSorted: boolean
/**
* Callback for handling the sorting of the cell
*/
triggerSorting: () => void
/**
* Current sort order
*
* Note: On click, the sort order should be updated as required
*/
sortOrder: SortingOrder
export type SortableTableHeaderCellProps = {
/**
* Label for the cell
*/
title: string
/**
* If true, the cell is disabled
*/
disabled: boolean
/**
* If false, the cell acts like normal table header cell
* @default true
*/
isSortable?: boolean
/**
* If true, the tippy is shown on Sortable header if text is truncated
* @default false
*/
showTippyOnTruncate?: boolean
} & (
| {
/**
* Unique identifier for the column
*/
id: string | number
/**
* If true, the cell is resizable
*
* @default false
*/
isResizable: true | boolean
/**
* Resize handler for the table
*/
handleResize: (id: string | number, deltaChange: number) => void
}
| {
id?: never
isResizable?: false | undefined
handleResize?: never
}
) &
(
| {
/**
* If false, the cell acts like normal table header cell
* @default true
*/
isSortable?: boolean | undefined
/**
* If true, the cell is disabled
*/
disabled: boolean
/**
* If true, the cell is sorted
*/
isSorted: boolean
/**
* Callback for handling the sorting of the cell
*/
triggerSorting: () => void
/**
* Current sort order
*
* Note: On click, the sort order should be updated as required
*/
sortOrder: SortingOrder
}
| {
isSortable: false
disabled?: never
isSorted?: never
triggerSorting?: never
sortOrder?: never
}
)

export interface UseResizableTableConfigProps {
headersConfig: (Pick<SortableTableHeaderCellProps, 'id'> & {
width: number | string
maxWidth?: number
minWidth?: number
})[]
}
Loading
Loading