Skip to content

Commit

Permalink
Merge pull request #3 from zenoxs/feature-edit-bundled-app
Browse files Browse the repository at this point in the history
Feature edit bundled app
  • Loading branch information
zenoxs authored May 25, 2022
2 parents 93ac51f + cfac2a8 commit 70f5570
Show file tree
Hide file tree
Showing 19 changed files with 410 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ jobs:
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A companion app written with **React** and **Tauri** to help you manage your app
- [x] Light/dark theme
- [ ] View the logs of your builds
- [ ] View all the available builds
- [ ] Edit / remove a bundled app
- [x] Edit / remove a bundled app

## How to use it ?

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "tauri-appcenter-companion",
"private": false,
"repository": "https://github.com/zenoxs/tauri-appcenter-companion",
"version": "0.3.6",
"version": "0.4.0",
"license": "GPL-3.0",
"author": "Amaury CIVIER",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint src --ext .ts,.tsx,.js,.jsx",
"lint": "eslint src --ext .ts,.tsx,.js,.jsx --max-warnings=0",
"tauri": "tauri",
"tauri:dev": "tauri dev",
"postinstall": "cd node_modules/tauri-plugin-websocket && yarn && yarn build"
Expand Down
21 changes: 20 additions & 1 deletion src-tauri/Cargo.lock

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

4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tauri-appcenter-companion"
version = "0.3.6"
version = "0.4.0"
description = "Companion app for Appcenter"
authors = ["Amaury CIVIER"]
license = "GPL-3.0"
Expand All @@ -18,7 +18,7 @@ tauri-build = { version = "1.0.0-rc.8", features = [] }
serde_json = "1.0"
window-vibrancy = "0.1.2"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-rc.10", features = ["http-all", "macos-private-api", "os-all", "updater", "window-start-dragging"] }
tauri = { version = "1.0.0-rc.10", features = ["http-all", "macos-private-api", "os-all", "shell-open", "updater", "window-start-dragging"] }

[target."cfg(target_os = \"macos\")".dependencies]
cocoa = "0.24"
Expand Down
5 changes: 4 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "AC Companion",
"version": "0.3.6"
"version": "0.4.0"
},
"build": {
"distDir": "../dist",
Expand Down Expand Up @@ -56,6 +56,9 @@
"window": {
"startDragging": true
},
"shell": {
"open": true
},
"http": {
"all": true,
"request": true,
Expand Down
10 changes: 7 additions & 3 deletions src/app/navigation/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
ThemeContext
} from '@fluentui/react'
import { os } from '@tauri-apps/api'
import { ApplicationList } from '../screens/application-list/ApplicationList'
import { ApplicationListScreen } from '../screens/application-list/ApplicationListScreen'
import { Routes, Route, useNavigate, useLocation, Location } from 'react-router-dom'
import './AppNavigator.css'
import { APITokenListModal } from '../screens/api-token/APITokenListModal'
import { AddBundledAppDialog } from '../screens/application-list/AddBundledAppDialog'
import { useConst } from '@fluentui/react-hooks'

const navStyles = (theme: Theme): Partial<INavStyles> => ({
root: {
Expand Down Expand Up @@ -63,6 +64,7 @@ export const AppNavigator = () => {
const navigate = useNavigate()
const location = useLocation()
const state = location.state as { backgroundLocation?: Location }
const titleBarHeight = useConst('35px')

// set non transparent background for linux systems
const [background, setBackground] = useState<string | undefined>()
Expand All @@ -76,7 +78,7 @@ export const AppNavigator = () => {

return (
<Stack verticalFill styles={{ root: { height: '100vh', width: '100vw', background } }}>
<div className='titlebar' data-tauri-drag-region style={{ height: '35px' }}></div>
<div className='titlebar' data-tauri-drag-region style={{ height: titleBarHeight }}></div>
<Stack className='container' grow horizontal styles={{ root: { display: 'flex' } }}>
<Stack>
<Stack.Item align='center'>
Expand Down Expand Up @@ -108,13 +110,15 @@ export const AppNavigator = () => {
root: {
backgroundColor: theme.semanticColors.bodyBackground,
overflowX: 'hidden',
overflowY: 'auto',
height: `calc(100vh - ${titleBarHeight})`,
borderRadius: '10px 0px 0px 0px'
}
}}
tokens={{ padding: theme.spacing.m }}
>
<Routes location={state?.backgroundLocation ?? location}>
<Route path='/' element={<ApplicationList />} />
<Route path='/' element={<ApplicationListScreen />} />
</Routes>
{state?.backgroundLocation && (
<Routes>
Expand Down
105 changes: 9 additions & 96 deletions src/app/screens/application-list/AddBundledAppDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,23 @@
import React, { useEffect, useState } from 'react'
import React from 'react'
import {
DefaultButton,
DetailsHeader,
Dialog,
DialogFooter,
DialogType,
IColumn,
IDetailsHeaderProps,
IGroup,
PrimaryButton,
Stack,
TextField,
Selection,
DetailsList,
Spinner,
SpinnerSize
Selection
} from '@fluentui/react'
import { useNavigate } from 'react-router-dom'
import { observer } from 'mobx-react-lite'
import { useForm } from 'react-hook-form'
import { Branch, BundledApplicationSnapshotIn, useStores } from '../../../models'
import { SelectApplicationList } from './SelectApplicationList'
import { useConst } from '@fluentui/react-hooks'

const columns: Array<IColumn> = [
{
key: 'name',
name: 'Name',
fieldName: 'name',
minWidth: 100,
maxWidth: 200,
isResizable: true
},
{
key: 'token',
name: 'token',
onRender: (item: Branch) => item.application?.token?.name,
minWidth: 100,
maxWidth: 200,
isResizable: true
}
]

export const AddBundledAppDialog = observer(() => {
export const AddBundledAppDialog = () => {
const {
applicationStore: { fetchApplications, applicationList },
bundledApplicationStore: { addBundledApplication },
tokenStore: { tokens }
bundledApplicationStore: { addBundledApplication }
} = useStores()

const navigate = useNavigate()
Expand All @@ -58,8 +30,6 @@ export const AddBundledAppDialog = observer(() => {
formState: { errors }
} = useForm<BundledApplicationSnapshotIn>()

const [isLoading, setIsLoading] = useState(true)

// TODO: a rules to check that their is at least one branches
React.useEffect(() => {
register('branches')
Expand All @@ -68,42 +38,16 @@ export const AddBundledAppDialog = observer(() => {

const selection = useConst(
() =>
new Selection({
new Selection<Branch>({
onSelectionChanged: () => {
setValue(
'branches',
(selection.getSelection() as Array<Branch>).map((b) => b.id)
selection.getSelection().map((branch) => branch.id)
)
}
})
)

useEffect(() => {
setIsLoading(true)
Promise.all(
tokens.map((token) => fetchApplications(token.token, { withBranches: true }))
).finally(() => setIsLoading(false))
}, [])

const [items, groups] = (() => {
let items: Array<Branch> = []
const groups: Array<IGroup> = []
for (const application of applicationList) {
const branches = application.configuredBranches
groups.push({
key: application.id,
name: application.displayName,
startIndex: items.length,
count: branches.length,
level: 0,
isCollapsed: true
})
items = items.concat(branches)
}

return [items, groups]
})()

const onDismiss = () => {
navigate(-1)
}
Expand Down Expand Up @@ -135,38 +79,7 @@ export const AddBundledAppDialog = observer(() => {
{...register('name', { required: { value: true, message: 'Name is required' } })}
errorMessage={errors.name?.message}
/>
{isLoading ? (
<Spinner size={SpinnerSize.large} label='Fetching applications...' />
) : (
<DetailsList
styles={{ root: { flex: 1 } }}
selection={selection}
items={items}
groups={groups}
columns={columns}
ariaLabelForSelectAllCheckbox='Toggle selection for all items'
ariaLabelForSelectionColumn='Toggle selection'
checkButtonAriaLabel='select row'
checkButtonGroupAriaLabel='select section'
onRenderDetailsHeader={(props?: IDetailsHeaderProps) => (
<DetailsHeader
{...props!}
ariaLabelForToggleAllGroupsButton={'Expand collapse groups'}
/>
)}
groupProps={{
showEmptyGroups: true
}}
onRenderItemColumn={(item?: Branch, index?: number, column?: IColumn) => {
const value =
item && column && column.fieldName
? item[column.fieldName as keyof Branch] || ''
: ''

return <div data-is-focusable={true}>{value}</div>
}}
/>
)}
<SelectApplicationList selection={selection} />
</Stack>
<DialogFooter>
<PrimaryButton type='submit' text='Save' />
Expand All @@ -175,4 +88,4 @@ export const AddBundledAppDialog = observer(() => {
</form>
</Dialog>
)
})
}
Loading

0 comments on commit 70f5570

Please sign in to comment.