-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(webapp): Add settings/apps page #1424
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f13d6b5
feat(webapp): add settings/apps page
StasDachinsky cee6097
fix(webapp): Table component for settings/apps
StasDachinsky 66cc28d
small improvements
petethepig e73eb54
feat(webapp): spinner for app under deletion
StasDachinsky d128322
fix(webapp): spinner's logic and styles for apps page
StasDachinsky 11fc434
chore(webapp): app name for delete app confirmation modal
StasDachinsky b657d18
fix(webapp): removed unused types
StasDachinsky 64817de
fix(webapp): small fixes for namings and types
StasDachinsky 36ad635
chore(webapp): update confirmDelete modal text and styles
StasDachinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 32 additions & 3 deletions
35
webapp/javascript/components/Modals/ConfirmDelete/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
webapp/javascript/components/Settings/Apps/AppTableItem.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.actions { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: right; | ||
} | ||
|
||
.loadingIcon { | ||
margin-right: 8px; | ||
} |
24 changes: 24 additions & 0 deletions
24
webapp/javascript/components/Settings/Apps/Apps.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.searchContainer { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.tabNameContrainer { | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
} | ||
|
||
.searchContainer button { | ||
padding: 5px 20px; | ||
} | ||
|
||
.appsTable { | ||
margin: 20px 0; | ||
width: 100%; | ||
} | ||
|
||
.appsTableEmptyMessage { | ||
text-align: center; | ||
color: var(--ps-ui-foreground-text); | ||
} |
72 changes: 72 additions & 0 deletions
72
webapp/javascript/components/Settings/Apps/getAppTableRows.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import { faTimes } from '@fortawesome/free-solid-svg-icons/faTimes'; | ||
|
||
import Button from '@webapp/ui/Button'; | ||
import Icon from '@webapp/ui/Icon'; | ||
import { App, Apps } from '@webapp/models/app'; | ||
import type { BodyRow } from '@webapp/ui/Table'; | ||
import confirmDelete from '@webapp/components/Modals/ConfirmDelete'; | ||
import LoadingSpinner from '@webapp/ui/LoadingSpinner'; | ||
|
||
import styles from './AppTableItem.module.css'; | ||
|
||
interface DeleteButtorProps { | ||
onDelete: (app: App) => void; | ||
isLoading: boolean; | ||
app: App; | ||
} | ||
|
||
function DeleteButton(props: DeleteButtorProps) { | ||
const { onDelete, app, isLoading } = props; | ||
|
||
const handleDeleteClick = () => { | ||
confirmDelete({ | ||
objectName: app.name, | ||
objectType: 'app', | ||
withConfirmationInput: true, | ||
warningMsg: `Note: This action can take up to ~15 minutes depending on the size of your application and wont' be reflected in the UI until it is complete.`, | ||
onConfirm: () => onDelete(app), | ||
}); | ||
}; | ||
|
||
return isLoading ? ( | ||
<LoadingSpinner className={styles.loadingIcon} /> | ||
) : ( | ||
<Button type="button" kind="danger" onClick={handleDeleteClick}> | ||
<Icon icon={faTimes} /> | ||
</Button> | ||
); | ||
} | ||
|
||
export function getAppTableRows( | ||
displayApps: Apps, | ||
appsInProcessing: string[], | ||
handleDeleteApp: (app: App) => void | ||
): BodyRow[] { | ||
const bodyRows = displayApps.reduce((acc, app) => { | ||
const { name } = app; | ||
|
||
const row = { | ||
cells: [ | ||
{ value: name }, | ||
{ | ||
value: ( | ||
<div className={styles.actions}> | ||
<DeleteButton | ||
app={app} | ||
onDelete={handleDeleteApp} | ||
isLoading={appsInProcessing.includes(name)} | ||
/> | ||
</div> | ||
), | ||
align: 'center', | ||
}, | ||
], | ||
}; | ||
|
||
acc.push(row); | ||
return acc; | ||
}, [] as BodyRow[]); | ||
|
||
return bodyRows; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import cl from 'classnames'; | ||
import { useAppDispatch, useAppSelector } from '@webapp/redux/hooks'; | ||
import { | ||
selectApps, | ||
reloadApps, | ||
deleteApp, | ||
selectIsLoadingApps, | ||
} from '@webapp/redux/reducers/settings'; | ||
import { addNotification } from '@webapp/redux/reducers/notifications'; | ||
import { type App } from '@webapp/models/app'; | ||
import Input from '@webapp/ui/Input'; | ||
import TableUI from '@webapp/ui/Table'; | ||
import LoadingSpinner from '@webapp/ui/LoadingSpinner'; | ||
import { getAppTableRows } from './getAppTableRows'; | ||
|
||
import appsStyles from './Apps.module.css'; | ||
import tableStyles from '../SettingsTable.module.scss'; | ||
|
||
const headRow = [ | ||
{ name: '', label: 'Name', sortable: 0 }, | ||
{ name: '', label: '', sortable: 0 }, | ||
]; | ||
|
||
function Apps() { | ||
const dispatch = useAppDispatch(); | ||
const apps = useAppSelector(selectApps); | ||
const isLoading = useAppSelector(selectIsLoadingApps); | ||
const [search, setSearchField] = useState(''); | ||
const [appsInProcessing, setAppsInProcessing] = useState<string[]>([]); | ||
const [deletedApps, setDeletedApps] = useState<string[]>([]); | ||
|
||
useEffect(() => { | ||
dispatch(reloadApps()); | ||
}, []); | ||
|
||
const displayApps = | ||
(apps && | ||
apps.filter( | ||
(x) => | ||
x.name.toLowerCase().indexOf(search.toLowerCase()) !== -1 && | ||
!deletedApps.includes(x.name) | ||
)) || | ||
[]; | ||
|
||
const handleDeleteApp = (app: App) => { | ||
setAppsInProcessing([...appsInProcessing, app.name]); | ||
dispatch(deleteApp(app)) | ||
.unwrap() | ||
.then(() => { | ||
setAppsInProcessing(appsInProcessing.filter((x) => x !== app.name)); | ||
setDeletedApps([...deletedApps, app.name]); | ||
dispatch( | ||
addNotification({ | ||
type: 'success', | ||
title: 'App has been deleted', | ||
message: `App ${app.name} has been successfully deleted`, | ||
}) | ||
); | ||
}) | ||
.catch(() => { | ||
setDeletedApps(deletedApps.filter((x) => x !== app.name)); | ||
setAppsInProcessing(appsInProcessing.filter((x) => x !== app.name)); | ||
}); | ||
}; | ||
|
||
const tableBodyProps = | ||
displayApps.length > 0 | ||
? { | ||
bodyRows: getAppTableRows( | ||
displayApps, | ||
appsInProcessing, | ||
handleDeleteApp | ||
), | ||
type: 'filled' as const, | ||
} | ||
: { | ||
type: 'not-filled' as const, | ||
value: 'The list is empty', | ||
bodyClassName: appsStyles.appsTableEmptyMessage, | ||
}; | ||
|
||
return ( | ||
<> | ||
<h2 className={appsStyles.tabNameContrainer}> | ||
Apps | ||
{isLoading && !!apps ? <LoadingSpinner /> : null} | ||
</h2> | ||
<div className={appsStyles.searchContainer}> | ||
<Input | ||
type="text" | ||
placeholder="Search app" | ||
value={search} | ||
onChange={(v) => setSearchField(v.target.value)} | ||
name="Search app input" | ||
/> | ||
</div> | ||
<TableUI | ||
className={cl(appsStyles.appsTable, tableStyles.settingsTable)} | ||
table={{ headRow, ...tableBodyProps }} | ||
isLoading={isLoading && !apps} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default Apps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { z } from 'zod'; | ||
|
||
export const appModel = z.object({ | ||
name: z.string(), | ||
}); | ||
|
||
export const appsModel = z.array(appModel); | ||
|
||
export type Apps = z.infer<typeof appsModel>; | ||
export type App = z.infer<typeof appModel>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eh-am should we use uppercase in zod entities?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like
appModel => AppModel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
AppSchema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made names here like in this users.ts file