Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/devtron-labs/dashboard i…
Browse files Browse the repository at this point in the history
…nto feat/deploy-button-animation
  • Loading branch information
arunjaindev committed Dec 24, 2024
2 parents aafc085 + bc158e7 commit 9e5b339
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 172 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ src/components/common/DatePickers/DayPickerRangeController.tsx
src/components/common/DeprecatedUpdateWarn.tsx
src/components/common/Description/GenericDescription.tsx
src/components/common/DynamicTabs/__tests__/DynamicTabs.test.tsx
src/components/common/ExportToCsv/ExportToCsv.tsx
src/components/common/FloatingVariablesSuggestions/FloatingVariablesSuggestions.tsx
src/components/common/FloatingVariablesSuggestions/SuggestionItem.tsx
src/components/common/FloatingVariablesSuggestions/Suggestions.tsx
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"homepage": "/dashboard",
"dependencies": {
"@devtron-labs/devtron-fe-common-lib": "1.3.2",
"@devtron-labs/devtron-fe-common-lib": "1.3.3",
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
"@rjsf/core": "^5.13.3",
"@rjsf/utils": "^5.13.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import moment from 'moment'
import { Moment12HourExportFormat } from '../../../../../config'
import { getFormattedUTCTimeForExport, UserTypeToFetchType } from '@devtron-labs/devtron-fe-common-lib'
import { ExportToCsvProps } from '@Components/common/ExportToCsv/types'

import { UserPermissionListHeaderProps } from './types'
import ExportToCsv from '../../../../../components/common/ExportToCsv/ExportToCsv'
Expand All @@ -26,6 +26,11 @@ import { LAST_LOGIN_TIME_NULL_STATE } from '../constants'
import { importComponentFromFELibrary } from '../../../../../components/common'

const getStatusExportText = importComponentFromFELibrary('getStatusExportText', null, 'function')
const getUserExportToCsvConfiguration = importComponentFromFELibrary(
'getUserExportToCsvConfiguration',
null,
'function',
)
const showStatus = !!getStatusExportText

const ExportUserPermissionsToCsv = ({
Expand All @@ -37,8 +42,8 @@ const ExportUserPermissionsToCsv = ({
/**
* Returns the list of users which have permission to devtron applications
*/
const getUsersDataToExport = async () => {
const { users } = await getDataToExport()
const getUsersDataToExport: ExportToCsvProps<UserTypeToFetchType>['apiPromise'] = async (selectedConfig) => {
const { users } = await getDataToExport(selectedConfig)
const userList = users.reduce((_usersList, _user) => {
let isRowAdded = false

Expand All @@ -51,19 +56,25 @@ const ExportUserPermissionsToCsv = ({
isRowAdded = true
}

const updatedOn = getFormattedUTCTimeForExport(_user.updatedOn)

const _userData = {
emailId: _user.emailId,
userId: _user.id,
...(showStatus
? {
status: getStatusExportText(_user.userStatus, _user.timeToLive),
permissionStatus: '-',
createdOn: getFormattedUTCTimeForExport(_user.createdOn),
updatedOn,
deletedOn: _user.isDeleted ? updatedOn : '-',
isDeleted: _user.isDeleted,
}
: {}),
lastLoginTime:
_user.lastLoginTime === LAST_LOGIN_TIME_NULL_STATE
? _user.lastLoginTime
: `${moment.utc(_user.lastLoginTime).format(Moment12HourExportFormat)} (UTC)`,
: getFormattedUTCTimeForExport(_user.lastLoginTime),
superAdmin: _user.superAdmin,
group: '-',
project: '-',
Expand Down Expand Up @@ -106,6 +117,10 @@ const ExportUserPermissionsToCsv = ({
},
)
}

if (!isRowAdded) {
_pushToUserList(_userData)
}
}

return _usersList
Expand All @@ -115,7 +130,15 @@ const ExportUserPermissionsToCsv = ({
}

return (
<ExportToCsv disabled={disabled} apiPromise={getUsersDataToExport} fileName={FILE_NAMES.Users} showOnlyIcon />
<ExportToCsv
disabled={disabled}
apiPromise={getUsersDataToExport}
fileName={FILE_NAMES.Users}
showOnlyIcon
{...(getUserExportToCsvConfiguration && {
configuration: getUserExportToCsvConfiguration(),
})}
/>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ import { User } from '../../types'
import { getIsAdminOrSystemUser, parseSearchParams } from '../utils'
import UserPermissionContainer from './UserPermissionContainer'
import { BulkSelectionModalConfig, BulkSelectionModalTypes } from '../../Shared/components/BulkSelection'
import { UserListFilter } from './types'
import { UserListFilter, UserPermissionContainerProps } from './types'

const StatusHeaderCell = importComponentFromFELibrary('StatusHeaderCell', null, 'function')
const getUserTypeToFetchFromSelectedConfigOptions = importComponentFromFELibrary(
'getUserTypeToFetchFromSelectedConfigOptions',
null,
'function',
)

const showStatus = !!StatusHeaderCell

Expand Down Expand Up @@ -102,14 +107,17 @@ const UserPermissionList = () => {

const showLoadingState = isLoading || getIsRequestAborted(error)

const getUserDataForExport = () =>
const getUserDataForExport: UserPermissionContainerProps['getUserDataForExport'] = (selectedConfig) =>
getUserList({
...filterConfig,
showAll: true,
offset: null,
size: null,
sortBy: UserListSortableKeys.email,
sortOrder: SortingOrder.ASC,
...(getUserTypeToFetchFromSelectedConfigOptions && {
typeToFetch: getUserTypeToFetchFromSelectedConfigOptions(selectedConfig),
}),
})

const getSelectAllDialogStatus = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const userListLoading: User[] = Array.from(Array(DEFAULT_SHIMMER_LOADING_
userRoleGroups: [],
userGroups: [],
superAdmin: false,
createdOn: '',
updatedOn: '',
isDeleted: false,
...getDefaultUserStatusAndTimeout(),
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
UserListSortableKeys,
UserStatus,
UseUrlFiltersReturnType,
UserTypeToFetchType,
} from '@devtron-labs/devtron-fe-common-lib'
import { ExportToCsvProps } from '@Components/common/ExportToCsv/types'
import { getUserList } from '../../authorization.service'
import { BulkSelectionActionWidgetProps, BulkSelectionModalConfig } from '../../Shared/components/BulkSelection'
import { User } from '../../types'
Expand All @@ -42,7 +44,9 @@ export interface UserPermissionListHeaderProps {
showStatus: boolean
handleSearch: SearchBarProps['handleEnter']
initialSearchText: SearchBarProps['initialSearchText']
getDataToExport: () => ReturnType<typeof getUserList>
getDataToExport: (
...params: Parameters<ExportToCsvProps<UserTypeToFetchType>['apiPromise']>
) => ReturnType<typeof getUserList>
status: UserStatus[]
handleStatusFilterChange: (status: UserStatus[]) => void
}
Expand Down
21 changes: 20 additions & 1 deletion src/Pages/GlobalConfigurations/Authorization/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ export interface UserDto {
timeoutWindowExpression?: string
}[]
userGroups: UserGroupDTO[]
/**
* Denotes the time when the user was created
*
* Note: Enterprise only
*/
createdOn: string
/**
* Denotes the time when the user was last updated
*
* Note: Enterprise only
*/
updatedOn: string
/**
* Denotes is the user is deleted
*
* Note: Enterprise only
*/
isDeleted: boolean
}

export interface User
Expand Down Expand Up @@ -160,7 +178,8 @@ export type UserCreateOrUpdateParamsType = Pick<
userGroups: Pick<UserGroupType, 'name' | 'userGroupId'>[]
}

export interface UserCreateOrUpdatePayloadType extends Omit<UserDto, 'userGroups'> {
export interface UserCreateOrUpdatePayloadType
extends Omit<UserDto, 'userGroups' | 'createdOn' | 'updatedOn' | 'isDeleted'> {
userGroups: Pick<UserGroupDTO, 'identifier'>[]
}

Expand Down
6 changes: 6 additions & 0 deletions src/Pages/GlobalConfigurations/Authorization/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export const transformUserResponse = (_user: UserDto): User => {
userRoleGroups,
roleFilters,
userGroups,
isDeleted,
createdOn,
updatedOn,
...user
} = _user
const timeToLive = getFormattedTimeToLive(timeoutWindowExpression)
Expand Down Expand Up @@ -128,6 +131,9 @@ export const transformUserResponse = (_user: UserDto): User => {
) ?? [],
roleFilters: transformRoleFilters(roleFilters),
userGroups: getParsedUserGroupList(userGroups),
createdOn: createdOn && createdOn !== ZERO_TIME_STRING ? moment(createdOn).format(Moment12HourFormat) : '',
updatedOn: updatedOn && updatedOn !== ZERO_TIME_STRING ? moment(updatedOn).format(Moment12HourFormat) : '',
isDeleted: isDeleted ?? false,
}
}

Expand Down
79 changes: 79 additions & 0 deletions src/components/common/ExportToCsv/ExportConfiguration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2024. Devtron Inc.
*
* 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 { ChangeEvent, useEffect } from 'react'
import { Checkbox, CHECKBOX_VALUE, Tooltip } from '@devtron-labs/devtron-fe-common-lib'
import { ExportConfigurationProps } from './types'
import { getDefaultValueFromConfiguration } from './utils'

export const ExportConfiguration = <ConfigValueType extends string>({
selectedConfig,
setSelectedConfig,
configuration,
}: ExportConfigurationProps<ConfigValueType>) => {
const { title, options } = configuration

const handleConfigSelectionChange = (e: ChangeEvent<HTMLInputElement>) => {
setSelectedConfig((prev) => ({
...prev,
[e.target.name]: e.target.checked,
}))
}

useEffect(
() => () => {
setSelectedConfig(getDefaultValueFromConfiguration(configuration))
},
[],
)

return (
<div className="fs-13 lh-20 flexbox-col dc__gap-8 flex-grow-1">
<h3 className="fw-6 cn-9 m-0 fs-13 lh-20 dc__truncate px-8">{title}</h3>
<div>
{options.map(({ label, value, description }) => (
<label
className={`m-0 py-6 px-8 flex left dc__gap-8 ${description ? 'top' : ''} dc__hover-n50 br-4 cursor`}
key={value}
htmlFor={value}
>
<Checkbox
value={CHECKBOX_VALUE.CHECKED}
name={value}
dataTestId={`check-${label}`}
id={value}
isChecked={selectedConfig[value] ?? false}
onChange={handleConfigSelectionChange}
rootClassName="m-0 w-20 h-20"
/>
<p className="m-0 flexbox-col">
<Tooltip content={label}>
<span className="fs-13 fw-4 lh-20 cn-9 dc__truncate">{label}</span>
</Tooltip>
{description && (
<Tooltip content={description}>
<span className="fs-12 fw-4 lh-18 cn-7 dc__ellipsis-right__2nd-line">
{description}
</span>
</Tooltip>
)}
</p>
</label>
))}
</div>
</div>
)
}
Loading

0 comments on commit 9e5b339

Please sign in to comment.