Skip to content

Commit

Permalink
chore: rename engine to dataEngine for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen committed Feb 4, 2025
1 parent 3246014 commit 2065d86
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
23 changes: 12 additions & 11 deletions src/actions/showDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ export const acSetShowDescription = (value) => ({
value,
})

export const tSetShowDescription = () => async (dispatch, getState, engine) => {
const onSuccess = (value) => {
dispatch(acSetShowDescription(value))
}
export const tSetShowDescription =
() => async (dispatch, getState, dataEngine) => {
const onSuccess = (value) => {
dispatch(acSetShowDescription(value))
}

try {
const showDescription = await apiGetShowDescription(engine)
return onSuccess(showDescription)
} catch (err) {
console.error('Error (apiGetShowDescription): ', err)
return err
try {
const showDescription = await apiGetShowDescription(dataEngine)
return onSuccess(showDescription)
} catch (err) {
console.error('Error (apiGetShowDescription): ', err)
return err
}
}
}
8 changes: 4 additions & 4 deletions src/api/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {

const KEY_SHOW_DESCRIPTION = 'showDescription'

export const apiGetShowDescription = async (engine) =>
export const apiGetShowDescription = async (dataEngine) =>
await apiGetUserDataStoreValue(
KEY_SHOW_DESCRIPTION,
DEFAULT_STATE_SHOW_DESCRIPTION,
engine
dataEngine
)

export const apiPostShowDescription = (value, engine) =>
apiPostUserDataStoreValue(KEY_SHOW_DESCRIPTION, value, engine)
export const apiPostShowDescription = (value, dataEngine) =>
apiPostUserDataStoreValue(KEY_SHOW_DESCRIPTION, value, dataEngine)
30 changes: 17 additions & 13 deletions src/api/userDataStore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const NAMESPACE = 'dashboard'

const hasDashboardNamespace = async (engine) => {
const userDataStore = await engine.query({
const hasDashboardNamespace = async (dataEngine) => {
const userDataStore = await dataEngine.query({
userDataStore: {
resource: 'userDataStore',
},
Expand All @@ -10,48 +10,52 @@ const hasDashboardNamespace = async (engine) => {
return userDataStore?.userDataStore?.find((ns) => ns === NAMESPACE)
}

const getNamespace = async (engine) => {
const hasNamespace = await hasDashboardNamespace(engine)
const getNamespace = async (dataEngine) => {
const hasNamespace = await hasDashboardNamespace(dataEngine)

if (hasNamespace) {
return await engine.query({
return await dataEngine.query({
dashboard: {
resource: `userDataStore/${NAMESPACE}`,
},
})
} else {
return await engine.mutate({
return await dataEngine.mutate({
resource: `userDataStore/${NAMESPACE}`,
type: 'create',
data: {},
})
}
}

export const apiPostUserDataStoreValue = async (key, value, engine) => {
await getNamespace(engine)
export const apiPostUserDataStoreValue = async (key, value, dataEngine) => {
await getNamespace(dataEngine)

return await engine.mutate({
return await dataEngine.mutate({
resource: `userDataStore/${NAMESPACE}/${key}`,
type: 'update',
data: value,
})
}

export const apiGetUserDataStoreValue = async (key, defaultValue, engine) => {
const ns = await getNamespace(engine)
export const apiGetUserDataStoreValue = async (
key,
defaultValue,
dataEngine
) => {
const ns = await getNamespace(dataEngine)
const nsKeys = ns[NAMESPACE]

const hasKey = nsKeys?.find((k) => k === key)

if (hasKey) {
return await engine.query({
return await dataEngine.query({
[key]: {
resource: `userDataStore/${NAMESPACE}/${key}`,
},
})
} else {
await apiPostUserDataStoreValue(key, defaultValue, engine)
await apiPostUserDataStoreValue(key, defaultValue, dataEngine)
console.log('(These errors to /userDataStore can be ignored)')
return defaultValue
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/DashboardsBar/InformationBlock/ActionsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ActionsBar = ({
dashboardItems,
}) => {
const history = useHistory()
const engine = useDataEngine()
const dataEngine = useDataEngine()
const [moreOptionsIsOpen, setMoreOptionsIsOpen] = useState(false)
const [sharingDialogIsOpen, setSharingDialogIsOpen] = useState(false)
const [confirmCacheDialogIsOpen, setConfirmCacheDialogIsOpen] =
Expand Down Expand Up @@ -91,8 +91,8 @@ const ActionsBar = ({
const onToggleShowDescription = useCallback(() => {
updateShowDescription(!showDescription)
setMoreOptionsIsOpen(false)
!offline && apiPostShowDescription(!showDescription, engine)
}, [offline, showDescription, updateShowDescription, engine])
!offline && apiPostShowDescription(!showDescription, dataEngine)
}, [offline, showDescription, updateShowDescription, dataEngine])

const onToggleSharingDialog = useCallback(
() => setSharingDialogIsOpen(!sharingDialogIsOpen),
Expand Down

0 comments on commit 2065d86

Please sign in to comment.