Skip to content

Commit 2d10797

Browse files
authored
Fix archived and viewlet bugs (#7927)
Signed-off-by: Denis Bykhov <[email protected]>
1 parent 71215a6 commit 2d10797

File tree

16 files changed

+77
-15
lines changed

16 files changed

+77
-15
lines changed

Diff for: packages/core/src/storage.ts

+16
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,19 @@ export interface Storage {
275275
export interface FulltextStorage {
276276
searchFulltext: (query: SearchQuery, options: SearchOptions) => Promise<SearchResult>
277277
}
278+
279+
export function shouldShowArchived<T extends Doc> (
280+
query: DocumentQuery<T>,
281+
options: FindOptions<T> | undefined
282+
): boolean {
283+
if (options?.showArchived !== undefined) {
284+
return options.showArchived
285+
}
286+
if (query._id !== undefined && typeof query._id === 'string') {
287+
return true
288+
}
289+
if (query.space !== undefined && typeof query.space === 'string') {
290+
return true
291+
}
292+
return false
293+
}

Diff for: packages/query/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import core, {
5454
getObjectValue,
5555
matchQuery,
5656
reduceCalls,
57+
shouldShowArchived,
5758
toFindResult
5859
} from '@hcengineering/core'
5960
import { PlatformError } from '@hcengineering/platform'
@@ -519,8 +520,7 @@ export class LiveQuery implements WithTx, Client {
519520
if (q.options?.lookup !== undefined) {
520521
options.lookup = q.options?.lookup
521522
}
522-
const showArchived: boolean =
523-
options?.showArchived ?? (q.query._id !== undefined && typeof q.query._id === 'string')
523+
const showArchived = shouldShowArchived(q.query, q.options)
524524

525525
options.showArchived = showArchived
526526
const docIdKey = _id + JSON.stringify(options ?? {}) + q._class

Diff for: plugins/contact-resources/src/components/Contacts.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
bind:viewlet
8787
bind:preference
8888
bind:loading
89+
ignoreFragment
8990
viewletQuery={{
9091
attachTo: contact.class.Contact,
9192
descriptor: view.viewlet.Table

Diff for: plugins/recruit-resources/src/components/Applications.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Table
5959
_class={recruit.class.Applicant}
6060
config={preference?.config ?? viewlet.config}
61+
options={{ showArchived: true }}
6162
query={{ attachedTo: objectId, ...(viewlet?.baseQuery ?? {}) }}
6263
loadingProps={{ length: applications }}
6364
{readonly}

Diff for: plugins/recruit-resources/src/components/ApplicationsPopup.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
_class={recruit.class.Applicant}
3636
config={['', '$lookup.space.name', '$lookup.space.company', 'status']}
3737
query={{ attachedTo: value._id }}
38+
options={{ showArchived: true }}
3839
loadingProps={{ length: value.applications ?? 0 }}
3940
/>
4041
</div>

Diff for: plugins/recruit-resources/src/components/Organizations.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
bind:loading
199199
bind:viewlet
200200
bind:preference
201+
ignoreFragment
201202
viewletQuery={{
202203
attachTo: recruit.mixin.VacancyList,
203204
descriptor: { $in: [view.viewlet.Table, view.viewlet.List] }

Diff for: plugins/recruit-resources/src/components/Vacancies.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
bind:loading
147147
bind:viewlet
148148
bind:preference
149+
ignoreFragment
149150
viewletQuery={{
150151
attachTo: recruit.class.Vacancy,
151152
descriptor: { $in: [view.viewlet.Table, view.viewlet.List] }

Diff for: plugins/recruit-resources/src/components/VacancyList.svelte

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<script lang="ts">
1616
import { Doc, Ref } from '@hcengineering/core'
1717
import presentation from '@hcengineering/presentation'
18-
import { Button, Icon, IconAdd, Label, showPopup, Scroller } from '@hcengineering/ui'
18+
import { Button, Icon, IconAdd, Label, Scroller, showPopup } from '@hcengineering/ui'
1919
import view, { BuildModelKey } from '@hcengineering/view'
2020
import { Table } from '@hcengineering/view-resources'
2121
import recruit from '../plugin'
@@ -66,6 +66,7 @@
6666
_class={recruit.class.Vacancy}
6767
{config}
6868
query={{ company: objectId }}
69+
options={{ showArchived: true }}
6970
{readonly}
7071
loadingProps={{ length: vacancies ?? 0 }}
7172
/>

Diff for: plugins/setting-resources/src/components/RelationSetting.svelte

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
<script lang="ts">
22
import core, { Association, Class, Data, Doc, Ref } from '@hcengineering/core'
3-
import { createQuery } from '@hcengineering/presentation'
4-
import { Button, Header, Breadcrumb, Separator, defineSeparators, twoPanelsSeparators } from '@hcengineering/ui'
3+
import { createQuery, getClient, MessageBox } from '@hcengineering/presentation'
4+
import {
5+
Button,
6+
Header,
7+
Breadcrumb,
8+
Separator,
9+
defineSeparators,
10+
twoPanelsSeparators,
11+
IconDelete,
12+
showPopup
13+
} from '@hcengineering/ui'
514
import settings from '../plugin'
6-
import view from '@hcengineering/view'
15+
import view from '@hcengineering/view-resources/src/plugin'
716
import AssociationEditor from './AssociationEditor.svelte'
817
918
const query = createQuery()
19+
const client = getClient()
1020
1121
let selected: Association | Data<Association> | undefined
1222
@@ -26,12 +36,37 @@
2636
}
2737
}
2838
39+
function isAssociation (data: Data<Association> | Association | undefined): data is Association {
40+
return (data as Association)?._id !== undefined
41+
}
42+
2943
defineSeparators('workspaceSettings', twoPanelsSeparators)
44+
45+
async function remove (val: Association | Data<Association> | undefined): Promise<void> {
46+
if (isAssociation(val)) {
47+
showPopup(MessageBox, {
48+
label: view.string.DeleteObject,
49+
message: view.string.DeleteObjectConfirm,
50+
params: { count: 1 },
51+
dangerous: true,
52+
action: async () => {
53+
selected = undefined
54+
await client.remove(val)
55+
}
56+
})
57+
}
58+
}
3059
</script>
3160

3261
<div class="hulyComponent">
3362
<Header adaptive={'disabled'}>
3463
<Breadcrumb icon={settings.icon.Relations} label={core.string.Relations} size={'large'} isCurrent />
64+
65+
<svelte:fragment slot="actions">
66+
{#if isAssociation(selected)}
67+
<Button icon={IconDelete} label={view.string.Delete} kind={'dangerous'} on:click={() => remove(selected)} />
68+
{/if}
69+
</svelte:fragment>
3570
</Header>
3671

3772
<div class="hulyComponent-content__container columns">

Diff for: plugins/task-resources/src/components/TypesView.svelte

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414
-->
1515
<script lang="ts">
16-
import { Class, Doc, DocumentQuery, FindOptions, mergeQueries, Ref, Space, WithLookup } from '@hcengineering/core'
16+
import { Class, Doc, DocumentQuery, mergeQueries, Ref, Space, WithLookup } from '@hcengineering/core'
1717
import { IntlString } from '@hcengineering/platform'
1818
import { createQuery } from '@hcengineering/presentation'
1919
import { Project, ProjectType, ProjectTypeDescriptor } from '@hcengineering/task'
@@ -97,6 +97,7 @@
9797
bind:viewlet
9898
bind:preference
9999
bind:viewlets
100+
ignoreFragment
100101
viewletQuery={{
101102
attachTo: _class,
102103
variant: { $exists: false },

Diff for: plugins/view-resources/src/components/ViewletSelector.svelte

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
export let preference: ViewletPreference | undefined = undefined
1313
export let loading = true
1414
export let hidden = false
15+
export let ignoreFragment = false
1516
1617
const query = createQuery()
1718
@@ -29,11 +30,11 @@
2930
}
3031
)
3132
32-
let key = makeViewletKey()
33+
let key = makeViewletKey(undefined, ignoreFragment)
3334
3435
onDestroy(
3536
resolvedLocationStore.subscribe((loc) => {
36-
key = makeViewletKey(loc)
37+
key = makeViewletKey(loc, ignoreFragment)
3738
})
3839
)
3940

Diff for: plugins/view-resources/src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,11 @@ export function categorizeFields (
750750
return result
751751
}
752752

753-
export function makeViewletKey (loc?: Location): string {
753+
export function makeViewletKey (loc?: Location, ignoreFragment = false): string {
754754
loc = loc != null ? { path: loc.path, fragment: loc.fragment } : getCurrentResolvedLocation()
755755
loc.query = undefined
756756

757-
if (loc.fragment != null && loc.fragment !== '') {
757+
if (!ignoreFragment && loc.fragment != null && loc.fragment !== '') {
758758
const props = decodeURIComponent(loc.fragment).split('|')
759759
if (props.length >= 3) {
760760
const [panel, , _class] = props

Diff for: plugins/workbench-resources/src/components/SpaceHeader.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
{#if space}
9696
<Header hideActions={createItemDialog === undefined}>
9797
<svelte:fragment slot="beforeTitle">
98-
<ViewletSelector {viewletQuery} bind:viewlet bind:viewlets />
98+
<ViewletSelector {viewletQuery} ignoreFragment bind:viewlet bind:viewlets />
9999
<ViewletSettingButton bind:viewOptions bind:viewlet />
100100
</svelte:fragment>
101101

Diff for: plugins/workbench-resources/src/components/SpecialView.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
bind:viewlet
115115
bind:preference
116116
bind:viewlets
117+
ignoreFragment
117118
viewletQuery={{
118119
attachTo: _class,
119120
variant: { $exists: false },

Diff for: server/middleware/src/spaceSecurity.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import core, {
4242
WorkspaceEvent,
4343
clone,
4444
generateId,
45+
shouldShowArchived,
4546
systemAccountEmail,
4647
toFindResult,
4748
type SessionData
@@ -538,7 +539,7 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar
538539
const account = ctx.contextData.account
539540
const isSpace = this.context.hierarchy.isDerived(_class, core.class.Space)
540541
const field = this.getKey(domain)
541-
const showArchived: boolean = options?.showArchived ?? (query._id !== undefined && typeof query._id === 'string')
542+
const showArchived: boolean = shouldShowArchived(query, options)
542543

543544
let clientFilterSpaces: Set<Ref<Space>> | undefined
544545

Diff for: server/postgres/src/storage.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import core, {
4343
type Ref,
4444
type ReverseLookups,
4545
type SessionData,
46+
shouldShowArchived,
4647
type SortingQuery,
4748
type StorageIterator,
4849
toFindResult,
@@ -665,7 +666,7 @@ abstract class PostgresAdapterBase implements DbAdapter {
665666

666667
const select = `SELECT ${this.getProjection(vars, domain, options?.projection, joins, options?.associations)} FROM ${domain}`
667668

668-
const showArchived = options?.showArchived ?? (query._id !== undefined && typeof query._id === 'string')
669+
const showArchived = shouldShowArchived(query, options)
669670
const secJoin = this.addSecurity(vars, query, showArchived, domain, ctx.contextData)
670671
if (secJoin !== undefined) {
671672
sqlChunks.push(secJoin)
@@ -686,7 +687,7 @@ abstract class PostgresAdapterBase implements DbAdapter {
686687
let total = options?.total === true ? 0 : -1
687688
if (options?.total === true) {
688689
const pvars = new ValuesVariables()
689-
const showArchived = options?.showArchived ?? (query._id !== undefined && typeof query._id === 'string')
690+
const showArchived = shouldShowArchived(query, options)
690691
const secJoin = this.addSecurity(pvars, query, showArchived, domain, ctx.contextData)
691692
const totalChunks: string[] = []
692693
if (secJoin !== undefined) {

0 commit comments

Comments
 (0)