From ca8bc92cbb49b64b69526a857f6bf037622637bc Mon Sep 17 00:00:00 2001
From: Vyacheslav Tumanov <me@slavatumanov.me>
Date: Wed, 29 Nov 2023 21:43:39 +0500
Subject: [PATCH] UBER-1006: Support Ref for Vacancies (#4104)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
---
 models/recruit/src/index.ts                   |  4 ++
 models/recruit/src/plugin.ts                  |  3 +-
 .../src/components/SpaceSelect.svelte         | 15 +++---
 .../src/components/VacancyEditor.svelte       | 51 +++++++++++++++++++
 plugins/recruit-resources/src/index.ts        |  4 +-
 5 files changed, 69 insertions(+), 8 deletions(-)
 create mode 100644 plugins/recruit-resources/src/components/VacancyEditor.svelte

diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts
index e1715270cd..c9aa78a017 100644
--- a/models/recruit/src/index.ts
+++ b/models/recruit/src/index.ts
@@ -217,6 +217,10 @@ export function createModel (builder: Builder): void {
     fields: ['createdBy']
   })
 
+  builder.mixin(recruit.class.Vacancy, core.class.Class, view.mixin.AttributeEditor, {
+    inlineEditor: recruit.component.VacancyEditor
+  })
+
   builder.mixin(recruit.class.Applicant, core.class.Class, notification.mixin.ClassCollaborators, {
     fields: ['createdBy']
   })
diff --git a/models/recruit/src/plugin.ts b/models/recruit/src/plugin.ts
index 96f9f529ea..d36b77ea47 100644
--- a/models/recruit/src/plugin.ts
+++ b/models/recruit/src/plugin.ts
@@ -115,7 +115,8 @@ export default mergeIds(recruitId, recruit, {
     ApplicationMatchPresenter: '' as AnyComponent,
 
     MatchVacancy: '' as AnyComponent,
-    NotificationApplicantPresenter: '' as AnyComponent
+    NotificationApplicantPresenter: '' as AnyComponent,
+    VacancyEditor: '' as AnyComponent
   },
   template: {
     DefaultVacancy: '' as Ref<ProjectType>
diff --git a/packages/presentation/src/components/SpaceSelect.svelte b/packages/presentation/src/components/SpaceSelect.svelte
index 6493580bde..eee4b982f5 100644
--- a/packages/presentation/src/components/SpaceSelect.svelte
+++ b/packages/presentation/src/components/SpaceSelect.svelte
@@ -58,6 +58,7 @@
   export let componentProps: any | undefined = undefined
   export let autoSelect = true
   export let readonly = false
+  export let ignoreFill = false
   export let iconWithEmoji: AnySvelteComponent | Asset | ComponentType | undefined = view.ids.IconWithEmoji
   export let defaultIcon: AnySvelteComponent | Asset | ComponentType = IconFolder
   export let findDefaultSpace: (() => Promise<Space | undefined>) | undefined = undefined
@@ -131,12 +132,14 @@
     icon={selected?.icon === iconWithEmoji && iconWithEmoji ? IconWithEmoji : selected?.icon ?? defaultIcon}
     iconProps={selected?.icon === iconWithEmoji && iconWithEmoji
       ? { icon: selected?.color }
-      : {
-          fill:
-            selected?.color !== undefined
-              ? getPlatformColorDef(selected?.color, $themeStore.dark).icon
-              : getPlatformColorForTextDef(selected?.name ?? '', $themeStore.dark).icon
-        }}
+      : ignoreFill
+        ? undefined
+        : {
+            fill:
+              selected?.color !== undefined
+                ? getPlatformColorDef(selected?.color, $themeStore.dark).icon
+                : getPlatformColorForTextDef(selected?.name ?? '', $themeStore.dark).icon
+          }}
     {size}
     {kind}
     {justify}
diff --git a/plugins/recruit-resources/src/components/VacancyEditor.svelte b/plugins/recruit-resources/src/components/VacancyEditor.svelte
new file mode 100644
index 0000000000..9e6cf4ab09
--- /dev/null
+++ b/plugins/recruit-resources/src/components/VacancyEditor.svelte
@@ -0,0 +1,51 @@
+<!--
+// Copyright © 2023 Hardcore Engineering Inc.
+//
+// Licensed under the Eclipse Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License. You may
+// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//
+// See the License for the specific language governing permissions and
+// limitations under the License.
+-->
+<script lang="ts">
+  import { Ref, RefTo } from '@hcengineering/core'
+  import { IntlString } from '@hcengineering/platform'
+  import { ButtonKind, ButtonSize } from '@hcengineering/ui'
+  import recruit from '../plugin'
+  import { Vacancy } from '@hcengineering/recruit'
+  import { SpaceSelect } from '@hcengineering/presentation'
+
+  export let value: Ref<Vacancy> | undefined
+  export let label: IntlString = recruit.string.Vacancy
+  export let onChange: (value: any) => void
+  export let type: RefTo<Vacancy> | undefined
+  export let kind: ButtonKind = 'no-border'
+  export let size: ButtonSize = 'small'
+  export let justify: 'left' | 'center' = 'center'
+  export let width: string | undefined = undefined
+  $: _value = value != null ? value : undefined
+  $: _class = type?.to ?? recruit.class.Vacancy
+</script>
+
+<SpaceSelect
+  {_class}
+  {label}
+  bind:value={_value}
+  {kind}
+  {size}
+  {justify}
+  {width}
+  allowDeselect
+  autoSelect={false}
+  defaultIcon={recruit.icon.Vacancy}
+  iconWithEmoji={recruit.icon.Vacancy}
+  ignoreFill
+  on:change={(e) => {
+    onChange(e.detail)
+  }}
+/>
diff --git a/plugins/recruit-resources/src/index.ts b/plugins/recruit-resources/src/index.ts
index 9f1724d423..658c9367e4 100644
--- a/plugins/recruit-resources/src/index.ts
+++ b/plugins/recruit-resources/src/index.ts
@@ -55,6 +55,7 @@ import VacancyList from './components/VacancyList.svelte'
 import VacancyModifiedPresenter from './components/VacancyModifiedPresenter.svelte'
 import VacancyPresenter from './components/VacancyPresenter.svelte'
 import VacancyTemplateEditor from './components/VacancyTemplateEditor.svelte'
+import VacancyEditor from './components/VacancyEditor.svelte'
 import CreateOpinion from './components/review/CreateOpinion.svelte'
 import CreateReview from './components/review/CreateReview.svelte'
 import EditReview from './components/review/EditReview.svelte'
@@ -357,7 +358,8 @@ export default async (): Promise<Resources> => ({
     VacancyTemplateEditor,
 
     MatchVacancy,
-    NotificationApplicantPresenter
+    NotificationApplicantPresenter,
+    VacancyEditor
   },
   completion: {
     ApplicationQuery: async (