Skip to content

Commit

Permalink
Feature jincy 457 (#504)
Browse files Browse the repository at this point in the history
* added checkbox list feature for merge dialog

* Added cardsToMerge as a prop

* removed console from store context
  • Loading branch information
jincypjose authored Jul 18, 2023
1 parent 24397a7 commit 3528ae3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 67 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
"react-icons": "^4.8.0",
"regenerator-runtime": "^0.13.7",
"resource-workspace-rcl": "2.1.4",

"scripture-resources-rcl": "5.4.1",
"single-scripture-rcl": "3.4.4",
"tailwindcss": "^2.0.4",
"tc-ui-toolkit": "5.3.3",
"translation-helps-rcl": "3.5.0",
"translation-helps-rcl": "3.5.2",
"use-deep-compare-effect": "^1.3.1",
"word-aligner": "^1.0.0",
"word-aligner-rcl": "1.0.2"
Expand Down
9 changes: 6 additions & 3 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { APP_NAME } from '@common/constants'
import AppHead from '@components/AppHead'
import theme from '../src/theme'
import '@styles/globals.css'
import { BranchMergerProvider } from 'translation-helps-rcl';

export default function Application({ Component, pageProps }) {
useEffect(() => {
Expand All @@ -26,9 +27,11 @@ export default function Application({ Component, pageProps }) {
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<AuthContextProvider>
<StoreContextProvider>
<Component {...pageProps} />
</StoreContextProvider>
<BranchMergerProvider>
<StoreContextProvider>
<Component {...pageProps} />
</StoreContextProvider>
</BranchMergerProvider>
</AuthContextProvider>
</ThemeProvider>
</>
Expand Down
12 changes: 9 additions & 3 deletions src/components/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,24 @@ export default function Drawer({
state: {
mergeStatusForCards,
cardsSaving,
cardsLoadingMerge
cardsLoadingMerge,
},
} = useContext(StoreContext)

const mergeButtonProps = useMergeCardsProps({ mergeStatusForCards, isMerging: cardsLoadingMerge?.length });

const {
onClick: onMergeClick,
onSubmit,
blocked: mergeBlocked,
pending: mergePending,
dialogMessage,
dialogTitle,
isErrorDialogOpen,
isMessageDialogOpen,
onCloseErrorDialog
} = mergeButtonProps;
onCloseErrorDialog,
cardsToMerge,
} = mergeButtonProps

async function onLogout() {
const okToContinue = await checkUnsavedChanges()
Expand Down Expand Up @@ -225,9 +228,12 @@ export default function Drawer({
<ListItemSecondaryAction>
<MergeBranchButton
{...mergeButtonProps}
{...mergeStatusForCards}
isLoading={ cardsLoadingMerge?.length || cardsSaving?.length }
/>
<MergeDialog
cardsToMerge={cardsToMerge}
mergeStatusForCards={mergeStatusForCards}
{...mergeButtonProps}
open={isMessageDialogOpen}
isLoading={ cardsLoadingMerge?.length }
Expand Down
2 changes: 1 addition & 1 deletion src/components/WorkspaceContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ function WorkspaceContainer() {
getLexiconData={getLexiconData}
/>

{(tokenNetworkError || networkError) && // If error, show error popup dialog
{(tokenNetworkError || networkError) && // Do not render workspace until user logged in and we have user settings
<>
{showNetworkError()}
</>
Expand Down
62 changes: 10 additions & 52 deletions src/context/StoreContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ import useLocalStorage from '@hooks/useLocalStorage'
import * as useULS from '@hooks/useUserLocalStorage'
import { AuthContext } from '@context/AuthContext'
import useSaveChangesPrompt from '@hooks/useSaveChangesPrompt'
import { useBranchMergerContext } from 'translation-helps-rcl'

export const StoreContext = createContext({})

export default function StoreContextProvider(props) {
const {
state: { mergeStatusForCards },
actions: {
updateMergeState,
getMergeFromMasterStatus,
callMergeFromMasterForCards,
},
} = useBranchMergerContext()

const {
state: {
authentication,
Expand Down Expand Up @@ -59,62 +69,10 @@ export default function StoreContextProvider(props) {
const [hebrewRepoUrl, setHebrewRepoUrl] = useLocalStorage('hebrewRepoUrl', null)
const [supportedBibles, setSupportedBibles] = useLocalStorage('bibles', [])
const [currentLayout, setCurrentLayout] = useUserLocalStorage('resourceLayout', null)
const [mergeStatusForCards, setMergeStatusForCards] = useState({})
const [cardsSaving, setCardsSaving] = useState([])
const [cardsLoadingUpdate, setCardsLoadingUpdate] = useState([])
const [cardsLoadingMerge, setCardsLoadingMerge] = useState([])

function updateMergeState(cardId, mergeFromMaster, mergeToMaster, mergeFromMasterIntoUserBranch, mergeToMasterFromUserBranch) {
console.log('updateMergeState',{cardId, mergeFromMaster, mergeToMaster})
const newMergeStatus = {
...mergeStatusForCards,
[cardId]: {
mergeFromMaster,
mergeToMaster,
mergeFromMasterIntoUserBranch,
mergeToMasterFromUserBranch,
},
}
setMergeStatusForCards(newMergeStatus)
}

function getMergeFromMasterStatus(_mergeStatusForCards = mergeStatusForCards) {
const cardIds = Object.keys(_mergeStatusForCards)
let mergeConflict = false
let mergeNeeded = false
let foundMergeStatusCard = false

for (const cardId of cardIds) {
const { mergeFromMaster } = _mergeStatusForCards[cardId]

if (mergeFromMaster && !mergeFromMaster.error) {
foundMergeStatusCard = true

if (mergeFromMaster.mergeNeeded) {
mergeNeeded = true
}

if (mergeFromMaster.conflict) {
mergeConflict = true
}
}
}
return {
mergeConflict,
mergeNeeded,
foundMergeStatusCard,
}
}

function callMergeFromMasterForCards(_mergeStatusForCards = mergeStatusForCards){
const cardIds = Object.keys(_mergeStatusForCards)

for (const cardId of cardIds){
const { mergeFromMasterIntoUserBranch } = _mergeStatusForCards[cardId]
mergeFromMasterIntoUserBranch && mergeFromMasterIntoUserBranch()
}
}

const {
savedChanges,
setSavedChanges,
Expand Down
12 changes: 9 additions & 3 deletions src/hooks/useMergeCardsProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function useMergeCardsProps({ mergeStatusForCards = {}, isMerging
const { conflict, mergeNeeded, error, message } = mergeStatus

if (conflict) return 'cardsWithConflicts'

if (error) {
if (message.includes('does not exist')) return 'cardsWithNoUserBranch'
if (message.includes('nothing to commit')) return 'cardsWithNoChanges'
Expand Down Expand Up @@ -129,8 +130,9 @@ export default function useMergeCardsProps({ mergeStatusForCards = {}, isMerging

}

const onSubmit = description => {
syncMergeableCards(cardsToMerge, description)
const onSubmit = ({ mergeableCardIds, description }) => {
console.log({ cardsToMerge, mergeableCardIds })
syncMergeableCards(mergeableCardIds, description)
}

return {
Expand All @@ -144,6 +146,10 @@ export default function useMergeCardsProps({ mergeStatusForCards = {}, isMerging
dialogTitle,
pending,
blocked,
loadingProps
loadingProps,
cardMergeGroupings,
cardsToMerge,
}
}

// cardsToMerge=[ult, ust]
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10582,10 +10582,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/transform-runtime/-/transform-runtime-0.0.0.tgz#e714d9b69211dd9537939d50e3aa5788c442b85c"
integrity sha512-PX3vXzO8lucrVm82vZb7BABBLHyMDPGzn9zElHr+DnvtS3JPXtqwB1iTRe+D6iFXYmjtAF3zH7O0Xc5XpLpMEg==

[email protected].0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/translation-helps-rcl/-/translation-helps-rcl-3.5.0.tgz#682886826970f4dc0330ab32d27efd30f4c13985"
integrity sha512-/goKN/52fwfnWCSZqVc5MdgQaqVOoBQh/+vWEVyyVVm+8NmVpCA+xBz0HCz1Mayp/HjJRXa5CxyRdeLZnLaZ+A==
[email protected].2:
version "3.5.2"
resolved "https://registry.yarnpkg.com/translation-helps-rcl/-/translation-helps-rcl-3.5.2.tgz#9387ca1f998672796e9fddf1957a8de26c5cd007"
integrity sha512-sb0z528ilijKnfGkDsJJ0r7od/WN9mUI1CJZkOZPbcdC+Bso6ggLp3s4AXr4XUThrIJjtLnFfYt0Gk0KoB4Xvg==
dependencies:
"@gwdevs/extensible-rcl" "^1.0.1"
"@mui/styled-engine" "npm:@mui/styled-engine-sc@latest"
Expand Down

0 comments on commit 3528ae3

Please sign in to comment.