Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
5a02867d
Commit
5a02867d
authored
Jul 05, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jul 06, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate direct-linked store module to TypeScript
parent
1125ec3a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
72 deletions
+52
-72
direct-linked.ts
src/sidebar/store/modules/direct-linked.ts
+52
-72
No files found.
src/sidebar/store/modules/direct-linked.
j
s
→
src/sidebar/store/modules/direct-linked.
t
s
View file @
5a02867d
import
type
{
SidebarSettings
}
from
'../../../types/config'
;
import
{
createStoreModule
,
makeAction
}
from
'../create-store'
;
/** @param {import('../../../types/config').SidebarSettings} settings */
function
initialState
(
settings
)
{
export
type
State
=
{
/**
* The ID of the direct-linked group.
*
* This ID is initialized from the client's configuration to indicate that
* the client should focus on a particular group initially. The user may
* need to log in for this step to complete. When the user navigates away
* from the group or clears the selection, the direct link is "consumed"
* and no longer used.
*/
directLinkedGroupId
:
string
|
null
;
/**
* The ID of the direct-linked annotation.
*
* This ID is initialized from the client's configuration to indicate that
* the client should focus on a particular annotation. The user may need to
* log in to see the annotation. When the user clears the selection or
* switches to a different group manually, the direct link is "consumed"
* and no longer used.
*/
directLinkedAnnotationId
:
string
|
null
;
/**
* Indicates that an error occurred in retrieving/showing the direct linked group.
* This could be because:
* - the group does not exist
* - the user does not have permission
* - the group is out of scope for the given page
*/
directLinkedGroupFetchFailed
:
boolean
;
};
function
initialState
(
settings
:
SidebarSettings
):
State
{
return
{
/**
* The ID of the direct-linked group.
*
* This ID is initialized from the client's configuration to indicate that
* the client should focus on a particular group initially. The user may
* need to login for this step to complete. When the user navigates away
* from the group or clears the selection, the direct link is "consumed"
* and no longer used.
*
* @type {string|null}
*/
directLinkedGroupId
:
settings
.
group
||
null
,
/**
* The ID of the direct-linked annotation.
*
* This ID is initialized from the client's configuration to indicate that
* the client should focus on a particular annotation. The user may need to
* login to see the annotation. When the user clears the selection or
* switches to a different group manually, the direct link is "consumed"
* and no longer used.
*
* @type {string|null}
*/
directLinkedAnnotationId
:
settings
.
annotations
||
null
,
/**
* Indicates that an error occurred in retrieving/showing the direct linked group.
* This could be because:
* - the group does not exist
* - the user does not have permission
* - the group is out of scope for the given page
* @type {boolean}
*/
directLinkedGroupFetchFailed
:
false
,
};
}
/** @typedef {ReturnType<initialState>} State */
const
reducers
=
{
/**
* @param {State} state
* @param {{ directLinkedGroupFetchFailed: boolean }} action
*/
UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED
(
state
,
action
)
{
UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED
(
state
:
State
,
action
:
{
directLinkedGroupFetchFailed
:
boolean
}
)
{
return
{
directLinkedGroupFetchFailed
:
action
.
directLinkedGroupFetchFailed
,
};
},
/**
* @param {State} state
* @param {{ directLinkedGroupId: string }} action
*/
UPDATE_DIRECT_LINKED_GROUP_ID
(
state
,
action
)
{
UPDATE_DIRECT_LINKED_GROUP_ID
(
state
:
State
,
action
:
{
directLinkedGroupId
:
string
}
)
{
return
{
directLinkedGroupId
:
action
.
directLinkedGroupId
,
};
},
/**
* @param {State} state
* @param {{ directLinkedAnnotationId: string }} action
*/
UPDATE_DIRECT_LINKED_ANNOTATION_ID
(
state
,
action
)
{
UPDATE_DIRECT_LINKED_ANNOTATION_ID
(
state
:
State
,
action
:
{
directLinkedAnnotationId
:
string
}
)
{
return
{
directLinkedAnnotationId
:
action
.
directLinkedAnnotationId
,
};
...
...
@@ -90,23 +86,13 @@ const reducers = {
},
};
/**
* Set the direct linked group id.
*
* @param {string} groupId
*/
function
setDirectLinkedGroupId
(
groupId
)
{
function
setDirectLinkedGroupId
(
groupId
:
string
)
{
return
makeAction
(
reducers
,
'UPDATE_DIRECT_LINKED_GROUP_ID'
,
{
directLinkedGroupId
:
groupId
,
});
}
/**
* Set the direct linked annotation's id.
*
* @param {string} annId
*/
function
setDirectLinkedAnnotationId
(
annId
)
{
function
setDirectLinkedAnnotationId
(
annId
:
string
)
{
return
makeAction
(
reducers
,
'UPDATE_DIRECT_LINKED_ANNOTATION_ID'
,
{
directLinkedAnnotationId
:
annId
,
});
...
...
@@ -121,9 +107,6 @@ function setDirectLinkedGroupFetchFailed() {
});
}
/**
* Clear the direct linked group fetch failure.
*/
function
clearDirectLinkedGroupFetchFailed
()
{
return
makeAction
(
reducers
,
'UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED'
,
{
directLinkedGroupFetchFailed
:
false
,
...
...
@@ -140,18 +123,15 @@ function clearDirectLinkedIds() {
return
makeAction
(
reducers
,
'CLEAR_DIRECT_LINKED_IDS'
,
undefined
);
}
/** @param {State} state */
function
directLinkedAnnotationId
(
state
)
{
function
directLinkedAnnotationId
(
state
:
State
)
{
return
state
.
directLinkedAnnotationId
;
}
/** @param {State} state */
function
directLinkedGroupId
(
state
)
{
function
directLinkedGroupId
(
state
:
State
)
{
return
state
.
directLinkedGroupId
;
}
/** @param {State} state */
function
directLinkedGroupFetchFailed
(
state
)
{
function
directLinkedGroupFetchFailed
(
state
:
State
)
{
return
state
.
directLinkedGroupFetchFailed
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment